Skip to content

Commit

Permalink
Remove condition on validate_in_register? in organisation model
Browse files Browse the repository at this point in the history
Since we use the DFE form builder, only one error per attribute is
ever shown and so this condition can be removed.
  • Loading branch information
koetsier committed Jan 28, 2025
1 parent 0afc661 commit f17e34d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/models/organisation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions spec/models/organisation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion spec/models/user_membership_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f17e34d

Please sign in to comment.