mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Improve validation feedback on new variant page and add test coverage
This commit is contained in:
@@ -43,6 +43,7 @@ module Spree
|
||||
flash[:success] = flash_message_for(@object, :successfully_created)
|
||||
redirect_to spree.admin_product_variants_url(params[:product_id], @url_filters)
|
||||
else
|
||||
flash[:error] = @object.errors.full_messages.to_sentence if @object.errors.any?
|
||||
redirect_to spree.new_admin_product_variant_url(params[:product_id], @url_filters)
|
||||
end
|
||||
|
||||
|
||||
@@ -60,11 +60,24 @@ describe '
|
||||
|
||||
# Expect variant_weight to accept 3 decimal places
|
||||
fill_in 'variant_weight', with: '1.234'
|
||||
fill_in 'unit_value_human', with: 1
|
||||
click_button 'Create'
|
||||
|
||||
# Then the variant should have been created
|
||||
expect(page).to have_content "Variant \"#{product.name}\" has been successfully created!"
|
||||
end
|
||||
|
||||
it "show validation errors if present" do
|
||||
product = create(:simple_product, variant_unit: "volume", variant_unit_scale: "1")
|
||||
login_as_admin
|
||||
visit spree.admin_product_variants_path product
|
||||
click_link 'New Variant'
|
||||
|
||||
fill_in 'unit_value_human', with: 0
|
||||
click_button 'Create'
|
||||
|
||||
expect(page).to have_content "Unit value must be greater than 0"
|
||||
end
|
||||
end
|
||||
|
||||
describe "viewing product variant" do
|
||||
|
||||
Reference in New Issue
Block a user