mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add test case for using sanitize method in the scope definition
Context: https://github.com/rails/rails/pull/29301#issuecomment-353200233
This commit is contained in:
parent
0901755283
commit
de2f1e073b
1 changed files with 10 additions and 2 deletions
|
@ -72,13 +72,21 @@ class SanitizeTest < ActiveRecord::TestCase
|
|||
|
||||
def test_sanitize_sql_like_example_use_case
|
||||
searchable_post = Class.new(Post) do
|
||||
def self.search(term)
|
||||
def self.search_as_method(term)
|
||||
where("title LIKE ?", sanitize_sql_like(term, "!"))
|
||||
end
|
||||
|
||||
scope :search_as_scope, -> (term) {
|
||||
where("title LIKE ?", sanitize_sql_like(term, "!"))
|
||||
}
|
||||
end
|
||||
|
||||
assert_sql(/LIKE '20!% !_reduction!_!!'/) do
|
||||
searchable_post.search("20% _reduction_!").to_a
|
||||
searchable_post.search_as_method("20% _reduction_!").to_a
|
||||
end
|
||||
|
||||
assert_sql(/LIKE '20!% !_reduction!_!!'/) do
|
||||
searchable_post.search_as_scope("20% _reduction_!").to_a
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue