• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / pdc_describe / b1776731-62d7-41a7-882d-6a5b4760db75

14 May 2024 12:28PM UTC coverage: 79.223% (-16.7%) from 95.9%
b1776731-62d7-41a7-882d-6a5b4760db75

push

circleci

carolyncole
Adding a submission completion page

fixes #1791

9 of 9 new or added lines in 2 files covered. (100.0%)

567 existing lines in 42 files now uncovered.

2692 of 3398 relevant lines covered (79.22%)

60.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.66
/app/models/background_upload_snapshot.rb
1
# frozen_string_literal: true
2
class BackgroundUploadSnapshot < UploadSnapshot
1✔
3
  def store_files(uploaded_files, pre_existing_files: [], current_user: nil)
1✔
4
    save # needed so I can point to this snapshot in the files to distinguish new files from existing ones froma past snapshot
6✔
5
    self.files = uploaded_files.map do |file|
6✔
6
      { "filename" => prefix_filename(file.original_filename),
9✔
7
        "upload_status" => "started", user_id: current_user&.id, snapshot_id: id }
8
    end
9
    files.concat pre_existing_files if pre_existing_files.present?
6✔
10
  end
11

12
  def mark_complete(filename, checksum)
1✔
13
    index = files.index { |file| file["filename"] == prefix_filename(filename) }
25✔
14
    if index.nil?
11✔
15
      Rails.logger.error("Uploaded a file that was not part of the orginal Upload: #{id} for work #{work_id}: #{filename}")
×
16
      Honeybadger.notify("Uploaded a file that was not part of the orginal Upload: #{id} for work #{work_id}: #{filename}")
×
17
    else
18
      files[index]["upload_status"] = "complete"
11✔
19
      files[index]["checksum"] = checksum
11✔
20
    end
21
    finalize_upload if upload_complete?
11✔
22
    save
11✔
23
  end
24

25
  def upload_complete?
1✔
26
    files.select { |file| file.keys.include?("upload_status") }.map { |file| file["upload_status"] }.uniq == ["complete"]
49✔
27
  end
28

29
  def existing_files
1✔
UNCOV
30
    super.select { |file| file["upload_status"].nil? || file["upload_status"] == "complete" }
×
31
  end
32

33
  def new_files
1✔
34
    files.select { |file| file["snapshot_id"] == id }
50✔
35
  end
36

37
  def finalize_upload
1✔
38
    new_files.each do |file|
6✔
39
      work.track_change(:added, file["filename"])
9✔
40
    end
41
    work.log_file_changes(new_files.first["user_id"])
6✔
42
  end
43

44
  def prefix_filename(filename)
1✔
45
    if filename.include?(work.prefix)
23✔
46
      filename
2✔
47
    else
48
      "#{work.prefix}#{filename}"
21✔
49
    end
50
  end
51
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc