Skip to content

Commit 0999e16

Browse files
authored
Adding resource_id sort fix and test
1 parent fefbaf3 commit 0999e16

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-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 LIKE ?", "%#{params[:q]}%").select(:id, :name).order(:name)
6969
object_json = objects.map do |obj|
7070
{
7171
id: obj.id,

spec/system/admin/users_system_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,24 @@
167167
end
168168
end
169169
end
170+
171+
describe "Resourse Dropdown List: Validate Order" do
172+
before do
173+
sign_in(super_admin)
174+
end
175+
176+
it "Should sort display resource in human alphabetical order" do
177+
FactoryBot.create(:organization, name: "Pawnee")
178+
FactoryBot.create(:organization, name: "SF Diaper")
179+
FactoryBot.create(:organization, name: "Second City")
180+
181+
# params
182+
# - resource_type - Organization, Resource
183+
# - q - query string
184+
# visit admin_users_resource_ids_path # (name: "Organization", q: "")
185+
186+
visit "/admin/users/resource_ids?resource_type=org_admin"
187+
expect(page).to have_content("{\"id\":2,\"text\":\"Pawnee\"},{\"id\":4,\"text\":\"Second City\"},{\"id\":3,\"text\":\"SF Diaper\"}")
188+
end
189+
end
170190
end

0 commit comments

Comments
 (0)