Skip to content

Commit

Permalink
Allow file list to not be finished by the time the dashboard renders (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
carolyncole authored Dec 16, 2024
1 parent 92be0d2 commit 0fdc443
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def file_list_to_file(session_id:, filename:)
iterator_resp = iterator_req.result
lines = files_from_iterator(iterator_resp)
file.write(lines.join("\r\n") + "\r\n")
break if iterator_resp[:complete]
break if iterator_resp[:complete] || iterator_req.error?
end
end

Expand Down
4 changes: 3 additions & 1 deletion app/presenters/project_dashboard_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ def latest_file_list_time
requests = FileInventoryRequest.where(project_id: project.id).order(completion_time: :desc)
if requests.empty?
"No Downloads"
else
elsif requests.first.completion_time
"Prepared #{time_ago_in_words(requests.first.completion_time)} ago"
else
"Preparing now"
end
end

Expand Down
11 changes: 11 additions & 0 deletions spec/models/project_dashboard_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@
expect(presenter.latest_file_list_time).to eq("Prepared 1 day ago")
end
end

context "when download in progress exist" do
before do
FileInventoryRequest.create!(user_id: FactoryBot.create(:user).id, project_id: project.id, job_id: 123, state: UserRequest::PENDING,
request_details: { project_title: project.title }, completion_time: nil)
end

it "returns the time ago" do
expect(presenter.latest_file_list_time).to eq("Preparing now")
end
end
end

describe "#last_activity" do
Expand Down

0 comments on commit 0fdc443

Please sign in to comment.