• 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/upload_snapshot.rb
1
# frozen_string_literal: true
UNCOV
2
class UploadSnapshot < ApplicationRecord
×
UNCOV
3
  belongs_to :work
×
UNCOV
4
  attr_writer :upload
×
5

UNCOV
6
  alias_attribute :existing_files, :files
×
7

UNCOV
8
  def snapshot_deletions(work_changes, s3_filenames)
×
UNCOV
9
    s3_filenames_sorted = s3_filenames.sort
×
UNCOV
10
    existing_files.each do |file|
×
UNCOV
11
      filename = file["filename"]
×
12
      # Use Ruby's Binary Search functionality instead of a plain Ruby Array `.include?`
13
      # to detect missing values in the array because the binary search performs
14
      # much faster when the list of files is large. Notice that the binary search
15
      # requires that the list of files is sorted.
16
      # See https://ruby-doc.org/3.3.6/bsearch_rdoc.html
UNCOV
17
      if s3_filenames_sorted.bsearch { |s3_filename| filename <=> s3_filename }.nil?
×
UNCOV
18
        work_changes << { action: "removed", filename:, checksum: file["checksum"] }
×
UNCOV
19
      end
×
UNCOV
20
    end
×
UNCOV
21
  end
×
22

UNCOV
23
  def snapshot_modifications(work_changes, s3_files)
×
24
    # check for modifications
UNCOV
25
    s3_files.each do |s3_file|
×
UNCOV
26
      match = existing_files_sorted.bsearch { |file| s3_file.filename <=> file["filename"] }
×
UNCOV
27
      if match.nil?
×
UNCOV
28
        work_changes << { action: "added", filename: s3_file.filename, checksum: s3_file.checksum }
×
UNCOV
29
      elsif UploadSnapshot.checksum_compare(match["checksum"], s3_file.checksum) == false
×
UNCOV
30
        work_changes << { action: "replaced", filename: s3_file.filename, checksum: s3_file.checksum }
×
UNCOV
31
      end
×
UNCOV
32
    end
×
UNCOV
33
  end
×
34

UNCOV
35
  def upload
×
UNCOV
36
    @upload ||= uploads.find { |s3_file| filenames.include?(s3_file.filename) }
×
UNCOV
37
  end
×
38

UNCOV
39
  def uri
×
UNCOV
40
    URI.parse(url)
×
UNCOV
41
  end
×
42

UNCOV
43
  def filenames
×
UNCOV
44
    files.map { |file| file["filename"] }
×
UNCOV
45
  end
×
46

UNCOV
47
  def store_files(s3_files)
×
UNCOV
48
    self.files = s3_files.map { |file| { "filename" => file.filename, "checksum" => file.checksum } }
×
UNCOV
49
  end
×
50

UNCOV
51
  def self.find_by_filename(work_id:, filename:)
×
UNCOV
52
    find_by("work_id = ? AND files @> ?", work_id, JSON.dump([{ filename: }]))
×
UNCOV
53
  end
×
54

UNCOV
55
  class << self
×
56
    # Compares two checksums. Accounts for the case in which one of them is
57
    # a plain MD5 value and the other has been encoded with base64.
58
    # See also
59
    #   https://ruby-doc.org/core-2.7.0/Array.html#method-i-pack
60
    #   https://ruby-doc.org/core-2.7.0/String.html#method-i-unpack
UNCOV
61
    def checksum_compare(checksum1, checksum2)
×
UNCOV
62
      if checksum1 == checksum2
×
UNCOV
63
        true
×
UNCOV
64
      elsif checksum1.nil? || checksum2.nil?
×
UNCOV
65
        false
×
UNCOV
66
      elsif checksum1.length < checksum2.length
×
67
        # Decode the first one and then compare
UNCOV
68
        checksum1.unpack("m0").first.unpack("H*").first == checksum2
×
UNCOV
69
      else
×
70
        # Decode the second one and then compare
UNCOV
71
        checksum1 == checksum2.unpack("m0").first.unpack("H*").first
×
UNCOV
72
      end
×
UNCOV
73
    rescue ArgumentError
×
74
      # One of the values was not properly encoded
UNCOV
75
      false
×
UNCOV
76
    end
×
UNCOV
77
  end
×
78

UNCOV
79
  private
×
80

UNCOV
81
    def existing_files_sorted
×
UNCOV
82
      @existing_files_sorted ||= files.sort_by { |file| file["filename"] }
×
UNCOV
83
    end
×
84

UNCOV
85
    def uploads
×
UNCOV
86
      work.uploads
×
UNCOV
87
    end
×
UNCOV
88
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