devel #254
2 changed files with 17 additions and 2 deletions
|
@ -70,7 +70,10 @@ defmodule Chiya.Tags.TagUpdater do
|
|||
end
|
||||
|
||||
defp add_tags(note, tags) do
|
||||
Enum.each(tags, &add_tag(note, &1))
|
||||
tags
|
||||
|> Enum.uniq()
|
||||
|> Enum.each(&add_tag(note, &1))
|
||||
|
||||
note
|
||||
end
|
||||
|
||||
|
@ -102,7 +105,10 @@ defmodule Chiya.Tags.TagUpdater do
|
|||
end
|
||||
|
||||
defp remove_tags(note, tags) do
|
||||
Enum.each(tags, &remove_tag(note, &1))
|
||||
tags
|
||||
|> Enum.uniq()
|
||||
|> Enum.each(&remove_tag(note, &1))
|
||||
|
||||
note
|
||||
end
|
||||
|
||||
|
|
|
@ -53,5 +53,14 @@ defmodule Chiya.TagUpdaterTest do
|
|||
tag = List.first(note.tags)
|
||||
assert tag.name == "foo"
|
||||
end
|
||||
|
||||
test "with the same tag twice only adds unique tags" do
|
||||
note = note_fixture()
|
||||
assert note.tags == []
|
||||
|
||||
TagUpdater.update_tags(note, "foo,foo")
|
||||
note = Chiya.Notes.get_note_preloaded!(note.id)
|
||||
assert Enum.count(note.tags) == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue