From e8d5f2d13338616c9c51c90561e24ece304dc645 Mon Sep 17 00:00:00 2001 From: Zee Spencer <50284+zspencer@users.noreply.github.com> Date: Fri, 14 Jul 2023 19:07:38 -0700 Subject: [PATCH] `Journal`: `Entry` stores each `Keyword` it uses only once. - https://github.com/zinc-collective/convene/issues/1566 - https://github.com/zinc-collective/convene/issues/1662 --- app/furniture/journal/entry.rb | 4 ++++ spec/furniture/journal/entry_spec.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/furniture/journal/entry.rb b/app/furniture/journal/entry.rb index 958f6ab1e..ff0603bae 100644 --- a/app/furniture/journal/entry.rb +++ b/app/furniture/journal/entry.rb @@ -55,6 +55,10 @@ def extract_keywords self.keywords = journal.keywords.extract_and_create_from!(body).pluck(:canonical_keyword) end + def keywords=(keywords) + super(keywords.uniq) + end + def to_param slug end diff --git a/spec/furniture/journal/entry_spec.rb b/spec/furniture/journal/entry_spec.rb index 14c2ca16d..60a8dba8d 100644 --- a/spec/furniture/journal/entry_spec.rb +++ b/spec/furniture/journal/entry_spec.rb @@ -29,7 +29,7 @@ bad_apple = entry.journal.keywords.create!(canonical_keyword: "BadApple", aliases: ["BadApples"]) good_times = entry.journal.keywords.find_by!(canonical_keyword: "GoodTimes") expect do - entry.update!(body: "#GoodTimes #HardCider #BadApples") + entry.update!(body: "#GoodTimes #HardCider #BadApple #BadApples") end.not_to change { "#{bad_apple.reload.updated_at} - #{good_times.reload.updated_at}" } expect(journal.keywords.where(canonical_keyword: "GoodTimes")).to exist