Skip to content

Commit 5170c66

Browse files
committed
Added user follow testing
1 parent 44071cb commit 5170c66

3 files changed

Lines changed: 25 additions & 6 deletions

File tree

app/models/user.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def unfollow! followee
7979
# this method returns true if we're following the given Hacker, and
8080
# false otherwise
8181
def following? hacker
82-
following.include? hacker
82+
following_ids.include? hacker.id
8383
end
8484

8585
# Everyone should have at least one follower. And steve would like to follow

spec/following_policy_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
require_relative '../app/models/following_policy'
22

33
describe FollowingPolicy do
4-
before(:each) do
4+
before(:each) do
55
@followee = double 'followee'
66
@follower = double 'follower'
77
end
8-
8+
99
it 'can follow another' do
1010
@follower.should_receive(:following?).with(@followee).and_return(false)
1111
policy = FollowingPolicy.new(@follower)
1212
policy.can_follow?(@followee).should be_true
1313
end
14-
14+
1515
it "cannot follow self" do
1616
policy = FollowingPolicy.new(@follower)
1717
policy.following_self?(@follower).should be_true
1818
policy.can_follow?(@follower).should be_false
1919
end
20-
20+
2121
it "cannot follow twice" do
2222
@follower.should_receive(:following?).twice.with(@followee).and_return(true)
2323
policy = FollowingPolicy.new(@follower)
2424
policy.already_following?(@followee).should be_true
2525
policy.can_follow?(@followee).should be_false
2626
end
27-
27+
2828
end

spec/models/user_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require 'spec_helper'
2+
3+
describe User do
4+
5+
let(:bob){Fabricate(:user)}
6+
let(:mozart){Fabricate(:user)}
7+
8+
it 'can be created validly' do
9+
bob.should be_valid
10+
mozart.should be_valid
11+
end
12+
13+
it 'Users can follow and unfollow' do
14+
bob.follow!(mozart)
15+
bob.following?(mozart).should be_true
16+
bob.unfollow!(mozart)
17+
bob.following?(mozart).should be_false
18+
end
19+
end

0 commit comments

Comments
 (0)