From 2eb6ee98a1010758b84e3c5f140f79f662dde423 Mon Sep 17 00:00:00 2001 From: Tim Fischbach Date: Wed, 26 Jul 2017 14:10:05 +0200 Subject: [PATCH 1/2] Call hook on entry publication Allow plugins to register custom functionality to be performed when an entry has been published. --- app/models/pageflow/entry_publication.rb | 2 ++ spec/models/pageflow/entry_publication_spec.rb | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/app/models/pageflow/entry_publication.rb b/app/models/pageflow/entry_publication.rb index b863613359..67e2629e4e 100644 --- a/app/models/pageflow/entry_publication.rb +++ b/app/models/pageflow/entry_publication.rb @@ -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 diff --git a/spec/models/pageflow/entry_publication_spec.rb b/spec/models/pageflow/entry_publication_spec.rb index 6f3bdbe00b..089415bce1 100644 --- a/spec/models/pageflow/entry_publication_spec.rb +++ b/spec/models/pageflow/entry_publication_spec.rb @@ -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 From 48b309ae9eeb5779c3d044ae9dcb80e925892a04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Fankh=C3=A4nel?= Date: Mon, 17 Jul 2017 13:38:48 +0200 Subject: [PATCH 2/2] Adjust spec to new permissions model --- spec/models/pageflow/entry_publication_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/pageflow/entry_publication_spec.rb b/spec/models/pageflow/entry_publication_spec.rb index 089415bce1..4c9388701c 100644 --- a/spec/models/pageflow/entry_publication_spec.rb +++ b/spec/models/pageflow/entry_publication_spec.rb @@ -87,7 +87,7 @@ module Pageflow it 'invokes entry_published hooks' do entry = create(:entry) - user = create(:user, account: entry.account) + user = create(:user, :previewer, on: entry) quota = QuotaDouble.available.new(:published_entries, entry.account) entry_publication = EntryPublication.new(entry, {}, quota, user) subscriber = double('subscriber', call: nil)