Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an alternative csv preview route #4445

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions spec/routing/csv_previews_spec.rb
Original file line number Diff line number Diff line change
@@ -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