From e6aa446c053b93c544757ead4290f1e40c9ab87d Mon Sep 17 00:00:00 2001 From: Zee <50284+zspencer@users.noreply.github.com> Date: Sun, 28 Jan 2024 20:40:19 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=F0=9F=A5=97=20`Journal`:=20Add=20`?= =?UTF-8?q?Entry#summary`=20field=20(#8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - https://github.com/zinc-collective/convene-journal/issues/10 What I'm driving towards here is similar to https://github.com/zinc-collective/convene/pull/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`. --- app/furniture/journal/entry.rb | 3 +++ .../20240129014151_journal_add_description_to_entry.rb | 5 +++++ db/schema.rb | 3 ++- spec/furniture/journal/entry_spec.rb | 4 ++++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20240129014151_journal_add_description_to_entry.rb diff --git a/app/furniture/journal/entry.rb b/app/furniture/journal/entry.rb index dd48dd6cd..e5aed1e5a 100644 --- a/app/furniture/journal/entry.rb +++ b/app/furniture/journal/entry.rb @@ -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) diff --git a/db/migrate/20240129014151_journal_add_description_to_entry.rb b/db/migrate/20240129014151_journal_add_description_to_entry.rb new file mode 100644 index 000000000..03ef6878c --- /dev/null +++ b/db/migrate/20240129014151_journal_add_description_to_entry.rb @@ -0,0 +1,5 @@ +class JournalAddDescriptionToEntry < ActiveRecord::Migration[7.1] + def change + add_column :journal_entries, :summary, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index d926915c1..ea83afecc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" @@ -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 diff --git a/spec/furniture/journal/entry_spec.rb b/spec/furniture/journal/entry_spec.rb index 8d16fff4d..840bbeb76 100644 --- a/spec/furniture/journal/entry_spec.rb +++ b/spec/furniture/journal/entry_spec.rb @@ -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 }