Skip to content

Commit

Permalink
makes member searches accent insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
nflorentin committed Dec 7, 2023
1 parent b508d99 commit 78d0fb0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/views/users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="col-md-12">
<%= search_form_for(@search, class: "navbar-form navbar-left", url: users_path) do |f| %>
<div class="form-group">
<%= f.search_field :member_search_cont, value: params.dig(:q, :member_search_cont), class: "form-control" %>
<%= f.search_field :member_search_unaccent_cont, value: params.dig(:q, :member_search_unaccent_cont), class: "form-control" %>
</div>
<button class="btn btn-default" type="submit">
<%= t 'global.search' %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/manage.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="col-md-12">
<%= search_form_for(@search, class: "navbar-form navbar-left", url: manage_users_path) do |f| %>
<div class="form-group">
<%= f.search_field :member_search_cont, value: params.dig(:q, :member_search_cont), class: "form-control" %>
<%= f.search_field :member_search_unaccent_cont, value: params.dig(:q, :member_search_unaccent_cont), class: "form-control" %>
</div>
<button class="btn btn-default" type="submit">
<%= t 'global.search' %>
Expand Down
8 changes: 8 additions & 0 deletions config/initializers/ransack.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Ransack.configure do |config|
config.add_predicate 'unaccent_cont',
arel_predicate: 'matches',
formatter: proc { |s| ActiveSupport::Inflector.transliterate("%#{s}%") },
validator: proc { |s| s.present? },
compounds: true,
type: :string
end
12 changes: 7 additions & 5 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
user = Fabricate(:user, username: 'foo', email: '[email protected]')
member = Fabricate(:member, user: user, organization: test_organization, member_uid: 1000)

get :index, params: { q: { member_search_cont: 1000 } }
get :index, params: { q: { member_search_unaccent_cont: 1000 } }

expect(assigns(:members)).to include(member)
end
Expand All @@ -133,7 +133,7 @@
user = Fabricate(:user, username: 'foo', email: '[email protected]')
member = Fabricate(:member, user: user, organization: test_organization, member_uid: 1000, tags: ["Boss"])

get :index, params: { q: { member_search_cont: "Bos" } }
get :index, params: { q: { member_search_unaccent_cont: "Bos" } }

expect(assigns(:members)).to include(member)
end
Expand All @@ -151,8 +151,10 @@
user = Fabricate(:user, username: 'fôô', email: '[email protected]')
member = Fabricate(:member, user: user, organization: test_organization)

get :index, params: { q: { member_search_cont: "foo" } }
get :index, params: { q: { member_search_unaccent_cont: "foo" } }
expect(assigns(:members)).to include(member)

get :index, params: { q: { member_search_unaccent_cont: "föö" } }
expect(assigns(:members)).to include(member)
end
end
Expand Down Expand Up @@ -200,7 +202,7 @@
user = Fabricate(:user, phone: 123456789)
member = Fabricate(:member, user: user, organization: test_organization)

get :manage, params: { q: { member_search_cont: 123456789 } }
get :manage, params: { q: { member_search_unaccent_cont: 123456789 } }

expect(assigns(:members)).to include(member)
end
Expand All @@ -209,7 +211,7 @@
user = Fabricate(:user)
member = Fabricate(:member, user: user, organization: test_organization, member_uid: 1000, tags: ["Boss"])

get :index, params: { q: { member_search_cont: "Bos" } }
get :index, params: { q: { member_search_unaccent_cont: "Bos" } }

expect(assigns(:members)).to include(member)
end
Expand Down

0 comments on commit 78d0fb0

Please sign in to comment.