tickets_shared_draft_starts_controller_policy_spec.rb 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. describe Controllers::TicketsSharedDraftStartsControllerPolicy do
  4. subject { described_class.new(user, record) }
  5. let(:record_class) { TicketsSharedDraftStartsController }
  6. let(:record) do
  7. rec = record_class.new
  8. rec.action_name = action_name
  9. rec
  10. end
  11. shared_examples 'basic checks' do
  12. context 'when has access to tickets' do
  13. let(:user) do
  14. user = create(:agent)
  15. user.user_groups.create! group: create(:group), access: :full
  16. user
  17. end
  18. it { is_expected.to permit_action(action_name) }
  19. end
  20. context 'when has no access to tickets' do
  21. let(:user) { create(:customer) }
  22. it { is_expected.to forbid_action(action_name) }
  23. end
  24. end
  25. describe '#index?' do
  26. let(:action_name) { :index }
  27. include_examples 'basic checks'
  28. context 'when has access through roles' do
  29. let(:role) do
  30. role = create(:role, :agent)
  31. role.group_names_access_map = {
  32. Group.first.name => %w[full],
  33. }
  34. role
  35. end
  36. let(:user) { create(:agent, role_ids: [role.id]) }
  37. it { is_expected.to permit_action(action_name) }
  38. end
  39. end
  40. describe '#show?' do
  41. let(:action_name) { :show }
  42. include_examples 'basic checks'
  43. end
  44. describe '#create?' do
  45. let(:action_name) { :create }
  46. include_examples 'basic checks'
  47. end
  48. describe '#update?' do
  49. let(:action_name) { :update }
  50. include_examples 'basic checks'
  51. end
  52. describe '#destroy?' do
  53. let(:action_name) { :destroy }
  54. include_examples 'basic checks'
  55. end
  56. describe '#import_attachments?' do
  57. let(:action_name) { :import_attachments }
  58. include_examples 'basic checks'
  59. end
  60. end