consider ancestors when matching classes in Ability#can, this way it works with STI - closes #55
This commit is contained in:
parent
a157b65fbf
commit
961b8c2477
|
@ -68,7 +68,11 @@ module CanCan
|
||||||
end
|
end
|
||||||
|
|
||||||
def matches_subject?(subject)
|
def matches_subject?(subject)
|
||||||
@subjects.include?(:all) || @subjects.include?(subject) || @subjects.any? { |sub| sub.kind_of?(Class) && subject.kind_of?(sub) }
|
@subjects.include?(:all) || @subjects.include?(subject) || matches_subject_class?(subject)
|
||||||
|
end
|
||||||
|
|
||||||
|
def matches_subject_class?(subject)
|
||||||
|
@subjects.any? { |sub| sub.kind_of?(Class) && (subject.kind_of?(sub) || subject.kind_of?(Class) && subject.ancestors.include?(sub)) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def matches_conditions_hash?(subject, conditions = @conditions)
|
def matches_conditions_hash?(subject, conditions = @conditions)
|
||||||
|
|
|
@ -135,6 +135,13 @@ describe CanCan::Ability do
|
||||||
@ability.can?(:read, :nonstats).should be_false
|
@ability.can?(:read, :nonstats).should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should check ancestors of class" do
|
||||||
|
@ability.can :read, Numeric
|
||||||
|
@ability.can?(:read, Integer).should be_true
|
||||||
|
@ability.can?(:read, 1.23).should be_true
|
||||||
|
@ability.can?(:read, "foo").should be_false
|
||||||
|
end
|
||||||
|
|
||||||
it "should support 'cannot' method to define what user cannot do" do
|
it "should support 'cannot' method to define what user cannot do" do
|
||||||
@ability.can :read, :all
|
@ability.can :read, :all
|
||||||
@ability.cannot :read, Integer
|
@ability.cannot :read, Integer
|
||||||
|
|
Loading…
Reference in New Issue
Block a user