2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2019-03-22 04:36:10 +00:00
|
|
|
require 'rails_helper'
|
2020-02-20 13:34:03 +00:00
|
|
|
require 'models/concerns/has_collection_update_examples'
|
2021-04-12 09:49:26 +00:00
|
|
|
require 'models/concerns/has_xss_sanitized_note_examples'
|
2019-03-22 04:36:10 +00:00
|
|
|
|
|
|
|
RSpec.describe Permission, type: :model do
|
2020-02-20 13:34:03 +00:00
|
|
|
it_behaves_like 'HasCollectionUpdate', collection_factory: :permission
|
2021-04-12 09:49:26 +00:00
|
|
|
it_behaves_like 'HasXssSanitizedNote', model_factory: :permission
|
2020-02-20 13:34:03 +00:00
|
|
|
|
2019-03-22 04:36:10 +00:00
|
|
|
describe '.with_parents' do
|
|
|
|
context 'when given a simple string (no dots)' do
|
|
|
|
it 'returns an array containing only that string' do
|
2019-09-16 15:04:17 +00:00
|
|
|
expect(described_class.with_parents('foo')).to eq(['foo'])
|
2019-03-22 04:36:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when given a String permission name (dot-delimited identifier)' do
|
|
|
|
it 'returns an array of String ancestors (desc. from root)' do
|
2019-09-16 15:04:17 +00:00
|
|
|
expect(described_class.with_parents('foo.bar.baz'))
|
2019-03-22 04:36:10 +00:00
|
|
|
.to eq(%w[foo foo.bar foo.bar.baz])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|