Skip to content

Commit

Permalink
Merge pull request #2029 from tf/inverse-entry
Browse files Browse the repository at this point in the history
Set inverse of draft and published_revision associations on entry
  • Loading branch information
tf authored Nov 16, 2023
2 parents fa8858e + 00393d4 commit e21d4f9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/models/pageflow/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class PasswordMissingError < StandardError

has_many :imports, class_name: 'Pageflow::FileImport', dependent: :destroy

has_one :draft, -> { editable }, :class_name => 'Revision'
has_one :published_revision, -> { published }, :class_name => 'Revision'
has_one :draft, -> { editable }, class_name: 'Revision', inverse_of: :entry
has_one :published_revision, -> { published }, class_name: 'Revision', inverse_of: :entry

has_one :edit_lock, :dependent => :destroy

Expand Down
16 changes: 16 additions & 0 deletions spec/models/pageflow/entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ module Pageflow
end
end

describe '#draft' do
it 'sets inverse of association' do
entry = create(:entry)

expect(entry.draft.entry).to be(entry)
end
end

describe '#published_revision' do
it 'sets inverse of association' do
entry = create(:entry, :published)

expect(entry.published_revision.entry).to be(entry)
end
end

describe '#entry_type' do
it 'returns entry type' do
pageflow_configure do |config|
Expand Down
21 changes: 19 additions & 2 deletions spec/models/pageflow/revision_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,26 @@ module Pageflow
config.themes.register(:named_theme)
end

site = build(:revision, theme_name: 'named_theme')
revision = build(:revision, theme_name: 'named_theme')

expect(site.theme.name).to eq('named_theme')
expect(revision.theme.name).to eq('named_theme')
end

it 'honors feature flags of transiently set account' do
pageflow_configure do |config|
config.themes.register(:some_theme, some: :option)

config.features.register('override_theme') do |feature_config|
feature_config.themes.register(:some_theme, some: :override)
end
end

entry = create(:entry, draft_attributes: {theme_name: 'some_theme'})
account_with_feature_flag = create(:account, with_feature: 'override_theme')

entry = Entry.find(entry.id)
entry.account = account_with_feature_flag
expect(entry.draft.theme.options[:some]).to eq(:override)
end
end

Expand Down

0 comments on commit e21d4f9

Please sign in to comment.