Skip to content

Commit

Permalink
Merge pull request #440 from BenZhang/master
Browse files Browse the repository at this point in the history
[Fix] Comparing tag names now respects strict_case_match
  • Loading branch information
bf4 committed Jan 2, 2014
2 parents 41c4751 + cfb72cb commit 3a04338
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
6 changes: 5 additions & 1 deletion lib/acts_as_taggable_on/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 18 additions & 4 deletions spec/acts_as_taggable_on/tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3a04338

Please sign in to comment.