Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/active_admin/pundit_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def policy_target(subject)
case subject
when nil then resource
when Class then subject.new
else subject
else undecorate(subject)
end
end

Expand Down Expand Up @@ -118,6 +118,9 @@ def policies
@policies ||= {}
end

def undecorate(subject)
ResourceController::Decorators.undecorate(subject)
end
end

end
32 changes: 32 additions & 0 deletions spec/unit/pundit_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,38 @@ def resolve
end
end

context "when decorator name contains policy namespace name" do
before do
allow(ActiveAdmin.application).to receive(:pundit_policy_namespace).and_return :foobar
end

class Admin::PostDecorator
attr_reader :object
delegate_missing_to :object

def initialize(object)
@object = object
end

def decorated?
true
end

def model
object
end
end

it "asks Pundit for a policy for the undecorated object" do
policy = DefaultPolicy.new(double, double)
allow(policy).to receive(:show?).and_return(true)

expect(Pundit).to receive(:policy).with(anything, [:foobar, an_instance_of(Post)]).and_return(policy)

auth.authorized?(:read, Admin::PostDecorator.new(Post.new))
end
end

context "when Pundit is unable to find policy scope" do
let(:collection) { double("collection", to_sym: :collection) }
subject(:scope) { auth.scope_collection(collection, :read) }
Expand Down