Skip to content

Commit

Permalink
Add support for cyrillic search
Browse files Browse the repository at this point in the history
  • Loading branch information
dminchev committed May 9, 2017
1 parent eabd77e commit 5d2221c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/administrate/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions spec/lib/administrate/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5d2221c

Please sign in to comment.