Merge branch 'master' into 2.0

This commit is contained in:
Ryan Bates 2011-09-28 13:35:52 -07:00
commit 2160183e86
3 changed files with 20 additions and 2 deletions

View File

@ -4,7 +4,7 @@ case ENV["MODEL_ADAPTER"]
when nil, "active_record"
gem "sqlite3"
gem "activerecord", '~> 3.0.9', :require => "active_record"
gem "with_model"
gem "with_model", '~> 0.1.5'
gem "meta_where"
when "data_mapper"
gem "dm-core", "~> 1.0.2"

View File

@ -141,7 +141,7 @@ module CanCan
def resource_class
case @options[:class]
when false then name.to_sym
when nil then name.to_s.camelize.constantize
when nil then namespaced_name.to_s.camelize.constantize
when String then @options[:class].constantize
else @options[:class]
end
@ -220,6 +220,12 @@ module CanCan
@name || name_from_controller
end
def namespaced_name
@params[:controller].sub("Controller", "").singularize.camelize.constantize
rescue NameError
name
end
def name_from_controller
@params[:controller].sub("Controller", "").underscore.split('/').last.singularize
end

View File

@ -33,6 +33,18 @@ describe CanCan::ControllerResource do
@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 => "MyEngine::ProjectsController", :action => "show", :id => project.id)
resource = CanCan::ControllerResource.new(@controller)
resource.load_resource
@controller.instance_variable_get(:@project).should == project
end
it "should properly load resource for namespaced controller when using '::' for namespace" do
project = Project.create!
@params.merge!(:controller => "Admin::ProjectsController", :action => "show", :id => project.id)