diff options
author | Jan <jan.h.xie@gmail.com> | 2010-10-12 12:42:09 +0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-10-20 09:00:36 -0700 |
commit | 21beedf1ff925613fb1ca9b3cf44d10526b64a2e (patch) | |
tree | c85d49124123f31f8da290b469a8aed51855cfd7 /activerecord/test/cases | |
parent | dbc5d2694f0c77ca9de43306602969fdd3dbd20e (diff) | |
download | rails-21beedf1ff925613fb1ca9b3cf44d10526b64a2e.tar.gz rails-21beedf1ff925613fb1ca9b3cf44d10526b64a2e.tar.bz2 rails-21beedf1ff925613fb1ca9b3cf44d10526b64a2e.zip |
default scope merge where clauses [#5488 state:resolved]
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/base_test.rb | 1 | ||||
-rw-r--r-- | activerecord/test/cases/relation_scoping_test.rb | 17 |
2 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 8acee9ac71..21bd61c096 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1456,6 +1456,7 @@ class BasicsTest < ActiveRecord::TestCase UnloadablePost.class_eval do default_scope order('posts.comments_count ASC') end + UnloadablePost.scoped_methods # make Thread.current[:UnloadablePost_scoped_methods] not nil UnloadablePost.unloadable assert_not_nil Thread.current[:UnloadablePost_scoped_methods] diff --git a/activerecord/test/cases/relation_scoping_test.rb b/activerecord/test/cases/relation_scoping_test.rb index 689cce8746..a27e2e72cd 100644 --- a/activerecord/test/cases/relation_scoping_test.rb +++ b/activerecord/test/cases/relation_scoping_test.rb @@ -393,6 +393,23 @@ class DefaultScopingTest < ActiveRecord::TestCase assert_equal 100000, klass.first.salary end + def test_default_scope_called_twice_in_different_place_merges_where_clause + Developer.destroy_all + Developer.create!(:name => "David", :salary => 80000) + Developer.create!(:name => "David", :salary => 100000) + Developer.create!(:name => "Brian", :salary => 100000) + + klass = Class.new(Developer) + klass.class_eval do + default_scope where("name = 'David'") + default_scope where("salary = 100000") + end + + assert_equal 1, klass.count + assert_equal "David", klass.first.name + assert_equal 100000, klass.first.salary + end + def test_method_scope expected = Developer.find(:all, :order => 'salary DESC, name DESC').collect { |dev| dev.salary } received = DeveloperOrderedBySalary.all_ordered_by_name.collect { |dev| dev.salary } |