Re-implement the member_uid searcher by avoiding the column casting thing (gives some problems when sorting the "casted" column as an string). The new strategy: rename the ransacker so the cast only happens when filtering

This commit is contained in:
Marc Anguera Insa
2018-08-15 17:40:07 +02:00
parent c4fb4aa295
commit fc3fa27c6c
3 changed files with 4 additions and 4 deletions

View File

@ -1,7 +1,7 @@
class Member < ActiveRecord::Base
# Cast the member_uid integer to a string to allow pg ILIKE search (from Ransack *_contains)
ransacker :member_uid do
Arel.sql("to_char(member_uid, '9999999')")
ransacker :member_uid_search do
Arel.sql("member_uid::text")
end
belongs_to :user

View File

@ -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 :user_username_or_user_email_or_member_uid_contains, class: "form-control" %>
<%= f.search_field :user_username_or_user_email_or_member_uid_search_contains, class: "form-control" %>
</div>
<button class="btn btn-default" type="submit">
<%= t 'global.search' %>

View File

@ -133,7 +133,7 @@ describe UsersController do
user = Fabricate(:user, username: 'foo', email: 'foo@email.com')
member = Fabricate(:member, user: user, organization: test_organization, member_uid: 1000)
get :index, q: { user_username_or_user_email_or_member_uid_contains: 1000 }
get :index, q: { user_username_or_user_email_or_member_uid_search_contains: 1000 }
expect(assigns(:members)).to include(member)
end