From 43cacfc2fcc497609757efdd3108f0b56fa139a1 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Wed, 12 Dec 2018 12:57:43 +0100 Subject: [PATCH] Fix redirection on admin/products controller specs In Spree v2.0 the product attributes being sent were no longer valid. Providing a shipping category and setting a stock location on the DB so that a stock item can be created fixes them. Remember `Variant#create_stock_item`, which is defined as an `after_create` callback, relies on `StockLocation` to create the item. --- .../spree/admin/products_controller_spec.rb | 53 +++++++------------ 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/spec/controllers/spree/admin/products_controller_spec.rb b/spec/controllers/spree/admin/products_controller_spec.rb index 35fdf054c4..de7275d4b2 100644 --- a/spec/controllers/spree/admin/products_controller_spec.rb +++ b/spec/controllers/spree/admin/products_controller_spec.rb @@ -74,46 +74,31 @@ describe Spree::Admin::ProductsController, type: :controller do end context "creating a new product" do - before { login_as_admin } + let(:supplier) { create(:supplier_enterprise) } + let(:taxon) { create(:taxon) } + let(:shipping_category) { create(:shipping_category) } + + let(:product_attrs) { + attributes_for(:product).merge( + shipping_category_id: shipping_category.id, + supplier_id: supplier.id, + primary_taxon_id: taxon.id + ) + } + + before do + login_as_admin + create(:stock_location) + end it "redirects to products when the user hits 'create'" do - s = create(:supplier_enterprise) - t = create(:taxon) - spree_post :create, { - product: { - name: "Product1", - supplier_id: s.id, - price: 5.0, - on_hand: 5, - variant_unit: 'weight', - variant_unit_scale: 1000, - unit_value: 10, - unit_description: "", - primary_taxon_id: t.id - }, - button: 'create' - } + spree_post :create, { product: product_attrs, button: 'create' } response.should redirect_to spree.admin_products_path end it "redirects to new when the user hits 'add_another'" do - s = create(:supplier_enterprise) - t = create(:taxon) - spree_post :create, { - product: { - name: "Product1", - supplier_id: s.id, - price: 5.0, - on_hand: 5, - variant_unit: 'weight', - variant_unit_scale: 1000, - unit_value: 10, - unit_description: "", - primary_taxon_id: t.id - }, - button: 'add_another' - } - response.should redirect_to "/admin/products/new" + spree_post :create, { product: product_attrs, button: 'add_another' } + response.should redirect_to spree.new_admin_product_path end end