aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/lib/active_record/named_scope.rb9
-rw-r--r--activerecord/test/cases/named_scope_test.rb12
2 files changed, 17 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb
index aac00cc54a..9abf979cd0 100644
--- a/activerecord/lib/active_record/named_scope.rb
+++ b/activerecord/lib/active_record/named_scope.rb
@@ -167,7 +167,14 @@ module ActiveRecord
end
def ==(other)
- other.respond_to?(:to_ary) ? to_a == other.to_a : false
+ case other
+ when Scope
+ to_sql == other.to_sql
+ when Relation
+ other == self
+ when Array
+ to_a == other.to_a
+ end
end
private
diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb
index 40c724b87e..2396ca10b0 100644
--- a/activerecord/test/cases/named_scope_test.rb
+++ b/activerecord/test/cases/named_scope_test.rb
@@ -374,14 +374,14 @@ class NamedScopeTest < ActiveRecord::TestCase
class << Topic
def public_method; end
public :public_method
-
+
def protected_method; end
protected :protected_method
-
+
def private_method; end
private :private_method
end
-
+
[:public_method, :protected_method, :private_method].each do |reserved_method|
assert Topic.respond_to?(reserved_method, true)
ActiveRecord::Base.logger.expects(:warn)
@@ -407,6 +407,12 @@ class NamedScopeTest < ActiveRecord::TestCase
assert_equal topics(:second), approved[0]
assert approved.loaded?
end
+
+ def test_nested_named_scopes_queries_size
+ assert_queries(1) do
+ Topic.approved.by_lifo.replied.written_before(Time.now).all
+ end
+ end
end
class DynamicScopeMatchTest < ActiveRecord::TestCase