diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-01-24 17:54:10 +0000 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-01-24 17:54:10 +0000 |
commit | fe6ffce51dc16285094be49244b26591956c2dd6 (patch) | |
tree | f83e9fb9cde96e2e5b5d2e89ea9ae0333d2f0b9b /activerecord/test/cases | |
parent | b2192888ab28b4cc36a54b5c918c6773de95a030 (diff) | |
download | rails-fe6ffce51dc16285094be49244b26591956c2dd6.tar.gz rails-fe6ffce51dc16285094be49244b26591956c2dd6.tar.bz2 rails-fe6ffce51dc16285094be49244b26591956c2dd6.zip |
Make sure inner scope conditions get a preference over the outer ones
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/named_scope_test.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index bab842cf66..e1e27fa130 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -277,6 +277,26 @@ class NamedScopeTest < ActiveRecord::TestCase post = Post.find(1) assert_equal post.comments.size, Post.scoped(:joins => join).scoped(:joins => join, :conditions => "posts.id = #{post.id}").size end + + def test_chanining_should_use_latest_conditions_when_creating + post1 = Topic.rejected.approved.new + assert post1.approved? + + post2 = Topic.approved.rejected.new + assert ! post2.approved? + end + + def test_chanining_should_use_latest_conditions_when_searching + # Normal hash conditions + assert_equal Topic.all(:conditions => {:approved => true}), Topic.rejected.approved.all + assert_equal Topic.all(:conditions => {:approved => false}), Topic.approved.rejected.all + + # Nested hash conditions with same keys + assert_equal [posts(:sti_comments)], Post.with_special_comments.with_very_special_comments.all + + # Nested hash conditions with different keys + assert_equal [posts(:sti_comments)], Post.with_special_comments.with_post(4).all.uniq + end end class DynamicScopeMatchTest < ActiveRecord::TestCase |