about summary refs log tree commit diff
path: root/spec/models
diff options
context:
space:
mode:
authorabcang <abcang1015@gmail.com>2021-04-25 13:33:28 +0900
committerGitHub <noreply@github.com>2021-04-25 06:33:28 +0200
commit7f0c49c58ab75bbd6b4dc44d47a8c4ab57db9d51 (patch)
tree3f58aeae3eab31145fb52560cc789aa0fe3d0a96 /spec/models
parentdaccc07dc170627b17564402296f6c8631d0cd97 (diff)
Improve tag search query (#16104)
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/tag_spec.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/spec/models/tag_spec.rb b/spec/models/tag_spec.rb
index df876593c..3949dbce5 100644
--- a/spec/models/tag_spec.rb
+++ b/spec/models/tag_spec.rb
@@ -96,6 +96,20 @@ RSpec.describe Tag, type: :model do
     end
   end
 
+  describe '.matches_name' do
+    it 'returns tags for multibyte case-insensitive names' do
+      upcase_string   = 'abcABCabcABCやゆよ'
+      downcase_string = 'abcabcabcabcやゆよ';
+
+      tag = Fabricate(:tag, name: downcase_string)
+      expect(Tag.matches_name(upcase_string)).to eq [tag]
+    end
+
+    it 'uses the LIKE operator' do
+      expect(Tag.matches_name('100%abc').to_sql).to eq %q[SELECT "tags".* FROM "tags" WHERE LOWER("tags"."name") LIKE LOWER('100\\%abc%')]
+    end
+  end
+
   describe '.matching_name' do
     it 'returns tags for multibyte case-insensitive names' do
       upcase_string   = 'abcABCabcABCやゆよ'