From 8d02afeaee8993bd0fde69687fdd9bf30921e805 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Fri, 7 Dec 2012 16:52:55 -0200 Subject: Rollback where.like and where.not_like The real win with these chain methods is where.not, that takes care of different scenarios in a graceful way, for instance when the given value is nil. where("author.id != ?", author_to_ignore.id) where.not("author.id", author_to_ignore.id) Both where.like and where.not_like compared to the SQL versions doesn't seem to give us that much: Post.where("title LIKE 'ruby on%'") Post.where.like(title: 'ruby on%'") Post.where("title NOT LIKE 'ruby on%'") Post.where.not_like(title: 'ruby on%'") Thus Rails is adding where.not, but not where.like/not_like and others. --- activerecord/test/cases/relation/where_chain_test.rb | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/relation/where_chain_test.rb b/activerecord/test/cases/relation/where_chain_test.rb index edb3ea48b9..8ce44636b4 100644 --- a/activerecord/test/cases/relation/where_chain_test.rb +++ b/activerecord/test/cases/relation/where_chain_test.rb @@ -62,29 +62,14 @@ module ActiveRecord assert_equal([expected], relation.where_values) end - def test_like - expected = Arel::Nodes::Matches.new(Post.arel_table[:title], 'a%') - relation = Post.where.like(title: 'a%') - assert_equal([expected], relation.where_values) - end - - def test_not_like - expected = Arel::Nodes::DoesNotMatch.new(Post.arel_table[:title], 'a%') - relation = Post.where.not_like(title: 'a%') - assert_equal([expected], relation.where_values) - end - def test_chaining_multiple - relation = Post.where.like(title: 'ruby on %').where.not(title: 'ruby on rails').where.not_like(title: '% ales') + relation = Post.where.not(author_id: [1, 2]).where.not(title: 'ruby on rails') - expected = Arel::Nodes::Matches.new(Post.arel_table[:title], 'ruby on %') + expected = Arel::Nodes::NotIn.new(Post.arel_table[:author_id], [1, 2]) assert_equal(expected, relation.where_values[0]) expected = Arel::Nodes::NotEqual.new(Post.arel_table[:title], 'ruby on rails') assert_equal(expected, relation.where_values[1]) - - expected = Arel::Nodes::DoesNotMatch.new(Post.arel_table[:title], '% ales') - assert_equal(expected, relation.where_values[2]) end end end -- cgit v1.2.3