Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding initial aliases for index, show, new and edit

  • Loading branch information...
commit be1892cca8b67d53d702cc14f0d4d57a19b01875 1 parent d5f6e05
Ryan Bates authored
Showing with 17 additions and 0 deletions.
  1. +3 −0  lib/cancan/ability.rb
  2. +14 −0 spec/cancan/ability_spec.rb
3  lib/cancan/ability.rb
View
@@ -2,6 +2,9 @@ module CanCan
module Ability
def self.included(base)
base.extend ClassMethods
+ base.alias_action :index, :show, :to => :read
+ base.alias_action :new, :to => :create
+ base.alias_action :edit, :to => :update
end
def can?(original_action, target)
14 spec/cancan/ability_spec.rb
View
@@ -18,6 +18,7 @@
end
it "should return what block returns on a can call" do
+ @ability_class.can :read, :all
@ability_class.can :read, Symbol do |sym|
sym
end
@@ -63,4 +64,17 @@
@ability.can?(:foo, 123).should == [:foo, Fixnum, 123]
@ability.can?(:bar, Fixnum).should == [:bar, Fixnum, nil]
end
+
+ it "should automatically alias index and show into read calls" do
+ @ability_class.can :read, :all
+ @ability.can?(:index, 123).should be_true
+ @ability.can?(:show, 123).should be_true
+ end
+
+ it "should automatically alias new and edit into create and update respectively" do
+ @ability_class.can(:create, :all) { :create_called }
+ @ability_class.can(:update, :all) { :update_called }
+ @ability.can?(:new, 123).should == :create_called
+ @ability.can?(:edit, 123).should == :update_called
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.