permission_spec.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'models/concerns/has_collection_update_examples'
  4. require 'models/concerns/has_xss_sanitized_note_examples'
  5. RSpec.describe Permission, type: :model do
  6. it_behaves_like 'HasCollectionUpdate', collection_factory: :permission
  7. it_behaves_like 'HasXssSanitizedNote', model_factory: :permission
  8. describe '.with_parents' do
  9. context 'when given a simple string (no dots)' do
  10. it 'returns an array containing only that string' do
  11. expect(described_class.with_parents('foo')).to eq(['foo'])
  12. end
  13. end
  14. context 'when given a String permission name (dot-delimited identifier)' do
  15. it 'returns an array of String ancestors (desc. from root)' do
  16. expect(described_class.with_parents('foo.bar.baz'))
  17. .to eq(%w[foo foo.bar foo.bar.baz])
  18. end
  19. end
  20. end
  21. describe '.join_with' do
  22. let!(:agents) { create_list(:agent, 5) }
  23. let!(:customers) { create_list(:customer, 5) }
  24. it 'does include agents' do
  25. expect(described_class.join_with(User, 'ticket.agent')).to include(*agents)
  26. end
  27. it 'does exclude customers' do
  28. expect(described_class.join_with(User, 'ticket.agent')).not_to include(*customers)
  29. end
  30. end
  31. end