Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

porting #668 to master branch #675

Merged
merged 1 commit into from

5 participants

@xinuc

No description provided.

@xinuc xinuc referenced this pull request
Merged

Fix namespace split #668

@ryanb
Owner

This doesn't make as much sense with the CanCan 1.x behavior since that Ability is intended to be focused on models and not controllers. With CanCan 2.0 using the controller name and mapping that to the model it makes sense in that release only.

@ryanb ryanb closed this
@andhapp
Collaborator

@ryanb: I think the spec is incorrectly written and I'm sure it'll make more sense if it's like this:

it "should properly load resource for namespaced controller" do
    project = Project.create!
    @params.merge!(:controller => "admin/projects", :action => "show", :id => project.id)
    resource = CanCan::ControllerResource.new(@controller)
    resource.load_resource
    @controller.instance_variable_get(:@project).should == project
  end

But a similar spec is in the project already and now I am totally confused about this issue. Anyways, ignore this comment.

@andhapp
Collaborator

@ryanb: This fix is related to this issue #663.

@stas

Hey guys, I would like to reopen this PR. It is relevant to me when working with a Rails engine.

Thanks.

@jrust

Agreed with @stas. @params[:controller] in an engine is engine_name/controller_name because it wraps the whole engine up in a routing scope.

@ryanb ryanb reopened this
@ryanb ryanb merged commit 60cf6a6 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 2, 2012
  1. @xinuc

    porting #668 to 1.6.x

    xinuc authored
This page is out of date. Refresh to see the latest.
View
2  lib/cancan/controller_resource.rb
@@ -220,7 +220,7 @@ def resource_params
end
def namespace
- @params[:controller].split("::")[0..-2]
+ @params[:controller].split(/::|\//)[0..-2]
end
def namespaced_name
View
10 spec/cancan/controller_resource_spec.rb
@@ -67,6 +67,16 @@ class Project < ::Project; end
@controller.instance_variable_get(:@project).should == project
end
+ it "has the specified nested resource_class when using / for namespace" do
+ module Admin
+ class Dashboard; end
+ end
+ @ability.can(:index, "admin/dashboard")
+ @params.merge!(:controller => "admin/dashboard", :action => "index")
+ resource = CanCan::ControllerResource.new(@controller, :authorize => true)
+ resource.send(:resource_class).should == Admin::Dashboard
+ end
+
it "should build a new resource with hash if params[:id] is not specified" do
@params.merge!(:action => "create", :project => {:name => "foobar"})
resource = CanCan::ControllerResource.new(@controller)
Something went wrong with that request. Please try again.