From fc79d133642f32dc08d75171145e502d948c4d7c Mon Sep 17 00:00:00 2001 From: Carl Mercier Date: Wed, 11 Jul 2012 11:58:53 -0400 Subject: [PATCH] Automatically remove social relationships when an actor or victim is deleted --- lib/socialization/actors/follower.rb | 2 ++ lib/socialization/actors/liker.rb | 2 ++ lib/socialization/actors/mentioner.rb | 2 ++ lib/socialization/victims/followable.rb | 2 ++ lib/socialization/victims/likeable.rb | 2 ++ lib/socialization/victims/mentionable.rb | 2 ++ test/actors/follower_test.rb | 12 ++++++++++++ test/actors/liker_test.rb | 4 ++++ test/actors/mentioner_test.rb | 5 +++++ test/victims/followable_test.rb | 12 ++++++++++++ test/victims/likeable_test.rb | 13 +++++++++++++ test/victims/mentionable_test.rb | 13 +++++++++++++ 12 files changed, 71 insertions(+) diff --git a/lib/socialization/actors/follower.rb b/lib/socialization/actors/follower.rb index 45ccf00..765c813 100644 --- a/lib/socialization/actors/follower.rb +++ b/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] diff --git a/lib/socialization/actors/liker.rb b/lib/socialization/actors/liker.rb index 15e453a..e202b49 100644 --- a/lib/socialization/actors/liker.rb +++ b/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] diff --git a/lib/socialization/actors/mentioner.rb b/lib/socialization/actors/mentioner.rb index 4a2c0af..9d9c212 100644 --- a/lib/socialization/actors/mentioner.rb +++ b/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] diff --git a/lib/socialization/victims/followable.rb b/lib/socialization/victims/followable.rb index a202575..f3f364c 100644 --- a/lib/socialization/victims/followable.rb +++ b/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] diff --git a/lib/socialization/victims/likeable.rb b/lib/socialization/victims/likeable.rb index ea83c06..718c655 100644 --- a/lib/socialization/victims/likeable.rb +++ b/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] diff --git a/lib/socialization/victims/mentionable.rb b/lib/socialization/victims/mentionable.rb index acb7123..1b22d45 100644 --- a/lib/socialization/victims/mentionable.rb +++ b/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] diff --git a/test/actors/follower_test.rb b/test/actors/follower_test.rb index ad44ffd..60859cf 100644 --- a/test/actors/follower_test.rb +++ b/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 diff --git a/test/actors/liker_test.rb b/test/actors/liker_test.rb index b3f6e3f..dce43f9 100644 --- a/test/actors/liker_test.rb +++ b/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 diff --git a/test/actors/mentioner_test.rb b/test/actors/mentioner_test.rb index 10b2841..6aa90c5 100644 --- a/test/actors/mentioner_test.rb +++ b/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 diff --git a/test/victims/followable_test.rb b/test/victims/followable_test.rb index 2701458..6935c17 100644 --- a/test/victims/followable_test.rb +++ b/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 \ No newline at end of file diff --git a/test/victims/likeable_test.rb b/test/victims/likeable_test.rb index 6723c94..e5bae5e 100644 --- a/test/victims/likeable_test.rb +++ b/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 \ No newline at end of file diff --git a/test/victims/mentionable_test.rb b/test/victims/mentionable_test.rb index 93968e7..c93a619 100644 --- a/test/victims/mentionable_test.rb +++ b/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 \ No newline at end of file