Commit fd72c0f4 authored by Rémy Coutable's avatar Rémy Coutable

Handle presenters in BasePolicy

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent b4f67cc2
......@@ -53,6 +53,10 @@ class BasePolicy
def self.class_for(subject)
return GlobalPolicy if subject.nil?
if subject.class.ancestors.include?(Gitlab::View::Presenter::Base)
subject = subject.subject
end
subject.class.ancestors.each do |klass|
next unless klass.name
......
require 'spec_helper'
describe BasePolicy, models: true do
let(:build) { create(:ci_build) }
describe '.class_for' do
it 'detects policy class based on the subject ancestors' do
expect(described_class.class_for(build)).to eq(Ci::BuildPolicy)
end
it 'detects policy class for a presented subject' do
presentee = Ci::Build::Presenter.new(build)
expect(described_class.class_for(presentee)).to eq(Ci::BuildPolicy)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment