Skip to content
Browse files

calling controller's load_resource and authorize_resource from load_a…

…nd_authorize_resource to maintain backwards compatability, even though it's not the most efficient way
  • Loading branch information...
1 parent da5a5c0 commit e32c5d0dfb525652318205fdfe3754efa213cbba @ryanb committed Nov 26, 2009
Showing with 8 additions and 6 deletions.
  1. +1 −1 lib/cancan/ability.rb
  2. +4 −3 lib/cancan/controller_additions.rb
  3. +3 −2 spec/cancan/controller_additions_spec.rb
View
2 lib/cancan/ability.rb
@@ -40,7 +40,7 @@ module Ability
# 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
View
7 lib/cancan/controller_additions.rb
@@ -82,7 +82,7 @@ def cannot?(*args)
#
# 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 @@ def load_resource # TODO this could use some refactoring
# 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 @@ def authorize_resource # TODO this could use some refactoring
# 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
View
5 spec/cancan/controller_additions_spec.rb
@@ -37,8 +37,9 @@
@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

0 comments on commit e32c5d0

Please sign in to comment.
Something went wrong with that request. Please try again.