mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Remove ship_address errors if shipping method isn't selected
This commit is contained in:
@@ -49,7 +49,7 @@ class SplitCheckoutController < ::BaseController
|
||||
def render_error
|
||||
flash.now[:error] ||= I18n.t(
|
||||
'split_checkout.errors.saving_failed',
|
||||
messages: @order.errors.full_messages.to_sentence
|
||||
messages: order_error_messages
|
||||
)
|
||||
|
||||
render status: :unprocessable_entity, operations: cable_car.
|
||||
@@ -57,6 +57,21 @@ class SplitCheckoutController < ::BaseController
|
||||
replace("#flashes", partial("shared/flashes", locals: { flashes: flash }))
|
||||
end
|
||||
|
||||
def order_error_messages
|
||||
# Remove ship_address.* errors if no shipping method is not selected
|
||||
remove_ship_address_errors if @order.errors[:shipping_method].present?
|
||||
|
||||
end
|
||||
|
||||
def remove_ship_address_errors
|
||||
@order.errors.delete("ship_address.firstname")
|
||||
@order.errors.delete("ship_address.address1")
|
||||
@order.errors.delete("ship_address.city")
|
||||
@order.errors.delete("ship_address.phone")
|
||||
@order.errors.delete("ship_address.lastname")
|
||||
@order.errors.delete("ship_address.zipcode")
|
||||
end
|
||||
|
||||
def flash_error_when_no_shipping_method_available
|
||||
flash[:error] = I18n.t('split_checkout.errors.no_shipping_methods_available')
|
||||
end
|
||||
|
||||
@@ -187,6 +187,19 @@ describe "As a consumer, I want to checkout my order" do
|
||||
click_on "Checkout as guest"
|
||||
end
|
||||
|
||||
context "should show proper list of errors" do
|
||||
before do
|
||||
click_button "Next - Payment method"
|
||||
expect(page).to have_content "Saving failed, please update the highlighted fields."
|
||||
end
|
||||
|
||||
it "should not display any shipping errors messages when shipping method is not selected" do
|
||||
expect(page).not_to have_content "Shipping address line 1 can't be blank"
|
||||
expect(page).not_to have_content "Shipping address suburb 1 can't be blank"
|
||||
expect(page).not_to have_content "Shipping address postcode can't be blank"
|
||||
end
|
||||
end
|
||||
|
||||
it "should allow visit '/checkout/details'" do
|
||||
expect(page).to have_current_path("/checkout/details")
|
||||
end
|
||||
@@ -306,8 +319,6 @@ describe "As a consumer, I want to checkout my order" do
|
||||
click_button "Next - Payment method"
|
||||
|
||||
expect(page).to have_content "Saving failed, please update the highlighted fields."
|
||||
expect(page).to have_content "Shipping address line 1 can't be blank"
|
||||
expect(page).to have_content "Shipping address same as billing address?"
|
||||
expect(page).to have_content "Save as default shipping address"
|
||||
expect(page).to have_checked_field "Shipping address same as billing address?"
|
||||
end
|
||||
@@ -563,7 +574,7 @@ describe "As a consumer, I want to checkout my order" do
|
||||
end
|
||||
within ".flash[type='error']" do
|
||||
expect(page).to have_content("Saving failed, please update the highlighted fields")
|
||||
expect(page).to have_content("can't be blank", count: 13)
|
||||
expect(page).to have_content("can't be blank", count: 7)
|
||||
expect(page).to have_content("is invalid", count: 1)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user