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

pulibrary / pdc_describe / e2b7cc8f-6e85-4359-a4fd-10005487ea11

pending completion
e2b7cc8f-6e85-4359-a4fd-10005487ea11

Pull #1060

circleci

Carolyn Cole
Removing UploadSnapshotController
Pull Request #1060: Integrating Support for Upload Snapshots

89 of 89 new or added lines in 6 files covered. (100.0%)

1955 of 2196 relevant lines covered (89.03%)

164.96 hits per line

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

90.91
/app/models/s3_file.rb
1
# frozen_string_literal: true
2
class S3File
1✔
3
  include Rails.application.routes.url_helpers
1✔
4

5
  attr_accessor :safe_id, :filename, :last_modified, :size, :checksum, :url, :filename_display, :last_modified_display
1✔
6
  alias key filename
1✔
7
  alias id filename
1✔
8

9
  def initialize(filename:, last_modified:, size:, checksum:, work:)
1✔
10
    @safe_id = filename_as_id(filename)
155✔
11
    @filename = filename
155✔
12
    @filename_display = filename_short(work, filename)
155✔
13
    @last_modified = last_modified
155✔
14
    @last_modified_display = last_modified.in_time_zone.strftime("%m/%d/%Y %I:%M %p") # mm/dd/YYYY HH:MM AM
155✔
15
    @size = size
155✔
16
    @checksum = checksum.delete('"')
155✔
17
    @url = work_download_path(work, filename: filename)
155✔
18
    @work = work
155✔
19
  end
20

21
  def created_at
1✔
22
    last_modified
20✔
23
  end
24

25
  def byte_size
1✔
26
    size
×
27
  end
28

29
  def globus_url
1✔
30
    encoded_filename = filename.split("/").map { |name| ERB::Util.url_encode(name) }.join("/")
217✔
31
    File.join(Rails.configuration.globus["post_curation_base_url"], encoded_filename)
44✔
32
  end
33

34
  def create_blob(key: nil)
1✔
35
    key ||= filename
1✔
36
    params = { filename: filename, content_type: "", byte_size: size, checksum: checksum }
1✔
37

38
    blob = ActiveStorage::Blob.create_before_direct_upload!(**params)
1✔
39
    blob.key = key
1✔
40
    blob
1✔
41
  end
42

43
  def to_blob
1✔
44
    existing_blob = ActiveStorage::Blob.find_by(key: filename)
2✔
45

46
    if existing_blob.present?
2✔
47
      Rails.logger.warn("There is a blob existing for #{filename}, which we are not expecting!  It will be reattached #{existing_blob.inspect}")
1✔
48
      return existing_blob
1✔
49
    end
50

51
    create_blob
1✔
52
  end
53

54
  delegate :s3_query_service, to: :@work
1✔
55
  delegate :bucket_name, to: :s3_query_service
1✔
56
  def s3_client
1✔
57
    s3_query_service.client
×
58
  end
59

60
  # Create a new snapshot of the current upload
61
  # @return [UploadSnapshot]
62
  def create_snapshot
1✔
63
    created = UploadSnapshot.create(url: url, filename: filename, work: @work, checksum: checksum)
1✔
64

65
    created.upload = self
1✔
66
    created.save
1✔
67
    created.reload
1✔
68
  end
69

70
  # @return [UploadSnapshot]
71
  def snapshots
1✔
72
    persisted = UploadSnapshot.where(key: key, url: url, work: @work)
×
73
    return [] if persisted.blank?
×
74

75
    persisted
×
76
  end
77

78
  private
1✔
79

80
    # Filename without the DOI/work-id/ in the path (but we preserve other path information if there is any)
81
    def filename_short(work, filename)
1✔
82
      prefix = "#{work.doi}/#{work.id}/"
155✔
83
      if filename.start_with?(prefix)
155✔
84
        filename[prefix.length..]
62✔
85
      else
86
        filename
93✔
87
      end
88
    end
89

90
    def filename_as_id(filename)
1✔
91
      # The full filename and path but only with alphanumeric characters
92
      # everything else becomes as dash.
93
      filename.gsub(/[^A-Za-z\d]/, "-")
155✔
94
    end
95
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