Use Active Storage to render attachments

This way we fix a bug we mentioned in commit 930bb753c which caused
links to documents to be broken when editing their title because the
title was used to generate the URL of the document.

Note we're still using Paperclip to render cached attachments because
this is the only case where we store files with just Paperclip and not
Active Storage.

With Active Storage, we render attachments just like any other resource,
using `polymorphic_path`. Paperclip included the `url` method in the
model; since the model doesn't have access to the request parameters
(like the host), this was inconvenient because it wasn't possible to
generate absolute URLs with Paperclip.

In order to simplify the code and make it similar to the way we used
Paperclip, we're adding a `variant` method accepting the name of a
variant and returning the variant.
This commit is contained in:
Javi Martín
2021-07-27 20:48:33 +02:00
parent 074934c154
commit 091abfc944
39 changed files with 88 additions and 55 deletions

View File

@@ -279,6 +279,26 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
expect(page).not_to have_css ".document"
end
scenario "Same attachment URL after editing the title" do
do_login_for user_to_login
visit send(path, arguments)
documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf"))
within_fieldset("Documents") { fill_in "Title", with: "Original" }
click_button submit_button
expect(page).to have_content documentable_success_notice
original_url = find_link("Download file")[:href]
visit send(path, arguments)
within_fieldset("Documents") { fill_in "Title", with: "Updated" }
click_button submit_button
expect(page).to have_content documentable_success_notice
expect(find_link("Download file")[:href]).to eq original_url
end
end
describe "When allow attached documents setting is disabled" do