Skip to content

Commit e51beb6

Browse files
kellis5137awwaiid
andauthored
4948 - Fixing the sorting issues within parts of the app - part 1 of X (#5299)
* Adding resource_id sort fix and test * Fixed use of ids to be able to pass tests anywhere. * Modified to work for Postgres and not MySQL :-) * Moved and cleaned up rspec * fixing lint issue * Replace regex rspec test. --------- Co-authored-by: Brock Wilcox <awwaiid@thelackthereof.org>
1 parent 95cae51 commit e51beb6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

app/controllers/admin/users_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def resource_ids
6565
raise "Unknown resource type #{params[:resource_type]}"
6666
end
6767

68-
objects = klass.where("name LIKE ?", "%#{params[:q]}%").select(:id, :name)
68+
objects = klass.where("name ILIKE ?", "%#{params[:q]}%").order("lower(name)").select(:id, :name)
6969
object_json = objects.map do |obj|
7070
{
7171
id: obj.id,

spec/requests/admin/users_requests_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
before do
1010
sign_in(super_admin)
1111
AddRoleService.call(user_id: user.id, resource_type: Role::PARTNER, resource_id: partner.id)
12+
create(:organization, name: "Pawnee")
13+
create(:organization, name: "SF Diaper")
14+
create(:organization, name: "Second City")
1215
end
1316

1417
describe "GET #index" do
@@ -237,6 +240,15 @@
237240
end
238241
end
239242
end
243+
describe "Validate Order of returned organization list" do
244+
it "Should sort display resource in human alphabetical order" do
245+
get "/admin/users/resource_ids?resource_type=org_admin"
246+
body_json = JSON.parse(response.body)
247+
expect(body_json["results"].length).to be(4)
248+
text_list = body_json["results"].map { |obj| obj["text"] }
249+
expect(text_list).to match_array(["Org ABC", "Pawnee", "SF Diaper", "Second City"])
250+
end
251+
end
240252
end
241253

242254
describe 'POST #resend_invitation' do

0 commit comments

Comments
 (0)