Skip to content

Commit

Permalink
Call hook on entry publication
Browse files Browse the repository at this point in the history
Allow plugins to register custom functionality to be performed when an
entry has been published.
  • Loading branch information
tf committed Jul 26, 2017
1 parent 966a98f commit 2eb6ee9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/models/pageflow/entry_publication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def exceeding?
def save!
assumed_quota.verify_not_exceeded!
entry.publish(attributes.merge(creator: user))

Pageflow.config.hooks.invoke(:entry_published, entry: entry)
end

private
Expand Down
13 changes: 13 additions & 0 deletions spec/models/pageflow/entry_publication_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ module Pageflow

entry_publication.save!
end

it 'invokes entry_published hooks' do
entry = create(:entry)
user = create(:user, account: entry.account)
quota = QuotaDouble.available.new(:published_entries, entry.account)
entry_publication = EntryPublication.new(entry, {}, quota, user)
subscriber = double('subscriber', call: nil)

Pageflow.config.hooks.on(:entry_published, subscriber)
entry_publication.save!

expect(subscriber).to have_received(:call).with(entry: entry)
end
end
end
end

0 comments on commit 2eb6ee9

Please sign in to comment.