diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index 91f0420b6..50d2d989f 100644 --- a/app/controllers/schemes_controller.rb +++ b/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? && arrangement_type_value(scheme_params[:arrangement_type]) != "D" @scheme.errors.delete(:managing_organisation_id) end end @@ -191,11 +191,15 @@ 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?) + arrangement_type_value(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? && arrangement_type_value(required_params[:arrangement_type]) != "D" && required_params[:managing_organisation_id].blank? + end + + def arrangement_type_value(key) + key.present? ? Scheme::ARRANGEMENT_TYPE[key.to_sym] : nil end def search_term diff --git a/app/models/scheme.rb b/app/models/scheme.rb index 3ad3639f1..1af0a9b74 100644 --- a/app/models/scheme.rb +++ b/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.present? && ARRANGEMENT_TYPE[arrangement_type.to_sym] == "D" end end