Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Automatically remove social relationships when an actor or victim is …

…deleted
  • Loading branch information...
commit fc79d133642f32dc08d75171145e502d948c4d7c 1 parent f4171ad
@cmer authored
View
2  lib/socialization/actors/follower.rb
@@ -12,6 +12,8 @@ module Follower
extend ActiveSupport::Concern
included do
+ after_destroy { Socialization.follow_model.remove_followables(self) }
+
# Specifies if self can follow {Followable} objects.
#
# @return [Boolean]
View
2  lib/socialization/actors/liker.rb
@@ -12,6 +12,8 @@ module Liker
extend ActiveSupport::Concern
included do
+ after_destroy { Socialization.like_model.remove_likeables(self) }
+
# Specifies if self can like {Likeable} objects.
#
# @return [Boolean]
View
2  lib/socialization/actors/mentioner.rb
@@ -12,6 +12,8 @@ module Mentioner
extend ActiveSupport::Concern
included do
+ after_destroy { Socialization.mention_model.remove_mentionables(self) }
+
# Specifies if self can mention {Mentionable} objects.
#
# @return [Boolean]
View
2  lib/socialization/victims/followable.rb
@@ -12,6 +12,8 @@ module Followable
extend ActiveSupport::Concern
included do
+ after_destroy { Socialization.follow_model.remove_followers(self) }
+
# Specifies if self can be followed.
#
# @return [Boolean]
View
2  lib/socialization/victims/likeable.rb
@@ -12,6 +12,8 @@ module Likeable
extend ActiveSupport::Concern
included do
+ after_destroy { Socialization.like_model.remove_likers(self) }
+
# Specifies if self can be liked.
#
# @return [Boolean]
View
2  lib/socialization/victims/mentionable.rb
@@ -12,6 +12,8 @@ module Mentionable
extend ActiveSupport::Concern
included do
+ after_destroy { Socialization.mention_model.remove_mentioners(self) }
+
# Specifies if self can be mentioned.
#
# @return [Boolean]
View
12 test/actors/follower_test.rb
@@ -98,5 +98,17 @@ class FollowerTest < Test::Unit::TestCase
end
end
+ context "deleting a follower" do
+ setup do
+ @follower = ImAFollower.create
+ @follower.follow!(@followable)
+ end
+
+ should "remove follow relationships" do
+ Socialization.follow_model.expects(:remove_followables).with(@follower)
+ @follower.destroy
+ end
+ end
+
end
end
View
4 test/actors/liker_test.rb
@@ -98,5 +98,9 @@ class LikerTest < Test::Unit::TestCase
end
end
+ should "remove like relationships" do
+ Socialization.like_model.expects(:remove_likeables).with(@liker)
+ @liker.destroy
+ end
end
end
View
5 test/actors/mentioner_test.rb
@@ -97,5 +97,10 @@ class MentionerTest < Test::Unit::TestCase
@mentioner.mentionees_relation(@mentionable.class, { :foo => :bar })
end
end
+
+ should "remove mention relationships" do
+ Socialization.mention_model.expects(:remove_mentionables).with(@mentioner)
+ @mentioner.destroy
+ end
end
end
View
12 test/victims/followable_test.rb
@@ -44,5 +44,17 @@ class FollowableTest < Test::Unit::TestCase
end
end
+ context "deleting a followable" do
+ setup do
+ @follower = ImAFollower.create
+ @follower.follow!(@followable)
+ end
+
+ should "remove follow relationships" do
+ Socialization.follow_model.expects(:remove_followers).with(@followable)
+ @followable.destroy
+ end
+ end
+
end
end
View
13 test/victims/likeable_test.rb
@@ -43,5 +43,18 @@ class LikeableTest < Test::Unit::TestCase
@likeable.likers_relation(@liker.class, { :foo => :bar })
end
end
+
+ context "deleting a likeable" do
+ setup do
+ @liker = ImALiker.create
+ @liker.like!(@likeable)
+ end
+
+ should "remove like relationships" do
+ Socialization.like_model.expects(:remove_likers).with(@likeable)
+ @likeable.destroy
+ end
+ end
+
end
end
View
13 test/victims/mentionable_test.rb
@@ -43,5 +43,18 @@ class MentionableTest < Test::Unit::TestCase
@mentionable.mentioners_relation(@mentioner.class, { :foo => :bar })
end
end
+
+ context "deleting a mentionable" do
+ setup do
+ @mentioner = ImAMentioner.create
+ @mentioner.mention!(@mentionable)
+ end
+
+ should "remove mention relationships" do
+ Socialization.mention_model.expects(:remove_mentioners).with(@mentionable)
+ @mentionable.destroy
+ end
+ end
+
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.