Skip to content

Commit

Permalink
Merge pull request #1678 from alphagov/assets-preview-redirect
Browse files Browse the repository at this point in the history
Support redirecting to asset preview URLs
  • Loading branch information
thomasleese authored Mar 9, 2020
2 parents e4c9a2e + 2f9ad4a commit c5a6f6d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

get "healthcheck", to: proc { [200, {}, [""]] }

get "/government/uploads/*path" => "asset_manager_redirect#show", format: true
get "/government/uploads/*path" => "asset_manager_redirect#show", format: false

get "*path/:variant" => "content_items#show",
constraints: {
Expand Down
11 changes: 9 additions & 2 deletions test/controllers/asset_manager_redirect_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@ class AssetManagerRedirectControllerTest < ActionController::TestCase

test "redirects asset requests made via public host to the public asset host" do
request.host = "some-host.com"
get :show, params: { path: "asset", format: "txt" }
get :show, params: { path: "asset.txt" }

assert_redirected_to "http://asset-host.com/government/uploads/asset.txt"
end

test "redirects asset requests made via draft host to the draft asset host" do
request.host = "draft-some-host.com"
get :show, params: { path: "asset", format: "txt" }
get :show, params: { path: "asset.txt" }

assert_redirected_to "http://draft-asset-host.com/government/uploads/asset.txt"
end

test "redirects asset preview requests made via public host to the public asset host" do
request.host = "some-host.com"
get :show, params: { path: "asset.csv/preview" }

assert_redirected_to "http://asset-host.com/government/uploads/asset.csv/preview"
end
end

0 comments on commit c5a6f6d

Please sign in to comment.