Permalink
Browse files

Merge pull request #8452 from claudiob/explain_where_chain_parameters

Document the types of arguments accepted by AR#not
  • Loading branch information...
2 parents 27ca915 + bb53c60 commit c2052846f4551d9eb24bb66ce7b05b23abc6cd1f @carlosantoniodasilva carlosantoniodasilva committed Dec 7, 2012
@@ -14,6 +14,15 @@ def initialize(scope)
# Returns a new relation expressing WHERE + NOT condition
# according to the conditions in the arguments.
#
+ # #not accepts conditions in one of these formats: String, Array, Hash.
+ # See #where for more details on each format.
+ #
+ # User.where.not("name = 'Jon'")
+ # # SELECT * FROM users WHERE name <> 'Jon'
+ #
+ # User.where.not(["name = ?", "Jon"])
+ # # SELECT * FROM users WHERE name <> 'Jon'
+ #
# User.where.not(name: "Jon")
# # SELECT * FROM users WHERE name <> 'Jon'
#
@@ -40,7 +49,7 @@ def not(opts, *rest)
end
# Returns a new relation expressing WHERE + LIKE condition
- # according to the conditions in the arguments.
+ # according to the conditions provided as a hash in the arguments.
#
# Book.where.like(title: "Rails%")
# # SELECT * FROM books WHERE title LIKE 'Rails%'
@@ -53,7 +62,7 @@ def like(opts, *rest)
end
# Returns a new relation expressing WHERE + NOT LIKE condition
- # according to the conditions in the arguments.
+ # according to the conditions provided as a hash in the arguments.
#
# Conference.where.not_like(name: "%Kaigi")
# # SELECT * FROM conferences WHERE name NOT LIKE '%Kaigi'
@@ -50,6 +50,18 @@ def test_not_eq_with_succeeding_where
assert_equal(expected, relation.where_values.last)
end
+ 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)
+ 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)
+ end
+
def test_like
expected = Arel::Nodes::Matches.new(Post.arel_table[:title], 'a%')
relation = Post.where.like(title: 'a%')

0 comments on commit c205284

Please sign in to comment.