Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion app/services/maglev/fetch_section_screenshot_url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@ class FetchSectionScreenshotUrl
argument :section

def call
fetch_section_screenshot_path.call(section: section) + "?#{section.screenshot_timestamp}"
screenshot_path = fetch_section_screenshot_path.call(section: section) + query_string
asset_host ? URI.join(asset_host, screenshot_path).to_s : screenshot_path
end

private

def asset_host
Rails.application.config.asset_host
end

def query_string
"?#{section.screenshot_timestamp}"
end
end
end
2 changes: 1 addition & 1 deletion lib/maglev.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def config
c.uploader = :active_storage
c.site_publishable = false
c.preview_host = nil
c.asset_host = Rails.application.config.action_controller.asset_host
c.asset_host = Rails.application.config.asset_host
c.ui_locale = nil
c.back_action = nil
c.services = {}
Expand Down
10 changes: 10 additions & 0 deletions spec/services/maglev/fetch_section_screenshot_url_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,14 @@
it 'returns the url to the screenshot of the section' do
expect(subject).to eq '/theme/jumbotron.png?42'
end

context 'when there is a Rails asset host set' do
before do
allow(Rails.application.config).to receive(:asset_host).and_return('https://assets.maglev.local')
end

it 'uses the Rails asset host to build the url' do
expect(subject).to eq 'https://assets.maglev.local/theme/jumbotron.png?42'
end
end
end