Merge pull request #8692 from jibees/8691-make-first-name-and-last-name-fields-mandatory

Validate the presence of first/last name if there is no company
This commit is contained in:
Filipe
2022-01-12 19:48:35 +00:00
committed by GitHub
2 changed files with 6 additions and 4 deletions

View File

@@ -15,7 +15,9 @@ module Spree
validates :address1, :city, :country, :phone, presence: true
validates :company, presence: true, unless: -> { first_name.blank? || last_name.blank? }
validates :firstname, :lastname, presence: true, unless: -> { company.present? }
validates :firstname, :lastname, presence: true, if: -> do
company.blank? || company == 'unused'
end
validates :zipcode, presence: true, if: :require_zipcode?
validate :state_validate

View File

@@ -68,9 +68,9 @@ describe "As a consumer, I want to checkout my order", js: true do
it "should display error when fields are empty" do
click_button "Next - Payment method"
expect(page).to have_content("Saving failed, please update the highlighted fields")
expect(page).to have_css 'span.field_with_errors label', count: 4
expect(page).to have_css 'span.field_with_errors input', count: 4
expect(page).to have_css 'span.formError', count: 5
expect(page).to have_css 'span.field_with_errors label', count: 6
expect(page).to have_css 'span.field_with_errors input', count: 6
expect(page).to have_css 'span.formError', count: 7
end
it "should validate once each needed field is filled" do