Permalink
Browse files

Expose the *_relation methods on actors and victims

  • Loading branch information...
1 parent 8403800 commit 4bc59a2b905a8dfe2772982ad6d7f5c83c47f422 @cmer committed Jun 6, 2012
@@ -69,6 +69,14 @@ def followables(klass, opts = {})
Socialization.follow_model.followables(self, klass, opts)
end
+ # Returns a relation for all the followables of a certain type that are followed by self
+ #
+ # @params [Followable] klass the type of {Followable} you want
+ # @params [Hash] opts a hash of options
+ # @return ActiveRecord::Relation
+ def followables_relation(klass, opts = {})
+ Socialization.follow_model.followables_relation(self, klass, opts)
+ end
end
end
end
@@ -69,6 +69,14 @@ def likeables(klass, opts = {})
Socialization.like_model.likeables(self, klass, opts)
end
+ # Returns a relation for all the likeables of a certain type that are liked by self
+ #
+ # @params [Likeable] klass the type of {Likeable} you want
+ # @params [Hash] opts a hash of options
+ # @return ActiveRecord::Relation
+ def likeables_relation(klass, opts = {})
+ Socialization.like_model.likeables_relation(self, klass, opts)
+ end
end
end
end
@@ -69,6 +69,14 @@ def mentionables(klass, opts = {})
Socialization.mention_model.mentionables(self, klass, opts)
end
+ # Returns a relation for all the mentionables of a certain type that are mentioned by self
+ #
+ # @params [Mentionable] klass the type of {Mentionable} you want
+ # @params [Hash] opts a hash of options
+ # @return ActiveRecord::Relation
+ def mentionables_relation(klass, opts = {})
+ Socialization.mention_model.mentionables_relation(self, klass, opts)
+ end
end
end
end
@@ -26,13 +26,21 @@ def followed_by?(follower)
Socialization.follow_model.follows?(follower, self)
end
- # Returns a scope of the {Follower}s following self.
+ # Returns an array of {Follower}s following self.
#
- # @param [Class] klass the {Follower} class to be included in the scope. e.g. `User`
+ # @param [Class] klass the {Follower} class to be included. e.g. `User`
# @return [Array<Follower, Numeric>] An array of Follower objects or IDs
def followers(klass, opts = {})
Socialization.follow_model.followers(self, klass, opts)
end
+
+ # Returns a scope of the {Follower}s following self.
+ #
+ # @param [Class] klass the {Follower} class to be included in the scope. e.g. `User`
+ # @return ActiveRecord::Relation
+ def followers_relation(klass, opts = {})
+ Socialization.follow_model.followers_relation(self, klass, opts)
+ end
end
end
end
@@ -26,13 +26,22 @@ def liked_by?(liker)
Socialization.like_model.likes?(liker, self)
end
- # Returns a scope of the {Liker}s likeing self.
+ # Returns an array of {Liker}s liking self.
#
- # @param [Class] klass the {Liker} class to be included in the scope. e.g. `User`.
+ # @param [Class] klass the {Liker} class to be included. e.g. `User`
# @return [Array<Liker, Numeric>] An array of Liker objects or IDs
def likers(klass, opts = {})
Socialization.like_model.likers(self, klass, opts)
end
+
+ # Returns a scope of the {Liker}s liking self.
+ #
+ # @param [Class] klass the {Liker} class to be included in the scope. e.g. `User`
+ # @return ActiveRecord::Relation
+ def likers_relation(klass, opts = {})
+ Socialization.like_model.likers_relation(self, klass, opts)
+ end
+
end
end
end
@@ -26,13 +26,22 @@ def mentioned_by?(mentioner)
Socialization.mention_model.mentions?(mentioner, self)
end
- # Returns a scope of the {Mentioner}s mentioning self.
+ # Returns an array of {Mentioner}s mentioning self.
#
- # @param [Class] klass the {Mentioner} class to be included in the scope. e.g. `User`.
+ # @param [Class] klass the {Mentioner} class to be included. e.g. `User`
# @return [Array<Mentioner, Numeric>] An array of Mentioner objects or IDs
def mentioners(klass, opts = {})
Socialization.mention_model.mentioners(self, klass, opts)
end
+
+ # Returns a scope of the {Mentioner}s mentioning self.
+ #
+ # @param [Class] klass the {Mentioner} class to be included in the scope. e.g. `User`
+ # @return ActiveRecord::Relation
+ def mentioners_relation(klass, opts = {})
+ Socialization.mention_model.mentioners_relation(self, klass, opts)
+ end
+
end
end
end
@@ -70,5 +70,12 @@ class FollowerTest < Test::Unit::TestCase
@follower.followables(@followable.class, { :foo => :bar })
end
end
+
+ context "#followables_relation" do
+ should "call $Follow.followables_relation" do
+ $Follow.expects(:followables_relation).with(@follower, @followable.class, { :foo => :bar })
+ @follower.followables_relation(@followable.class, { :foo => :bar })
+ end
+ end
end
end
@@ -70,5 +70,12 @@ class LikerTest < Test::Unit::TestCase
@liker.likeables(@likeable.class, { :foo => :bar })
end
end
+
+ context "#likeables_relation" do
+ should "call $Follow.likeables_relation" do
+ $Like.expects(:likeables_relation).with(@liker, @likeable.class, { :foo => :bar })
+ @liker.likeables_relation(@likeable.class, { :foo => :bar })
+ end
+ end
end
end
@@ -70,5 +70,12 @@ class MentionerTest < Test::Unit::TestCase
@mentioner.mentionables(@mentionable.class, { :foo => :bar })
end
end
+
+ context "#mentionables_relation" do
+ should "call $Mention.mentionables_relation" do
+ $Mention.expects(:mentionables_relation).with(@mentioner, @mentionable.class, { :foo => :bar })
+ @mentioner.mentionables_relation(@mentionable.class, { :foo => :bar })
+ end
+ end
end
end
@@ -30,5 +30,13 @@ class FollowableTest < Test::Unit::TestCase
@followable.followers(@follower.class, { :foo => :bar })
end
end
+
+ context "#followers_relation" do
+ should "call $Follow.followers_relation" do
+ $Follow.expects(:followers_relation).with(@followable, @follower.class, { :foo => :bar })
+ @followable.followers_relation(@follower.class, { :foo => :bar })
+ end
+ end
+
end
end
@@ -30,5 +30,12 @@ class LikeableTest < Test::Unit::TestCase
@likeable.likers(@liker.class, { :foo => :bar })
end
end
+
+ context "#likers_relation" do
+ should "call $Like.likers_relation" do
+ $Like.expects(:likers_relation).with(@likeable, @liker.class, { :foo => :bar })
+ @likeable.likers_relation(@liker.class, { :foo => :bar })
+ end
+ end
end
end
@@ -25,10 +25,17 @@ class MentionableTest < Test::Unit::TestCase
end
context "#mentioners" do
- should "call $Mentionmentioners" do
+ should "call $Mention.mentioners" do
$Mention.expects(:mentioners).with(@mentionable, @mentioner.class, { :foo => :bar })
@mentionable.mentioners(@mentioner.class, { :foo => :bar })
end
end
+
+ context "#mentioners_relation" do
+ should "call $Mention.mentioners" do
+ $Mention.expects(:mentioners_relation).with(@mentionable, @mentioner.class, { :foo => :bar })
+ @mentionable.mentioners_relation(@mentioner.class, { :foo => :bar })
+ end
+ end
end
end

0 comments on commit 4bc59a2

Please sign in to comment.