Skip to content

Commit

Permalink
Ran scaffold for shares.
Browse files Browse the repository at this point in the history
Ran
  'script/generate scaffold share link_id:integer recipient_id:integer
  viewed:boolean read:boolean'
oneforwonder committed Apr 4, 2010
1 parent 0e8f6ab commit 58a654b
Showing 14 changed files with 298 additions and 0 deletions.
85 changes: 85 additions & 0 deletions app/controllers/shares_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
class SharesController < ApplicationController
# GET /shares
# GET /shares.xml
def index
@shares = Share.all

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @shares }
end
end

# GET /shares/1
# GET /shares/1.xml
def show
@share = Share.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @share }
end
end

# GET /shares/new
# GET /shares/new.xml
def new
@share = Share.new

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @share }
end
end

# GET /shares/1/edit
def edit
@share = Share.find(params[:id])
end

# POST /shares
# POST /shares.xml
def create
@share = Share.new(params[:share])

respond_to do |format|
if @share.save
flash[:notice] = 'Share was successfully created.'
format.html { redirect_to(@share) }
format.xml { render :xml => @share, :status => :created, :location => @share }
else
format.html { render :action => "new" }
format.xml { render :xml => @share.errors, :status => :unprocessable_entity }
end
end
end

# PUT /shares/1
# PUT /shares/1.xml
def update
@share = Share.find(params[:id])

respond_to do |format|
if @share.update_attributes(params[:share])
flash[:notice] = 'Share was successfully updated.'
format.html { redirect_to(@share) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @share.errors, :status => :unprocessable_entity }
end
end
end

# DELETE /shares/1
# DELETE /shares/1.xml
def destroy
@share = Share.find(params[:id])
@share.destroy

respond_to do |format|
format.html { redirect_to(shares_url) }
format.xml { head :ok }
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/shares_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module SharesHelper
end
2 changes: 2 additions & 0 deletions app/models/share.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Share < ActiveRecord::Base
end
17 changes: 17 additions & 0 deletions app/views/layouts/shares.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>Shares: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
</head>
<body>

<p style="color: green"><%= flash[:notice] %></p>

<%= yield %>

</body>
</html>
28 changes: 28 additions & 0 deletions app/views/shares/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<h1>Editing share</h1>

<% form_for(@share) do |f| %>
<%= f.error_messages %>

<p>
<%= f.label :link_id %><br />
<%= f.text_field :link_id %>
</p>
<p>
<%= f.label :recipient_id %><br />
<%= f.text_field :recipient_id %>
</p>
<p>
<%= f.label :viewed %><br />
<%= f.check_box :viewed %>
</p>
<p>
<%= f.label :read %><br />
<%= f.check_box :read %>
</p>
<p>
<%= f.submit 'Update' %>
</p>
<% end %>

<%= link_to 'Show', @share %> |
<%= link_to 'Back', shares_path %>
26 changes: 26 additions & 0 deletions app/views/shares/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<h1>Listing shares</h1>

<table>
<tr>
<th>Link</th>
<th>Recipient</th>
<th>Viewed</th>
<th>Read</th>
</tr>

<% @shares.each do |share| %>
<tr>
<td><%=h share.link_id %></td>
<td><%=h share.recipient_id %></td>
<td><%=h share.viewed %></td>
<td><%=h share.read %></td>
<td><%= link_to 'Show', share %></td>
<td><%= link_to 'Edit', edit_share_path(share) %></td>
<td><%= link_to 'Destroy', share, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>

<br />

<%= link_to 'New share', new_share_path %>
27 changes: 27 additions & 0 deletions app/views/shares/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<h1>New share</h1>

<% form_for(@share) do |f| %>
<%= f.error_messages %>

<p>
<%= f.label :link_id %><br />
<%= f.text_field :link_id %>
</p>
<p>
<%= f.label :recipient_id %><br />
<%= f.text_field :recipient_id %>
</p>
<p>
<%= f.label :viewed %><br />
<%= f.check_box :viewed %>
</p>
<p>
<%= f.label :read %><br />
<%= f.check_box :read %>
</p>
<p>
<%= f.submit 'Create' %>
</p>
<% end %>

<%= link_to 'Back', shares_path %>
23 changes: 23 additions & 0 deletions app/views/shares/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<p>
<b>Link:</b>
<%=h @share.link_id %>
</p>

<p>
<b>Recipient:</b>
<%=h @share.recipient_id %>
</p>

<p>
<b>Viewed:</b>
<%=h @share.viewed %>
</p>

<p>
<b>Read:</b>
<%=h @share.read %>
</p>


<%= link_to 'Edit', edit_share_path(@share) %> |
<%= link_to 'Back', shares_path %>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
ActionController::Routing::Routes.draw do |map|
map.resources :shares

map.resources :links

map.log_in "log_in", :controller => "user_sessions", :action => "new"
16 changes: 16 additions & 0 deletions db/migrate/20100404051242_create_shares.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class CreateShares < ActiveRecord::Migration
def self.up
create_table :shares do |t|
t.integer :link_id
t.integer :recipient_id
t.boolean :viewed
t.boolean :read

t.timestamps
end
end

def self.down
drop_table :shares
end
end
13 changes: 13 additions & 0 deletions test/fixtures/shares.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

one:
link_id: 1
recipient_id: 1
viewed: false
read: false

two:
link_id: 1
recipient_id: 1
viewed: false
read: false
45 changes: 45 additions & 0 deletions test/functional/shares_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'test_helper'

class SharesControllerTest < ActionController::TestCase
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:shares)
end

test "should get new" do
get :new
assert_response :success
end

test "should create share" do
assert_difference('Share.count') do
post :create, :share => { }
end

assert_redirected_to share_path(assigns(:share))
end

test "should show share" do
get :show, :id => shares(:one).to_param
assert_response :success
end

test "should get edit" do
get :edit, :id => shares(:one).to_param
assert_response :success
end

test "should update share" do
put :update, :id => shares(:one).to_param, :share => { }
assert_redirected_to share_path(assigns(:share))
end

test "should destroy share" do
assert_difference('Share.count', -1) do
delete :destroy, :id => shares(:one).to_param
end

assert_redirected_to shares_path
end
end
4 changes: 4 additions & 0 deletions test/unit/helpers/shares_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'test_helper'

class SharesHelperTest < ActionView::TestCase
end
8 changes: 8 additions & 0 deletions test/unit/share_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'test_helper'

class ShareTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end

0 comments on commit 58a654b

Please sign in to comment.