Skip to content

Commit d5e7f9a

Browse files
committed
Remove obsolete 'publishing_api_payload' method from configurable block models
Based on the new schema refactor to use "forms" property, we have now moved publishing api presenting to our new block abstraction method so this is no longer needed. See `app/presenters/publishing_api/payload_builder/block_content.rb`
1 parent 7a53e43 commit d5e7f9a

11 files changed

Lines changed: 0 additions & 203 deletions

File tree

app/models/configurable_content_blocks/default_date.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
module ConfigurableContentBlocks
22
class DefaultDate
3-
def publishing_api_payload(content)
4-
content&.rfc3339
5-
end
6-
73
def to_partial_path
84
"admin/configurable_content_blocks/default_date"
95
end

app/models/configurable_content_blocks/default_object.rb

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,5 @@ def initialize(block_factory)
99
def to_partial_path
1010
"admin/configurable_content_blocks/default_object"
1111
end
12-
13-
def publishing_api_payload(schema, content)
14-
output = {}
15-
schema["properties"].each do |property_key, property_schema|
16-
block = block_factory.build(property_schema["type"], property_schema["format"] || "default")
17-
leaf_block = !%w[object array].include?(property_schema["type"])
18-
payload = leaf_block ? block.publishing_api_payload(content[property_key]) : block.publishing_api_payload(property_schema, content[property_key])
19-
20-
next if payload.nil?
21-
22-
output.merge!({ property_key.to_sym => payload })
23-
end
24-
25-
output
26-
end
2712
end
2813
end

app/models/configurable_content_blocks/default_string.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
module ConfigurableContentBlocks
22
class DefaultString
3-
def publishing_api_payload(content)
4-
content
5-
end
6-
73
def to_partial_path
84
"admin/configurable_content_blocks/default_string"
95
end

app/models/configurable_content_blocks/govspeak.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ def initialize(images = [], attachments = [])
1010
@attachments = attachments
1111
end
1212

13-
def publishing_api_payload(content)
14-
return nil if content.nil?
15-
16-
govspeak_to_html(content, images: @images, attachments: @attachments)
17-
end
18-
1913
def to_partial_path
2014
"admin/configurable_content_blocks/govspeak"
2115
end

app/models/configurable_content_blocks/image_select.rb

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,6 @@ def initialize(images = [])
66
@images = images
77
end
88

9-
def publishing_api_payload(content)
10-
return nil if content.nil?
11-
12-
if (selected_image = images.find { |image| image.image_data.id == content })&.image_data&.all_asset_variants_uploaded?
13-
{
14-
url: selected_image.url,
15-
caption: image_caption(selected_image),
16-
}.compact
17-
end
18-
end
19-
209
def to_partial_path
2110
"admin/configurable_content_blocks/image_select"
2211
end

app/models/configurable_content_blocks/lead_image_select.rb

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,6 @@ def initialize(images = [], default_lead_image: nil, placeholder_image_url: nil)
88
@default_lead_image = default_lead_image
99
end
1010

11-
def publishing_api_payload(content)
12-
selected_image = images.find { |image| image.image_data.id == content.to_i }
13-
if selected_image
14-
if selected_image.image_data&.all_asset_variants_uploaded?
15-
# The payload for lead image must include a "high resolution url", used for metadata: https://github.com/alphagov/frontend/blob/693747dc55d9a42ba209789e6861d9b592b48c8e/spec/system/news_article_spec.rb#L65
16-
# The "url" is used for the lead image rendered on the document page.
17-
return {
18-
high_resolution_url: selected_image.image_data.url(:s960),
19-
url: selected_image.image_data.url(:s300),
20-
caption: lead_image_caption(selected_image),
21-
}.compact
22-
end
23-
elsif default_lead_image&.all_asset_variants_uploaded?
24-
return {
25-
high_resolution_url: default_lead_image.url(:s960),
26-
url: default_lead_image.url(:s300),
27-
} # default images do not have captions
28-
end
29-
30-
placeholder_payload
31-
end
32-
3311
def to_partial_path
3412
"admin/configurable_content_blocks/lead_image_select"
3513
end

