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

pulibrary / pdc_describe / 9091a1ae-29be-458c-984a-339d213919c4

12 Dec 2024 07:41PM UTC coverage: 26.434% (-69.7%) from 96.113%
9091a1ae-29be-458c-984a-339d213919c4

Pull #2000

circleci

jrgriffiniii
Removing integration with ActiveStorage
Pull Request #2000: Bump actionpack from 7.2.1.1 to 7.2.2.1

945 of 3575 relevant lines covered (26.43%)

0.35 hits per line

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

22.86
/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
×
5

6
    raise(ArgumentError, "Failed to resolve the user ID from #{self}") if current_user.nil?
×
7
    user_id = current_user&.id
×
8
    self.files = uploaded_files.map do |file|
×
9
      { "filename" => prefix_filename(file.original_filename),
×
10
        "upload_status" => "started", user_id:, snapshot_id: id }
11
    end
12
    files.concat pre_existing_files if pre_existing_files.present?
×
13
  end
14

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

28
  def upload_complete?
1✔
29
    files.select { |file| file.keys.include?("upload_status") }.map { |file| file["upload_status"] }.uniq == ["complete"]
×
30
  end
31

32
  def existing_files
1✔
33
    super.select { |file| file["upload_status"].nil? || file["upload_status"] == "complete" }
×
34
  end
35

36
  def new_files
1✔
37
    files.select { |file| file["snapshot_id"] == id }
×
38
  end
39

40
  def finalize_upload
1✔
41
    new_files.each do |file|
×
42
      work.track_change(:added, file["filename"])
×
43
    end
44

45
    raise(ArgumentError, "Upload failed with empty files.") if new_files.empty?
×
46
    first_new_file = new_files.first
×
47

48
    user_id = first_new_file["user_id"]
×
49
    raise(ArgumentError, "Failed to resolve the user ID from #{first_new_file['filename']}") if user_id.nil?
×
50

51
    work.log_file_changes(user_id)
×
52
  end
53

54
  def prefix_filename(filename)
1✔
55
    if filename.include?(work.prefix)
×
56
      filename
×
57
    else
58
      "#{work.prefix}#{filename}"
×
59
    end
60
  end
61
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