diff --git a/config/routes.rb b/config/routes.rb index ab8de6a96e..31e8bb8dee 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -67,8 +67,10 @@ get "/find-licences/:slug/:authority_slug", to: "licence_transaction#authority", as: "licence_transaction_authority" get "/find-licences/:slug/:authority_slug/:interaction", to: "licence_transaction#authority_interaction", as: "licence_transaction_authority_interaction" - # Media previews + # Old style media previews (compatible with preview_url) get "/media/:id/:filename/preview", to: "csv_preview#show", filename: /[^\/]+/ + # New style CSV previews (using a different path to avoid the special routing for preview_url) + get "/csv-preview/:id/:filename", to: "csv_preview#show", filename: /[^\/]+/ scope "/government" do # Placeholder for attachments being virus-scanned diff --git a/spec/routing/csv_previews_spec.rb b/spec/routing/csv_previews_spec.rb new file mode 100644 index 0000000000..dbe534f5a3 --- /dev/null +++ b/spec/routing/csv_previews_spec.rb @@ -0,0 +1,19 @@ +RSpec.describe "CSV previews" do + it "routes old style paths to the CsvPreviewController" do + expect(get("/media/000000000000000000000000/some-file.csv/preview")).to route_to( + controller: "csv_preview", + action: "show", + id: "000000000000000000000000", + filename: "some-file.csv", + ) + end + + it "routes new style paths to the CsvPreviewController" do + expect(get("/csv-preview/000000000000000000000000/some-file.csv")).to route_to( + controller: "csv_preview", + action: "show", + id: "000000000000000000000000", + filename: "some-file.csv", + ) + end +end