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

pulibrary / pdc_describe / 31a62f9e-3a5b-4033-a3e3-effd2d651737

pending completion
31a62f9e-3a5b-4033-a3e3-effd2d651737

Pull #962

circleci

Hector Correa
Fixes tests for S3 query service (and a couple of code duplications from a merge?)
Pull Request #962: Fetch pre-curation files from directly from AWS

35 of 35 new or added lines in 4 files covered. (100.0%)

1821 of 1864 relevant lines covered (97.69%)

149.32 hits per line

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

87.5
/app/services/work_uploads_edit_service.rb
1
# frozen_string_literal: true
2
class WorkUploadsEditService
1✔
3
  attr_reader :work, :s3_service
1✔
4

5
  def initialize(work, current_user)
1✔
6
    @work = work
35✔
7
    @s3_service = work.s3_query_service
35✔
8
    @current_user = current_user
35✔
9
    @changes = []
35✔
10
  end
11

12
  def update_precurated_file_list(work_params)
1✔
13
    if work_params.key?(:deleted_uploads) || work_params.key?(:pre_curation_uploads) || work_params.key?(:replaced_uploads)
30✔
14
      if work_params.key?(:deleted_uploads)
9✔
15
        delete_pre_curation_uploads(work_params[:deleted_uploads])
2✔
16
      elsif work_params.key?(:pre_curation_uploads)
7✔
17
        update_uploads(work_params)
5✔
18
      elsif work_params.key?(:replaced_uploads)
2✔
19
        replace_uploads(work_params[:replaced_uploads])
2✔
20
      end
21
      work.log_file_changes(@changes, @current_user.id)
4✔
22
      s3_service.client_s3_files(reload: true)
4✔
23
      work.reload # reload the work to pick up the changes in the attachments
×
24
    else # no changes in the parameters, just return the original work
25
      work
21✔
26
    end
27
  end
28

29
  def find_post_curation_uploads(upload_keys: [])
1✔
30
    return [] unless work.approved? && !upload_keys.empty?
5✔
31
    work.post_curation_uploads.select { |upload| upload_keys.include?(upload.key) }
3✔
32
  end
33

34
  private
1✔
35

36
    def replace_uploads(replaced_uploads_params)
1✔
37
      new_uploads = []
2✔
38
      work.pre_curation_uploads.each_with_index do |existing|
2✔
39
        key = existing.key
6✔
40
        next unless replaced_uploads_params.key?(key)
6✔
41
        new_uploads << replaced_uploads_params[key]
3✔
42
        track_change(:deleted, existing.filename.to_s)
3✔
43
        existing.purge
3✔
44
      end
45
      work.reload
2✔
46
      new_uploads.each do |new_upload|
2✔
47
        track_change(:added, new_upload.original_filename)
3✔
48
        work.pre_curation_uploads.attach(new_upload)
3✔
49
      end
50
    end
51

52
    def delete_pre_curation_uploads(deleted_uploads_params)
1✔
53
      deleted_uploads_params.each do |delete_s3|
2✔
54
        s3_service.delete_s3_object(delete_s3.first) if delete_s3.last == "1"
4✔
55
        track_change(:deleted, delete_s3.first)
4✔
56
      end
57
    end
58

59
    def update_uploads(work_params)
1✔
60
      # delete all existing uploads...
61
      work.pre_curation_uploads_fast.each do |existing_upload|
5✔
62
        track_change(:deleted, existing_upload.filename.to_s)
×
63
        s3_service.delete_s3_object(existing_upload.key)
×
64
      end
65

66
      # ...reload the work to pick up the changes in the attachments
67
      work.reload
×
68

69
      # ...and then and then track the ones indicated in the parameters
70
      # todo - How do we know what has been attached in the background?
71
      Array(work_params[:pre_curation_uploads]).each do |new_upload|
×
72
        track_change(:added, new_upload.original_filename)
×
73
      end
74
    end
75

76
    def track_change(action, filename)
1✔
77
      @changes << { action: action, filename: filename }
10✔
78
    end
79
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