consistency addition for ability check on Module
This commit is contained in:
parent
cef55c95e7
commit
ebef3cc745
|
@ -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)
|
||||
|
|
|
@ -24,6 +24,14 @@ describe CanCan::Ability do
|
|||
@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
|
||||
@ability.can :read, Integer do |i|
|
||||
|
@ -258,6 +266,17 @@ describe CanCan::Ability do
|
|||
@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}
|
||||
@ability.can?(:read, "foo" => Range).should be_true
|
||||
|
|
Loading…
Reference in New Issue
Block a user