提交 8d99ec9a 编写于 作者: E Emilio Tagua 提交者: José Valim

Named scopes shouldn't test equality using to_a if it's not an Array, this was...

Named scopes shouldn't test equality using to_a if it's not an Array, this was causing records to be loaded before they were needed.
Signed-off-by: NJosé Valim <jose.valim@gmail.com>
上级 41b45d56
...@@ -167,7 +167,14 @@ def last(*args) ...@@ -167,7 +167,14 @@ def last(*args)
end end
def ==(other) 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 end
private private
......
...@@ -374,14 +374,14 @@ def test_named_scopes_with_reserved_names ...@@ -374,14 +374,14 @@ def test_named_scopes_with_reserved_names
class << Topic class << Topic
def public_method; end def public_method; end
public :public_method public :public_method
def protected_method; end def protected_method; end
protected :protected_method protected :protected_method
def private_method; end def private_method; end
private :private_method private :private_method
end end
[:public_method, :protected_method, :private_method].each do |reserved_method| [:public_method, :protected_method, :private_method].each do |reserved_method|
assert Topic.respond_to?(reserved_method, true) assert Topic.respond_to?(reserved_method, true)
ActiveRecord::Base.logger.expects(:warn) ActiveRecord::Base.logger.expects(:warn)
...@@ -407,6 +407,12 @@ def test_index_on_named_scope ...@@ -407,6 +407,12 @@ def test_index_on_named_scope
assert_equal topics(:second), approved[0] assert_equal topics(:second), approved[0]
assert approved.loaded? assert approved.loaded?
end 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 end
class DynamicScopeMatchTest < ActiveRecord::TestCase class DynamicScopeMatchTest < ActiveRecord::TestCase
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册