Skip to content

Commit 9e8a0a5

Browse files
committed
add spec for simple redirects for uploads controller
1 parent 8208cae commit 9e8a0a5

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
# == Schema Information
4+
#
5+
# Table name: uploaded_documents
6+
#
7+
# id :integer not null, primary key
8+
# name :string
9+
# author :string
10+
# caption :string
11+
# file :string
12+
# created_at :datetime not null
13+
# updated_at :datetime not null
14+
#
15+
16+
FactoryBot.define do
17+
factory :uploaded_document do
18+
name { "Document Name" }
19+
author { "Document Author" }
20+
caption { "Document Caption" }
21+
file { Rack::Test::UploadedFile.new(File.join(Rails.root, "spec", "support", "files", "doc.pdf")) }
22+
end
23+
end

spec/integration/uploads_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,5 +305,16 @@
305305
expect(response).to have_http_status(:not_found)
306306
end
307307
end
308+
309+
context "Redirects handling" do
310+
it "redirects old /uploads/documents path to new /uploads/uploaded_document/file path" do
311+
uploaded_document = create(:uploaded_document)
312+
313+
get "/uploads/documents/#{uploaded_document.id}/#{uploaded_document.file.identifier}"
314+
315+
expect(response).to have_http_status(:found)
316+
expect(response).to redirect_to(uploaded_document.file.url)
317+
end
318+
end
308319
end
309320
end

0 commit comments

Comments
 (0)