Browse Source

CLDC-1854 Make schemes with 0 locations be incomplete rather than active (#1456)

* feat: update scheme status so incomplete unless has active locations

* feat: change active -> completed

* feat: change to confirmed to add clarification in code

* feat: fix tests

* refactor: rubocop

* feat: add tests for incomplete schemes

* refactor: linting

* refactor: simplify
pull/1477/head
natdeanlewissoftwire 2 years ago committed by GitHub
parent
commit
b5c2584a6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/models/location.rb
  2. 2
      app/models/scheme.rb
  3. 47
      spec/helpers/schemes_helper_spec.rb
  4. 1
      spec/models/scheme_spec.rb
  5. 2
      spec/models/validations/date_validations_spec.rb
  6. 2
      spec/models/validations/setup_validations_spec.rb
  7. 7
      spec/requests/schemes_controller_spec.rb

1
app/models/location.rb

@ -23,6 +23,7 @@ class Location < ApplicationRecord
scope :search_by, ->(param) { search_by_name(param).or(search_by_postcode(param)) } scope :search_by, ->(param) { search_by_name(param).or(search_by_postcode(param)) }
scope :started, -> { where("startdate <= ?", Time.zone.today).or(where(startdate: nil)) } scope :started, -> { where("startdate <= ?", Time.zone.today).or(where(startdate: nil)) }
scope :active, -> { where(confirmed: true).and(started) } scope :active, -> { where(confirmed: true).and(started) }
scope :confirmed, -> { where(confirmed: true) }
LOCAL_AUTHORITIES = LocalAuthority.all.map { |la| [la.name, la.code] }.to_h LOCAL_AUTHORITIES = LocalAuthority.all.map { |la| [la.name, la.code] }.to_h

2
app/models/scheme.rb

@ -235,7 +235,7 @@ class Scheme < ApplicationRecord
end end
def status_at(date) def status_at(date)
return :incomplete unless confirmed return :incomplete unless confirmed && locations.confirmed.any?
return :deactivated if open_deactivation&.deactivation_date.present? && date >= open_deactivation.deactivation_date return :deactivated if open_deactivation&.deactivation_date.present? && date >= open_deactivation.deactivation_date
return :deactivating_soon if open_deactivation&.deactivation_date.present? && date < open_deactivation.deactivation_date return :deactivating_soon if open_deactivation&.deactivation_date.present? && date < open_deactivation.deactivation_date
return :reactivating_soon if recent_deactivation&.reactivation_date.present? && date < recent_deactivation.reactivation_date return :reactivating_soon if recent_deactivation&.reactivation_date.present? && date < recent_deactivation.reactivation_date

47
spec/helpers/schemes_helper_spec.rb

@ -110,6 +110,52 @@ RSpec.describe SchemesHelper do
let(:support_user) { FactoryBot.create(:user, :support) } let(:support_user) { FactoryBot.create(:user, :support) }
let(:coordinator_user) { FactoryBot.create(:user, :data_coordinator) } let(:coordinator_user) { FactoryBot.create(:user, :data_coordinator) }
context "when scheme has no locations" do
it "returns correct display attributes for a support user" do
attributes = [
{ name: "Scheme code", value: "S#{scheme.id}" },
{ name: "Name", value: "Test service_name", edit: true },
{ name: "Confidential information", value: "No", edit: true },
{ name: "Type of scheme", value: "Housing for older people" },
{ name: "Registered under Care Standards Act 2000", value: "Yes – registered care home providing personal care" },
{ name: "Housing stock owned by", value: "Acme LTD Owning", edit: true },
{ name: "Support services provided by", value: "A registered charity or voluntary organisation" },
{ name: "Primary client group", value: "Rough sleepers" },
{ name: "Has another client group", value: "Yes" },
{ name: "Secondary client group", value: "Refugees (permanent)" },
{ name: "Level of support given", value: "High level" },
{ name: "Intended length of stay", value: "Permanent" },
{ name: "Availability", value: "Active from 1 April 2022" },
{ name: "Status", value: status_tag(:incomplete) },
]
expect(display_scheme_attributes(scheme, support_user)).to eq(attributes)
end
it "returns correct display attributes for a coordinator user" do
attributes = [
{ name: "Scheme code", value: "S#{scheme.id}" },
{ name: "Name", value: "Test service_name", edit: true },
{ name: "Confidential information", value: "No", edit: true },
{ name: "Type of scheme", value: "Housing for older people" },
{ name: "Registered under Care Standards Act 2000", value: "Yes – registered care home providing personal care" },
{ name: "Support services provided by", value: "A registered charity or voluntary organisation" },
{ name: "Primary client group", value: "Rough sleepers" },
{ name: "Has another client group", value: "Yes" },
{ name: "Secondary client group", value: "Refugees (permanent)" },
{ name: "Level of support given", value: "High level" },
{ name: "Intended length of stay", value: "Permanent" },
{ name: "Availability", value: "Active from 1 April 2022" },
{ name: "Status", value: status_tag(:incomplete) },
]
expect(display_scheme_attributes(scheme, coordinator_user)).to eq(attributes)
end
end
context "when scheme has a location" do
before do
FactoryBot.create(:location, scheme:)
end
it "returns correct display attributes for a support user" do it "returns correct display attributes for a support user" do
attributes = [ attributes = [
{ name: "Scheme code", value: "S#{scheme.id}" }, { name: "Scheme code", value: "S#{scheme.id}" },
@ -272,4 +318,5 @@ RSpec.describe SchemesHelper do
end end
end end
end end
end
end end

1
spec/models/scheme_spec.rb

@ -96,6 +96,7 @@ RSpec.describe Scheme, type: :model do
let(:scheme) { FactoryBot.build(:scheme) } let(:scheme) { FactoryBot.build(:scheme) }
before do before do
FactoryBot.create(:location, scheme:)
Timecop.freeze(2022, 6, 7) Timecop.freeze(2022, 6, 7)
end end

2
spec/models/validations/date_validations_spec.rb

@ -165,6 +165,7 @@ RSpec.describe Validations::DateValidations do
let(:scheme) { create(:scheme) } let(:scheme) { create(:scheme) }
before do before do
FactoryBot.create(:location, scheme:)
create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:)
scheme.reload scheme.reload
end end
@ -189,6 +190,7 @@ RSpec.describe Validations::DateValidations do
let(:scheme) { create(:scheme) } let(:scheme) { create(:scheme) }
before do before do
FactoryBot.create(:location, scheme:)
create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:)
create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 2), reactivation_date: Time.zone.local(2022, 8, 3), scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 2), reactivation_date: Time.zone.local(2022, 8, 3), scheme:)
create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), scheme:)

