Skip to content

Commit

Permalink
Ran scaffold for friendships.
Browse files Browse the repository at this point in the history
  • Loading branch information
oneforwonder committed Apr 4, 2010
1 parent cf20a96 commit a989ca0
Show file tree
Hide file tree
Showing 14 changed files with 262 additions and 0 deletions.
85 changes: 85 additions & 0 deletions app/controllers/friendships_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
class FriendshipsController < ApplicationController
# GET /friendships
# GET /friendships.xml
def index
@friendships = Friendship.all

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

# GET /friendships/1
# GET /friendships/1.xml
def show
@friendship = Friendship.find(params[:id])

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

# GET /friendships/new
# GET /friendships/new.xml
def new
@friendship = Friendship.new

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

# GET /friendships/1/edit
def edit
@friendship = Friendship.find(params[:id])
end

# POST /friendships
# POST /friendships.xml
def create
@friendship = Friendship.new(params[:friendship])

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

# PUT /friendships/1
# PUT /friendships/1.xml
def update
@friendship = Friendship.find(params[:id])

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

# DELETE /friendships/1
# DELETE /friendships/1.xml
def destroy
@friendship = Friendship.find(params[:id])
@friendship.destroy

respond_to do |format|
format.html { redirect_to(friendships_url) }
format.xml { head :ok }
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/friendships_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module FriendshipsHelper
end
2 changes: 2 additions & 0 deletions app/models/friendship.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Friendship < ActiveRecord::Base
end
20 changes: 20 additions & 0 deletions app/views/friendships/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<h1>Editing friendship</h1>

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

<p>
<%= f.label :user_id %><br />
<%= f.text_field :user_id %>
</p>
<p>
<%= f.label :friend_id %><br />
<%= f.text_field :friend_id %>
</p>
<p>
<%= f.submit 'Update' %>
</p>
<% end %>

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

<table>
<tr>
<th>User</th>
<th>Friend</th>
</tr>

<% @friendships.each do |friendship| %>
<tr>
<td><%=h friendship.user_id %></td>
<td><%=h friendship.friend_id %></td>
<td><%= link_to 'Show', friendship %></td>
<td><%= link_to 'Edit', edit_friendship_path(friendship) %></td>
<td><%= link_to 'Destroy', friendship, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>

<br />

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

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

<p>
<%= f.label :user_id %><br />
<%= f.text_field :user_id %>
</p>
<p>
<%= f.label :friend_id %><br />
<%= f.text_field :friend_id %>
</p>
<p>
<%= f.submit 'Create' %>
</p>
<% end %>

<%= link_to 'Back', friendships_path %>
13 changes: 13 additions & 0 deletions app/views/friendships/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<p>
<b>User:</b>
<%=h @friendship.user_id %>
</p>

<p>
<b>Friend:</b>
<%=h @friendship.friend_id %>
</p>


<%= link_to 'Edit', edit_friendship_path(@friendship) %> |
<%= link_to 'Back', friendships_path %>
17 changes: 17 additions & 0 deletions app/views/layouts/friendships.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>Friendships: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
</head>
<body>

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

<%= yield %>

</body>
</html>
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 :friendships

map.resources :comments

map.resources :shares
Expand Down
14 changes: 14 additions & 0 deletions db/migrate/20100404051723_create_friendships.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateFriendships < ActiveRecord::Migration
def self.up
create_table :friendships do |t|
t.integer :user_id
t.integer :friend_id

t.timestamps
end
end

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

one:
user_id: 1
friend_id: 1

two:
user_id: 1
friend_id: 1
45 changes: 45 additions & 0 deletions test/functional/friendships_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'test_helper'

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

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

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

assert_redirected_to friendship_path(assigns(:friendship))
end

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

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

test "should update friendship" do
put :update, :id => friendships(:one).to_param, :friendship => { }
assert_redirected_to friendship_path(assigns(:friendship))
end

test "should destroy friendship" do
assert_difference('Friendship.count', -1) do
delete :destroy, :id => friendships(:one).to_param
end

assert_redirected_to friendships_path
end
end
8 changes: 8 additions & 0 deletions test/unit/friendship_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'test_helper'

class FriendshipTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end
4 changes: 4 additions & 0 deletions test/unit/helpers/friendships_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'test_helper'

class FriendshipsHelperTest < ActionView::TestCase
end

0 comments on commit a989ca0

Please sign in to comment.