From 11684dae659f46a40d203d3997251fa6168fbfcb Mon Sep 17 00:00:00 2001 From: Eduardo Date: Sun, 2 Aug 2020 19:14:59 -0300 Subject: [PATCH 1/3] hide environment on payment methods when user is not admin --- .../admin/payment_methods/index.html.haml | 9 ++-- .../payment_methods/index.html.haml_spec.rb | 50 +++++++++++++++++-- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/app/views/spree/admin/payment_methods/index.html.haml b/app/views/spree/admin/payment_methods/index.html.haml index adb14d5caa..59e3508375 100644 --- a/app/views/spree/admin/payment_methods/index.html.haml +++ b/app/views/spree/admin/payment_methods/index.html.haml @@ -11,7 +11,8 @@ %col{style: "width: 13%"} %col{style: "width: 14%"} %col{style: "width: 32%"} - %col{style: "width: 14%"} + - if spree_current_user.admin? + %col{style: "width: 14%"} %col{style: "width: 8%"} %col{style: "width: 8%"} %col{style: "width: 11%"} @@ -20,7 +21,8 @@ %th= t('.name') %th= t('.products_distributor') %th= t('.provider') - %th= t('.environment') + - if spree_current_user.admin? + %th= t('.environment') %th= t('.display') %th= t('.active') %th.actions @@ -33,7 +35,8 @@ = distributor.name %br/ %td= method.class.clean_name - %td.align-center= method.environment.to_s.titleize + - if spree_current_user.admin? + %td.align-center= method.environment.to_s.titleize %td.align-center= method.display_on.blank? ? t('.both') : t('.' + method.display_on.to_s) %td.align-center= method.active ? t('.active_yes') : t('.active_no') %td.actions diff --git a/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb b/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb index 84007bf961..1e82831a40 100644 --- a/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb +++ b/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb @@ -1,6 +1,8 @@ require "spec_helper" describe "spree/admin/payment_methods/index.html.haml" do + include AuthenticationWorkflow + before do controller.singleton_class.class_eval do helper_method :new_object_url, :edit_object_url, :object_url @@ -19,10 +21,52 @@ describe "spree/admin/payment_methods/index.html.haml" do end describe "payment methods index page" do - it "shows only the providers of the existing payment methods" do - render + context "when user is not admin" do + before do + allow(view).to receive_messages spree_current_user: create_enterprise_user + end - expect(rendered).to have_content "Cash/EFT/etc. (payments for which automatic validation is not required)", count: 2 + it "shows only the providers of the existing payment methods" do + render + + expect(rendered).to have_content "Cash/EFT/etc. (payments for which automatic validation is not required)", count: 2 + end + + it "does not show Enviroment column when user is not admin" do + render + + expect(rendered).not_to have_content "Environment" + end + + it "does not show column content when user is not admin" do + render + + expect(rendered).not_to have_content "Test" + end + end + + context "when user is admin" do + before do + allow(view).to receive_messages spree_current_user: create(:admin_user) + end + + it "shows only the providers of the existing payment methods" do + render + + expect(rendered).to have_content "Cash/EFT/etc. (payments for which automatic validation is not required)", count: 2 + end + + it "does not show Enviroment column when user is not admin" do + render + + expect(rendered).to have_content "Environment" + end + + it "does not show column content when user is not admin" do + render + + expect(rendered).to have_content "Test" + end end end end From 07e5f8ed8dcf27e99cd28427831f3374a30a3e37 Mon Sep 17 00:00:00 2001 From: Eduardo Date: Sun, 9 Aug 2020 20:38:12 -0300 Subject: [PATCH 2/3] fix typo on title of specs --- .../spree/admin/payment_methods/index.html.haml_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb b/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb index 1e82831a40..e4b0882bf9 100644 --- a/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb +++ b/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb @@ -32,13 +32,13 @@ describe "spree/admin/payment_methods/index.html.haml" do expect(rendered).to have_content "Cash/EFT/etc. (payments for which automatic validation is not required)", count: 2 end - it "does not show Enviroment column when user is not admin" do + it "does not show Enviroment column" do render expect(rendered).not_to have_content "Environment" end - it "does not show column content when user is not admin" do + it "does not show column content" do render expect(rendered).not_to have_content "Test" @@ -56,13 +56,13 @@ describe "spree/admin/payment_methods/index.html.haml" do expect(rendered).to have_content "Cash/EFT/etc. (payments for which automatic validation is not required)", count: 2 end - it "does not show Enviroment column when user is not admin" do + it "shows the Enviroment column" do render expect(rendered).to have_content "Environment" end - it "does not show column content when user is not admin" do + it "shows the column content" do render expect(rendered).to have_content "Test" From 71876ca23a99e5de992e06da0099ef9ff3988d6a Mon Sep 17 00:00:00 2001 From: Eduardo Date: Fri, 4 Sep 2020 08:48:16 -0300 Subject: [PATCH 3/3] change spec to use new authentication helper and user factory --- .../views/spree/admin/payment_methods/index.html.haml_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb b/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb index e4b0882bf9..301ad5fcc1 100644 --- a/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb +++ b/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb @@ -1,7 +1,7 @@ require "spec_helper" describe "spree/admin/payment_methods/index.html.haml" do - include AuthenticationWorkflow + include AuthenticationHelper before do controller.singleton_class.class_eval do @@ -23,7 +23,7 @@ describe "spree/admin/payment_methods/index.html.haml" do describe "payment methods index page" do context "when user is not admin" do before do - allow(view).to receive_messages spree_current_user: create_enterprise_user + allow(view).to receive_messages spree_current_user: create(:user) end it "shows only the providers of the existing payment methods" do