From d16308011554c9da955bdd0f638b88a0d3f85277 Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 16 Apr 2024 14:52:17 -0400 Subject: [PATCH 1/9] added test for if user isn't logged in for payments_controller --- spec/controllers/payments_controller_spec.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 spec/controllers/payments_controller_spec.rb diff --git a/spec/controllers/payments_controller_spec.rb b/spec/controllers/payments_controller_spec.rb new file mode 100644 index 0000000000..64c663de99 --- /dev/null +++ b/spec/controllers/payments_controller_spec.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe PaymentsController, type: :controller do + + 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") + end + end + + context "when user is logged in" do + + end + +end \ No newline at end of file From 7d814e739d4ad5d15e5ab88c657816fec41c2806 Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 16 Apr 2024 15:09:21 -0400 Subject: [PATCH 2/9] added objects necessary for testing - user, order, payment --- spec/controllers/payments_controller_spec.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/controllers/payments_controller_spec.rb b/spec/controllers/payments_controller_spec.rb index 64c663de99..e3b2cf5d90 100644 --- a/spec/controllers/payments_controller_spec.rb +++ b/spec/controllers/payments_controller_spec.rb @@ -3,6 +3,9 @@ require 'spec_helper' describe PaymentsController, type: :controller do + let!(:user) { create(:user) } + let!(:order) { create(:order, user: user) } + let!(:payment) { create(:payment, order: order) } describe "testing redirect_to_authorize" do context "when user isn't logged in" do @@ -13,8 +16,8 @@ describe PaymentsController, type: :controller do end end - context "when user is logged in" do - + context "when user is logged in" do + + end end - end \ No newline at end of file From 1ad544820c37ef53a8e91cdb51839a0e022c3459 Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 16 Apr 2024 15:21:49 -0400 Subject: [PATCH 3/9] completed payments_controller_spec testing --- spec/controllers/payments_controller_spec.rb | 23 +++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/spec/controllers/payments_controller_spec.rb b/spec/controllers/payments_controller_spec.rb index e3b2cf5d90..b68478eb4c 100644 --- a/spec/controllers/payments_controller_spec.rb +++ b/spec/controllers/payments_controller_spec.rb @@ -17,7 +17,28 @@ describe PaymentsController, type: :controller do 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 + end end end end \ No newline at end of file From 954125b7f6862f2bcfa701d0a37867795bde59bb Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 16 Apr 2024 15:30:21 -0400 Subject: [PATCH 4/9] style improvements after running rubocop --- spec/controllers/payments_controller_spec.rb | 74 ++++++++++---------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/spec/controllers/payments_controller_spec.rb b/spec/controllers/payments_controller_spec.rb index b68478eb4c..2af4e7a481 100644 --- a/spec/controllers/payments_controller_spec.rb +++ b/spec/controllers/payments_controller_spec.rb @@ -3,42 +3,42 @@ require 'spec_helper' describe PaymentsController, type: :controller do - let!(:user) { create(:user) } - let!(:order) { create(:order, user: user) } - let!(:payment) { create(:payment, order: 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") - end - end - - context "when user is logged in" do - before do - allow(controller).to receive(:spree_current_user).and_return(user) - end + let!(:user) { create(:user) } + let!(:order) { create(:order, user:) } + let!(:payment) { create(:payment, order:) } - 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 - end - end + 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") + end end -end \ No newline at end of file + + 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 + end + end + end +end From c64519ae2fb35992c318080a1bbffe35a17d4124 Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 23 Apr 2024 12:02:32 -0400 Subject: [PATCH 5/9] 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 From 64a1fd927003d24bf5d09a7835da76be3cde852a Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 23 Apr 2024 22:15:43 -0400 Subject: [PATCH 6/9] removed changes to routes.rb --- config/routes.rb | 7 ------- spec/controllers/payments_controller_spec.rb | 6 +++--- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 5a5441f3b3..ba182c9607 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -54,13 +54,6 @@ 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 a1e919ee88..f678e7de86 100644 --- a/spec/controllers/payments_controller_spec.rb +++ b/spec/controllers/payments_controller_spec.rb @@ -9,7 +9,7 @@ describe "/payments/redirect_to_authorize", type: :request do 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) + get 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 @@ -24,14 +24,14 @@ describe "/payments/redirect_to_authorize", type: :request do end it "redirects to the CVV response URL" do - get redirect_to_authorize_payment_path(payment) + get authorize_payment_path(payment) 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_payment_path(payment) + get authorize_payment_path(payment) expect(response).to redirect_to(order_url(order)) end end From eda97ef3f7d109e700689116d0b3a3fa8f9c1649 Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 23 Apr 2024 22:17:08 -0400 Subject: [PATCH 7/9] fixed path --- spec/controllers/payments_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/controllers/payments_controller_spec.rb b/spec/controllers/payments_controller_spec.rb index f678e7de86..11cb19fd8c 100644 --- a/spec/controllers/payments_controller_spec.rb +++ b/spec/controllers/payments_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe "/payments/redirect_to_authorize", type: :request do +describe "/payments/:id/authorize", type: :request do let!(:user) { create(:user) } let!(:order) { create(:order, user:) } let!(:payment) { create(:payment, order:) } From 6b5be213a333177b5ab1b84bd2291961d0e36b40 Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 25 Apr 2024 12:10:32 -0400 Subject: [PATCH 8/9] changed location - now in requests folder --- spec/{controllers => requests}/payments_controller_spec.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spec/{controllers => requests}/payments_controller_spec.rb (100%) diff --git a/spec/controllers/payments_controller_spec.rb b/spec/requests/payments_controller_spec.rb similarity index 100% rename from spec/controllers/payments_controller_spec.rb rename to spec/requests/payments_controller_spec.rb From ccf3d5873a0d1406f29a11e9e01bf789e36f45f0 Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 25 Apr 2024 12:24:19 -0400 Subject: [PATCH 9/9] style fix - remove type --- spec/requests/payments_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/requests/payments_controller_spec.rb b/spec/requests/payments_controller_spec.rb index 11cb19fd8c..5201b53b86 100644 --- a/spec/requests/payments_controller_spec.rb +++ b/spec/requests/payments_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe "/payments/:id/authorize", type: :request do +describe "/payments/:id/authorize" do let!(:user) { create(:user) } let!(:order) { create(:order, user:) } let!(:payment) { create(:payment, order:) }