From cfb72cb189703fda2f07aae29faec2b0dbd02ac5 Mon Sep 17 00:00:00 2001 From: Ben Zhang Date: Sat, 21 Dec 2013 11:44:57 +1030 Subject: [PATCH] fix strict_case_match bug --- lib/acts_as_taggable_on/tag.rb | 6 +++++- spec/acts_as_taggable_on/tag_spec.rb | 22 ++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/acts_as_taggable_on/tag.rb b/lib/acts_as_taggable_on/tag.rb index 336f8ba9f..b3727dbf7 100644 --- a/lib/acts_as_taggable_on/tag.rb +++ b/lib/acts_as_taggable_on/tag.rb @@ -100,7 +100,11 @@ class << self private def comparable_name(str) - as_8bit_ascii(str).downcase + if ActsAsTaggableOn.strict_case_match + as_8bit_ascii(str) + else + as_8bit_ascii(str).downcase + end end def binary diff --git a/spec/acts_as_taggable_on/tag_spec.rb b/spec/acts_as_taggable_on/tag_spec.rb index 74c9d4550..01a7df289 100644 --- a/spec/acts_as_taggable_on/tag_spec.rb +++ b/spec/acts_as_taggable_on/tag_spec.rb @@ -72,16 +72,30 @@ ActsAsTaggableOn::Tag.find_or_create_all_with_like_by_name("AWESOME").should == [@tag] end + it "should find by name case sensitive" do + ActsAsTaggableOn.strict_case_match = true + expect { + ActsAsTaggableOn::Tag.find_or_create_all_with_like_by_name("AWESOME") + }.to change(ActsAsTaggableOn::Tag, :count).by(1) + end + it "should create by name" do - lambda { + expect { ActsAsTaggableOn::Tag.find_or_create_all_with_like_by_name("epic") - }.should change(ActsAsTaggableOn::Tag, :count).by(1) + }.to change(ActsAsTaggableOn::Tag, :count).by(1) + end + + it "should find or create by name case sensitive" do + ActsAsTaggableOn.strict_case_match = true + expect { + ActsAsTaggableOn::Tag.find_or_create_all_with_like_by_name("AWESOME", 'awesome').map(&:name).should == ["AWESOME", "awesome"] + }.to change(ActsAsTaggableOn::Tag, :count).by(1) end it "should find or create by name" do - lambda { + expect { ActsAsTaggableOn::Tag.find_or_create_all_with_like_by_name("awesome", "epic").map(&:name).should == ["awesome", "epic"] - }.should change(ActsAsTaggableOn::Tag, :count).by(1) + }.to change(ActsAsTaggableOn::Tag, :count).by(1) end it "should return an empty array if no tags are specified" do