From 8247dce2dcbc816e4b445cdc3a10f69912e0eb06 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 22 May 2023 20:20:09 +0100 Subject: [PATCH] Improve validation feedback on new variant page and add test coverage --- app/controllers/spree/admin/variants_controller.rb | 1 + spec/system/admin/variants_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/app/controllers/spree/admin/variants_controller.rb b/app/controllers/spree/admin/variants_controller.rb index ad82fb5461..078554953f 100644 --- a/app/controllers/spree/admin/variants_controller.rb +++ b/app/controllers/spree/admin/variants_controller.rb @@ -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 diff --git a/spec/system/admin/variants_spec.rb b/spec/system/admin/variants_spec.rb index df0d4326b3..d843f4c4ae 100644 --- a/spec/system/admin/variants_spec.rb +++ b/spec/system/admin/variants_spec.rb @@ -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