提交 91b98cf0 编写于 作者: E Elijah Miller 提交者: Pratik Naik

Returning nil from named scope lambda is equivalent to an empty hash [#1773 state:resolved]

Signed-off-by: NPratik Naik <pratiknaik@gmail.com>
上级 aa57e66f
......@@ -117,6 +117,7 @@ class Scope
delegate :scopes, :with_scope, :to => :proxy_scope
def initialize(proxy_scope, options, &block)
options ||= {}
[options[:extend]].flatten.each { |extension| extend extension } if options[:extend]
extend Module.new(&block) if block_given?
unless Scope === proxy_scope
......
......@@ -99,6 +99,12 @@ def test_procedural_scopes
assert_equal topics_written_before_the_second, Topic.written_before(topics(:second).written_on)
end
def test_procedural_scopes_returning_nil
all_topics = Topic.find(:all)
assert_equal all_topics, Topic.written_before(nil)
end
def test_scopes_with_joins
address = author_addresses(:david_address)
posts_with_authors_at_address = Post.find(
......
class Topic < ActiveRecord::Base
named_scope :base
named_scope :written_before, lambda { |time|
{ :conditions => ['written_on < ?', time] }
if time
{ :conditions => ['written_on < ?', time] }
end
}
named_scope :approved, :conditions => {:approved => true}
named_scope :rejected, :conditions => {:approved => false}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册