shared_draft_start_policy_spec.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. describe Ticket::SharedDraftStartPolicy do
  4. subject { described_class.new(user, record) }
  5. let(:group) { record.group }
  6. let(:record) { create(:ticket_shared_draft_start) }
  7. let(:user) { create(:agent) }
  8. shared_examples 'access allowed' do
  9. it { is_expected.to be_create }
  10. it { is_expected.to be_update }
  11. it { is_expected.to be_show }
  12. it { is_expected.to be_destroy }
  13. end
  14. shared_examples 'access denied' do
  15. it { is_expected.not_to be_create }
  16. it { is_expected.not_to be_update }
  17. it { is_expected.not_to be_show }
  18. it { is_expected.not_to be_destroy }
  19. end
  20. context 'when user has no tickets access' do
  21. let(:user) { create(:customer) }
  22. include_examples 'access denied'
  23. end
  24. context 'when user has ticket access' do
  25. context 'when draft has same group as user' do
  26. before do
  27. user.user_groups.create! group: group, access: :full
  28. end
  29. include_examples 'access allowed'
  30. end
  31. context 'when draft has same group as user but read-only' do
  32. before do
  33. user.user_groups.create! group: group, access: :read
  34. end
  35. include_examples 'access denied'
  36. end
  37. context 'when draft has one of the groups of the user' do
  38. before do
  39. user.user_groups.create! group: group, access: :full
  40. user.user_groups.create! group: create(:group), access: :full
  41. end
  42. include_examples 'access allowed'
  43. end
  44. end
  45. end