Skip to content

Commit

Permalink
Update validation message tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vertism committed Sep 23, 2024
1 parent bf5ead4 commit 637ac29
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 21 deletions.
2 changes: 0 additions & 2 deletions app/models/correspondence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class Correspondence < ApplicationRecord
validates :email, presence: { message: "Email can't be blank" }
validates :message, presence: { message: "Your message can't be blank" }

validates :email, confirmation: { case_sensitive: false }

validates :email, format: { with: /\A.*@.*\z/,
message: "Email is invalid",
if: proc { email.present? } }
Expand Down
1 change: 0 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ en:
label:
correspondence:
name: Full name
email_confirmation: Confirm email
message: |
Your message
topic:
Expand Down
2 changes: 0 additions & 2 deletions spec/controllers/correspondence_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
{
name: external_user.name,
email: external_user.email,
email_confirmation: external_user.email,
topic: "prisons and probations",
message: "Question about prisons and probation",
}
Expand Down Expand Up @@ -159,7 +158,6 @@
{
# no name
email: external_user.email,
email_confirmation: external_user.email,
topic: "prisons and probations",
message: "Question about prisons and probation",
}
Expand Down
1 change: 0 additions & 1 deletion spec/factories/correspondence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
factory :correspondence do
name { Faker::Name.name }
email { Faker::Internet.email }
email_confirmation { email }
category { "general_enquiries" }
topic { (Faker::Hipster.sentence word_count: 4, supplemental: false, random_words_to_add: 2)[0..59] }
message { Faker::Lorem.paragraph(sentence_count: 1) }
Expand Down
22 changes: 7 additions & 15 deletions spec/models/correspondence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,11 @@
end

describe "validations" do
it { is_expected.to validate_presence_of :name }
it { is_expected.to validate_presence_of :email }
it { is_expected.to validate_presence_of :category }

it do
expect(correspondence).to validate_presence_of(:topic)
.with_message(
"can't be blank",
)
end

it { is_expected.to validate_presence_of :message }
it { is_expected.to validate_confirmation_of :email }
it { is_expected.to validate_presence_of(:name).with_message("Full name can't be blank") }
it { is_expected.to validate_presence_of(:email).with_message("Email can't be blank") }
it { is_expected.to validate_presence_of :category }
it { is_expected.to validate_presence_of(:topic).with_message("can't be blank") }
it { is_expected.to validate_presence_of(:message).with_message("Your message can't be blank") }

it do
expect(correspondence).to validate_inclusion_of(:category)
Expand All @@ -87,7 +79,7 @@
it { is_expected.to allow_value("[email protected]").for :email }
it { is_expected.not_to allow_value("foobar.com").for :email }
it { is_expected.to validate_length_of(:topic).is_at_most(60) }
it { is_expected.to validate_length_of(:message).is_at_most(5000) }
it { is_expected.to validate_length_of(:message).is_at_most(5000).with_message("Message is too long (maximum is 5000 characters)") }

it { is_expected.to validate_inclusion_of(:contact_requested).in_array(%w[yes no]) }
end
Expand Down Expand Up @@ -115,7 +107,7 @@

it "has an error messages" do
correspondence.topic_present?
expect(correspondence.errors[:topic]).to eq [" can't be blank"]
expect(correspondence.errors[:topic]).to eq ["What are you contacting the Ministry of Justice about? can't be blank"]
end
end
end
Expand Down

0 comments on commit 637ac29

Please sign in to comment.