From f17e34d7541a1fc63d3176c2258fefab293274cb Mon Sep 17 00:00:00 2001 From: koetsier Date: Mon, 27 Jan 2025 10:14:16 +0000 Subject: [PATCH] Remove condition on validate_in_register? in organisation model Since we use the DFE form builder, only one error per attribute is ever shown and so this condition can be removed. --- app/models/organisation.rb | 2 +- spec/models/organisation_spec.rb | 4 ++-- spec/models/user_membership_form_spec.rb | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/models/organisation.rb b/app/models/organisation.rb index b796a9d00..3cfdf039a 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -10,7 +10,7 @@ class Organisation < ApplicationRecord validates :name, presence: true, uniqueness: { case_sensitive: false } validates :service_email, format: { with: Devise.email_regexp } - validate :validate_in_register?, unless: proc { |org| org.name.blank? } + validate :validate_in_register? validates :cba_enabled, inclusion: { in: [true, false] }, allow_nil: true diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index 33ff58162..c69773f08 100644 --- a/spec/models/organisation_spec.rb +++ b/spec/models/organisation_spec.rb @@ -82,8 +82,8 @@ it "explains why it is invalid" do organisation.valid? - expect(organisation.errors.full_messages).to eq([ - "Name can't be blank", + expect(organisation.errors.full_messages).to match_array([ + "Name can't be blank", "Name isn't in the organisations allow list" ]) end end diff --git a/spec/models/user_membership_form_spec.rb b/spec/models/user_membership_form_spec.rb index 5f112775e..368bd4bba 100644 --- a/spec/models/user_membership_form_spec.rb +++ b/spec/models/user_membership_form_spec.rb @@ -63,7 +63,8 @@ it "copies the validations" do form.write_to(user) expect(form.errors.map(&:full_message)).to match_array(["Name can't be blank", - "Service email must be in the correct format, like name@example.com"]) + "Service email must be in the correct format, like name@example.com", + "Name isn't in the organisations allow list"]) end end end