load member through method instead of instance variable to improve decent_exposure support
This commit is contained in:
parent
f6c2054f7e
commit
b8ff2dbc6a
|
@ -148,7 +148,13 @@ module CanCan
|
||||||
end
|
end
|
||||||
|
|
||||||
def resource_instance
|
def resource_instance
|
||||||
@controller.instance_variable_get("@#{instance_name}") if load_instance?
|
if load_instance?
|
||||||
|
if @controller.instance_variable_defined? "@#{instance_name}"
|
||||||
|
@controller.instance_variable_get("@#{instance_name}")
|
||||||
|
elsif @controller.respond_to?(instance_name, true)
|
||||||
|
@controller.send(instance_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def collection_instance=(instance)
|
def collection_instance=(instance)
|
||||||
|
|
|
@ -336,6 +336,14 @@ describe CanCan::ControllerResource do
|
||||||
CanCan::ControllerResource.new(@controller, :authorize => true).process
|
CanCan::ControllerResource.new(@controller, :authorize => true).process
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should fetch member through method when instance variable is not provided" do
|
||||||
|
stub(@controller).project { :some_project }
|
||||||
|
@params.merge!(:action => "show", :id => 123)
|
||||||
|
stub(@controller).authorize!(:show, :some_project) { raise CanCan::Unauthorized }
|
||||||
|
resource = CanCan::ControllerResource.new(@controller, :authorize => true)
|
||||||
|
lambda { resource.process }.should raise_error(CanCan::Unauthorized)
|
||||||
|
end
|
||||||
|
|
||||||
# it "should raise ImplementationRemoved when adding :name option" do
|
# it "should raise ImplementationRemoved when adding :name option" do
|
||||||
# lambda {
|
# lambda {
|
||||||
# CanCan::ControllerResource.new(@controller, :name => :foo)
|
# CanCan::ControllerResource.new(@controller, :name => :foo)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user