text_module_policy_spec.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. describe TextModulePolicy do
  4. subject { described_class.new(user, record) }
  5. let(:group) { create(:group) }
  6. context 'when user is an admin' do
  7. let(:user) { create(:admin) }
  8. context 'when record has no limits' do
  9. let(:record) { create(:text_module) }
  10. it { is_expected.to permit_action(:show) }
  11. end
  12. context 'when record has group limits and user is listed' do
  13. let(:user) { create(:agent, groups: [group]) }
  14. let(:record) { create(:text_module, groups: user.groups) }
  15. it { is_expected.to permit_action(:show) }
  16. end
  17. context 'when record has group limits and user is not listed' do
  18. let(:record) { create(:text_module, groups: [group]) }
  19. it { is_expected.to permit_action(:show) }
  20. end
  21. end
  22. context 'when user is an agent' do
  23. let(:user) { create(:agent) }
  24. context 'when record has no limits' do
  25. let(:record) { create(:text_module) }
  26. it { is_expected.to permit_action(:show) }
  27. end
  28. context 'when record has group limits and user is listed' do
  29. let(:user) { create(:agent, groups: [group]) }
  30. let(:record) { create(:text_module, groups: user.groups) }
  31. it { is_expected.to permit_action(:show) }
  32. end
  33. context 'when record has group limits and user is not listed' do
  34. let(:record) { create(:text_module, groups: [group]) }
  35. it { is_expected.to forbid_action(:show) }
  36. end
  37. end
  38. end