diff options
author | laurocaetano <laurocaetano1@gmail.com> | 2013-10-22 18:39:29 -0200 |
---|---|---|
committer | Lauro Caetano <laurocaetano1@gmail.com> | 2013-12-12 19:31:48 -0200 |
commit | d1987846b3857f49db8c15f2d1ae8dc8a14d8a2f (patch) | |
tree | 5a58f3266f02ebd6bd5150720c336cba0346ebf2 /activerecord/test | |
parent | a176bd095c3cba498369870681695bb29a68f0f9 (diff) | |
download | rails-d1987846b3857f49db8c15f2d1ae8dc8a14d8a2f.tar.gz rails-d1987846b3857f49db8c15f2d1ae8dc8a14d8a2f.tar.bz2 rails-d1987846b3857f49db8c15f2d1ae8dc8a14d8a2f.zip |
Remove delegation test.
This test was removed, since Relation will not delegate class
methods to Array.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 63 |
1 files changed, 46 insertions, 17 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 09724d9884..2ccf4c7578 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -1506,26 +1506,55 @@ class RelationTest < ActiveRecord::TestCase assert !Post.all.respond_to?(:by_lifo) end - class OMGTopic < ActiveRecord::Base - self.table_name = 'topics' + test "merge collapses wheres from the LHS only" do + left = Post.where(title: "omg").where(comments_count: 1) + right = Post.where(title: "wtf").where(title: "bbq") - def self.__omg__ - "omgtopic" - end + expected = [left.where_values[1]] + right.where_values + merged = left.merge(right) + + assert_equal expected, merged.where_values + assert !merged.to_sql.include?("omg") + assert merged.to_sql.include?("wtf") + assert merged.to_sql.include?("bbq") end - test "delegations do not clash across classes" do - begin - class ::Array - def __omg__ - "array" - end - end + def test_merging_removes_rhs_bind_parameters + left = Post.where(id: Arel::Nodes::BindParam.new('?')) + column = Post.columns_hash['id'] + left.bind_values += [[column, 20]] + right = Post.where(id: 10) - assert_equal "array", Topic.all.__omg__ - assert_equal "omgtopic", OMGTopic.all.__omg__ - ensure - Array.send(:remove_method, :__omg__) - end + merged = left.merge(right) + assert_equal [], merged.bind_values + end + + def test_merging_keeps_lhs_bind_parameters + column = Post.columns_hash['id'] + binds = [[column, 20]] + + right = Post.where(id: Arel::Nodes::BindParam.new('?')) + right.bind_values += binds + left = Post.where(id: 10) + + merged = left.merge(right) + assert_equal binds, merged.bind_values + end + + def test_merging_reorders_bind_params + post = Post.first + id_column = Post.columns_hash['id'] + title_column = Post.columns_hash['title'] + + bv = Post.connection.substitute_at id_column, 0 + + right = Post.where(id: bv) + right.bind_values += [[id_column, post.id]] + + left = Post.where(title: bv) + left.bind_values += [[title_column, post.title]] + + merged = left.merge(right) + assert_equal post, merged.first end end |