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

pulibrary / pdc_describe / cace366a-ffad-45f1-9b60-678e607fa527

14 May 2024 02:21PM UTC coverage: 60.862% (-35.0%) from 95.908%
cace366a-ffad-45f1-9b60-678e607fa527

push

circleci

jrgriffiniii
wip

1 of 3 new or added lines in 2 files covered. (33.33%)

1194 existing lines in 57 files now uncovered.

2076 of 3411 relevant lines covered (60.86%)

22.71 hits per line

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

34.29
/app/models/readme.rb
1
# frozen_string_literal: true
2
class Readme
1✔
3
  attr_reader :work, :current_user
1✔
4

5
  def initialize(work, current_user)
1✔
UNCOV
6
    @work = work
×
UNCOV
7
    @current_user = current_user
×
8
  end
9

10
  def attach(readme_file_param)
1✔
UNCOV
11
    return "A README file is required!" if readme_file_param.blank? && blank?
×
UNCOV
12
    return nil if readme_file_param.blank?
×
UNCOV
13
    remove_old_readme
×
14

UNCOV
15
    key = upload_readme(readme_file_param)
×
UNCOV
16
    if key
×
UNCOV
17
      @file_names = [readme_file_param.original_filename]
×
UNCOV
18
      @s3_readme_idx = 0
×
UNCOV
19
      log_changes
×
20
      nil
21
    else
UNCOV
22
      "An error uploading your README was encountered.  Please try again."
×
23
    end
24
  end
25

26
  def blank?
1✔
UNCOV
27
    s3_readme_idx.nil?
×
28
  end
29

30
  def file_name
1✔
UNCOV
31
    return nil if blank?
×
UNCOV
32
    file_names[s3_readme_idx]
×
33
  end
34

35
    private
1✔
36

37
      def s3_readme_idx
1✔
UNCOV
38
        @s3_readme_idx ||= file_names.find_index { |file_name| file_name.start_with?("README") }
×
39
      end
40

41
      def file_names
1✔
UNCOV
42
        @file_names ||= work.pre_curation_uploads.map(&:filename_display)
×
43
      end
44

45
      def remove_old_readme
1✔
UNCOV
46
        return if blank?
×
UNCOV
47
        work.s3_query_service.delete_s3_object(work.pre_curation_uploads[s3_readme_idx].key)
×
48
      end
49

50
      def upload_readme(readme_file_param)
1✔
UNCOV
51
        readme_name = readme_file_param.original_filename
×
UNCOV
52
        size = readme_file_param.size
×
UNCOV
53
        work.s3_query_service.upload_file(io: readme_file_param.to_io, filename: readme_name, size:)
×
54
      end
55

56
      def log_changes
1✔
UNCOV
57
        work.s3_query_service.client_s3_files(reload: true)
×
UNCOV
58
        work.reload_snapshots(user_id: current_user.id)
×
59
      end
60
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