spec the new behavior of .class_for

and more robustly spec the ancestor behavior
This commit is contained in:
http://jneen.net/ 2017-03-02 17:49:23 -08:00
parent f1d3a92bd6
commit 275a46c523
1 changed files with 6 additions and 4 deletions

View File

@ -1,17 +1,19 @@
require 'spec_helper'
describe BasePolicy, models: true do
let(:build) { Ci::Build.new }
describe '.class_for' do
it 'detects policy class based on the subject ancestors' do
expect(described_class.class_for(build)).to eq(Ci::BuildPolicy)
expect(described_class.class_for(GenericCommitStatus.new)).to eq(CommitStatusPolicy)
end
it 'detects policy class for a presented subject' do
presentee = Ci::BuildPresenter.new(build)
presentee = Ci::BuildPresenter.new(Ci::Build.new)
expect(described_class.class_for(presentee)).to eq(Ci::BuildPolicy)
end
it 'uses GlobalPolicy when :global is given' do
expect(described_class.class_for(:global)).to eq(GlobalPolicy)
end
end
end