Skip to content

Commit e7630a1

Browse files
committed
Unfollowing now works.
You can unfollow people. Sweet.
1 parent a3cc9be commit e7630a1

4 files changed

Lines changed: 37 additions & 0 deletions

File tree

controllers/hacker.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,25 @@
2929

3030
end
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
3352
get '/hackers/:name/followers' do
3453
#find the hacker with the given name

features/hacker.feature

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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"

models/hacker.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff 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

views/hackers/show.haml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
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}

0 commit comments

Comments
 (0)