Skip to content

Commit

Permalink
Merge pull request spree-contrib#71 from spark-solutions/sdp-286-emai…
Browse files Browse the repository at this point in the history
…l-errors

[SDP-286] Shows invalid email error only when email is present
  • Loading branch information
damianlegawiec authored Jun 9, 2020
2 parents 6e09fa6 + 0cf9cbd commit 9bacb32
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/spree/contact_us/contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class Contact
[^\s.@] # non-at-sign and non-period character
\z/x.freeze

validates :email, format: { with: EMAIL_REGEX },
presence: true
validates :email, presence: true
validates :email, format: { with: EMAIL_REGEX }, if: -> { email.present? }
validates :message, presence: true
validates :name, presence: { if: proc { SpreeContactUs.require_name } }
validates :subject, presence: { if: proc { SpreeContactUs.require_subject } }
Expand Down
16 changes: 16 additions & 0 deletions spec/features/spree_contact_us_lint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@
expect(page).to have_field('contact_us_contact_message')
expect(page).to have_button('Send')
end

it 'shows only invalid email error for email field' do
expect(page).not_to have_content "Email can't be blank"
end
end

context 'Email is blank' do
before do
fill_in 'Email', with: ''
fill_in 'Message', with: ''
click_button 'Send'
end

it 'shows only email blank error for email field' do
expect(page).not_to have_content 'Email is invalid'
end
end
end
end
Expand Down

0 comments on commit 9bacb32

Please sign in to comment.