Skip to content

Commit 269def8

Browse files
committed
Merge pull request #21 from DefactoSoftware/allow-case-insensitive-tags
allow case insensitive tags
2 parents 9392b53 + 2667c85 commit 269def8

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

app/models/entry.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ def tag_list
3333

3434
def tag_list=(names)
3535
self.tags = names.split(",").map do |n|
36-
Tag.where(name: n.strip).first_or_create!
36+
Tag.where("name ILIKE ?", n.strip).first_or_initialize.tap do |tag|
37+
tag.name = n.strip
38+
tag.save!
39+
end
3740
end
3841
end
3942
end

spec/models/entry_spec.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,26 @@
4343
end
4444

4545
describe "#taglist=" do
46+
let(:entry) { create(:entry) }
4647
it "takes a strint of comma separated values and sets the tags" do
47-
entry = create(:entry)
4848
existing_tag = create(:tag)
4949
entry.tag_list = "#{existing_tag.name}, New Tag"
5050
expect(entry.tag_list).to eq("#{existing_tag.name}, New Tag")
5151
end
5252

5353
it "removes any tagging that is left out" do
54-
entry = create(:entry)
5554
entry.tag_list = "tag1, tag2, tag3, tag4"
5655
entry.tag_list = "tag1, tag3"
5756
expect(entry.tag_list).to eq("tag1, tag3")
5857
end
58+
59+
it "finds the tag case insensitive" do
60+
entry.tag_list = "tdd"
61+
expect {
62+
entry.tag_list = "TDD"
63+
}.to_not raise_error
64+
expect(Tag.last.name).to eq("TDD")
65+
expect(entry.reload.tag_list).to include("TDD")
66+
end
5967
end
6068
end

0 commit comments

Comments
 (0)