mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-11 18:26:50 +00:00
Automate replacement of generated image URLs in Swagger doc
This commit is contained in:
@@ -105,18 +105,6 @@ RSpec.describe "Enterprises", swagger_doc: "dfc.yaml" do
|
||||
run_test! do
|
||||
expect(response.body).to include "Fred's Farm"
|
||||
expect(response.body).to include "Fred's Icecream"
|
||||
|
||||
# Insert static value to keep documentation deterministic:
|
||||
response.body.gsub!(
|
||||
%r{active_storage/[0-9A-Za-z/=-]*/logo-white.png},
|
||||
"active_storage/url/logo-white.png",
|
||||
).gsub!(
|
||||
%r{active_storage/[0-9A-Za-z/=-]*/logo.png},
|
||||
"active_storage/url/logo.png",
|
||||
).gsub!(
|
||||
%r{active_storage/[0-9A-Za-z/=-]*/promo.png},
|
||||
"active_storage/url/promo.png",
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -168,18 +156,6 @@ RSpec.describe "Enterprises", swagger_doc: "dfc.yaml" do
|
||||
"dfc-b:affiliates" => "http://test.host/api/dfc/enterprise_groups/60000",
|
||||
"dfc-b:websitePage" => "https://openfoodnetwork.org",
|
||||
)
|
||||
|
||||
# Insert static value to keep documentation deterministic:
|
||||
response.body.gsub!(
|
||||
%r{active_storage/[0-9A-Za-z/=-]*/logo-white.png},
|
||||
"active_storage/url/logo-white.png",
|
||||
).gsub!(
|
||||
%r{active_storage/[0-9A-Za-z/=-]*/logo.png},
|
||||
"active_storage/url/logo.png",
|
||||
).gsub!(
|
||||
%r{active_storage/[0-9A-Za-z/=-]*/promo.png},
|
||||
"active_storage/url/promo.png",
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -73,12 +73,6 @@ RSpec.describe "SuppliedProducts", swagger_doc: "dfc.yaml" do
|
||||
context "as user owning two enterprises" do
|
||||
run_test! do
|
||||
expect(response.body).to include "Pesto"
|
||||
|
||||
# Insert static value to keep documentation deterministic:
|
||||
response.body.gsub!(
|
||||
%r{active_storage/[0-9A-Za-z/=-]*/logo-white.png},
|
||||
"active_storage/url/logo-white.png",
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -218,10 +212,6 @@ RSpec.describe "SuppliedProducts", swagger_doc: "dfc.yaml" do
|
||||
"supplied_products/#{variant_id}",
|
||||
"supplied_products/10001"
|
||||
)
|
||||
.gsub!(
|
||||
%r{active_storage/[0-9A-Za-z/=-]*/logo-white.png},
|
||||
"active_storage/url/logo-white.png",
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -246,12 +236,6 @@ RSpec.describe "SuppliedProducts", swagger_doc: "dfc.yaml" do
|
||||
expect(json_response["ofn:spree_product_id"]).to eq 90_000
|
||||
expect(json_response["dfc-b:hasType"]).to eq("dfc-pt:processed-vegetable")
|
||||
expect(json_response["ofn:image"]).to include("logo-white.png")
|
||||
|
||||
# Insert static value to keep documentation deterministic:
|
||||
response.body.gsub!(
|
||||
%r{active_storage/[0-9A-Za-z/=-]*/logo-white.png},
|
||||
"active_storage/url/logo-white.png",
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -80,6 +80,12 @@ RSpec.configure do |config|
|
||||
|
||||
next if response&.body.blank?
|
||||
|
||||
# Replace random values from generated strings for a deterministic documentation.
|
||||
response.body.gsub!(
|
||||
%r{/rails/active_storage/[0-9A-Za-z/=-]*/([^/.]+).png},
|
||||
'/rails/active_storage/url/\1.png',
|
||||
)
|
||||
|
||||
# Include response as example in the documentation.
|
||||
example.metadata[:response][:content] ||= {}
|
||||
example.metadata[:response][:content].deep_merge!(
|
||||
|
||||
Reference in New Issue
Block a user