From c64519ae2fb35992c318080a1bbffe35a17d4124 Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 23 Apr 2024 12:02:32 -0400 Subject: [PATCH] rewrote payments_controller_spec to be of request spec format --- config/routes.rb | 7 +++ spec/controllers/payments_controller_spec.rb | 53 +++++++++----------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index ba182c9607..5a5441f3b3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -54,6 +54,13 @@ Openfoodnetwork::Application.routes.draw do end end + # used for payments_controller_spec.rb + resources :payments do + member do + get :redirect_to_authorize + end + end + resources :line_items, only: [:destroy] do get :bought, on: :collection end diff --git a/spec/controllers/payments_controller_spec.rb b/spec/controllers/payments_controller_spec.rb index 2af4e7a481..a1e919ee88 100644 --- a/spec/controllers/payments_controller_spec.rb +++ b/spec/controllers/payments_controller_spec.rb @@ -2,42 +2,37 @@ require 'spec_helper' -describe PaymentsController, type: :controller do +describe "/payments/redirect_to_authorize", type: :request do let!(:user) { create(:user) } let!(:order) { create(:order, user:) } let!(:payment) { create(:payment, order:) } - describe "testing redirect_to_authorize" do - context "when user isn't logged in" do - it "redirects to the login page and set error flash msg" do - get :redirect_to_authorize, params: { id: payment.id } - expect(response).to redirect_to(root_path(anchor: "/login", - after_login: request.original_fullpath)) - expect(flash[:error]).to eq I18n.t("spree.orders.edit.login_to_view_order") + describe "when user isn't logged in" do + it "redirects to the login page and set error flash msg" do + get redirect_to_authorize_payment_path(payment) + expect(response).to redirect_to(root_path(anchor: "/login", after_login: request.fullpath)) + expect(flash[:error]).to eq I18n.t("spree.orders.edit.login_to_view_order") + end + end + + describe "when user is logged in" do + before { sign_in user } + + context "has cvv response message" do + before do + allow_any_instance_of(Spree::Payment).to receive(:cvv_response_message).and_return('http://example.com') + end + + it "redirects to the CVV response URL" do + get redirect_to_authorize_payment_path(payment) + expect(response).to redirect_to('http://example.com') end end - context "when user is logged in" do - before do - allow(controller).to receive(:spree_current_user).and_return(user) - end - - context "has cvv response message" do - before do - allow_any_instance_of(Spree::Payment).to receive(:cvv_response_message).and_return('http://example.com') - end - - it "redirects to the CVV response URL" do - get :redirect_to_authorize, params: { id: payment.id } - expect(response).to redirect_to('http://example.com') - end - end - - context "doesn't have cvv response message" do - it "redirect to order URL" do - get :redirect_to_authorize, params: { id: payment.id } - expect(response).to redirect_to(order_url(order)) - end + context "doesn't have cvv response message" do + it "redirect to order URL" do + get redirect_to_authorize_payment_path(payment) + expect(response).to redirect_to(order_url(order)) end end end