Skip to content

Commit

Permalink
Journal: Entry stores each Keyword it uses only once.
Browse files Browse the repository at this point in the history
  • Loading branch information
zspencer committed Jul 15, 2023
1 parent d413ff8 commit e8d5f2d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/furniture/journal/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/furniture/journal/entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e8d5f2d

Please sign in to comment.