Permalink
Browse files

Adding Ability#merge

  • Loading branch information...
1 parent 9eebeb2 commit 7797b37c7e70a4299c144a0da5dbc3b347416715 @rogercampos rogercampos committed Oct 31, 2011
Showing with 20 additions and 0 deletions.
  1. +7 −0 lib/cancan/ability.rb
  2. +13 −0 spec/cancan/ability_spec.rb
View
@@ -228,6 +228,13 @@ def has_raw_sql?(action, subject)
relevant_rules(action, subject).any?(&:only_raw_sql?)
end
+ def merge(ability)
+ ability.send(:rules).each do |rule|
+ rules << rule.dup
+ end
+ self
+ end
+
private
def unauthorized_message_keys(action, subject)
@@ -416,4 +416,17 @@ class Container < Hash; end
@ability.unauthorized_message(:edit, 1..3).should == "edit range"
end
end
+
+ describe "#merge" do
+ it "should add the rules from the given ability" do
+ @ability.can :use, :tools
+ another_ability = Object.new
+ another_ability.extend(CanCan::Ability)
@knoopx

knoopx Jan 18, 2013

another_ability = Class.new(CanCan::Ability) 😄

+ another_ability.can :use, :search
+
+ @ability.merge(another_ability)
+ @ability.can?(:use, :search).should be_true
+ @ability.send(:rules).size.should == 2
+ end
+ end
end

0 comments on commit 7797b37

Please sign in to comment.