From a163c0b2dd85707a452178bd10b1d000bfb47984 Mon Sep 17 00:00:00 2001 From: Zee Spencer <50284+zspencer@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:56:57 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=F0=9F=A5=97=20`Journal`:=20Add=20`?= =?UTF-8?q?Entry#description`=20field?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - https://github.com/zinc-collective/convene-journal/issues/6 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..9c95cf615 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) } + DESCRIPTION_MAX_LENGTH = 300 + validates :description, length: {maximum: DESCRIPTION_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..a22df9498 --- /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, :description, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index d926915c1..8b17c6771 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 "description" 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..73c995b2d 100644 --- a/spec/furniture/journal/entry_spec.rb +++ b/spec/furniture/journal/entry_spec.rb @@ -22,6 +22,10 @@ end end + describe "#description" do + it { is_expected.to validate_length_of(:description).is_at_most(300).allow_blank } + end + describe "#save" do let(:entry) { create(:journal_entry, body: "#GoodTimes") } let(:journal) { entry.journal }