aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorElijah Miller <elijah.miller@gmail.com>2009-03-12 15:06:19 +0000
committerPratik Naik <pratiknaik@gmail.com>2009-03-12 15:06:19 +0000
commit91b98cf0a5417ce4042a0b3cd1930d5a221b737f (patch)
tree625c8bdf652ca584fcadf6599e6eec13078ebb54 /activerecord/test
parentaa57e66fec3a131f5d246b8950a2c3286f858b78 (diff)
downloadrails-91b98cf0a5417ce4042a0b3cd1930d5a221b737f.tar.gz
rails-91b98cf0a5417ce4042a0b3cd1930d5a221b737f.tar.bz2
rails-91b98cf0a5417ce4042a0b3cd1930d5a221b737f.zip
Returning nil from named scope lambda is equivalent to an empty hash [#1773 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/named_scope_test.rb6
-rw-r--r--activerecord/test/models/topic.rb4
2 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb
index 8045b136c2..ae6a54a5bd 100644
--- a/activerecord/test/cases/named_scope_test.rb
+++ b/activerecord/test/cases/named_scope_test.rb
@@ -99,6 +99,12 @@ class NamedScopeTest < ActiveRecord::TestCase
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(
diff --git a/activerecord/test/models/topic.rb b/activerecord/test/models/topic.rb
index f1b7bbae3b..51012d22ed 100644
--- a/activerecord/test/models/topic.rb
+++ b/activerecord/test/models/topic.rb
@@ -1,7 +1,9 @@
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}