scope_spec.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Ticket::SharedDraftStartPolicy::Scope do
  4. subject(:scope) { described_class.new(user, original_collection) }
  5. let(:original_collection) { Ticket::SharedDraftStart }
  6. let(:group_a) { create(:group) }
  7. let(:draft_a) { create(:ticket_shared_draft_start, group: group_a) }
  8. let(:group_b) { create(:group) }
  9. let(:draft_b) { create(:ticket_shared_draft_start, group: group_b) }
  10. before do
  11. draft_a && draft_b
  12. end
  13. describe '#resolve' do
  14. context 'without user' do
  15. let(:user) { nil }
  16. it 'throws exception' do
  17. expect { scope.resolve }.to raise_error %r{Authentication required}
  18. end
  19. end
  20. context 'with customer' do
  21. let(:user) { create(:customer) }
  22. it 'returns empty' do
  23. expect(scope.resolve).to be_empty
  24. end
  25. end
  26. context 'with agent' do
  27. let(:user) { create(:agent) }
  28. before { user.groups << group_a }
  29. it 'returns group a' do
  30. expect(scope.resolve).to contain_exactly(draft_a)
  31. end
  32. end
  33. end
  34. end