Skip to content

Commit

Permalink
Fix CanCanCommunity#115 - specify custom parent authorization action.
Browse files Browse the repository at this point in the history
  • Loading branch information
phallguy committed Sep 4, 2014
1 parent dbc6bfe commit c3d3cd4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Develop

1.10.0 (Auguest 28, 2014)

* Complete cancancan#115 - Specify authorization action for parent resources.

1.9.2 (August 8th, 2014)

Expand Down
6 changes: 5 additions & 1 deletion lib/cancan/controller_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ def adapter
end

def authorization_action
parent? ? :show : @params[:action].to_sym
parent? ? parent_authorization_action : @params[:action].to_sym
end

def parent_authorization_action
@options[:parent_action] || :show
end

def id_param
Expand Down
2 changes: 1 addition & 1 deletion lib/cancan/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module CanCan
VERSION = "1.9.2"
VERSION = "1.10.0"
end
8 changes: 8 additions & 0 deletions spec/cancan/controller_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,14 @@ class Model < ::Model; end
expect { resource.authorize_resource }.to raise_error(CanCan::AccessDenied)
end

it "authorizes with :custom_action for parent collection action" do
controller.instance_variable_set(:@category, :some_category)
allow(controller).to receive(:authorize!).with(:custom_action, :some_category) { raise CanCan::AccessDenied }

resource = CanCan::ControllerResource.new(controller, :category, :parent => true, :parent_action => :custom_action )
expect { resource.authorize_resource }.to raise_error(CanCan::AccessDenied)
end

it "has the specified nested resource_class when using / for namespace" do
module Admin
class Dashboard; end
Expand Down

0 comments on commit c3d3cd4

Please sign in to comment.