-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf20a96
commit a989ca0
Showing
14 changed files
with
262 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module FriendshipsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Friendship < ActiveRecord::Base | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require 'test_helper' | ||
|
||
class FriendshipsHelperTest < ActionView::TestCase | ||
end |