Browse Source

Extract scopes and remove wrong test

pull/1039/head
Kat 4 years ago
parent
commit
c4af7c456d
  1. 2
      app/controllers/organisations_controller.rb
  2. 2
      app/controllers/schemes_controller.rb
  3. 3
      app/models/scheme.rb
  4. 18
      spec/models/scheme_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).order("confirmed ASC NULLS FIRST", service_name: :asc) 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 NULLS FIRST", 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

18
spec/models/scheme_spec.rb

@ -176,24 +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)
FactoryBot.create_list(:scheme, 2, confirmed: nil)
end
it "can sort the schemes by status" do
all_schemes = described_class.all.order("confirmed ASC NULLS FIRST", service_name: :asc)
expect(all_schemes.count).to eq(9)
expect(all_schemes[0].status).to eq(:incomplete)
expect(all_schemes[1].status).to eq(:incomplete)
expect(all_schemes[2].status).to eq(:incomplete)
expect(all_schemes[3].status).to eq(:incomplete)
expect(all_schemes[4].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)) }

Loading…
Cancel
Save