Browse Source

Add sorting per org (#1039)

* Add sorting per org

* Pull out confirmed set to null because they're also not marked as confirmed

* Create relevant tests

* Extract scopes and remove wrong test
pull/1057/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
2cbb3080b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/controllers/organisations_controller.rb
  2. 2
      app/controllers/schemes_controller.rb
  3. 3
      app/models/scheme.rb
  4. 15
      spec/models/scheme_spec.rb
  5. 11
      spec/requests/organisations_controller_spec.rb
  6. 11
      spec/requests/schemes_controller_spec.rb

2
app/controllers/organisations_controller.rb

@ -19,7 +19,7 @@ class OrganisationsController < ApplicationController
end end
def schemes def schemes
all_schemes = Scheme.where(owning_organisation: @organisation) all_schemes = Scheme.where(owning_organisation: @organisation).order_by_completion.order_by_service_name
@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

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.order(confirmed: :asc, service_name: :asc) all_schemes = Scheme.order_by_completion.order_by_service_name
@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

3
app/models/scheme.rb

@ -18,6 +18,9 @@ class Scheme < ApplicationRecord
.or(filter_by_id(param)).distinct .or(filter_by_id(param)).distinct
} }
scope :order_by_completion, -> { order("confirmed ASC NULLS FIRST") }
scope :order_by_service_name, -> { order(service_name: :asc) }
validate :validate_confirmed validate :validate_confirmed
auto_strip_attributes :service_name auto_strip_attributes :service_name

15
spec/models/scheme_spec.rb

@ -176,21 +176,6 @@ RSpec.describe Scheme, type: :model do
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
describe "available_from" do describe "available_from" do
context "when the scheme was created at the start of the 2022/23 collection window" do context "when the scheme was created at the start of the 2022/23 collection window" do
let(:scheme) { FactoryBot.build(:scheme, created_at: Time.zone.local(2022, 4, 6)) } let(:scheme) { FactoryBot.build(:scheme, created_at: Time.zone.local(2022, 4, 6)) }

11
spec/requests/organisations_controller_spec.rb

@ -123,6 +123,17 @@ RSpec.describe OrganisationsController, type: :request do
end end
end end
it "shows incomplete schemes at the top" do
schemes[0].update!(confirmed: nil, owning_organisation: user.organisation)
schemes[2].update!(confirmed: false, owning_organisation: user.organisation)
schemes[4].update!(confirmed: false, owning_organisation: user.organisation)
get "/organisations/#{organisation.id}/schemes", headers:, params: {}
expect(page.all(".govuk-tag")[1].text).to eq("Incomplete")
expect(page.all(".govuk-tag")[2].text).to eq("Incomplete")
expect(page.all(".govuk-tag")[3].text).to eq("Incomplete")
end
context "with schemes that are not in scope for the user, i.e. that they do not belong to" do context "with schemes that are not in scope for the user, i.e. that they do not belong to" do
let!(:unauthorised_organisation) { FactoryBot.create(:organisation) } let!(:unauthorised_organisation) { FactoryBot.create(:organisation) }

11
spec/requests/schemes_controller_spec.rb

@ -66,6 +66,17 @@ RSpec.describe SchemesController, type: :request do
assert_select ".govuk-tag", text: /Incomplete/, count: 1 assert_select ".govuk-tag", text: /Incomplete/, count: 1
end end
it "shows incomplete schemes at the top" do
schemes[0].update!(confirmed: nil)
schemes[2].update!(confirmed: false)
schemes[4].update!(confirmed: false)
get "/schemes"
expect(page.all(".govuk-tag")[1].text).to eq("Incomplete")
expect(page.all(".govuk-tag")[2].text).to eq("Incomplete")
expect(page.all(".govuk-tag")[3].text).to eq("Incomplete")
end
it "displays a link to check answers page if the scheme is incomplete" do it "displays a link to check answers page if the scheme is incomplete" do
scheme = schemes[0] scheme = schemes[0]
scheme.update!(confirmed: nil) scheme.update!(confirmed: nil)

Loading…
Cancel
Save