Permalink
Browse files

merging with master and resolving a couple conflicts

  • Loading branch information...
2 parents 75eb191 + cad4259 commit 5d8f04363d9bb4825171c40cb3cf28682cdf636a @ryanb committed Jul 19, 2010
Showing with 29 additions and 13 deletions.
  1. +5 −0 CHANGELOG.rdoc
  2. +1 −1 cancan.gemspec
  3. +10 −1 lib/cancan/ability.rb
  4. +5 −11 lib/cancan/can_definition.rb
  5. +7 −0 spec/cancan/ability_spec.rb
  6. +1 −0 spec/spec.opts
View
@@ -1,3 +1,7 @@
+* Supporting deeply nested aliases - see issue #98
+
+1.2.0 (July 16, 2010)
+
* Load nested parent resources on collection actions such as "index" (thanks dohzya)
* Adding :name option to load_and_authorize_resource if it does not match controller - see issue #65
@@ -10,6 +14,7 @@
* Adding joins clause to accessible_by when conditions are across associations
+
1.1.1 (April 17, 2010)
* Fixing behavior in Rails 3 by properly initializing ResourceAuthorization
View
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = "cancan"
- s.version = "1.1.1"
+ s.version = "1.2.0"
s.author = "Ryan Bates"
s.email = "ryan@railscasts.com"
s.homepage = "http://github.com/ryanb/cancan"
View
@@ -267,6 +267,15 @@ def association_joins(action, subject)
end
private
+
+ # Accepts a hash of aliased actions and returns an array of actions which match.
+ # This should be called before "matches?" and other checking methods since they
+ # rely on the actions to be expanded.
+ def expand_actions(actions)
+ actions.map do |action|
+ aliased_actions[action] ? [action, *expand_actions(aliased_actions[action])] : action
+ end.flatten
+ end
def can_definitions
@can_definitions ||= []
@@ -275,7 +284,7 @@ def can_definitions
def matching_can_definition(action, subject)
if block_given?
can_definitions.reverse.each do |can_definition|
- can_definition.expand_actions(aliased_actions)
+ can_definition.expanded_actions = expand_actions(can_definition.actions)
if can_definition.matches? action, subject
yield can_definition
break if can_definition.definitive?
@@ -5,7 +5,10 @@ module CanCan
class CanDefinition # :nodoc:
attr_reader :conditions, :block, :base_behavior, :definitive
include ActiveSupport::Inflector
-
+ attr_reader :block
+ attr_reader :actions
+ attr_writer :expanded_actions
+
# The first argument when initializing is the base_behavior which is a true/false
# value. True for "can" and false for "cannot". The next two arguments are the action
# and subject respectively (such as :read, @project). The third argument is a hash
@@ -18,15 +21,6 @@ def initialize(base_behavior, action, subject, conditions, block)
@block = block
end
- # Accepts a hash of aliased actions and returns an array of actions which match.
- # This should be called before "matches?" and other checking methods since they
- # rely on the actions to be expanded.
- def expand_actions(aliased_actions)
- @expanded_actions = @actions.map do |action|
- aliased_actions[action] ? [action, *aliased_actions[action]] : action
- end.flatten
- end
-
def matches?(action, subject)
matches_action?(action) && matches_subject?(subject)
end
@@ -54,7 +48,7 @@ def conditions(options = {})
def definitive?
conditions_empty? && @block.nil?
end
-
+
def only_block?
conditions_empty? && !@block.nil?
end
@@ -68,6 +68,13 @@
@ability.can?(:destroy, 123).should == :modify_called
end
+ it "should allow deeply nested aliased actions" do
+ @ability.alias_action :increment, :to => :sort
+ @ability.alias_action :sort, :to => :modify
+ @ability.can :modify, :all
+ @ability.can?(:increment, 123).should be_true
+ end
+
it "should return block result for action, object_class, and object for any action" do
@ability.can :manage, :all do |action, object_class, object|
[action, object_class, object]
View
@@ -0,0 +1 @@
+--color

0 comments on commit 5d8f043

Please sign in to comment.