test/unit/app/models/configurable_content_blocks/default_date_test.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
require "test_helper"
22

3-
class ConfigurableContentBlocks::DefaultDateTest < ActiveSupport::TestCase
4-
test "it presents the content" do
5-
payload = ConfigurableContentBlocks::DefaultDate.new.publishing_api_payload(Time.zone.now)
6-
assert_equal(Time.zone.now.rfc3339, payload)
7-
end
8-
end
9-
103
class ConfigurableContentBlocks::DefaultDateRenderingTest < ActionView::TestCase
114
setup do
125
@schema = {

test/unit/app/models/configurable_content_blocks/default_string_test.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
require "test_helper"
22

3-
class ConfigurableContentBlocks::DefaultStringTest < ActiveSupport::TestCase
4-
test "it presents the content" do
5-
payload = ConfigurableContentBlocks::DefaultString.new.publishing_api_payload("foo")
6-
assert_equal("foo", payload)
7-
end
8-
end
9-
103
class ConfigurableContentBlocks::DefaultStringRenderingTest < ActionView::TestCase
114
setup do
125
@schema = {

test/unit/app/models/configurable_content_blocks/govspeak_test.rb

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,5 @@
11
require "test_helper"
22

3-
class ConfigurableContentBlocks::GovspeakTest < ActiveSupport::TestCase
4-
test "it presents the govspeak content as HTML, including images and attachments" do
5-
image = create(:image)
6-
attachment = create(:file_attachment)
7-
govspeak = "A paragraph followed by an image:\n[Image: #{image.filename}]\n[Attachment: #{attachment.filename}]"
8-
images = [image]
9-
attachments = [attachment]
10-
payload = ConfigurableContentBlocks::Govspeak.new(images, attachments).publishing_api_payload(govspeak)
11-
doc = Nokogiri::HTML(payload)
12-
assert_not doc.css("a[href=\"#{attachment.url}\"]").empty?
13-
assert_not doc.css("img[src=\"#{image.embed_url}\"]").empty?
14-
assert_match(/A paragraph followed by an image/m, doc.text)
15-
end
16-
17-
test "does not have a publishing api payload if content is nil" do
18-
payload = ConfigurableContentBlocks::Govspeak.new.publishing_api_payload(nil)
19-
20-
assert_nil payload
21-
end
22-
end
23-
243
class ConfigurableContentBlocks::GovspeakRenderingTest < ActionView::TestCase
254
setup do
265
@schema = {

test/unit/app/models/configurable_content_blocks/image_select_test.rb

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,5 @@
11
require "test_helper"
22

3-
class ConfigurableContentBlocks::ImageSelectTest < ActiveSupport::TestCase
4-
test "it loads the correct image and presents the image attributes" do
5-
images = [create(:image), create(:image, caption: "Example caption")]
6-
payload = ConfigurableContentBlocks::ImageSelect.new(images).publishing_api_payload(images[1].image_data.id)
7-
8-
assert_equal({
9-
url: images[1].url,
10-
caption: images[1].caption,
11-
}, payload)
12-
end
13-
14-
test "it does not send the the caption if nil" do
15-
image = create(:image, caption: nil)
16-
payload = ConfigurableContentBlocks::ImageSelect.new([image]).publishing_api_payload(image.image_data.id)
17-
18-
assert_equal({
19-
url: image.url,
20-
}, payload)
21-
end
22-
23-
test "does not have a publishing api payload if content is nil" do
24-
image = create(:image)
25-
payload = ConfigurableContentBlocks::ImageSelect.new([image]).publishing_api_payload(nil)
26-
27-
assert_nil payload
28-
end
29-
30-
test "does not have a publishing api payload if selected image's assets are not ready" do
31-
images = create_list(:image, 3)
32-
images[1].image_data.assets = []
33-
images[1].image_data.save!
34-
35-
payload = ConfigurableContentBlocks::ImageSelect.new(images).publishing_api_payload(images[1].image_data.id)
36-
37-
assert_nil payload
38-
end
39-
end
40-
413
class ConfigurableContentBlocks::ImageSelectRenderingTest < ActionView::TestCase
424
setup do
435
@schema = {

0 commit comments

Comments
 (0)