2019-03-22 04:36:10 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Permission, type: :model do
|
|
|
|
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
|