Skip to content
This repository

Fix namespace split #668

Merged
merged 1 commit into from almost 2 years ago

6 participants

Nugroho Herucahyono Diego R. V. Anuj Dutta Linda Julien Jared Beck Ryan Bates
Nugroho Herucahyono
xinuc commented June 29, 2012
#ability.rb
can :index, "admin/dashboard"

this code will incorrectly try to load Dashboard class, not Admin::Dashboard class

Anuj Dutta andhapp referenced this pull request June 29, 2012
Closed

fix namespace regression #665

Diego R. V.

+1

Nugroho Herucahyono xinuc referenced this pull request from a commit in bukalapak/cancan June 29, 2012
Nugroho Herucahyono porting #668 to 1.6.x ce7d3fe
Nugroho Herucahyono
xinuc commented July 01, 2012

@andhapp I've ported this pull request to master and submit pull request at #675

thanks

Anuj Dutta
Collaborator

@xinuc: Thanks a lot. I was going to do it at some point but I'm glad that you've already done it. Cheers.

Ryan Bates ryanb merged commit aed9f26 into from July 02, 2012
Ryan Bates ryanb closed this July 02, 2012
Linda Julien

Is there any chance of getting this released on the 1.6.x line? I could really use it.

Diego R. V.

@ljulien, the last commit was 2 months ago... :/

Make a cancan fork and fix that for you...

It was my choice.. :/

Jared Beck

@diegorv, @ljulien, please note that this patch is now available in 1.6.10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jun 29, 2012
Nugroho Herucahyono fix namespace split, so we can use / for namespace 6c1828a
This page is out of date. Refresh to see the latest.
2  lib/cancan/controller_resource.rb
@@ -237,7 +237,7 @@ def resource_params
237 237
     end
238 238
 
239 239
     def namespace
240  
-      @params[:controller].split("::")[0..-2]
  240
+      @params[:controller].split(/::|\//)[0..-2]
241 241
     end
242 242
 
243 243
     def namespaced_name
11  spec/cancan/controller_resource_spec.rb
@@ -62,6 +62,17 @@ class Project < ::Project; end
62 62
     @controller.instance_variable_get(:@project).should == project
63 63
   end
64 64
 
  65
+  it "has the specified nested resource_class when using / for namespace" do
  66
+    module Admin
  67
+      class Dashboard; end
  68
+    end
  69
+    @ability.can(:index, "admin/dashboard")
  70
+    @params.merge!(:controller => "admin/dashboard", :action => "index")
  71
+    @controller.authorize!(:index, "admin/dashboard")
  72
+    resource = CanCan::ControllerResource.new(@controller, :authorize => true)
  73
+    resource.send(:resource_class).should == Admin::Dashboard
  74
+  end
  75
+
65 76
   it "builds a new resource with hash if params[:id] is not specified and authorize on each attribute" do
66 77
     @params.merge!(:action => "create", :project => {:name => "foobar"})
67 78
     CanCan::ControllerResource.new(@controller, :load => true).process
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.