• 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

91.11
/app/controllers/upload_snapshots_controller.rb
1
# frozen_string_literal: true
2
class UploadSnapshotsController < ApplicationController
1✔
3
  # POST /upload-snapshots/:work_id/:uri
4
  # Here the URI specifies the specific upload for which the snapshot is being generated
5
  def create
1✔
6
    @upload = find_upload(key: key_param)
2✔
7
    @upload_snapshot = @upload.create_snapshot
1✔
8

9
    flash[:notice] = "Successfully created the snapshot for upload #{@upload_snapshot.key} attached to work #{work.id}."
×
10
    redirect_to edit_upload_snapshot_path(@work)
×
11
  rescue StandardError => error
12
    error_message = "Failed to create the upload snapshot: #{error}"
2✔
13
    Rails.logger.error(error_message)
2✔
14
    flash[:notice] = error_message
2✔
15

16
    response_location = if @work.nil?
2✔
17
                          works_path
1✔
18
                        else
19
                          edit_upload_snapshot_path(@work)
1✔
20
                        end
21

22
    redirect_to response_location
2✔
23
  end
24

25
  def edit
1✔
26
    @uploads = work.uploads
×
27

28
    render :edit
×
29
  end
30

31
  # DELETE /upload-snapshots/:id
32
  # Destroys the snapshot after resolving it from the database ID
33
  def destroy
1✔
34
    current_work = upload_snapshot.work
2✔
35
    upload_snapshot.destroy
1✔
36
    flash[:notice] = "Successfully deleted the upload snapshot #{upload_snapshot_id}."
1✔
37

38
    redirect_to edit_upload_snapshot_path(current_work)
1✔
39
  rescue StandardError => error
40
    error_message = "Failed to delete the upload snapshot: #{error}"
1✔
41
    Rails.logger.error(error_message)
1✔
42
    flash[:notice] = error_message
1✔
43

44
    redirect_to works_path
1✔
45
  end
46

47
  private
1✔
48

49
    def upload_snapshot_id
1✔
50
      @upload_snapshot_id = params[:id]
6✔
51
      raise(ArgumentError, "No ID provided for the upload snapshot.") unless @upload_snapshot_id
6✔
52

53
      @upload_snapshot_id
6✔
54
    end
55

56
    def upload_snapshot
1✔
57
      return unless upload_snapshot_id
3✔
58

59
      @upload_snapshot ||= UploadSnapshot.find(upload_snapshot_id)
3✔
60
    end
61

62
    def work_id
1✔
63
      @work_id = params[:work_id]
2✔
64
      raise(ArgumentError, "No ID provided for the work.") unless @work_id
2✔
65

66
      @work_id
2✔
67
    end
68

69
    def key_param
1✔
70
      @key_param = params[:key]
2✔
71
      raise(ArgumentError, "No URI provided for the file upload.") unless @key_param
2✔
72

73
      @key_param
2✔
74
    end
75

76
    def work
1✔
77
      @work ||= Work.find(work_id)
2✔
78
    end
79

80
    def find_upload(key:)
1✔
81
      work.uploads.find { |s3_file| key.include?(s3_file.key) }
3✔
82
    end
83
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