Skip to content

Commit

Permalink
add ability to view all friends
Browse files Browse the repository at this point in the history
  • Loading branch information
drapergeek committed May 19, 2012
1 parent f27df63 commit a930378
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/controllers/friends_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class FriendsController < ApplicationController
def index
@friends = current_user.friends
end
end
8 changes: 8 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@ class User < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation, :remember_me
has_many :for_me, foreign_key: :recommendee_id, class_name: "MovieRecommendation"
has_many :from_me, foreign_key: :recommender_id, class_name: "MovieRecommendation"

def friends
User.where("id != ?", id)
end

def to_s
email
end
end
3 changes: 3 additions & 0 deletions app/views/friends/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%ul.friends
- @friends.each do |user|
= link_to user, friend_path(user)
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
devise_for :users
resources :movie_recommendations, only: [:index, :show]
resources :my_recommendations, only: [:index]
resources :friends, only: [:index, :show]
root to: "movie_recommendations#index"
end
9 changes: 9 additions & 0 deletions features/friends.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Feature: Interact with other users

Scenario: View all users
Given 5 users exist
And I am signed in as "person@example.com"
When I visit my friends page
Then I should see links to 5 users

Scenario: View an individual user
9 changes: 9 additions & 0 deletions features/step_definitions/friend_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
When /^I visit my friends page$/ do
visit friends_path
end

Then /^I should see links to (\d+) users$/ do |count|
within ".friends" do
page.should have_css("a", count: count)
end
end
11 changes: 11 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,15 @@
from_user.from_me.should == [recommendation]
to_user.for_me.should == [recommendation]
end

it "#friends returns all other users" do
other_users = create_list(:user, 5)
user = create(:user)
user.friends.should == other_users
end

it "shows the email for to_s" do
user = build_stubbed(:user)
user.to_s.should == user.email
end
end

0 comments on commit a930378

Please sign in to comment.