Skip to content

spec & fix for params[:controller] in underscore format #681

Closed
wants to merge 2 commits into from

3 participants

@joxxoxo
joxxoxo commented Jul 5, 2012

code supposed that @params[:controller] is in camel case, but actually in rails it's in snake case

so i added .camelize in some methods

@joxxoxo
joxxoxo commented Apr 8, 2013

Exactly! But code in cancan

@params[:controller].split("::")[0..-2]

splits it by :: as if it was MyEngine::ProjectsController

looks like there's also unnecessary .gsub('Controller', '') in such case.
But I'm not sure if anyone needs this patch except me

@stevenpetryk stevenpetryk commented on an outdated diff Apr 9, 2013
spec/cancan/controller_resource_spec.rb
@@ -47,6 +47,18 @@ class Project < ::Project; end
@controller.instance_variable_get(:@project).should == project
end
+ it "should attempt to load a resource with the same namespace as the controller when using / for namespace" do
+ module MyEngine
+ class Project < ::Project; end
+ end
+
+ project = MyEngine::Project.create!
+ @params.merge!(:controller => "my_engine/projects_controller", :action => "show", :id => project.id)
+ resource = CanCan::ControllerResource.new(@controller)
+ resource.load_resource
+ @controller.instance_variable_get(:@project).should == project
@stevenpetryk
stevenpetryk added a note Apr 9, 2013

IIRC, @ryanb prefers to use .should eq instead of .should ==

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@joxxoxo
joxxoxo commented Apr 10, 2013

I've rebased against ryanb / cancan and changed == to eq :)

@xhoy
xhoy commented Apr 10, 2014

Dear submitter, Since cancan/raynB hasn't been active for more than 6 months and no body else then ryam himself has commit permissions the cancan project is on a stand still.
Since cancan has several issues including missing support for rails 4 cancan is moving forward to cancancan. More details on: #994

If your feel that your pull request or bug is still applicable (and hasn't been merged in to cancan) it would be really appreciated if you would resubmit it to cancancan (https://github.com/cancancommunity/cancancan)

We hope to see you on the other side!

@joxxoxo joxxoxo closed this Feb 13, 2016
@joxxoxo
joxxoxo commented Feb 13, 2016

Closed, as it's fixed differently in cancancan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.