hide environment on payment methods when user is not admin

This commit is contained in:
Eduardo
2020-08-02 19:14:59 -03:00
parent 4fe24da3ec
commit 11684dae65
2 changed files with 53 additions and 6 deletions

View File

@@ -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

View File

@@ -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