diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2013-11-02 17:35:34 -0700 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2013-11-02 17:36:45 -0700 |
commit | f950b2699f97749ef706c6939a84dfc85f0b05f2 (patch) | |
tree | d6a8f95705fd23605db1c904acfffa158cfff7c8 /activerecord/test/cases/relation | |
parent | 4d7080f80c1ec4792730943b33b6eac2a1562b2a (diff) | |
download | rails-f950b2699f97749ef706c6939a84dfc85f0b05f2.tar.gz rails-f950b2699f97749ef706c6939a84dfc85f0b05f2.tar.bz2 rails-f950b2699f97749ef706c6939a84dfc85f0b05f2.zip |
Added ActiveRecord::QueryMethods#rewhere which will overwrite an existing, named where condition.
Diffstat (limited to 'activerecord/test/cases/relation')
-rw-r--r-- | activerecord/test/cases/relation/where_chain_test.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/activerecord/test/cases/relation/where_chain_test.rb b/activerecord/test/cases/relation/where_chain_test.rb index 92d1e013e8..d44b4dfe3d 100644 --- a/activerecord/test/cases/relation/where_chain_test.rb +++ b/activerecord/test/cases/relation/where_chain_test.rb @@ -76,5 +76,35 @@ module ActiveRecord expected = Arel::Nodes::NotEqual.new(Post.arel_table[@name], 'ruby on rails') assert_equal(expected, relation.where_values[1]) end + + def test_rewhere_with_one_condition + relation = Post.where(title: 'hello').where(title: 'world').rewhere(title: 'alone') + + expected = Arel::Nodes::Equality.new(Post.arel_table[@name], 'alone') + assert_equal 1, relation.where_values.size + assert_equal expected, relation.where_values.first + end + + def test_rewhere_with_multiple_overwriting_conditions + relation = Post.where(title: 'hello').where(body: 'world').rewhere(title: 'alone', body: 'again') + + title_expected = Arel::Nodes::Equality.new(Post.arel_table['title'], 'alone') + body_expected = Arel::Nodes::Equality.new(Post.arel_table['body'], 'again') + + assert_equal 2, relation.where_values.size + assert_equal title_expected, relation.where_values.first + assert_equal body_expected, relation.where_values.second + end + + def test_rewhere_with_one_overwriting_condition_and_one_unrelated + relation = Post.where(title: 'hello').where(body: 'world').rewhere(title: 'alone') + + title_expected = Arel::Nodes::Equality.new(Post.arel_table['title'], 'alone') + body_expected = Arel::Nodes::Equality.new(Post.arel_table['body'], 'world') + + assert_equal 2, relation.where_values.size + assert_equal body_expected, relation.where_values.first + assert_equal title_expected, relation.where_values.second + end end end |