ticket_policy_spec.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. require 'rails_helper'
  2. describe TicketPolicy do
  3. subject { described_class.new(user, record) }
  4. let(:record) { create(:ticket) }
  5. context 'when given ticket’s owner' do
  6. let(:user) { record.owner }
  7. it { is_expected.to permit_actions(%i[show full]) }
  8. end
  9. context 'when given a user that is neither owner nor customer' do
  10. let(:user) { create(:agent) }
  11. it { is_expected.not_to permit_actions(%i[show full]) }
  12. context 'but the user is an agent with full access to ticket’s group' do
  13. before { user.group_names_access_map = { record.group.name => 'full' } }
  14. it { is_expected.to permit_actions(%i[show full]) }
  15. end
  16. context 'but the user is a customer from the same organization as ticket’s customer' do
  17. let(:record) { create(:ticket, customer: customer) }
  18. let(:customer) { create(:customer, organization: create(:organization)) }
  19. let(:user) { create(:customer, organization: customer.organization) }
  20. context 'and organization.shared is true (default)' do
  21. it { is_expected.to permit_actions(%i[show full]) }
  22. end
  23. context 'but organization.shared is false' do
  24. before { customer.organization.update(shared: false) }
  25. it { is_expected.not_to permit_actions(%i[show full]) }
  26. end
  27. end
  28. end
  29. end