Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge commit '0f6fcfdf6c612fb7b5b7dd93d7a391f4d67fb06f' into sti

  • Loading branch information...
commit ffff2849add79e251092a05c6e7c3c5bff3a9fd7 2 parents be75e17 + 0f6fcfd
@cmer authored
View
2  lib/socialization/follower.rb
@@ -65,7 +65,7 @@ def toggle_follow!(followable)
# @return [Boolean]
def follows?(followable)
raise ArgumentError, "#{followable} is not followable!" unless followable.is_followable?
- !self.follows.where(:followable_type => followable.class.to_s, :followable_id => followable.id).empty?
+ !self.follows.where(:followable_type => followable.class.table_name.classify, :followable_id => followable.id).empty?
end
# Returns a scope of the {Followable}s followed by self.
View
2  lib/socialization/liker.rb
@@ -64,7 +64,7 @@ def toggle_like!(likeable)
# @return [Boolean]
def likes?(likeable)
ensure_likeable!(likeable)
- !self.likes.where(:likeable_type => likeable.class.to_s, :likeable_id => likeable.id).empty?
+ !self.likes.where(:likeable_type => likeable.class.table_name.classify, :likeable_id => likeable.id).empty?
end
# Returns a scope of the {Likeable}s followed by self.
View
2  lib/socialization/mentioner.rb
@@ -63,7 +63,7 @@ def toggle_mention!(mentionable)
# @return [Boolean]
def mentions?(mentionable)
ensure_mentionable!(mentionable)
- !self.mentions.where(:mentionable_type => mentionable.class.to_s, :mentionable_id => mentionable.id).empty?
+ !self.mentions.where(:mentionable_type => mentionable.class.table_name.classify, :mentionable_id => mentionable.id).empty?
end
# Returns a scope of the {Mentionable}s mentioned by self.
View
12 test/follow_test.rb
@@ -126,6 +126,18 @@ class FollowTest < Test::Unit::TestCase
end
end
+ context "Single Table Inheritance" do
+ setup do
+ @follower = ImAFollower.create
+ @followable_child = ImAFollowableChild.create
+ end
+
+ should "be able to follow a model inheriting from Followable" do
+ assert @follower.follow!(@followable_child)
+ assert_equal true, @follower.follows?(@followable_child)
+ end
+ end
+
def seed
@follower1 = ImAFollower.create
@follower2 = ImAFollower.create
View
12 test/like_test.rb
@@ -126,6 +126,18 @@ class LikeTest < Test::Unit::TestCase
end
end
+ context "Single Table Inheritance" do
+ setup do
+ @liker = ImALiker.create
+ @likeable_child = ImALikeableChild.create
+ end
+
+ should "be able to like a model inheriting from a Likeable" do
+ assert @liker.like!(@likeable_child)
+ assert_equal true, @liker.likes?(@likeable_child)
+ end
+ end
+
def seed
@liker1 = ImALiker.create
@liker2 = ImALiker.create
View
12 test/mention_test.rb
@@ -116,6 +116,18 @@ class MentionTest < Test::Unit::TestCase
end
end
+ context "Single Table Inheritance" do
+ setup do
+ @mentioner = ImAMentioner.create
+ @mentionable_child = ImAMentionableChild.create
+ end
+
+ should "be able to mention a model inheriting from mentionable" do
+ assert @mentioner.mention!(@mentionable_child)
+ assert_equal true, @mentioner.mentions?(@mentionable_child)
+ end
+ end
+
def seed
@mentioner1 = ImAMentioner.create
@mentioner2 = ImAMentioner.create
View
12 test/test_helper.rb
@@ -72,6 +72,7 @@ def assert_false(object, message="")
end
create_table :im_a_followables do |t|
+ t.string :type
t.timestamps
end
@@ -80,6 +81,7 @@ def assert_false(object, message="")
end
create_table :im_a_likeables do |t|
+ t.string :type
t.timestamps
end
@@ -88,6 +90,7 @@ def assert_false(object, message="")
end
create_table :im_a_mentionables do |t|
+ t.string :type
t.timestamps
end
@@ -146,6 +149,9 @@ class ImAFollowable < ActiveRecord::Base
acts_as_followable
end
+class ImAFollowableChild < ImAFollowable
+end
+
class ImALiker < ActiveRecord::Base
acts_as_liker
end
@@ -154,6 +160,9 @@ class ImALikeable < ActiveRecord::Base
acts_as_likeable
end
+class ImALikeableChild < ImALikeable
+end
+
class ImAMentioner < ActiveRecord::Base
acts_as_mentioner
end
@@ -162,6 +171,9 @@ class ImAMentionable < ActiveRecord::Base
acts_as_mentionable
end
+class ImAMentionableChild < ImAMentionable
+end
+
class ImAMentionerAndMentionable < ActiveRecord::Base
acts_as_mentioner
acts_as_mentionable
Please sign in to comment.
Something went wrong with that request. Please try again.