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

pulibrary / pdc_describe / 246d1c21-d1e3-4992-98a7-13140240fbdc

pending completion
246d1c21-d1e3-4992-98a7-13140240fbdc

Pull #1028

circleci

jrgriffiniii
wip
Pull Request #1028: Implementing the UploadSnapshotsController

71 of 71 new or added lines in 5 files covered. (100.0%)

1911 of 1952 relevant lines covered (97.9%)

172.9 hits per line

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

84.78
/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 :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
    @filename = filename
132✔
11
    @filename_display = filename_short(work, filename)
132✔
12
    @last_modified = last_modified
132✔
13
    @last_modified_display = last_modified.in_time_zone.strftime("%m/%d/%Y %I:%M %p") # mm/dd/YYYY HH:MM AM
132✔
14
    @size = size
132✔
15
    @checksum = checksum.delete('"')
132✔
16
    @url = work_download_path(work, filename: filename)
132✔
17
    @work = work
132✔
18
  end
19

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

24
  def byte_size
1✔
25
    size
×
26
  end
27

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

33
  def to_blob
1✔
34
    existing_blob = ActiveStorage::Blob.find_by(key: filename)
4✔
35

36
    if existing_blob.present?
4✔
37
      Rails.logger.warn("There is a blob existing for #{filename}, which we are not expecting!  It will be reattached #{existing_blob.inspect}")
1✔
38
      return existing_blob
1✔
39
    end
40

41
    params = { filename: filename, content_type: "", byte_size: size, checksum: checksum }
3✔
42
    blob = ActiveStorage::Blob.create_before_direct_upload!(**params)
3✔
43
    blob.key = filename
3✔
44
    blob
3✔
45
  end
46

47
  # Create a new snapshot of the current upload
48
  # @return [UploadSnapshot]
49
  def create_snapshot
1✔
50
    created = UploadSnapshot.create(key: key, url: url, work: @work)
2✔
51
    created.binary.attach(to_blob)
2✔
52
    created.upload = self
×
53
    created.save
×
54
    created.reload
×
55
  end
56

57
  # @return [UploadSnapshot]
58
  def snapshots
1✔
59
    persisted = UploadSnapshot.where(key: key, url: url, work: @work)
×
60
    return [] if persisted.blank?
×
61

62
    persisted
×
63
  end
64

65
  private
1✔
66

67
    # Filename without the DOI/work-id/ in the path (but we preserve other path information if there is any)
68
    def filename_short(work, filename)
1✔
69
      prefix = "#{work.doi}/#{work.id}/"
132✔
70
      if filename.start_with?(prefix)
132✔
71
        filename[prefix.length..]
69✔
72
      else
73
        filename
63✔
74
      end
75
    end
76
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