-
-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1957 from tvdeyen/publish-targets
Add Publish Targets
- Loading branch information
Showing
4 changed files
with
73 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
module Alchemy | ||
YAML_WHITELIST_CLASSES = %w(Symbol Date Regexp) | ||
|
||
# Define page publish targets | ||
# | ||
# A publish target is a ActiveJob that gets performed | ||
# whenever a user clicks the publish page button. | ||
# | ||
# Use this to trigger deployment hooks of external | ||
# services in an asychronous way. | ||
# | ||
# == Example | ||
# | ||
# # app/jobs/publish_job.rb | ||
# class PublishJob < ApplicationJob | ||
# def perform(page) | ||
# RestClient.post(ENV['BUILD_HOOK_URL']) | ||
# end | ||
# end | ||
# | ||
# # config/initializers/alchemy.rb | ||
# Alchemy.publish_targets << PublishJob | ||
# | ||
def self.publish_targets | ||
@_publish_targets ||= Set.new | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe Alchemy::Admin::PagesController do | ||
routes { Alchemy::Engine.routes } | ||
|
||
before do | ||
authorize_user(:as_admin) | ||
end | ||
|
||
describe "#publish" do | ||
let(:page) { create(:alchemy_page) } | ||
|
||
it "publishes the page" do | ||
expect_any_instance_of(Alchemy::Page).to receive(:publish!) | ||
post :publish, params: { id: page } | ||
end | ||
|
||
context "with publish targets" do | ||
class FooTarget < ActiveJob::Base | ||
def perform(_page) | ||
end | ||
end | ||
|
||
around do |example| | ||
Alchemy.publish_targets << FooTarget | ||
example.run | ||
Alchemy.instance_variable_set(:@_publish_targets, nil) | ||
end | ||
|
||
it "performs each target" do | ||
expect(FooTarget).to receive(:perform_later).with(page) | ||
post :publish, params: { id: page } | ||
end | ||
end | ||
end | ||
end |