macro_policy_spec.rb 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. describe MacroPolicy do
  4. subject { described_class.new(user, record) }
  5. let(:record) { create(:macro, groups:) }
  6. context 'when user is admin' do
  7. let(:user) { create(:admin) }
  8. context 'when macro is not active' do
  9. before { record.update! active: false }
  10. let(:groups) { [] }
  11. it { is_expected.to permit_actions(:show, :create, :update, :destroy) }
  12. end
  13. context 'when macro has group user does not have access to' do
  14. let(:groups) { [create(:group)] }
  15. it { is_expected.to permit_actions(:show, :create, :update, :destroy) }
  16. end
  17. end
  18. context 'when user is agent' do
  19. let(:group) { create(:group) }
  20. let(:user) { create(:agent, groups: [group]) }
  21. context 'when macro has no group' do
  22. let(:groups) { [] }
  23. it { is_expected.to permit_action(:show) }
  24. it { is_expected.to forbid_actions(:create, :update, :destroy) }
  25. context 'when macro is not active' do
  26. before { record.update! active: false }
  27. it { is_expected.to forbid_actions(:show, :create, :update, :destroy) }
  28. end
  29. end
  30. context 'when macro has group user has access to' do
  31. let(:groups) { [group, create(:group)] }
  32. it { is_expected.to permit_action(:show) }
  33. it { is_expected.to forbid_actions(:create, :update, :destroy) }
  34. context 'when macro is not active' do
  35. before { record.update! active: false }
  36. it { is_expected.to forbid_actions(:show, :create, :update, :destroy) }
  37. end
  38. end
  39. context 'when macro has group user no access to' do
  40. let(:groups) { [create(:group)] }
  41. it { is_expected.to forbid_actions(:show, :create, :update, :destroy) }
  42. end
  43. end
  44. context 'when user is customer' do
  45. let(:user) { create(:customer) }
  46. let(:groups) { [] }
  47. it { is_expected.to forbid_actions(:show, :create, :update, :destroy) }
  48. end
  49. end