commit
						b3f9ffe93b
					
				| @ -228,6 +228,13 @@ module CanCan | |||||||
|       relevant_rules(action, subject).any?(&:only_raw_sql?) |       relevant_rules(action, subject).any?(&:only_raw_sql?) | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|  |     def merge(ability) | ||||||
|  |       ability.send(:rules).each do |rule| | ||||||
|  |         rules << rule.dup | ||||||
|  |       end | ||||||
|  |       self | ||||||
|  |     end | ||||||
|  | 
 | ||||||
|     private |     private | ||||||
| 
 | 
 | ||||||
|     def unauthorized_message_keys(action, subject) |     def unauthorized_message_keys(action, subject) | ||||||
|  | |||||||
| @ -432,4 +432,17 @@ describe CanCan::Ability do | |||||||
|       @ability.unauthorized_message(:edit, 1..3).should == "edit range" |       @ability.unauthorized_message(:edit, 1..3).should == "edit range" | ||||||
|     end |     end | ||||||
|   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) | ||||||
|  |       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 | end | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Ryan Bates
						Ryan Bates