Skip to content
2 changes: 1 addition & 1 deletion app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def resource_ids
raise "Unknown resource type #{params[:resource_type]}"
end

objects = klass.where("name LIKE ?", "%#{params[:q]}%").select(:id, :name)
objects = klass.where("name ILIKE ?", "%#{params[:q]}%").order("lower(name)").select(:id, :name)
object_json = objects.map do |obj|
{
id: obj.id,
Expand Down
12 changes: 12 additions & 0 deletions spec/requests/admin/users_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
before do
sign_in(super_admin)
AddRoleService.call(user_id: user.id, resource_type: Role::PARTNER, resource_id: partner.id)
create(:organization, name: "Pawnee")
create(:organization, name: "SF Diaper")
create(:organization, name: "Second City")
end

describe "GET #index" do
Expand Down Expand Up @@ -237,6 +240,15 @@
end
end
end
describe "Validate Order of returned organization list" do
it "Should sort display resource in human alphabetical order" do
get "/admin/users/resource_ids?resource_type=org_admin"
body_json = JSON.parse(response.body)
expect(body_json["results"].length).to be(4)
text_list = body_json["results"].map { |obj| obj["text"] }
expect(text_list).to match_array(["Org ABC", "Pawnee", "SF Diaper", "Second City"])
end
end
end

describe 'POST #resend_invitation' do
Expand Down