From f710bbed3efd47795f0fa99026b321cc70bf77a3 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Sat, 13 Mar 2021 12:08:10 +0000 Subject: [PATCH] Convert calls to xhr to post or put with xhr: true --- .../admin/bulk_line_items_controller_spec.rb | 2 +- .../api/product_images_controller_spec.rb | 4 ++-- spec/controllers/cart_controller_spec.rb | 14 +++++++------- spec/controllers/enterprises_controller_spec.rb | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/spec/controllers/admin/bulk_line_items_controller_spec.rb b/spec/controllers/admin/bulk_line_items_controller_spec.rb index 4d94591a0e..cdc1d8c0cc 100644 --- a/spec/controllers/admin/bulk_line_items_controller_spec.rb +++ b/spec/controllers/admin/bulk_line_items_controller_spec.rb @@ -237,7 +237,7 @@ describe Admin::BulkLineItemsController, type: :controller do context "hub enterprise" do before do allow(controller).to receive_messages spree_current_user: distributor1.owner - xhr :put, :update, params + put :update, params: params, xhr: true end it "updates the line item" do diff --git a/spec/controllers/api/product_images_controller_spec.rb b/spec/controllers/api/product_images_controller_spec.rb index 95ee3bd3de..b4858ae49e 100644 --- a/spec/controllers/api/product_images_controller_spec.rb +++ b/spec/controllers/api/product_images_controller_spec.rb @@ -19,14 +19,14 @@ module Api let(:current_api_user) { create(:admin_user) } it "saves a new image when none is present" do - xhr :post, :update_product_image, product_id: product_without_image.id, file: image, use_route: :product_images + post :update_product_image, xhr: true, params: { product_id: product_without_image.id, file: image, use_route: :product_images } expect(response.status).to eq 201 expect(product_without_image.images.first.id).to eq json_response['id'] end it "updates an existing product image" do - xhr :post, :update_product_image, product_id: product_with_image.id, file: image, use_route: :product_images + post :update_product_image, xhr: true, params: { product_id: product_with_image.id, file: image, use_route: :product_images } expect(response.status).to eq 200 expect(product_with_image.images.first.id).to eq json_response['id'] diff --git a/spec/controllers/cart_controller_spec.rb b/spec/controllers/cart_controller_spec.rb index b3f6d46c8f..836f7fa5da 100644 --- a/spec/controllers/cart_controller_spec.rb +++ b/spec/controllers/cart_controller_spec.rb @@ -17,7 +17,7 @@ describe CartController, type: :controller do allow(cart_service).to receive(:populate) { true } allow(cart_service).to receive(:valid?) { true } allow(cart_service).to receive(:variants_h) { {} } - xhr :post, :populate, use_route: :spree, format: :json + post :populate, xhr: true, params: { use_route: :spree, format: :json } expect(response.status).to eq(200) end @@ -26,7 +26,7 @@ describe CartController, type: :controller do allow(cart_service).to receive(:valid?) { false } allow(cart_service).to receive(:errors) { errors } allow(errors).to receive(:full_messages).and_return(["Error: foo"]) - xhr :post, :populate, use_route: :spree, format: :json + post :populate, xhr: true, params: { use_route: :spree, format: :json } expect(response.status).to eq(412) end @@ -34,7 +34,7 @@ describe CartController, type: :controller do allow(cart_service).to receive(:variants_h) { {} } allow(cart_service).to receive(:valid?) { true } expect(cart_service).to receive(:populate).with({}, true) - xhr :post, :populate, use_route: :spree, format: :json + post :populate, xhr: true, params: { use_route: :spree, format: :json } end it "returns stock levels as JSON on success" do @@ -44,7 +44,7 @@ describe CartController, type: :controller do allow(cart_service).to receive(:valid?) { true } allow(cart_service).to receive(:variants_h) { {} } - xhr :post, :populate, use_route: :spree, format: :json + post :populate, xhr: true, params: { use_route: :spree, format: :json } data = JSON.parse(response.body) expect(data['stock_levels']).to eq('my_stock_levels') @@ -82,7 +82,7 @@ describe CartController, type: :controller do end it "returns the variant override stock levels of the variant in the order" do - spree_post :populate, variants: { variant_in_the_order.id => 1 } + spree_post :populate, params: { variants: { variant_in_the_order.id => 1 } } data = JSON.parse(response.body) expect(data['stock_levels'][variant_in_the_order.id.to_s]["on_hand"]).to eq 20 @@ -93,7 +93,7 @@ describe CartController, type: :controller do # If the variant was not added to the order, VariantsStockLevels alternative calculation would fail # See #3222 for more details # This indicates that the VariantsStockLevels alternative calculation is never reached - spree_post :populate, variants: { variant_not_in_the_order.id => 1 } + spree_post :populate, params: { variants: { variant_not_in_the_order.id => 1 } } data = JSON.parse(response.body) expect(data['stock_levels'][variant_not_in_the_order.id.to_s]["on_hand"]).to eq 7 @@ -114,7 +114,7 @@ describe CartController, type: :controller do allow(controller).to receive(:current_order).and_return(order) expect do - spree_post :populate, variants: { variant.id => 1 }, variant_attributes: { variant.id => { max_quantity: "3" } } + spree_post :populate, params: { variants: { variant.id => 1 }, variant_attributes: { variant.id => { max_quantity: "3" } } } end.to change(Spree::LineItem, :count).by(1) end end diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb index 86ff995516..cdfa2ef964 100644 --- a/spec/controllers/enterprises_controller_spec.rb +++ b/spec/controllers/enterprises_controller_spec.rb @@ -150,7 +150,7 @@ describe EnterprisesController, type: :controller do # let(:enterprise) { create(:enterprise, permalink: 'enterprise_permalink') } it "responds with status of 200 when the route does not exist" do - xhr :get, :check_permalink, permalink: 'some_nonexistent_route', format: :js + get :check_permalink, xhr: true, params: { permalink: 'some_nonexistent_route', format: :js } expect(response.status).to be 200 end