2017-01-09 15:43:15 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe BasePolicy, models: true do
|
|
|
|
describe '.class_for' do
|
|
|
|
it 'detects policy class based on the subject ancestors' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(DeclarativePolicy.class_for(GenericCommitStatus.new)).to eq(CommitStatusPolicy)
|
2017-01-09 15:43:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'detects policy class for a presented subject' do
|
2017-03-02 20:49:23 -05:00
|
|
|
presentee = Ci::BuildPresenter.new(Ci::Build.new)
|
2017-01-09 15:43:15 -05:00
|
|
|
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(DeclarativePolicy.class_for(presentee)).to eq(Ci::BuildPolicy)
|
2017-01-09 15:43:15 -05:00
|
|
|
end
|
2017-03-02 20:49:23 -05:00
|
|
|
|
|
|
|
it 'uses GlobalPolicy when :global is given' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(DeclarativePolicy.class_for(:global)).to eq(GlobalPolicy)
|
2017-03-02 20:49:23 -05:00
|
|
|
end
|
2017-01-09 15:43:15 -05:00
|
|
|
end
|
|
|
|
end
|