From a059c11d0f5bf8b03f0d9d75e46feba9bae73ed8 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 23 Dec 2019 11:07:58 +0100 Subject: [PATCH] Update post/delete calls in credit_cards_controller_spec.rb ActionController::UrlGenerationError: No route matches {:action=>"new_from_token", :cc_type=>"visa", :controller=>"spree/credit_cards", :exp_month=>12, :exp_year=>2020, :format=>:json, :last4=>4242, :token=>"tok_234bd2c22"} # ./spec/controllers/spree/credit_cards_controller_spec.rb:36:in `block (5 levels) in ' # ./spec/controllers/spree/credit_cards_controller_spec.rb:36:in `block (4 levels) in ' --- .../spree/credit_cards_controller_spec.rb | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/spec/controllers/spree/credit_cards_controller_spec.rb b/spec/controllers/spree/credit_cards_controller_spec.rb index a89db449ea..e8996433f3 100644 --- a/spec/controllers/spree/credit_cards_controller_spec.rb +++ b/spec/controllers/spree/credit_cards_controller_spec.rb @@ -33,7 +33,7 @@ describe Spree::CreditCardsController, type: :controller do let(:response_mock) { { status: 200, body: JSON.generate(id: "cus_AZNMJ", default_source: "card_1AEEb") } } it "saves the card locally" do - expect{ post :new_from_token, params }.to change(Spree::CreditCard, :count).by(1) + expect{ spree_post :new_from_token, params }.to change(Spree::CreditCard, :count).by(1) card = Spree::CreditCard.last expect(card.gateway_payment_profile_id).to eq "card_1AEEb" @@ -48,7 +48,7 @@ describe Spree::CreditCardsController, type: :controller do end it "renders a flash error" do - expect{ post :new_from_token, params }.to_not change(Spree::CreditCard, :count) + expect{ spree_post :new_from_token, params }.to_not change(Spree::CreditCard, :count) json_response = JSON.parse(response.body) flash_message = I18n.t(:spree_gateway_error_flash_for_checkout, error: I18n.t(:card_could_not_be_saved)) @@ -60,7 +60,7 @@ describe Spree::CreditCardsController, type: :controller do context "when the request to store the customer/card with Stripe fails" do let(:response_mock) { { status: 402, body: JSON.generate(error: { message: "Bup-bow..." }) } } it "doesn't save the card locally, and renders a flash error" do - expect{ post :new_from_token, params }.to_not change(Spree::CreditCard, :count) + expect{ spree_post :new_from_token, params }.to_not change(Spree::CreditCard, :count) json_response = JSON.parse(response.body) flash_message = I18n.t(:spree_gateway_error_flash_for_checkout, error: "Bup-bow...") @@ -75,7 +75,7 @@ describe Spree::CreditCardsController, type: :controller do before { params[:id] = 123 } it "renders a flash error" do - put :update, params + spree_put :update, params json_response = JSON.parse(response.body) expect(json_response['flash']['error']).to eq I18n.t(:card_could_not_be_updated) end @@ -87,7 +87,7 @@ describe Spree::CreditCardsController, type: :controller do context "but the card is not owned by the user" do it "redirects to unauthorized" do - put :update, params + spree_put :update, params expect(response).to redirect_to spree.unauthorized_path end end @@ -97,7 +97,7 @@ describe Spree::CreditCardsController, type: :controller do context "when the update completes successfully" do it "renders a serialized copy of the updated card" do - expect{ put :update, params }.to change { card.reload.is_default }.to(true) + expect{ spree_put :update, params }.to change { card.reload.is_default }.to(true) json_response = JSON.parse(response.body) expect(json_response['id']).to eq card.id expect(json_response['is_default']).to eq true @@ -107,7 +107,7 @@ describe Spree::CreditCardsController, type: :controller do context "when the update fails" do before { params[:credit_card][:month] = 'some illegal month' } it "renders an error" do - put :update, params + spree_put :update, params json_response = JSON.parse(response.body) expect(json_response['flash']['error']).to eq I18n.t(:card_could_not_be_updated) end @@ -122,7 +122,7 @@ describe Spree::CreditCardsController, type: :controller do it "redirects to /account with a flash error, does not request deletion with Stripe" do expect(controller).to_not receive(:destroy_at_stripe) - delete :destroy, params + spree_delete :destroy, params expect(flash[:error]).to eq I18n.t(:card_could_not_be_removed) expect(response).to redirect_to spree.account_path(anchor: 'cards') end @@ -134,7 +134,7 @@ describe Spree::CreditCardsController, type: :controller do context "but the card is not owned by the user" do it "redirects to unauthorized" do - delete :destroy, params + spree_delete :destroy, params expect(response).to redirect_to spree.unauthorized_path end end @@ -154,7 +154,7 @@ describe Spree::CreditCardsController, type: :controller do end it "doesn't delete the card" do - expect{ delete :destroy, params }.to_not change(Spree::CreditCard, :count) + expect{ spree_delete :destroy, params }.to_not change(Spree::CreditCard, :count) expect(flash[:error]).to eq I18n.t(:card_could_not_be_removed) expect(response).to redirect_to spree.account_path(anchor: 'cards') end @@ -167,7 +167,7 @@ describe Spree::CreditCardsController, type: :controller do end it "deletes the card and redirects to account_path" do - expect{ delete :destroy, params }.to change(Spree::CreditCard, :count).by(-1) + expect{ spree_delete :destroy, params }.to change(Spree::CreditCard, :count).by(-1) expect(flash[:success]).to eq I18n.t(:card_has_been_removed, number: "x-#{card.last_digits}") expect(response).to redirect_to spree.account_path(anchor: 'cards') end