Skip to content

Commit

Permalink
Use upload filename
Browse files Browse the repository at this point in the history
This updates the code to use the upload filename everywhere when we want
to render the upload name previously.
  • Loading branch information
thomasleese committed Apr 11, 2024
1 parent 6809e82 commit 3a90eee
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 31 deletions.
2 changes: 1 addition & 1 deletion app/helpers/upload_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module UploadHelper
def upload_link_to(upload)
href =
govuk_link_to(
"#{upload.name} (opens in a new tab)",
"#{upload.filename} (opens in a new tab)",
upload_path(upload),
target: :_blank,
rel: :noopener,
Expand Down
6 changes: 0 additions & 6 deletions app/models/upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ def original?
!translation?
end

def name
return "File upload error" if scan_result_suspect?

attachment.filename.to_s
end

def url
attachment.url(expires_in: 5.minutes)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<h2 class="govuk-heading-m">Returned file</h2>

<% if @consent_request.received? %>
<p class="govuk-body"><%= upload.name %></p>
<p class="govuk-body"><%= upload.filename %></p>

<div class="govuk-button-group">
<% if upload.is_pdf? %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/teacher_interface/documents/edit_uploads.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
row.with_action(
text: "Delete",
href: delete_teacher_interface_application_form_document_upload_path(@document, upload),
visually_hidden_text: upload.attachment.filename
visually_hidden_text: upload.filename
)
else
row.with_action(
text: "Change",
href: new_teacher_interface_application_form_document_upload_path(@document),
visually_hidden_text: upload.attachment.filename
visually_hidden_text: upload.filename
)
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/teacher_interface/uploads/delete.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% content_for :page_title, title_with_error_prefix("Delete #{@upload.attachment.filename}", error: @form.errors.any?) %>
<% content_for :page_title, title_with_error_prefix("Delete #{@upload.filename}", error: @form.errors.any?) %>
<% content_for :back_link_url, back_history_path(default: edit_teacher_interface_application_form_document_path(@document)) %>

<%= form_with model: @form, url: [:teacher_interface, :application_form, @document, @upload], method: :delete do |f| %>
Expand All @@ -9,7 +9,7 @@
:id,
:name,
inline: true,
legend: { text: "Are you sure you want to delete #{@upload.attachment.filename}?", size: "l", tag: "h1" } %>
legend: { text: "Are you sure you want to delete #{@upload.filename}?", size: "l", tag: "h1" } %>

<%= f.govuk_submit %>
<% end %>
4 changes: 2 additions & 2 deletions spec/factories/documents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@

trait :with_upload do
after(:create) do |document, _evaluator|
create(:upload, :clean, document:)
create(:upload, :clean, document:, filename: "upload.pdf")
end
end

trait :with_translation do
after(:create) do |document, _evaluator|
create(:upload, :translation, :clean, document:)
create(:upload, :translation, :clean, document:, filename: "upload.pdf")
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/helpers/upload_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

it "returns a link to the upload" do
expect(upload_link_to).to have_link(
"#{upload.name} (opens in a new tab)",
"#{upload.filename} (opens in a new tab)",
href:
"/teacher/application/documents/#{upload.document.id}/uploads/#{upload.id}",
)
Expand All @@ -24,7 +24,7 @@

it "returns a link to the upload" do
expect(upload_link_to).to have_link(
"#{upload.name} (opens in a new tab)",
"#{upload.filename} (opens in a new tab)",
href:
"/assessor/application/documents/#{upload.document.id}/uploads/#{upload.id}",
)
Expand All @@ -39,7 +39,7 @@

it "returns text for a pending scan" do
expect(upload_link_to).to have_link(
upload.name,
upload.filename,
href:
"/teacher/application/documents/#{upload.document.id}/uploads/#{upload.id}",
)
Expand Down
11 changes: 0 additions & 11 deletions spec/models/upload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,6 @@
end
end

describe "#name" do
subject(:name) { upload.name }

it { is_expected.to eq("upload.pdf") }

context "when a malware scan is suspect" do
before { upload.malware_scan_result = "suspect" }
it { is_expected.to eq("File upload error") }
end
end

describe "#url" do
subject(:url) { upload.url }

Expand Down
6 changes: 3 additions & 3 deletions spec/system/teacher_interface/malware_scanning_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def then_i_see_the_check_your_uploaded_files_page

def and_the_uploaded_files_have_been_marked_as_malware
expect(teacher_check_uploaded_files_page.files).to have_content(
"File 1\tFile upload error (opens in a new tab)\nThere’s a problem with this file",
"File 1\tupload.pdf (opens in a new tab)\nThere’s a problem with this file",
)
expect(teacher_check_uploaded_files_page.files).to have_content(
"File 2\tFile upload error (opens in a new tab)\nThere’s a problem with this file",
"File 2\tupload.pdf (opens in a new tab)\nThere’s a problem with this file",
)
end

Expand All @@ -76,7 +76,7 @@ def and_the_uploaded_files_have_been_removed
end

def when_i_click_on_a_file_marked_as_malware
first("a", text: "File upload error").click
first("a", text: "upload.pdf").click
end

def then_i_see_theres_a_problem_with_the_file
Expand Down

0 comments on commit 3a90eee

Please sign in to comment.