diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-12-22 23:49:34 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-12-22 23:49:34 +0900 |
commit | de2f1e073b37f98a99334a909b8bc29f36ad506b (patch) | |
tree | aaef331e502b77b6c8a71fcbd5e7a339762908a0 /activerecord | |
parent | 0901755283645be1a59d625deb3471c40d664712 (diff) | |
download | rails-de2f1e073b37f98a99334a909b8bc29f36ad506b.tar.gz rails-de2f1e073b37f98a99334a909b8bc29f36ad506b.tar.bz2 rails-de2f1e073b37f98a99334a909b8bc29f36ad506b.zip |
Add test case for using sanitize method in the scope definition
Context: https://github.com/rails/rails/pull/29301#issuecomment-353200233
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/test/cases/sanitize_test.rb | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/activerecord/test/cases/sanitize_test.rb b/activerecord/test/cases/sanitize_test.rb index 86e45b3cbd..1b0605e369 100644 --- a/activerecord/test/cases/sanitize_test.rb +++ b/activerecord/test/cases/sanitize_test.rb @@ -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_as_method("20% _reduction_!").to_a end assert_sql(/LIKE '20!% !_reduction!_!!'/) do - searchable_post.search("20% _reduction_!").to_a + searchable_post.search_as_scope("20% _reduction_!").to_a end end |