File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2929
3030end
3131
32+ #this lets you unfollow a Hacker
33+ get '/hackers/:name/unfollow' do
34+ #we have to be logged in to unfollow someone
35+ require_login! :return => "/hackers/#{ params [ :name ] } /unfollow"
36+
37+ #find the hacker with the given name
38+ @hacker = Hacker . first ( :username => params [ :name ] )
39+
40+ #follow them!
41+ current_user . unfollow! @hacker
42+
43+ #set a message
44+ flash [ :notice ] = "No longer following #{ params [ :name ] } ."
45+
46+ #redirect back to your page!
47+ redirect "/hackers/#{ current_user . username } "
48+
49+ end
50+
3251#this lets us see followers
3352get '/hackers/:name/followers' do
3453 #find the hacker with the given name
Original file line number Diff line number Diff line change @@ -54,3 +54,12 @@ Feature: Hacker management
5454 When I go to the hacker page for "steve"
5555 And I follow "1"
5656 Then I should see "fela"
57+ Scenario : Unfollowing a Hacker
58+ Given I'm logged in as "steve"
59+ And there's a hacker with the username "fela"
60+ And the hacker "steve" is following the hacker "fela"
61+ When I go to the hacker page for "fela"
62+ And I follow "Unfollow fela"
63+ Then I should be on the hacker page for "steve"
64+ And I should see "No longer following fela."
65+ And I should see "Following: 0"
Original file line number Diff line number Diff line change @@ -82,6 +82,14 @@ def follow! followee
8282 followee . followers << self
8383 followee . save
8484 end
85+
86+ #this function makes the hacker unfollow the followee
87+ def unfollow! followee
88+ following_ids . delete ( followee . id )
89+ save
90+ followee . followers_ids . delete ( id )
91+ followee . save
92+ end
8593
8694 private
8795
Original file line number Diff line number Diff line change 77- if logged_in? && @hacker.username != current_user.username
88 %a{:href => " /messages/new/to/#{ @hacker .username} " }= " Send #{ @hacker .username} a message"
99 %a{:href => " /hackers/#{ @hacker .username} /follow" } Follow #{@hacker.username}
10+ %a{:href => " /hackers/#{ @hacker .username} /unfollow" } Unfollow #{@hacker.username}
You can’t perform that action at this time.
0 commit comments