From 55a8ad4b448895e27bff970d2ad4c77569d4276b Mon Sep 17 00:00:00 2001 From: jacobherrington Date: Fri, 7 Sep 2018 16:03:51 -0500 Subject: [PATCH 1/4] allow multiple taxons on product creation --- .../spree/admin/products_controller.rb | 16 ++++++++++------ .../spree/admin/products_controller_spec.rb | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/backend/app/controllers/spree/admin/products_controller.rb b/backend/app/controllers/spree/admin/products_controller.rb index 160ab8c2a31..ffffde186a7 100644 --- a/backend/app/controllers/spree/admin/products_controller.rb +++ b/backend/app/controllers/spree/admin/products_controller.rb @@ -8,6 +8,7 @@ class ProductsController < ResourceController before_action :load_data, except: [:index] update.before :update_before helper_method :clone_object_url + before_action :split_params, only: [:create, :update] def show redirect_to action: :edit @@ -19,12 +20,6 @@ def index end def update - if params[:product][:taxon_ids].present? - params[:product][:taxon_ids] = params[:product][:taxon_ids].split(',') - end - if params[:product][:option_type_ids].present? - params[:product][:option_type_ids] = params[:product][:option_type_ids].split(',') - end if updating_variant_property_rules? params[:product][:variant_property_rules_attributes].each do |_index, param_attrs| param_attrs[:option_value_ids] = param_attrs[:option_value_ids].split(',') @@ -73,6 +68,15 @@ def clone private + def split_params + if params[:product][:taxon_ids].present? + params[:product][:taxon_ids] = params[:product][:taxon_ids].split(',') + end + if params[:product][:option_type_ids].present? + params[:product][:option_type_ids] = params[:product][:option_type_ids].split(',') + end + end + def find_resource Spree::Product.with_deleted.friendly.find(params[:id]) end diff --git a/backend/spec/controllers/spree/admin/products_controller_spec.rb b/backend/spec/controllers/spree/admin/products_controller_spec.rb index d6713527616..3cf12785766 100644 --- a/backend/spec/controllers/spree/admin/products_controller_spec.rb +++ b/backend/spec/controllers/spree/admin/products_controller_spec.rb @@ -50,6 +50,23 @@ end end + # regression test for https://github.com/spree/spree/issues/2791 + context "adding taxons to a product" do + let!(:product) { create(:product) } + let!(:first_taxon) { create(:taxon) } + let!(:second_taxon) { create(:taxon) } + + it "adds a single taxon to a product" do + put :update, params: { id: product.to_param, product: { taxon_ids: first_taxon.id.to_s } } + expect(flash[:success]).to eq("Product #{product.name.inspect} has been successfully updated!") + end + + it "adds multiple taxons to a product" do + put :update, params: { id: product.to_param, product: { taxon_ids: "#{first_taxon.id}, #{second_taxon.id}" } } + expect(flash[:success]).to eq("Product #{product.name.inspect} has been successfully updated!") + end + end + describe "creating variant property rules" do let(:first_property) { create(:property) } let(:second_property) { create(:property) } From f55dfece839d0f795efbc32bf5da277645dee367 Mon Sep 17 00:00:00 2001 From: jacobherrington Date: Mon, 10 Sep 2018 17:43:38 -0500 Subject: [PATCH 2/4] improve test code quality by moving unecessary let --- .../spree/admin/products_controller_spec.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/backend/spec/controllers/spree/admin/products_controller_spec.rb b/backend/spec/controllers/spree/admin/products_controller_spec.rb index 3cf12785766..a43263b861d 100644 --- a/backend/spec/controllers/spree/admin/products_controller_spec.rb +++ b/backend/spec/controllers/spree/admin/products_controller_spec.rb @@ -52,18 +52,21 @@ # regression test for https://github.com/spree/spree/issues/2791 context "adding taxons to a product" do - let!(:product) { create(:product) } - let!(:first_taxon) { create(:taxon) } - let!(:second_taxon) { create(:taxon) } + let(:product) { create(:product) } + let(:first_taxon) { create(:taxon) } it "adds a single taxon to a product" do put :update, params: { id: product.to_param, product: { taxon_ids: first_taxon.id.to_s } } expect(flash[:success]).to eq("Product #{product.name.inspect} has been successfully updated!") end - it "adds multiple taxons to a product" do - put :update, params: { id: product.to_param, product: { taxon_ids: "#{first_taxon.id}, #{second_taxon.id}" } } - expect(flash[:success]).to eq("Product #{product.name.inspect} has been successfully updated!") + context "when there are mulitple taxons" do + let(:second_taxon) { create(:taxon) } + + it "adds multiple taxons to a product" do + put :update, params: { id: product.to_param, product: { taxon_ids: "#{first_taxon.id}, #{second_taxon.id}" } } + expect(flash[:success]).to eq("Product #{product.name.inspect} has been successfully updated!") + end end end From 320c17891fe423f0d5e341998ea4d03f27978ed1 Mon Sep 17 00:00:00 2001 From: jacobherrington Date: Thu, 13 Sep 2018 11:33:52 -0500 Subject: [PATCH 3/4] add tests for creating products with taxons --- .../spree/admin/products_controller_spec.rb | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/backend/spec/controllers/spree/admin/products_controller_spec.rb b/backend/spec/controllers/spree/admin/products_controller_spec.rb index a43263b861d..17c1cbf7a33 100644 --- a/backend/spec/controllers/spree/admin/products_controller_spec.rb +++ b/backend/spec/controllers/spree/admin/products_controller_spec.rb @@ -51,6 +51,58 @@ end # regression test for https://github.com/spree/spree/issues/2791 + context "creating a product" do + before(:all) do + create(:shipping_category) + end + + it "creates a product" do + post :create, params: { + product: { + name: "Product #1 - 9632", + description: "As seen on TV!", + price: 19.99, + shipping_category_id: Spree::ShippingCategory.first.id, + } + } + expect(flash[:success]).to eq("Product \"Product #1 - 9632\" has been successfully created!") + end + + context "when there is a taxon" do + let(:first_taxon) { create(:taxon) } + + it "creates a product with a taxon" do + post :create, params: { + product: { + name: "Product #1 - 9632", + description: "As seen on TV!", + price: 19.99, + shipping_category_id: Spree::ShippingCategory.first.id, + taxon_ids: first_taxon.id.to_s + } + } + expect(flash[:success]).to eq("Product \"Product #1 - 9632\" has been successfully created!") + end + + context "when their are multiple taxons" do + let(:second_taxon) { create(:taxon) } + + it "creates a product with multiple taxons" do + post :create, params: { + product: { + name: "Product #1 - 9632", + description: "As seen on TV!", + price: 19.99, + shipping_category_id: Spree::ShippingCategory.first.id, + taxon_ids: "#{first_taxon.id}, #{second_taxon.id}" + } + } + expect(flash[:success]).to eq("Product \"Product #1 - 9632\" has been successfully created!") + end + end + end + end + context "adding taxons to a product" do let(:product) { create(:product) } let(:first_taxon) { create(:taxon) } From 016d8f8e91dfcddd2824af7e735861409668166b Mon Sep 17 00:00:00 2001 From: jacobherrington Date: Thu, 13 Sep 2018 11:40:42 -0500 Subject: [PATCH 4/4] fix typo in comment --- .../spec/controllers/spree/admin/products_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/spec/controllers/spree/admin/products_controller_spec.rb b/backend/spec/controllers/spree/admin/products_controller_spec.rb index 17c1cbf7a33..2592f0322f8 100644 --- a/backend/spec/controllers/spree/admin/products_controller_spec.rb +++ b/backend/spec/controllers/spree/admin/products_controller_spec.rb @@ -50,7 +50,7 @@ end end - # regression test for https://github.com/spree/spree/issues/2791 + # regression test for https://github.com/solidusio/solidus/issues/2791 context "creating a product" do before(:all) do create(:shipping_category)