article_policy_spec.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. require 'rails_helper'
  2. describe Ticket::ArticlePolicy do
  3. subject { described_class.new(user, record) }
  4. let!(:group) { create(:group) }
  5. let!(:ticket_customer) { create(:customer) }
  6. let(:record) do
  7. ticket = create(:ticket, group: group, customer: ticket_customer)
  8. create(:ticket_article, ticket: ticket)
  9. end
  10. context 'when article internal' do
  11. let(:record) do
  12. ticket = create(:ticket, group: group, customer: ticket_customer)
  13. create(:ticket_article, ticket: ticket, internal: true)
  14. end
  15. context 'when agent' do
  16. let(:user) { create(:agent, groups: [group]) }
  17. it { is_expected.to permit_actions(%i[show]) }
  18. end
  19. context 'when agent and customer' do
  20. let(:user) { create(:agent_and_customer, groups: [group]) }
  21. it { is_expected.to permit_actions(%i[show]) }
  22. end
  23. context 'when agent and customer but no agent group access' do
  24. let(:user) do
  25. customer_role = create(:role, :customer)
  26. create(:agent_and_customer, roles: [customer_role])
  27. end
  28. it { is_expected.not_to permit_actions(%i[show]) }
  29. end
  30. context 'when customer' do
  31. let(:user) { ticket_customer }
  32. it { is_expected.not_to permit_actions(%i[show]) }
  33. end
  34. end
  35. context 'when agent' do
  36. let(:user) { create(:agent, groups: [group]) }
  37. it { is_expected.to permit_actions(%i[show]) }
  38. end
  39. context 'when agent and customer' do
  40. let(:user) { create(:agent_and_customer, groups: [group]) }
  41. it { is_expected.to permit_actions(%i[show]) }
  42. end
  43. context 'when customer' do
  44. let(:user) { ticket_customer }
  45. it { is_expected.to permit_actions(%i[show]) }
  46. end
  47. end