Skip to content

Commit

Permalink
Merge pull request #314 from ministryofjustice/feature/RST-679-email-…
Browse files Browse the repository at this point in the history
…mandatory

Applicant has to fill the email
  • Loading branch information
zaparka authored Jan 10, 2018
2 parents 18e1203 + 8f7e431 commit 0aa3ec3
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/models/forms/contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Contact < Base

email_regex = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
validates :email,
format: { with: email_regex, allow_nil: true, allow_blank: true },
format: { with: email_regex },
length: { maximum: 99 }
validates :feedback_opt_in, inclusion: { in: [true, false] }

Expand Down
2 changes: 0 additions & 2 deletions app/views/questions/forms/_contact.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ fieldset
- if @form.errors[:email].any?
span.error-message#email = @form.errors[:email].join(' ')
= f.label :email, t('email_label', scope: @form.i18n_scope), class: 'form-label'
.hint
=t('optional')
= f.text_field :email, type: 'email', class: 'form-control'

.form-group
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ en:
forms/contact:
attributes:
email:
invalid: Enter a valid email address
invalid: Please enter a valid email address in the format [email protected]
too_long: Email must be less than 100 characters
phone:
blank: Enter your phone number
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/step_eighteen_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
step 'I enter a valid date of birth'
step 'I enter my full name'
step 'I enter my address with postcode'
step 'I click continue'
step 'I enter a valid email address'
end

Then(/^I should see '([^\"]*)'$/) do |step|
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/step_nineteen_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
step 'I enter a valid date of birth'
step 'I enter my full name'
step 'I enter my address with postcode'
step 'I click continue'
step 'I enter a valid email address'
step 'I click submit application and continue'
end

Expand Down
1 change: 0 additions & 1 deletion features/step_definitions/step_seventeen_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

When(/^I enter a valid email address$/) do
expect(step_seventeen_page.form_group[1].text).to have_content 'Email address'
expect(step_seventeen_page.hint.text).to eq '(Optional)'
step_seventeen_page.contact_email.set('[email protected]')
common_page.continue_button.click
end
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/step_twenty_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
step 'I enter a valid date of birth'
step 'I enter my full name'
step 'I enter my address with postcode'
step 'I click continue'
step 'I enter a valid email address'
step 'I click submit application and continue'
step 'I click continue'
end
Expand Down
2 changes: 1 addition & 1 deletion features/step_eighteen.feature
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Feature: Step eighteen page
| Date of birth |
| Full name |
| Address |
| Contact |
| Email |
And I should be able to go back and change my details:
| url |
| form_name |
Expand Down
2 changes: 1 addition & 1 deletion features/step_seventeen.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ Feature: Step seventeen page

Scenario: Continuing without supplying an email address
When I click continue
Then I go to step 18 summary
Then I remain on step 17
3 changes: 2 additions & 1 deletion spec/features/pages/contact_question_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

context 'completing the form correctly' do
before do
fill_in :contact_email, with: '[email protected]'
click_button 'Continue'
end

Expand All @@ -27,7 +28,7 @@
end

scenario 'I expect the fields to have specific errors' do
expect(page).to have_xpath('//span[@class="error-message"]', text: 'Enter a valid email address')
expect(page).to have_xpath('//span[@class="error-message"]', text: 'Please enter a valid email address in the format [email protected]')
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/features/pages/summary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
end

scenario 'I expect confirmation ' do
expect(page).to have_content 'ContactContact details not provided'
expect(page).to have_content 'Please enter a valid email address in the format [email protected]'
end
end

Expand Down
10 changes: 8 additions & 2 deletions spec/models/forms/contact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@
it { is_expected.not_to be_valid }
end

context 'when email is not given' do
context 'when email is empty string' do
let(:email) { '' }

it { is_expected.to be_valid }
it { is_expected.not_to be_valid }
end

context 'when email is nil' do
let(:email) { nil }

it { is_expected.not_to be_valid }
end
end

Expand Down

0 comments on commit 0aa3ec3

Please sign in to comment.