Skip to content

Commit

Permalink
🧹🥗 Journal: Add Entry#summary field (#8)
Browse files Browse the repository at this point in the history
- zinc-collective#10

What I'm driving towards here is similar to
#2055, where a
`Journal::Entry` has an affordance for being opinionated about how it's
represented when linked to in search engines or peer-to-peer sharing; as
well as short text for when there are a several on `Journal#show`.
  • Loading branch information
zspencer authored Jan 29, 2024
1 parent 7c33d7b commit e6aa446
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/furniture/journal/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class Entry < ApplicationRecord

scope :matching_keywords, ->(keywords) { where("keywords::text[] && ARRAY[?]::text[]", keywords) }

SUMMARY_MAX_LENGTH = 300
validates :summary, length: {maximum: SUMMARY_MAX_LENGTH, allow_blank: true}

def migrate_to(journal:, keywords: [])
new_body = keywords.present? ? body + "\n##{keywords.join(" #")}" : body
update(journal: journal, body: new_body)
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20240129014151_journal_add_description_to_entry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class JournalAddDescriptionToEntry < ActiveRecord::Migration[7.1]
def change
add_column :journal_entries, :summary, :text
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2024_01_20_034325) do
ActiveRecord::Schema[7.1].define(version: 2024_01_29_014151) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
Expand Down Expand Up @@ -116,6 +116,7 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "keywords", array: true
t.text "summary"
t.index ["journal_id"], name: "index_journal_entries_on_journal_id"
end

Expand Down
4 changes: 4 additions & 0 deletions spec/furniture/journal/entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
end
end

describe "#summary" do
it { is_expected.to validate_length_of(:summary).is_at_most(300).allow_blank }
end

describe "#save" do
let(:entry) { create(:journal_entry, body: "#GoodTimes") }
let(:journal) { entry.journal }
Expand Down

0 comments on commit e6aa446

Please sign in to comment.