Commit 2485fa6003ad40b6f5177df01e9f3affd839e15b

Authored by Douglas F Shearer
Committed by Tom Cocca
1 parent 0ec6f7af

Fixed :dependent => :nullify does not play nice with polymorphic relationships bug.

Added tests for above.
Props to m3talsmith for the bug deploy.

Signed-off-by: Tom Cocca <tom.cocca@gmail.com>
lib/acts_as_followable.rb
... ... @@ -8,7 +8,7 @@ module ActiveRecord #:nodoc:
8 8  
9 9 module ClassMethods
10 10 def acts_as_followable
11   - has_many :follows, :as => :followable, :dependent => :nullify
  11 + has_many :follows, :as => :followable, :dependent => :destroy
12 12 include ActiveRecord::Acts::Followable::InstanceMethods
13 13 end
14 14 end
... ...
test/acts_as_followable_test.rb
... ... @@ -24,4 +24,10 @@ class ActsAsFollowableTest &lt; Test::Unit::TestCase
24 24 assert_equal false, users(:sam).followed_by?(users(:jon))
25 25 end
26 26  
  27 + def test_destroyed_followable_should_destroy_related_follows_records
  28 + assert_difference "Follow.count && users(:sam).all_following.size", -1 do
  29 + users(:jon).destroy
  30 + end
  31 + end
  32 +
27 33 end
... ...
test/acts_as_follower_test.rb
... ... @@ -75,4 +75,10 @@ class ActsAsFollowerTest &lt; Test::Unit::TestCase
75 75 assert_raises (NoMethodError){ users(:sam).foobar }
76 76 end
77 77  
  78 + def test_destroyed_follower_should_nullifys_related_follows_records
  79 + assert_difference "Follow.count && users(:sam).following_users.size", -1 do
  80 + users(:jon).destroy
  81 + end
  82 + end
  83 +
78 84 end
... ...