Skip to content

Commit

Permalink
Automatically remove social relationships when an actor or victim is …
Browse files Browse the repository at this point in the history
…deleted
  • Loading branch information
cmer committed Jul 11, 2012
1 parent f4171ad commit fc79d13
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/socialization/actors/follower.rb
Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions lib/socialization/actors/liker.rb
Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions lib/socialization/actors/mentioner.rb
Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions lib/socialization/victims/followable.rb
Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions lib/socialization/victims/likeable.rb
Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions lib/socialization/victims/mentionable.rb
Expand Up @@ -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]
Expand Down
12 changes: 12 additions & 0 deletions test/actors/follower_test.rb
Expand Up @@ -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
4 changes: 4 additions & 0 deletions test/actors/liker_test.rb
Expand Up @@ -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
5 changes: 5 additions & 0 deletions test/actors/mentioner_test.rb
Expand Up @@ -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
12 changes: 12 additions & 0 deletions test/victims/followable_test.rb
Expand Up @@ -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
13 changes: 13 additions & 0 deletions test/victims/likeable_test.rb
Expand Up @@ -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
13 changes: 13 additions & 0 deletions test/victims/mentionable_test.rb
Expand Up @@ -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

0 comments on commit fc79d13

Please sign in to comment.