From 17b1b5d77342db8fe3aa064d848d46052cb4695c Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Sun, 25 Jan 2015 17:35:46 -0700 Subject: [PATCH] Remove all references to `where_values` in tests --- .../associations/association_scope_test.rb | 6 +- .../has_many_associations_test.rb | 8 +-- .../associations/has_one_associations_test.rb | 8 +-- activerecord/test/cases/associations_test.rb | 2 +- .../test/cases/relation/mutation_test.rb | 6 +- .../test/cases/relation/where_chain_test.rb | 72 +++++++++---------- activerecord/test/cases/relation_test.rb | 8 +-- .../cases/scoping/default_scoping_test.rb | 10 +-- .../test/cases/scoping/named_scoping_test.rb | 2 +- .../cases/scoping/relation_scoping_test.rb | 2 +- 10 files changed, 62 insertions(+), 62 deletions(-) diff --git a/activerecord/test/cases/associations/association_scope_test.rb b/activerecord/test/cases/associations/association_scope_test.rb index 3e0032ec73..dd26a85e44 100644 --- a/activerecord/test/cases/associations/association_scope_test.rb +++ b/activerecord/test/cases/associations/association_scope_test.rb @@ -8,9 +8,9 @@ class AssociationScopeTest < ActiveRecord::TestCase test 'does not duplicate conditions' do scope = AssociationScope.scope(Author.new.association(:welcome_posts), Author.connection) - wheres = scope.where_values.map(&:right) - binds = scope.bind_values.map(&:last) - wheres = scope.where_values.map(&:right).reject { |node| + wheres = scope.where_clause.predicates.map(&:right) + binds = scope.where_clause.binds.map(&:last) + wheres.reject! { |node| Arel::Nodes::BindParam === node } assert_equal wheres.uniq, wheres diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 3bd7506bb5..5ef84562ad 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -316,16 +316,16 @@ def test_association_protect_foreign_key # would be convenient), because this would cause that scope to be applied to any callbacks etc. def test_build_and_create_should_not_happen_within_scope car = cars(:honda) - scoped_count = car.foo_bulbs.where_values.count + scoped_count = car.foo_bulbs.where_clause.predicates.count bulb = car.foo_bulbs.build - assert_not_equal scoped_count, bulb.scope_after_initialize.where_values.count + assert_not_equal scoped_count, bulb.scope_after_initialize.where_clause.predicates.count bulb = car.foo_bulbs.create - assert_not_equal scoped_count, bulb.scope_after_initialize.where_values.count + assert_not_equal scoped_count, bulb.scope_after_initialize.where_clause.predicates.count bulb = car.foo_bulbs.create! - assert_not_equal scoped_count, bulb.scope_after_initialize.where_values.count + assert_not_equal scoped_count, bulb.scope_after_initialize.where_clause.predicates.count end def test_no_sql_should_be_fired_if_association_already_loaded diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb index 4df75adeb4..c02509db46 100644 --- a/activerecord/test/cases/associations/has_one_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_associations_test.rb @@ -237,16 +237,16 @@ def test_building_the_associated_object_with_an_unrelated_type def test_build_and_create_should_not_happen_within_scope pirate = pirates(:blackbeard) - scoped_count = pirate.association(:foo_bulb).scope.where_values.count + scoped_count = pirate.association(:foo_bulb).scope.where_clause.predicates.count bulb = pirate.build_foo_bulb - assert_not_equal scoped_count, bulb.scope_after_initialize.where_values.count + assert_not_equal scoped_count, bulb.scope_after_initialize.where_clause.predicates.count bulb = pirate.create_foo_bulb - assert_not_equal scoped_count, bulb.scope_after_initialize.where_values.count + assert_not_equal scoped_count, bulb.scope_after_initialize.where_clause.predicates.count bulb = pirate.create_foo_bulb! - assert_not_equal scoped_count, bulb.scope_after_initialize.where_values.count + assert_not_equal scoped_count, bulb.scope_after_initialize.where_clause.predicates.count end def test_create_association diff --git a/activerecord/test/cases/associations_test.rb b/activerecord/test/cases/associations_test.rb index 72963fd56c..705f86a699 100644 --- a/activerecord/test/cases/associations_test.rb +++ b/activerecord/test/cases/associations_test.rb @@ -238,7 +238,7 @@ def test_proxy_association_accessor end def test_scoped_allows_conditions - assert developers(:david).projects.merge!(where: 'foo').where_values.include?('foo') + assert developers(:david).projects.merge!(where: 'foo').where_clause.predicates.include?('foo') end test "getting a scope from an association" do diff --git a/activerecord/test/cases/relation/mutation_test.rb b/activerecord/test/cases/relation/mutation_test.rb index 2443f10269..003d870045 100644 --- a/activerecord/test/cases/relation/mutation_test.rb +++ b/activerecord/test/cases/relation/mutation_test.rb @@ -136,12 +136,12 @@ def relation end test 'test_merge!' do - assert relation.merge!(where: :foo).equal?(relation) - assert_equal [:foo], relation.where_values + assert relation.merge!(select: :foo).equal?(relation) + assert_equal [:foo], relation.select_values end test 'merge with a proc' do - assert_equal [:foo], relation.merge(-> { where(:foo) }).where_values + assert_equal [:foo], relation.merge(-> { select(:foo) }).select_values end test 'none!' do diff --git a/activerecord/test/cases/relation/where_chain_test.rb b/activerecord/test/cases/relation/where_chain_test.rb index 0f9019bb1b..00c9a001c0 100644 --- a/activerecord/test/cases/relation/where_chain_test.rb +++ b/activerecord/test/cases/relation/where_chain_test.rb @@ -14,10 +14,10 @@ def setup def test_not_eq relation = Post.where.not(title: 'hello') - assert_equal 1, relation.where_values.length + assert_equal 1, relation.where_clause.predicates.length - value = relation.where_values.first - bind = relation.bind_values.first + value = relation.where_clause.predicates.first + bind = relation.where_clause.binds.first assert_bound_ast value, Post.arel_table[@name], Arel::Nodes::NotEqual assert_equal 'hello', bind.last @@ -26,7 +26,7 @@ def test_not_eq def test_not_null expected = Post.arel_table[@name].not_eq(nil) relation = Post.where.not(title: nil) - assert_equal([expected], relation.where_values) + assert_equal([expected], relation.where_clause.predicates) end def test_not_with_nil @@ -38,25 +38,25 @@ def test_not_with_nil def test_not_in expected = Post.arel_table[@name].not_in(%w[hello goodbye]) relation = Post.where.not(title: %w[hello goodbye]) - assert_equal([expected], relation.where_values) + assert_equal([expected], relation.where_clause.predicates) end def test_association_not_eq expected = Comment.arel_table[@name].not_eq(Arel::Nodes::BindParam.new) relation = Post.joins(:comments).where.not(comments: {title: 'hello'}) - assert_equal(expected.to_sql, relation.where_values.first.to_sql) + assert_equal(expected.to_sql, relation.where_clause.predicates.first.to_sql) end def test_not_eq_with_preceding_where relation = Post.where(title: 'hello').where.not(title: 'world') - value = relation.where_values.first - bind = relation.bind_values.first + value = relation.where_clause.predicates.first + bind = relation.where_clause.binds.first assert_bound_ast value, Post.arel_table[@name], Arel::Nodes::Equality assert_equal 'hello', bind.last - value = relation.where_values.last - bind = relation.bind_values.last + value = relation.where_clause.predicates.last + bind = relation.where_clause.binds.last assert_bound_ast value, Post.arel_table[@name], Arel::Nodes::NotEqual assert_equal 'world', bind.last end @@ -64,13 +64,13 @@ def test_not_eq_with_preceding_where def test_not_eq_with_succeeding_where relation = Post.where.not(title: 'hello').where(title: 'world') - value = relation.where_values.first - bind = relation.bind_values.first + value = relation.where_clause.predicates.first + bind = relation.where_clause.binds.first assert_bound_ast value, Post.arel_table[@name], Arel::Nodes::NotEqual assert_equal 'hello', bind.last - value = relation.where_values.last - bind = relation.bind_values.last + value = relation.where_clause.predicates.last + bind = relation.where_clause.binds.last assert_bound_ast value, Post.arel_table[@name], Arel::Nodes::Equality assert_equal 'world', bind.last end @@ -78,23 +78,23 @@ def test_not_eq_with_succeeding_where def test_not_eq_with_string_parameter expected = Arel::Nodes::Not.new("title = 'hello'") relation = Post.where.not("title = 'hello'") - assert_equal([expected], relation.where_values) + assert_equal([expected], relation.where_clause.predicates) end def test_not_eq_with_array_parameter expected = Arel::Nodes::Not.new("title = 'hello'") relation = Post.where.not(['title = ?', 'hello']) - assert_equal([expected], relation.where_values) + assert_equal([expected], relation.where_clause.predicates) end def test_chaining_multiple relation = Post.where.not(author_id: [1, 2]).where.not(title: 'ruby on rails') expected = Post.arel_table['author_id'].not_in([1, 2]) - assert_equal(expected, relation.where_values[0]) + assert_equal(expected, relation.where_clause.predicates[0]) - value = relation.where_values[1] - bind = relation.bind_values.first + value = relation.where_clause.predicates[1] + bind = relation.where_clause.binds.first assert_bound_ast value, Post.arel_table[@name], Arel::Nodes::NotEqual assert_equal 'ruby on rails', bind.last @@ -103,9 +103,9 @@ def test_chaining_multiple def test_rewhere_with_one_condition relation = Post.where(title: 'hello').where(title: 'world').rewhere(title: 'alone') - assert_equal 1, relation.where_values.size - value = relation.where_values.first - bind = relation.bind_values.first + assert_equal 1, relation.where_clause.predicates.size + value = relation.where_clause.predicates.first + bind = relation.where_clause.binds.first assert_bound_ast value, Post.arel_table[@name], Arel::Nodes::Equality assert_equal 'alone', bind.last end @@ -113,15 +113,15 @@ def test_rewhere_with_one_condition def test_rewhere_with_multiple_overwriting_conditions relation = Post.where(title: 'hello').where(body: 'world').rewhere(title: 'alone', body: 'again') - assert_equal 2, relation.where_values.size + assert_equal 2, relation.where_clause.predicates.size - value = relation.where_values.first - bind = relation.bind_values.first + value = relation.where_clause.predicates.first + bind = relation.where_clause.binds.first assert_bound_ast value, Post.arel_table['title'], Arel::Nodes::Equality assert_equal 'alone', bind.last - value = relation.where_values[1] - bind = relation.bind_values[1] + value = relation.where_clause.predicates[1] + bind = relation.where_clause.binds[1] assert_bound_ast value, Post.arel_table['body'], Arel::Nodes::Equality assert_equal 'again', bind.last end @@ -135,16 +135,16 @@ def assert_bound_ast value, table, type def test_rewhere_with_one_overwriting_condition_and_one_unrelated relation = Post.where(title: 'hello').where(body: 'world').rewhere(title: 'alone') - assert_equal 2, relation.where_values.size + assert_equal 2, relation.where_clause.predicates.size - value = relation.where_values.first - bind = relation.bind_values.first + value = relation.where_clause.predicates.first + bind = relation.where_clause.binds.first assert_bound_ast value, Post.arel_table['body'], Arel::Nodes::Equality assert_equal 'world', bind.last - value = relation.where_values.second - bind = relation.bind_values.second + value = relation.where_clause.predicates.second + bind = relation.where_clause.binds.second assert_bound_ast value, Post.arel_table['title'], Arel::Nodes::Equality assert_equal 'alone', bind.last @@ -153,28 +153,28 @@ def test_rewhere_with_one_overwriting_condition_and_one_unrelated def test_rewhere_with_range relation = Post.where(comments_count: 1..3).rewhere(comments_count: 3..5) - assert_equal 1, relation.where_values.size + assert_equal 1, relation.where_clause.predicates.size assert_equal Post.where(comments_count: 3..5), relation end def test_rewhere_with_infinite_upper_bound_range relation = Post.where(comments_count: 1..Float::INFINITY).rewhere(comments_count: 3..5) - assert_equal 1, relation.where_values.size + assert_equal 1, relation.where_clause.predicates.size assert_equal Post.where(comments_count: 3..5), relation end def test_rewhere_with_infinite_lower_bound_range relation = Post.where(comments_count: -Float::INFINITY..1).rewhere(comments_count: 3..5) - assert_equal 1, relation.where_values.size + assert_equal 1, relation.where_clause.predicates.size assert_equal Post.where(comments_count: 3..5), relation end def test_rewhere_with_infinite_range relation = Post.where(comments_count: -Float::INFINITY..Float::INFINITY).rewhere(comments_count: 3..5) - assert_equal 1, relation.where_values.size + assert_equal 1, relation.where_clause.predicates.size assert_equal Post.where(comments_count: 3..5), relation end end diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index 75d74ddc7b..d75c5435c6 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -156,12 +156,12 @@ def test_references_values_dont_duplicate relation = Relation.new(FakeKlass, :b, nil) relation = relation.merge where: :lol, readonly: true - assert_equal [:lol], relation.where_values + assert_equal [:lol], relation.where_clause.predicates assert_equal true, relation.readonly_value end test 'merging an empty hash into a relation' do - assert_equal [], Relation.new(FakeKlass, :b, nil).merge({}).where_values + assert_equal Relation::WhereClause.empty, Relation.new(FakeKlass, :b, nil).merge({}).where_clause end test 'merging a hash with unknown keys raises' do @@ -173,7 +173,7 @@ def test_references_values_dont_duplicate values = relation.values values[:where] = nil - assert_not_nil relation.where_values + assert_not_nil relation.where_clause end test 'relations can be created with a values hash' do @@ -191,7 +191,7 @@ def self.sanitize_sql(args) relation = Relation.new(klass, :b, nil) relation.merge!(where: ['foo = ?', 'bar']) - assert_equal ['foo = bar'], relation.where_values + assert_equal ['foo = bar'], relation.where_clause.predicates end def test_merging_readonly_false diff --git a/activerecord/test/cases/scoping/default_scoping_test.rb b/activerecord/test/cases/scoping/default_scoping_test.rb index 0738df1b54..d0835ba3e5 100644 --- a/activerecord/test/cases/scoping/default_scoping_test.rb +++ b/activerecord/test/cases/scoping/default_scoping_test.rb @@ -284,8 +284,8 @@ def test_unscope_errors_with_non_symbol_or_hash_arguments def test_unscope_merging merged = Developer.where(name: "Jamis").merge(Developer.unscope(:where)) - assert merged.where_values.empty? - assert !merged.where(name: "Jon").where_values.empty? + assert merged.where_clause.empty? + assert !merged.where(name: "Jon").where_clause.empty? end def test_order_in_default_scope_should_not_prevail @@ -426,19 +426,19 @@ def test_default_scope_is_threadsafe test "additional conditions are ANDed with the default scope" do scope = DeveloperCalledJamis.where(name: "David") - assert_equal 2, scope.where_values.length + assert_equal 2, scope.where_clause.predicates.length assert_equal [], scope.to_a end test "additional conditions in a scope are ANDed with the default scope" do scope = DeveloperCalledJamis.david - assert_equal 2, scope.where_values.length + assert_equal 2, scope.where_clause.predicates.length assert_equal [], scope.to_a end test "a scope can remove the condition from the default scope" do scope = DeveloperCalledJamis.david2 - assert_equal 1, scope.where_values.length + assert_equal 1, scope.where_clause.predicates.length assert_equal Developer.where(name: "David").map(&:id), scope.map(&:id) end end diff --git a/activerecord/test/cases/scoping/named_scoping_test.rb b/activerecord/test/cases/scoping/named_scoping_test.rb index 41f3449828..57c9ff6a8d 100644 --- a/activerecord/test/cases/scoping/named_scoping_test.rb +++ b/activerecord/test/cases/scoping/named_scoping_test.rb @@ -380,7 +380,7 @@ def test_size_should_use_length_when_results_are_loaded end def test_should_not_duplicates_where_values - where_values = Topic.where("1=1").scope_with_lambda.where_values + where_values = Topic.where("1=1").scope_with_lambda.where_clause.predicates assert_equal ["1=1"], where_values end diff --git a/activerecord/test/cases/scoping/relation_scoping_test.rb b/activerecord/test/cases/scoping/relation_scoping_test.rb index d7bcbf6203..73760e628b 100644 --- a/activerecord/test/cases/scoping/relation_scoping_test.rb +++ b/activerecord/test/cases/scoping/relation_scoping_test.rb @@ -184,7 +184,7 @@ def test_ensure_that_method_scoping_is_correctly_restored rescue end - assert !Developer.all.where_values.include?("name = 'Jamis'") + assert !Developer.all.where_clause.predicates.include?("name = 'Jamis'") end def test_default_scope_filters_on_joins -- GitLab