permission_spec.rb 913 B

12345678910111213141516171819202122232425
  1. # Copyright (C) 2012-2022 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. end