aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-12-07 16:52:55 -0200
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-12-07 16:52:55 -0200
commit8d02afeaee8993bd0fde69687fdd9bf30921e805 (patch)
tree93cfbc3e5b18379c69abe6befa2bb3e78e542e86 /activerecord/test
parent7b50dc5316f1db83b2d138a12bb0b0ab5ea90a33 (diff)
downloadrails-8d02afeaee8993bd0fde69687fdd9bf30921e805.tar.gz
rails-8d02afeaee8993bd0fde69687fdd9bf30921e805.tar.bz2
rails-8d02afeaee8993bd0fde69687fdd9bf30921e805.zip
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.
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/relation/where_chain_test.rb19
1 files changed, 2 insertions, 17 deletions
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