File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ class FollowingPolicy
2+ def initialize ( follower , target )
3+ @follower = follower
4+ @target = target
5+ end
6+
7+ def can_follow?
8+ !following_self? && !already_following?
9+ end
10+
11+ def already_following?
12+ @follower . following? ( @target )
13+ end
14+
15+ def following_self?
16+ @follower == @target
17+ end
18+ end
Original file line number Diff line number Diff line change 1+ require_relative '../app/models/following_policy'
2+
3+ describe FollowingPolicy do
4+ before ( :each ) do
5+ @followed = stub ( )
6+ @follower = stub ( )
7+ end
8+
9+ it 'can follow another' do
10+ @follower . should_receive ( :following? ) . with ( @followed ) . and_return ( false )
11+ policy = FollowingPolicy . new ( @follower , @followed )
12+ policy . can_follow? . should be_true
13+ end
14+
15+ it "cannot follow self" do
16+ policy = FollowingPolicy . new ( @follower , @follower )
17+ policy . can_follow? . should be_false
18+ end
19+
20+ it "cannot follow twice" do
21+ @follower . should_receive ( :following? ) . with ( @followed ) . and_return ( true )
22+ policy = FollowingPolicy . new ( @follower , @followed )
23+ policy . can_follow? . should be_false
24+ end
25+
26+ end
You can’t perform that action at this time.
0 commit comments