From e32c5d0dfb525652318205fdfe3754efa213cbba Mon Sep 17 00:00:00 2001 From: Ryan Bates Date: Thu, 26 Nov 2009 09:53:16 -0800 Subject: [PATCH] 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 --- lib/cancan/ability.rb | 2 +- lib/cancan/controller_additions.rb | 7 ++++--- spec/cancan/controller_additions_spec.rb | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/cancan/ability.rb b/lib/cancan/ability.rb index 48b0b0b..4783e7b 100644 --- a/lib/cancan/ability.rb +++ b/lib/cancan/ability.rb @@ -40,7 +40,7 @@ module CanCan # assert ability.cannot?(:destroy, Project.new) # 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| defined_actions = expand_actions(defined_action) defined_nouns = [defined_noun].flatten diff --git a/lib/cancan/controller_additions.rb b/lib/cancan/controller_additions.rb index 8f346bd..81a97a9 100644 --- a/lib/cancan/controller_additions.rb +++ b/lib/cancan/controller_additions.rb @@ -82,7 +82,7 @@ module CanCan # # before_filter :load_resource # - def load_resource # TODO this could use some refactoring + def load_resource ResourceAuthorization.new(self, params).load_resource end @@ -98,7 +98,7 @@ module CanCan # before_filter :authorize_resource # # 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 end @@ -109,7 +109,8 @@ module CanCan # before_filter :load_and_authorize_resource # def load_and_authorize_resource - ResourceAuthorization.new(self, params).load_and_authorize_resource + load_resource + authorize_resource end end end diff --git a/spec/cancan/controller_additions_spec.rb b/spec/cancan/controller_additions_spec.rb index 59749ac..eb83a51 100644 --- a/spec/cancan/controller_additions_spec.rb +++ b/spec/cancan/controller_additions_spec.rb @@ -37,8 +37,9 @@ describe CanCan::ControllerAdditions do @controller.authorize_resource end - it "should load and authorize resource in one call" do - mock.instance_of(CanCan::ResourceAuthorization).load_and_authorize_resource + it "should load and authorize resource in one call through controller" do + mock(@controller).load_resource + mock(@controller).authorize_resource @controller.load_and_authorize_resource end end