Skip to content

Commit 5521c38

Browse files
authored
feat: use the Rails asset host to generate the URL of the static section screenshots (#187)
1 parent c7ed9a7 commit 5521c38

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

app/services/maglev/fetch_section_screenshot_url.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,18 @@ class FetchSectionScreenshotUrl
88
argument :section
99

1010
def call
11-
fetch_section_screenshot_path.call(section: section) + "?#{section.screenshot_timestamp}"
11+
screenshot_path = fetch_section_screenshot_path.call(section: section) + query_string
12+
asset_host ? URI.join(asset_host, screenshot_path).to_s : screenshot_path
13+
end
14+
15+
private
16+
17+
def asset_host
18+
Rails.application.config.asset_host
19+
end
20+
21+
def query_string
22+
"?#{section.screenshot_timestamp}"
1223
end
1324
end
1425
end

lib/maglev.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def config
2929
c.uploader = :active_storage
3030
c.site_publishable = false
3131
c.preview_host = nil
32-
c.asset_host = Rails.application.config.action_controller.asset_host
32+
c.asset_host = Rails.application.config.asset_host
3333
c.ui_locale = nil
3434
c.back_action = nil
3535
c.services = {}

spec/services/maglev/fetch_section_screenshot_url_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,14 @@
1313
it 'returns the url to the screenshot of the section' do
1414
expect(subject).to eq '/theme/jumbotron.png?42'
1515
end
16+
17+
context 'when there is a Rails asset host set' do
18+
before do
19+
allow(Rails.application.config).to receive(:asset_host).and_return('https://assets.maglev.local')
20+
end
21+
22+
it 'uses the Rails asset host to build the url' do
23+
expect(subject).to eq 'https://assets.maglev.local/theme/jumbotron.png?42'
24+
end
25+
end
1626
end

0 commit comments

Comments
 (0)