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

pulibrary / pdc_describe / b1776731-62d7-41a7-882d-6a5b4760db75

14 May 2024 12:28PM UTC coverage: 79.223% (-16.7%) from 95.9%
b1776731-62d7-41a7-882d-6a5b4760db75

push

circleci

carolyncole
Adding a submission completion page

fixes #1791

9 of 9 new or added lines in 2 files covered. (100.0%)

567 existing lines in 42 files now uncovered.

2692 of 3398 relevant lines covered (79.22%)

60.03 hits per line

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

80.36
/app/models/s3_file.rb
1
# frozen_string_literal: true
2
class S3File
1✔
3
  include Rails.application.routes.url_helpers
1✔
4
  include ActionView::Helpers::NumberHelper
1✔
5

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

10
  def self.from_json(json_string)
1✔
11
    json = if json_string.is_a? String
9✔
12
             JSON.parse(json_string)
×
13
           else
14
             json_string
9✔
15
           end
16

17
    new(filename: json["filename"], last_modified: DateTime.parse(json["last_modified"]), size: json["size"],
9✔
18
        checksum: json["checksum"], work: Work.find(json["work_id"]), filename_display: json["filename_display"], url: json["url"])
19
  end
20

21
  def initialize(filename:, last_modified:, size:, checksum:, work:, filename_display: nil, url: nil)
1✔
22
    @safe_id = filename_as_id(filename)
111✔
23
    @filename = filename
111✔
24
    @filename_display = filename_display || filename_short(work, filename)
111✔
25
    @last_modified = last_modified
111✔
26
    @last_modified_display = last_modified.in_time_zone.strftime("%m/%d/%Y %I:%M %p") # mm/dd/YYYY HH:MM AM
111✔
27
    @size = size
111✔
28
    @display_size = number_to_human_size(size)
111✔
29
    @checksum = checksum.delete('"')
111✔
30
    @url = url || work_download_path(work, filename:)
111✔
31
    @work = work
111✔
32
  end
33

34
  def created_at
1✔
35
    last_modified
14✔
36
  end
37

38
  def byte_size
1✔
39
    size
×
40
  end
41

42
  def directory?
1✔
43
    size == 0
36✔
44
  end
45

46
  def empty?
1✔
UNCOV
47
    size == 0
×
48
  end
49

50
  def globus_url
1✔
51
    encoded_filename = filename.split("/").map { |name| ERB::Util.url_encode(name) }.join("/")
4✔
52
    File.join(Rails.configuration.globus["post_curation_base_url"], encoded_filename)
2✔
53
  end
54

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

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

UNCOV
66
    created.upload = self
×
UNCOV
67
    created.save
×
UNCOV
68
    created.reload
×
69
  end
70

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

76
    persisted
×
77
  end
78

79
  def to_json
1✔
80
    {
81
      filename:, last_modified:, size:,
21✔
82
      checksum:, work_id: @work.id, filename_display:, url:
83
    }.to_json
84
  end
85

86
  private
1✔
87

88
    # Filename without the DOI/work-id/ in the path (but we preserve other path information if there is any)
89
    def filename_short(work, filename)
1✔
90
      prefix = "#{work.doi}/#{work.id}/"
92✔
91
      if filename.start_with?(prefix)
92✔
92
        filename[prefix.length..]
14✔
93
      else
94
        filename
78✔
95
      end
96
    end
97

98
    def filename_as_id(filename)
1✔
99
      # The full filename and path but only with alphanumeric characters
100
      # everything else becomes as dash.
101
      filename.gsub(/[^A-Za-z\d]/, "-")
111✔
102
    end
103
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