Browse Source

Add a default ordering for schemes (#1030)

* Add a default ordering for schemes

* Move ordering back to the controller

* Update app/controllers/schemes_controller.rb

Co-authored-by: James Rose <james@jbpr.net>

Co-authored-by: James Rose <james@jbpr.net>
CLDC-1672-scheme-reactivation-review-app
kosiakkatrina 2 years ago committed by GitHub
parent
commit
41c726ce9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/controllers/schemes_controller.rb
  2. 15
      spec/models/scheme_spec.rb

2
app/controllers/schemes_controller.rb

@ -9,7 +9,7 @@ class SchemesController < ApplicationController
def index def index
redirect_to schemes_organisation_path(current_user.organisation) unless current_user.support? redirect_to schemes_organisation_path(current_user.organisation) unless current_user.support?
all_schemes = Scheme.all.order("service_name ASC") all_schemes = Scheme.order(confirmed: :asc, service_name: :asc)
@pagy, @schemes = pagy(filtered_collection(all_schemes, search_term)) @pagy, @schemes = pagy(filtered_collection(all_schemes, search_term))
@searched = search_term.presence @searched = search_term.presence

15
spec/models/scheme_spec.rb

@ -175,4 +175,19 @@ RSpec.describe Scheme, type: :model do
end end
end end
end end
describe "all schemes" do
before do
FactoryBot.create_list(:scheme, 4)
FactoryBot.create_list(:scheme, 3, confirmed: false)
end
it "can sort the schemes by status" do
all_schemes = described_class.all.order(confirmed: :asc, service_name: :asc)
expect(all_schemes.count).to eq(7)
expect(all_schemes[0].status).to eq(:incomplete)
expect(all_schemes[1].status).to eq(:incomplete)
expect(all_schemes[2].status).to eq(:incomplete)
end
end
end end

Loading…
Cancel
Save