2
spec/models/validations/setup_validations_spec.rb

@ -188,6 +188,7 @@ RSpec.describe Validations::SetupValidations do
let(:scheme) { create(:scheme, created_at: Time.zone.local(2022, 4, 1)) } let(:scheme) { create(:scheme, created_at: Time.zone.local(2022, 4, 1)) }
before do before do
FactoryBot.create(:location, scheme:)
create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:)
scheme.reload scheme.reload
end end
@ -212,6 +213,7 @@ RSpec.describe Validations::SetupValidations do
let(:scheme) { create(:scheme, created_at: Time.zone.local(2022, 4, 1)) } let(:scheme) { create(:scheme, created_at: Time.zone.local(2022, 4, 1)) }
before do before do
FactoryBot.create(:location, scheme:)
create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:)
create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 2), reactivation_date: Time.zone.local(2022, 8, 3), scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 2), reactivation_date: Time.zone.local(2022, 8, 3), scheme:)
create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), scheme:)

7
spec/requests/schemes_controller_spec.rb

@ -7,6 +7,12 @@ RSpec.describe SchemesController, type: :request do
let(:user) { FactoryBot.create(:user, :support) } let(:user) { FactoryBot.create(:user, :support) }
let!(:schemes) { FactoryBot.create_list(:scheme, 5) } let!(:schemes) { FactoryBot.create_list(:scheme, 5) }
before do
schemes.each do |scheme|
FactoryBot.create(:location, scheme:)
end
end
describe "#index" do describe "#index" do
context "when not signed in" do context "when not signed in" do
it "redirects to the sign in page" do it "redirects to the sign in page" do
@ -260,6 +266,7 @@ RSpec.describe SchemesController, type: :request do
let(:add_deactivations) { scheme.scheme_deactivation_periods << scheme_deactivation_period } let(:add_deactivations) { scheme.scheme_deactivation_periods << scheme_deactivation_period }
before do before do
FactoryBot.create(:location, scheme:)
Timecop.freeze(Time.utc(2022, 10, 10)) Timecop.freeze(Time.utc(2022, 10, 10))
sign_in user sign_in user
add_deactivations add_deactivations

Loading…
Cancel
Save