Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Named resources were not loading correctly in 2.0 #635

Merged
merged 3 commits into from

4 participants

@ollym

See #633

@ollym

@andhapp would be nice to have this pulled asap. All tests pass on my machine

@safarista

Beautiful @ollym Thanks.

@ollym ollym Classify causes plural model names to be incorrectly renamed
Some model names will be renamed incorrectly e.g. 'business'. It should
be the responsibility of the user to make sure they use a name that
directly corresponds to the model name. The only filtering performed
should be camelize.
245b83f
@andhapp
Collaborator

@ryanb All the specs pass for me.

@ollym

^^ Yet another bug relating to that faultly commit. I've added 2 fixing tests. @ryanb can you merge this already?

@safarista

Please @ryanb check this out and merge if you can _

@ryanb ryanb merged commit 76d465a into ryanb:2.0
@ryanb
Owner

Pulling in. Thank you for your work on this @ollym.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 30, 2012
  1. @ollym
Commits on May 31, 2012
  1. @ollym

    Classify causes plural model names to be incorrectly renamed

    ollym authored
    Some model names will be renamed incorrectly e.g. 'business'. It should
    be the responsibility of the user to make sure they use a name that
    directly corresponds to the model name. The only filtering performed
    should be camelize.
Commits on Jun 4, 2012
  1. @ollym
This page is out of date. Refresh to see the latest.
View
2  lib/cancan/controller_resource.rb
@@ -230,7 +230,7 @@ def resource_params
end
def namespaced_name
- @params[:controller].sub("Controller", "").singularize.camelize.constantize
+ (@name || @params[:controller].sub("Controller", "")).singularize.camelize.constantize
rescue NameError
name
end
View
25 spec/cancan/controller_resource_spec.rb
@@ -223,6 +223,31 @@ class CustomModel
@controller.instance_variable_get(:@project).should be_nil
end
+ it "named resources should be loaded independently of the controller name" do
+ category = Category.create!
+ @params.merge!(:action => "new", :category_id => category.id)
+
+ CanCan::ControllerResource.new(@controller, :category, :load => true).process
+ CanCan::ControllerResource.new(@controller, :project, :load => true, :through => :category).process
+
+ @controller.instance_variable_get(:@category).should eq(category)
+
+ project = @controller.instance_variable_get(:@project)
+ project.category.should eq(category)
+ end
+
+ it "parent resources shouldn't be altered" do
+ category = Category.create!
+ @params.merge!(:action => "create", :category_id => category.id, :project => { :name => 'foo' })
+
+ CanCan::ControllerResource.new(@controller, :category, :load => true).process
+ CanCan::ControllerResource.new(@controller, :project, :load => true, :through => :category).process
+
+ project = @controller.instance_variable_get(:@project)
+ project.new_record?.should eq(true)
+ project.name.should eq('foo')
+ end
+
it "authorizes nested resource through parent association on index action" do
pending
@params.merge!(:action => "index")
Something went wrong with that request. Please try again.