Skip to content
Browse files

Merge pull request #296 from bnorton/master

Fix broken spec around case sensitive taggings
  • Loading branch information...
2 parents 53e2e14 + 5022671 commit cebde2bbc173b6120053f1dd17320d66b3ce22ec @artemk artemk committed Oct 9, 2012
Showing with 14 additions and 6 deletions.
  1. +7 −2 lib/acts_as_taggable_on/tag.rb
  2. +7 −4 spec/acts_as_taggable_on/tag_spec.rb
View
9 lib/acts_as_taggable_on/tag.rb
@@ -18,15 +18,15 @@ class Tag < ::ActiveRecord::Base
def self.named(name)
if ActsAsTaggableOn.strict_case_match
- where(["name = ?", name])
+ where(["name = #{binary}?", name])
else
where(["lower(name) = ?", name.downcase])
end
end
def self.named_any(list)
if ActsAsTaggableOn.strict_case_match
- where(list.map { |tag| sanitize_sql(["name = ?", tag.to_s.mb_chars]) }.join(" OR "))
+ where(list.map { |tag| sanitize_sql(["name = #{binary}?", tag.to_s.mb_chars]) }.join(" OR "))
else
where(list.map { |tag| sanitize_sql(["lower(name) = ?", tag.to_s.mb_chars.downcase]) }.join(" OR "))
end
@@ -81,9 +81,14 @@ def count
class << self
private
+
def comparable_name(str)
str.mb_chars.downcase.to_s
end
+
+ def binary
+ /mysql/ === ActiveRecord::Base.connection_config[:adapter] ? "BINARY " : nil
+ end
end
end
end
View
11 spec/acts_as_taggable_on/tag_spec.rb
@@ -153,6 +153,8 @@
describe "when using strict_case_match" do
before do
ActsAsTaggableOn.strict_case_match = true
+ @tag.name = "awesome"
+ @tag.save!
end
after do
@@ -164,17 +166,18 @@
end
it "should find by name case sensitively" do
- tag_count = ActsAsTaggableOn::Tag.count
- tag = ActsAsTaggableOn::Tag.find_or_create_with_like_by_name("AWESOME")
+ expect {
+ ActsAsTaggableOn::Tag.find_or_create_with_like_by_name("AWESOME")
+ }.to change(ActsAsTaggableOn::Tag, :count)
- ActsAsTaggableOn::Tag.count.should == tag_count + 1
- tag.name.should == "AWESOME"
+ ActsAsTaggableOn::Tag.last.name.should == "AWESOME"
end
it "should have a named_scope named(something) that matches exactly" do
uppercase_tag = ActsAsTaggableOn::Tag.create(:name => "Cool")
@tag.name = "cool"
@tag.save!
+
ActsAsTaggableOn::Tag.named('cool').should include(@tag)
ActsAsTaggableOn::Tag.named('cool').should_not include(uppercase_tag)
end

0 comments on commit cebde2b

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