ticket_shared_draft_zoom_controller_policy_spec.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. describe Controllers::TicketSharedDraftZoomControllerPolicy do
  4. subject { described_class.new(user, record) }
  5. let(:record_class) { TicketSharedDraftZoomController }
  6. let(:ticket) { create(:ticket) }
  7. let(:user) { create(:agent) }
  8. let(:record) do
  9. rec = record_class.new
  10. rec.action_name = action_name
  11. rec.params = params
  12. rec
  13. end
  14. shared_examples 'basic checks' do
  15. let(:params) { { ticket_id: ticket.id } }
  16. context 'when has access to ticket' do
  17. before do
  18. user.user_groups.create! group: ticket.group, access: :full
  19. end
  20. it { is_expected.to permit_action(action_name) }
  21. end
  22. context 'when has no access to ticket' do
  23. it { is_expected.to forbid_action(action_name) }
  24. end
  25. end
  26. describe '#show?' do
  27. let(:action_name) { :show }
  28. include_examples 'basic checks'
  29. end
  30. describe '#create?' do
  31. let(:action_name) { :create }
  32. include_examples 'basic checks'
  33. end
  34. describe '#update?' do
  35. let(:action_name) { :update }
  36. include_examples 'basic checks'
  37. end
  38. describe '#destroy?' do
  39. let(:action_name) { :destroy }
  40. include_examples 'basic checks'
  41. end
  42. describe '#import_attachments?' do
  43. let(:action_name) { :import_attachments }
  44. include_examples 'basic checks'
  45. end
  46. end