From 5d2221c1089157c5b0596857b0ade984b74c3ae5 Mon Sep 17 00:00:00 2001 From: Dobromir Minchev Date: Tue, 9 May 2017 15:00:24 +0300 Subject: [PATCH] Add support for cyrillic search --- lib/administrate/search.rb | 2 +- spec/lib/administrate/search_spec.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/administrate/search.rb b/lib/administrate/search.rb index 312bee3152..936e2c3a24 100644 --- a/lib/administrate/search.rb +++ b/lib/administrate/search.rb @@ -30,7 +30,7 @@ def query end def search_terms - ["%#{term.downcase}%"] * search_attributes.count + ["%#{term.mb_chars.downcase}%"] * search_attributes.count end def search_attributes diff --git a/spec/lib/administrate/search_spec.rb b/spec/lib/administrate/search_spec.rb index 706de51660..11f83244b9 100644 --- a/spec/lib/administrate/search_spec.rb +++ b/spec/lib/administrate/search_spec.rb @@ -59,5 +59,24 @@ class User < ActiveRecord::Base; end remove_constants :User end end + + it "converts search term lower case for latin and cyrillic strings" do + begin + class User < ActiveRecord::Base; end + resolver = double(resource_class: User, dashboard_class: MockDashboard) + search = Administrate::Search.new(resolver, "Тест Test") + expected_query = [ + "lower(\"users\".\"name\") LIKE ?"\ + " OR lower(\"users\".\"email\") LIKE ?", + "%тест test%", + "%тест test%", + ] + expect(User).to receive(:where).with(*expected_query) + + search.run + ensure + remove_constants :User + end + end end end