Commit 96313d04a4c9211646bc23bc7f226b98b5198a4d
1 parent
e18d8a48
Exists in
master
and in
3 other branches
Should not be able to follow yourself (cherry picking from commit 861d276f034f02…
…7420c8f698a0fba0a7417e2dd3)
Showing
2 changed files
with
21 additions
and
2 deletions
Show diff stats
lib/acts_as_follower.rb
... | ... | @@ -38,7 +38,9 @@ module ActiveRecord #:nodoc: |
38 | 38 | def follow(followable) |
39 | 39 | follow = get_follow(followable) |
40 | 40 | unless follow |
41 | - Follow.create(:followable => followable, :follower => self) | |
41 | + if self != followable | |
42 | + Follow.create(:followable => followable, :follower => self) | |
43 | + end | |
42 | 44 | end |
43 | 45 | end |
44 | 46 | ... | ... |
test/acts_as_follower_test.rb
... | ... | @@ -38,7 +38,7 @@ class ActsAsFollowerTest < Test::Unit::TestCase |
38 | 38 | end |
39 | 39 | end |
40 | 40 | |
41 | - context "follow" do | |
41 | + context "follow a friend" do | |
42 | 42 | setup do |
43 | 43 | @jon.follow(@sam) |
44 | 44 | end |
... | ... | @@ -55,6 +55,23 @@ class ActsAsFollowerTest < Test::Unit::TestCase |
55 | 55 | end |
56 | 56 | end |
57 | 57 | |
58 | + context "follow yourself" do | |
59 | + setup do | |
60 | + @jon.follow(@jon) | |
61 | + end | |
62 | + | |
63 | + should_not_change("Follow count") { Follow.count } | |
64 | + should_not_change("@jon.follow_count") { @jon.follow_count } | |
65 | + | |
66 | + should "not set the follower" do | |
67 | + assert_not_equal @jon, Follow.last.follower | |
68 | + end | |
69 | + | |
70 | + should "not set the followable" do | |
71 | + assert_not_equal @jon, Follow.last.followable | |
72 | + end | |
73 | + end | |
74 | + | |
58 | 75 | context "stop_following" do |
59 | 76 | setup do |
60 | 77 | @sam.stop_following(@jon) | ... | ... |