adding initial aliases for index, show, new and edit

This commit is contained in:
Ryan Bates 2009-11-16 15:09:25 -08:00
parent d5f6e0570c
commit be1892cca8
2 changed files with 17 additions and 0 deletions

View File

@ -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)

View File

@ -18,6 +18,7 @@ describe CanCan::Ability do
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 @@ describe CanCan::Ability do
@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