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

pulibrary / pdc_describe / 4e4e59fc-9df4-4838-9fd4-6c7ea33cdb7c

07 Apr 2025 06:36PM UTC coverage: 1.283% (-94.6%) from 95.862%
4e4e59fc-9df4-4838-9fd4-6c7ea33cdb7c

Pull #1994

circleci

hectorcorrea
Switched to use the autocomplete that we aleady use for ROR. Integrated it with the existing logic for creators
Pull Request #1994: Started adding auto complete to contributors

0 of 46 new or added lines in 2 files covered. (0.0%)

4806 existing lines in 74 files now uncovered.

65 of 5065 relevant lines covered (1.28%)

0.01 hits per line

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

0.0
/app/models/background_upload_snapshot.rb
1
# frozen_string_literal: true
UNCOV
2
class BackgroundUploadSnapshot < UploadSnapshot
×
UNCOV
3
  def store_files(uploaded_files, pre_existing_files: [], current_user: nil)
×
UNCOV
4
    save # needed so I can point to this snapshot in the files to distinguish new files from existing ones froma past snapshot
×
5

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

UNCOV
15
  def mark_complete(filename, checksum)
×
UNCOV
16
    index = files.index { |file| file["filename"] == prefix_filename(filename) }
×
UNCOV
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}")
×
UNCOV
20
    else
×
UNCOV
21
      files[index]["upload_status"] = "complete"
×
UNCOV
22
      files[index]["checksum"] = checksum
×
UNCOV
23
    end
×
UNCOV
24
    finalize_upload if upload_complete?
×
UNCOV
25
    save
×
UNCOV
26
  end
×
27

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

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

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

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

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

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

UNCOV
51
    work.log_file_changes(user_id)
×
UNCOV
52
  end
×
53

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