Skip to content

Commit

Permalink
🥗🧹Journal: Make relationships of Entry Rails-able (#1648)
Browse files Browse the repository at this point in the history
- #1633

I noticed I'd left the active-record relationship cables on the
`Journal::Entry` loose. Getting rid of `delegate`s in favor of the
`has_one :x, through: :y`
  • Loading branch information
zspencer authored Jul 13, 2023
1 parent 6f53009 commit 7df4c96
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/furniture/journal/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ class Entry < ApplicationRecord

# @!attribute journal
# @return [Journal::Journal]
belongs_to :journal, class_name: "Journal::Journal", inverse_of: :entries
delegate :room, :space, to: :journal
belongs_to :journal, inverse_of: :entries
has_one :room, through: :journal
has_one :space, through: :journal

def published?
published_at.present?
Expand Down
3 changes: 3 additions & 0 deletions spec/furniture/journal/entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
it { is_expected.to validate_presence_of(:headline) }
it { is_expected.to validate_presence_of(:body) }
it { is_expected.to strip_attributes(:slug, :body, :headline) }
it { is_expected.to belong_to(:journal).inverse_of(:entries) }
it { is_expected.to have_one(:room).through(:journal) }
it { is_expected.to have_one(:space).through(:journal) }

describe "#to_html" do
subject(:to_html) { entry.to_html }
Expand Down

0 comments on commit 7df4c96

Please sign in to comment.