Skip to content

Commit

Permalink
Add rake task to send content-item to publishing-api
Browse files Browse the repository at this point in the history
This rake task will be run on every deploy (this is configured
in the private alphagov-deployment repo). It will send the
smart-answers to the content-store via the publishing-api.
  • Loading branch information
tijmenb committed Sep 24, 2015
1 parent ad8ddcb commit 34f8f7f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/services/content_item_publisher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class ContentItemPublisher
def publish(flow_presenters)
flow_presenters.each do |smart_answer|
content_item = FlowContentItem.new(smart_answer)
Services.publishing_api.put_content_item(content_item.base_path, content_item.payload)
end
end
end
7 changes: 7 additions & 0 deletions lib/services.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'gds_api/publishing_api'

module Services
def self.publishing_api
@publishing_api ||= GdsApi::PublishingApi.new(Plek.new.find('publishing-api'))
end
end
7 changes: 7 additions & 0 deletions lib/tasks/publishing_api.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace :publishing_api do
desc "Publish smart answers to the content-store"
task :publish => [:environment] do
flow_presenters = RegisterableSmartAnswers.new.flow_presenters
ContentItemPublisher.new.publish(flow_presenters)
end
end
12 changes: 12 additions & 0 deletions test/unit/services/content_item_publisher_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'test_helper'

class ContentItemPublisherTest < ActiveSupport::TestCase
def test_sending_item_to_content_store
request = stub_request(:put, "http://publishing-api.dev.gov.uk/content/a-flow-name")
presenter = FlowRegistrationPresenter.new(stub('flow', name: 'a-flow-name', content_id: '3e6f33b8-0723-4dd5-94a2-cab06f23a685'))

ContentItemPublisher.new.publish([presenter])

assert_requested request
end
end

0 comments on commit 34f8f7f

Please sign in to comment.