diff --git a/app/models/correspondence.rb b/app/models/correspondence.rb index 7304ceb4..03440fe9 100644 --- a/app/models/correspondence.rb +++ b/app/models/correspondence.rb @@ -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? } } diff --git a/config/locales/en.yml b/config/locales/en.yml index b8df6939..b39d2f93 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -31,7 +31,6 @@ en: label: correspondence: name: Full name - email_confirmation: Confirm email message: | Your message topic: diff --git a/spec/controllers/correspondence_controller_spec.rb b/spec/controllers/correspondence_controller_spec.rb index 4beafdbd..d7493bb7 100644 --- a/spec/controllers/correspondence_controller_spec.rb +++ b/spec/controllers/correspondence_controller_spec.rb @@ -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", } @@ -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", } diff --git a/spec/factories/correspondence.rb b/spec/factories/correspondence.rb index 4229fc57..73113624 100644 --- a/spec/factories/correspondence.rb +++ b/spec/factories/correspondence.rb @@ -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) } diff --git a/spec/models/correspondence_spec.rb b/spec/models/correspondence_spec.rb index 5c4d7eef..842ac141 100644 --- a/spec/models/correspondence_spec.rb +++ b/spec/models/correspondence_spec.rb @@ -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) @@ -87,7 +79,7 @@ it { is_expected.to allow_value("foo@bar.com").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 @@ -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