From fb769d37f9ad0143cbaeff6ce79a1490e3fb7645 Mon Sep 17 00:00:00 2001 From: Tsara Sudrajat Date: Mon, 26 Oct 2020 11:13:54 +0700 Subject: [PATCH] Fix error when setting stock for new product --- spec/features/admin/products_spec.rb | 21 +++++++++++++++++++++ spec/models/spree/product_spec.rb | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/spec/features/admin/products_spec.rb b/spec/features/admin/products_spec.rb index 1549983e45..f77e9f092c 100644 --- a/spec/features/admin/products_spec.rb +++ b/spec/features/admin/products_spec.rb @@ -112,6 +112,27 @@ feature ' variant = product.variants.first expect(variant.on_demand).to be true end + + scenario "creating product with empty unit value", js: true do + login_as_admin_and_visit spree.admin_products_path + + click_link 'New Product' + + fill_in 'product_name', with: 'Hot Cakes' + select 'New supplier', from: 'product_supplier_id' + select "Weight (kg)", from: 'product_variant_unit_with_scale' + select taxon.name, from: "product_primary_taxon_id" + fill_in 'product_price', with: '1.99' + fill_in 'product_on_hand', with: 0 + check 'product_on_demand' + select 'Test Tax Category', from: 'product_tax_category_id' + page.find("div[id^='taTextElement']").native.send_keys('In demand, and on_demand! The hottest cakes in town.') + + click_button 'Create' + + expect(current_path).to eq spree.admin_products_path + expect(page).to have_content "Unit value can't be blank" + end end context "as an enterprise user" do diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index 919f5d2720..4a506e9210 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -247,6 +247,10 @@ module Spree expect(build(:simple_product, taxons: [], primary_taxon: nil)).not_to be_valid end + it "requires a unit value" do + expect(build(:simple_product, unit_value: nil)).not_to be_valid + end + it "requires a supplier" do expect(build(:simple_product, supplier: nil)).not_to be_valid end