calling controller's load_resource and authorize_resource from load_and_authorize_resource to maintain backwards compatability, even though it's not the most efficient way

This commit is contained in:
Ryan Bates 2009-11-26 09:53:16 -08:00
parent da5a5c031f
commit e32c5d0dfb
3 changed files with 8 additions and 6 deletions

View File

@ -40,7 +40,7 @@ module CanCan
# assert ability.cannot?(:destroy, Project.new) # assert ability.cannot?(:destroy, Project.new)
# end # end
# #
def can?(action, noun) # TODO this could use some refactoring def can?(action, noun)
(@can_definitions || []).reverse.each do |base_behavior, defined_action, defined_noun, defined_block| (@can_definitions || []).reverse.each do |base_behavior, defined_action, defined_noun, defined_block|
defined_actions = expand_actions(defined_action) defined_actions = expand_actions(defined_action)
defined_nouns = [defined_noun].flatten defined_nouns = [defined_noun].flatten

View File

@ -82,7 +82,7 @@ module CanCan
# #
# before_filter :load_resource # before_filter :load_resource
# #
def load_resource # TODO this could use some refactoring def load_resource
ResourceAuthorization.new(self, params).load_resource ResourceAuthorization.new(self, params).load_resource
end end
@ -98,7 +98,7 @@ module CanCan
# before_filter :authorize_resource # before_filter :authorize_resource
# #
# See load_and_authorize_resource to automatically load the resource too. # See load_and_authorize_resource to automatically load the resource too.
def authorize_resource # TODO this could use some refactoring def authorize_resource
ResourceAuthorization.new(self, params).authorize_resource ResourceAuthorization.new(self, params).authorize_resource
end end
@ -109,7 +109,8 @@ module CanCan
# before_filter :load_and_authorize_resource # before_filter :load_and_authorize_resource
# #
def load_and_authorize_resource def load_and_authorize_resource
ResourceAuthorization.new(self, params).load_and_authorize_resource load_resource
authorize_resource
end end
end end
end end

View File

@ -37,8 +37,9 @@ describe CanCan::ControllerAdditions do
@controller.authorize_resource @controller.authorize_resource
end end
it "should load and authorize resource in one call" do it "should load and authorize resource in one call through controller" do
mock.instance_of(CanCan::ResourceAuthorization).load_and_authorize_resource mock(@controller).load_resource
mock(@controller).authorize_resource
@controller.load_and_authorize_resource @controller.load_and_authorize_resource
end end
end end