Skip to content
This repository
Browse code

fix matches_conditons_hash for string values on 1.8

  • Loading branch information...
commit ea2b07f4163a47c7ce52cea2601cffea09ed8c50 1 parent 60cf6a6
Ryan Bates authored May 07, 2013
2  lib/cancan/rule.rb
@@ -116,7 +116,7 @@ def matches_conditions_hash?(subject, conditions = @conditions)
116 116
                 else
117 117
                   !attribute.nil? && matches_conditions_hash?(attribute, value)
118 118
                 end
119  
-              elsif value.kind_of?(Enumerable)
  119
+              elsif !value.is_a?(String) && value.kind_of?(Enumerable)
120 120
                 value.include? attribute
121 121
               else
122 122
                 attribute == value
6  spec/cancan/ability_spec.rb
@@ -269,6 +269,12 @@
269 269
     @ability.can?(:read, []).should be_false
270 270
   end
271 271
 
  272
+  it "should match strings but not substrings specified in a conditions hash" do
  273
+    @ability.can :read, String, :presence => "declassified"
  274
+    @ability.can?(:read, "declassified").should be_true
  275
+    @ability.can?(:read, "classified").should be_false
  276
+  end
  277
+
272 278
   it "should not stop at cannot definition when comparing class" do
273 279
     @ability.can :read, Range
274 280
     @ability.cannot :read, Range, :begin => 1

0 notes on commit ea2b07f

Please sign in to comment.
Something went wrong with that request. Please try again.