diff --git a/app/services/organization_update_service.rb b/app/services/organization_update_service.rb index 01eaa702b7..61c3a560d8 100644 --- a/app/services/organization_update_service.rb +++ b/app/services/organization_update_service.rb @@ -11,7 +11,6 @@ class << self # @return [Boolean] def update(organization, params) return false unless valid?(organization, params) - # return organization unless valid?(organization, params) if params.has_key?("partner_form_fields") @@ -45,17 +44,16 @@ def update_partner_flags(organization) def valid?(organization, params) fields_marked_for_disabling = FIELDS.select { |field| params[field] == "false" } - # Here we do a check: if applying the params for disabling request types to all # partners would mean any one partner would have all its request types disabled, # then we should not apply the params and return an error message. As per: # github.com/rubyforgood/human-essentials/issues/3264 - invalid_partner_names = find_invalid_partners(organization, fields_marked_for_disabling) + invalid_partner_names = find_invalid_partners(organization, fields_marked_for_disabling).map(&:name) if invalid_partner_names.empty? return true else - organization.errors.add(:base, "Please update #{invalid_partner_names.join(", ")}, so that they could make requests if you completed this change, then try again. Thank you.") + organization.errors.add(:base, "The following partners would be unable to make requests with this update: #{invalid_partner_names.join(", ")}") return false end end @@ -64,7 +62,7 @@ def find_invalid_partners(organization, fields_marked_for_disabling) #finds any partners who's request types will all be disabled organization.partners.select do |partner| all_fields_will_be_disabled?(partner, fields_marked_for_disabling) - end.map(&:name) + end end def all_fields_will_be_disabled?(partner, fields_marked_for_disabling) diff --git a/spec/services/organization_update_service_spec.rb b/spec/services/organization_update_service_spec.rb index ff102700ff..74868754b1 100644 --- a/spec/services/organization_update_service_spec.rb +++ b/spec/services/organization_update_service_spec.rb @@ -14,7 +14,7 @@ end context "when object is invalid" do - it "should not update, return false" do + it "should not update and return false" do params = {name: "A brand NEW NEW name", url: "something that IS NOT A URL"} described_class.update(organization, params) @@ -63,7 +63,7 @@ end it "should add an error message to the organization" do - expect(organization.errors.full_messages).to eq(["Please update #{partner_one.name}, so that they could make requests if you completed this change, then try again. Thank you."]) + expect(organization.errors.full_messages).to eq(["The following partners would be unable to make requests with this update: #{partner_one.name}"]) end end