diff --git a/lib/administrate/search.rb b/lib/administrate/search.rb index 2b7fa453b0..be204bdf1c 100644 --- a/lib/administrate/search.rb +++ b/lib/administrate/search.rb @@ -24,7 +24,7 @@ def query table_name = ActiveRecord::Base.connection. quote_table_name(@scoped_resource.table_name) attr_name = ActiveRecord::Base.connection.quote_column_name(attr) - "lower(#{table_name}.#{attr_name}) LIKE ?" + "LOWER(TEXT(#{table_name}.#{attr_name})) LIKE ?" end.join(" OR ") end diff --git a/spec/lib/administrate/search_spec.rb b/spec/lib/administrate/search_spec.rb index 9785ca5483..25a26feff1 100644 --- a/spec/lib/administrate/search_spec.rb +++ b/spec/lib/administrate/search_spec.rb @@ -1,5 +1,4 @@ -require "spec_helper" -require "support/constant_helpers" +require "rails_helper" require "administrate/field/string" require "administrate/field/email" require "administrate/field/number" @@ -45,7 +44,7 @@ class User < ActiveRecord::Base; end end end - it "searches using lower() + LIKE for all searchable fields" do + it "searches using LOWER + LIKE for all searchable fields" do begin class User < ActiveRecord::Base; end scoped_object = User.default_scoped @@ -53,8 +52,8 @@ class User < ActiveRecord::Base; end MockDashboard, "test") expected_query = [ - "lower(\"users\".\"name\") LIKE ?"\ - " OR lower(\"users\".\"email\") LIKE ?", + "LOWER(TEXT(\"users\".\"name\")) LIKE ?"\ + " OR LOWER(TEXT(\"users\".\"email\")) LIKE ?", "%test%", "%test%", ] @@ -66,7 +65,7 @@ class User < ActiveRecord::Base; end end end - it "converts search term lower case for latin and cyrillic strings" do + it "converts search term LOWER case for latin and cyrillic strings" do begin class User < ActiveRecord::Base; end scoped_object = User.default_scoped @@ -74,8 +73,8 @@ class User < ActiveRecord::Base; end MockDashboard, "Тест Test") expected_query = [ - "lower(\"users\".\"name\") LIKE ?"\ - " OR lower(\"users\".\"email\") LIKE ?", + "LOWER(TEXT(\"users\".\"name\")) LIKE ?"\ + " OR LOWER(TEXT(\"users\".\"email\")) LIKE ?", "%тест test%", "%тест test%", ]