Skip to content
This repository

Adding Ability#merge #625

Merged
merged 1 commit into from almost 2 years ago

5 participants

Roger Campos Yvan Cottyn Anuj Dutta Víctor Martínez Ryan Bates
Roger Campos

No description provided.

Yvan Cottyn
vanne commented May 19, 2012

See Issue 501 for comment history.

Anuj Dutta
Collaborator
andhapp commented May 20, 2012

@ryanb: I've tested this and applies cleanly, so you can merge.

Ryan Bates ryanb merged commit b3f9ffe into from May 28, 2012
Ryan Bates ryanb closed this May 28, 2012
Víctor Martínez

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Oct 31, 2011
Roger Campos Adding Ability#merge 7797b37
This page is out of date. Refresh to see the latest.
7  lib/cancan/ability.rb
@@ -228,6 +228,13 @@ def has_raw_sql?(action, subject)
228 228
       relevant_rules(action, subject).any?(&:only_raw_sql?)
229 229
     end
230 230
 
  231
+    def merge(ability)
  232
+      ability.send(:rules).each do |rule|
  233
+        rules << rule.dup
  234
+      end
  235
+      self
  236
+    end
  237
+
231 238
     private
232 239
 
233 240
     def unauthorized_message_keys(action, subject)
13  spec/cancan/ability_spec.rb
@@ -416,4 +416,17 @@ class Container < Hash; end
416 416
       @ability.unauthorized_message(:edit, 1..3).should == "edit range"
417 417
     end
418 418
   end
  419
+
  420
+  describe "#merge" do
  421
+    it "should add the rules from the given ability" do
  422
+      @ability.can :use, :tools
  423
+      another_ability = Object.new
  424
+      another_ability.extend(CanCan::Ability)
  425
+      another_ability.can :use, :search
  426
+
  427
+      @ability.merge(another_ability)
  428
+      @ability.can?(:use, :search).should be_true
  429
+      @ability.send(:rules).size.should == 2
  430
+    end
  431
+  end
419 432
 end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.