Skip to content

Commit

Permalink
fix matches_conditons_hash for string values on 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanb committed May 7, 2013
1 parent 60cf6a6 commit ea2b07f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/cancan/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def matches_conditions_hash?(subject, conditions = @conditions)
else
!attribute.nil? && matches_conditions_hash?(attribute, value)
end
elsif value.kind_of?(Enumerable)
elsif !value.is_a?(String) && value.kind_of?(Enumerable)
value.include? attribute
else
attribute == value
Expand Down
6 changes: 6 additions & 0 deletions spec/cancan/ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@
@ability.can?(:read, []).should be_false
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
@ability.can :read, Range
@ability.cannot :read, Range, :begin => 1
Expand Down

0 comments on commit ea2b07f

Please sign in to comment.