fix matches_conditons_hash for string values on 1.8

This commit is contained in:
Ryan Bates 2013-05-07 11:23:08 -07:00
parent 60cf6a67ef
commit ea2b07f416
2 changed files with 7 additions and 1 deletions

View File

@ -116,7 +116,7 @@ module CanCan
else else
!attribute.nil? && matches_conditions_hash?(attribute, value) !attribute.nil? && matches_conditions_hash?(attribute, value)
end end
elsif value.kind_of?(Enumerable) elsif !value.is_a?(String) && value.kind_of?(Enumerable)
value.include? attribute value.include? attribute
else else
attribute == value attribute == value

View File

@ -269,6 +269,12 @@ describe CanCan::Ability do
@ability.can?(:read, []).should be_false @ability.can?(:read, []).should be_false
end end
it "should match strings but not substrings specified in a conditions hash" do
@ability.can :read, String, :presence => "declassified"
@ability.can?(:read, "declassified").should be_true
@ability.can?(:read, "classified").should be_false
end
it "should not stop at cannot definition when comparing class" do it "should not stop at cannot definition when comparing class" do
@ability.can :read, Range @ability.can :read, Range
@ability.cannot :read, Range, :begin => 1 @ability.cannot :read, Range, :begin => 1