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
20 changes: 20 additions & 0 deletions spec/system/admin/users_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,24 @@
end
end
end

describe "Resourse Dropdown List: Validate Order" do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change this to a request spec? System specs are slow and flaky and should only be used if there needs to be browser / JavaScript interaction.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dorner Take a look now and let me know if that looks better

before do
sign_in(super_admin)
end

it "Should sort display resource in human alphabetical order" do
FactoryBot.create(:organization, id: 2, name: "Pawnee")
FactoryBot.create(:organization, id: 3, name: "SF Diaper")
FactoryBot.create(:organization, id: 4, name: "Second City")

# params
# - resource_type - Organization, Resource
# - q - query string
# visit admin_users_resource_ids_path # (name: "Organization", q: "")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty basic Rails info and I don't think we need a comment for it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dorner Take a look now and let me know if that looks better


visit "/admin/users/resource_ids?resource_type=org_admin"
expect(page).to have_content("{\"id\":2,\"text\":\"Pawnee\"},{\"id\":4,\"text\":\"Second City\"},{\"id\":3,\"text\":\"SF Diaper\"}")
end
end
end