consistency addition for ability check on Module

This commit is contained in:
Sokolov Yura 2010-09-20 04:39:06 +08:00 committed by Ryan Bates
parent cef55c95e7
commit ebef3cc745
2 changed files with 21 additions and 1 deletions

View File

@ -79,7 +79,8 @@ module CanCan
private
def subject_class?(subject)
(subject.kind_of?(Hash) ? subject.values.first : subject).class == Class
klass = (subject.kind_of?(Hash) ? subject.values.first : subject).class
klass == Class || klass == Module
end
def matches_action?(action)

View File

@ -23,6 +23,14 @@ describe CanCan::Ability do
end
@ability.can?(:read, :some_symbol).should == true
end
it "should pass nil to a block when no instance is passed" do
@ability.can :read, Symbol do |sym|
sym.should be_nil
true
end
@ability.can?(:read, Symbol).should be_true
end
it "should pass to previous can definition, if block returns false or nil" do
@ability.can :read, Symbol
@ -257,6 +265,17 @@ describe CanCan::Ability do
@ability.can?(:read, A).should be_true
@ability.can?(:read, A.new).should be_true
end
it "should pass nil to a block for ability on Module when no instance is passed" do
module B; end
class A; include B; end
@ability.can :read, B do |sym|
sym.should be_nil
true
end
@ability.can?(:read, B).should be_true
@ability.can?(:read, A).should be_true
end
it "passing a hash of subjects should check permissions through association" do
@ability.can :read, Range, :string => {:length => 3}