Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹🥗 Journal: Add Entry#description field #2159

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) }

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)
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, :description, :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 "description"
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 "#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 }
Expand Down