diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-03-24 17:20:55 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-03-24 17:24:20 -0700 |
commit | c7191e31957a4c8adca492a3f0ce1909a7b68e23 (patch) | |
tree | dfe2041146b6dc351ab5032702ec661b7a855076 | |
parent | e2097235b6d81a350f0a8d33980269fda63dec28 (diff) | |
download | rails-c7191e31957a4c8adca492a3f0ce1909a7b68e23.tar.gz rails-c7191e31957a4c8adca492a3f0ce1909a7b68e23.tar.bz2 rails-c7191e31957a4c8adca492a3f0ce1909a7b68e23.zip |
use ARel factory methods for building AST nodes
This abstracts us from the actual construction of the nodes
-rw-r--r-- | activerecord/test/cases/relation/predicate_builder_test.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/relation/where_chain_test.rb | 30 |
2 files changed, 17 insertions, 17 deletions
diff --git a/activerecord/test/cases/relation/predicate_builder_test.rb b/activerecord/test/cases/relation/predicate_builder_test.rb index 14a8d97d36..4057835688 100644 --- a/activerecord/test/cases/relation/predicate_builder_test.rb +++ b/activerecord/test/cases/relation/predicate_builder_test.rb @@ -5,10 +5,10 @@ module ActiveRecord class PredicateBuilderTest < ActiveRecord::TestCase def test_registering_new_handlers PredicateBuilder.register_handler(Regexp, proc do |column, value| - Arel::Nodes::InfixOperation.new('~', column, value.source) + Arel::Nodes::InfixOperation.new('~', column, Arel.sql(value.source)) end) - assert_match %r{["`]topics["`].["`]title["`] ~ 'rails'}i, Topic.where(title: /rails/).to_sql + assert_match %r{["`]topics["`].["`]title["`] ~ rails}i, Topic.where(title: /rails/).to_sql end end end diff --git a/activerecord/test/cases/relation/where_chain_test.rb b/activerecord/test/cases/relation/where_chain_test.rb index fd2420cb88..c628ca44ff 100644 --- a/activerecord/test/cases/relation/where_chain_test.rb +++ b/activerecord/test/cases/relation/where_chain_test.rb @@ -12,13 +12,13 @@ module ActiveRecord end def test_not_eq - expected = Arel::Nodes::NotEqual.new(Post.arel_table[@name], 'hello') + expected = Post.arel_table[@name].not_eq('hello') relation = Post.where.not(title: 'hello') assert_equal([expected], relation.where_values) end def test_not_null - expected = Arel::Nodes::NotEqual.new(Post.arel_table[@name], nil) + expected = Post.arel_table[@name].not_eq(nil) relation = Post.where.not(title: nil) assert_equal([expected], relation.where_values) end @@ -30,13 +30,13 @@ module ActiveRecord end def test_not_in - expected = Arel::Nodes::NotIn.new(Post.arel_table[@name], %w[hello goodbye]) + expected = Post.arel_table[@name].not_in(%w[hello goodbye]) relation = Post.where.not(title: %w[hello goodbye]) assert_equal([expected], relation.where_values) end def test_association_not_eq - expected = Arel::Nodes::NotEqual.new(Comment.arel_table[@name], 'hello') + expected = Comment.arel_table[@name].not_eq('hello') relation = Post.joins(:comments).where.not(comments: {title: 'hello'}) assert_equal(expected.to_sql, relation.where_values.first.to_sql) end @@ -44,20 +44,20 @@ module ActiveRecord def test_not_eq_with_preceding_where relation = Post.where(title: 'hello').where.not(title: 'world') - expected = Arel::Nodes::Equality.new(Post.arel_table[@name], 'hello') + expected = Post.arel_table[@name].eq('hello') assert_equal(expected, relation.where_values.first) - expected = Arel::Nodes::NotEqual.new(Post.arel_table[@name], 'world') + expected = Post.arel_table[@name].not_eq('world') assert_equal(expected, relation.where_values.last) end def test_not_eq_with_succeeding_where relation = Post.where.not(title: 'hello').where(title: 'world') - expected = Arel::Nodes::NotEqual.new(Post.arel_table[@name], 'hello') + expected = Post.arel_table[@name].not_eq('hello') assert_equal(expected, relation.where_values.first) - expected = Arel::Nodes::Equality.new(Post.arel_table[@name], 'world') + expected = Post.arel_table[@name].eq('world') assert_equal(expected, relation.where_values.last) end @@ -76,17 +76,17 @@ module ActiveRecord def test_chaining_multiple relation = Post.where.not(author_id: [1, 2]).where.not(title: 'ruby on rails') - expected = Arel::Nodes::NotIn.new(Post.arel_table['author_id'], [1, 2]) + expected = Post.arel_table['author_id'].not_in([1, 2]) assert_equal(expected, relation.where_values[0]) - expected = Arel::Nodes::NotEqual.new(Post.arel_table[@name], 'ruby on rails') + expected = Post.arel_table[@name].not_eq('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') + expected = Post.arel_table[@name].eq('alone') assert_equal 1, relation.where_values.size assert_equal expected, relation.where_values.first end @@ -94,8 +94,8 @@ module ActiveRecord 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') + title_expected = Post.arel_table['title'].eq('alone') + body_expected = Post.arel_table['body'].eq('again') assert_equal 2, relation.where_values.size assert_equal title_expected, relation.where_values.first @@ -105,8 +105,8 @@ module ActiveRecord 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') + title_expected = Post.arel_table['title'].eq('alone') + body_expected = Post.arel_table['body'].eq('world') assert_equal 2, relation.where_values.size assert_equal body_expected, relation.where_values.first |