Browse Source

convert to use values that won't change for checks

pull/775/head
Dushan Despotovic 3 years ago committed by Kat
parent
commit
6e003f6bae
  1. 6
      app/controllers/schemes_controller.rb
  2. 2
      app/models/scheme.rb
  3. 2
      spec/features/schemes_spec.rb
  4. 2
      spec/requests/schemes_controller_spec.rb

6
app/controllers/schemes_controller.rb

@ -104,7 +104,7 @@ private
end
end
if @scheme.arrangement_type_same? && scheme_params[:arrangement_type] != "The same organisation that owns the housing stock"
if @scheme.arrangement_type_same? && scheme_params[:arrangement_type] != "D"
@scheme.errors.delete(:managing_organisation_id)
end
end
@ -191,11 +191,11 @@ private
end
def arrangement_type_set_to_same_org?(required_params)
required_params[:arrangement_type] == "The same organisation that owns the housing stock" || (required_params[:arrangement_type].blank? && @scheme.present? && @scheme.arrangement_type_same?)
required_params[:arrangement_type] == "D" || (required_params[:arrangement_type].blank? && @scheme.present? && @scheme.arrangement_type_same?)
end
def arrangement_type_changed_to_different_org?(required_params)
@scheme.present? && @scheme.arrangement_type_same? && required_params[:arrangement_type] != "The same organisation that owns the housing stock" && required_params[:managing_organisation_id].blank?
@scheme.present? && @scheme.arrangement_type_same? && required_params[:arrangement_type] != "D" && required_params[:managing_organisation_id].blank?
end
def search_term

2
app/models/scheme.rb

@ -203,6 +203,6 @@ class Scheme < ApplicationRecord
end
def arrangement_type_same?
arrangement_type == "The same organisation that owns the housing stock"
arrangement_type_before_type_cast == "D"
end
end

2
spec/features/schemes_spec.rb

@ -843,7 +843,7 @@ RSpec.describe "Schemes scheme Features" do
context "when selecting a scheme" do
let!(:user) { FactoryBot.create(:user, :data_coordinator, last_sign_in_at: Time.zone.now) }
let!(:schemes) { FactoryBot.create_list(:scheme, 5, owning_organisation: user.organisation, managing_organisation: user.organisation, arrangement_type: "The same organisation that owns the housing stock") }
let!(:schemes) { FactoryBot.create_list(:scheme, 5, owning_organisation: user.organisation, managing_organisation: user.organisation, arrangement_type: "D") }
let(:location) { FactoryBot.create(:location, scheme: schemes[2]) }
let!(:case_log) { FactoryBot.create(:case_log, created_by: user, needstype: 2) }

2
spec/requests/schemes_controller_spec.rb

@ -1043,7 +1043,7 @@ RSpec.describe SchemesController, type: :request do
scheme_type: "Foyer",
registered_under_care_act: "No",
page: "details",
arrangement_type: "The same organisation that owns the housing stock",
arrangement_type: "D",
owning_organisation_id: another_organisation.id } }
end

Loading…
Cancel
Save