From ea2b07f4163a47c7ce52cea2601cffea09ed8c50 Mon Sep 17 00:00:00 2001 From: Ryan Bates Date: Tue, 7 May 2013 11:23:08 -0700 Subject: [PATCH] fix matches_conditons_hash for string values on 1.8 --- lib/cancan/rule.rb | 2 +- spec/cancan/ability_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/cancan/rule.rb b/lib/cancan/rule.rb index f86296f..c0415de 100644 --- a/lib/cancan/rule.rb +++ b/lib/cancan/rule.rb @@ -116,7 +116,7 @@ module CanCan 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 diff --git a/spec/cancan/ability_spec.rb b/spec/cancan/ability_spec.rb index 0cc84e5..38595cb 100644 --- a/spec/cancan/ability_spec.rb +++ b/spec/cancan/ability_spec.rb @@ -269,6 +269,12 @@ describe CanCan::Ability do @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