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

pulibrary / pdc_describe / 704e072a-60a4-43a6-a47a-6fa4f15ea520

03 Apr 2024 03:22PM UTC coverage: 95.821% (-0.05%) from 95.875%
704e072a-60a4-43a6-a47a-6fa4f15ea520

Pull #1729

circleci

carolyncole
Updating tests to click on the new button text
Also completed the other file path test
Pull Request #1729: Adding Save, Next and Previous buttons to the wizard form

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

1 existing line in 1 file now uncovered.

3233 of 3374 relevant lines covered (95.82%)

206.0 hits per line

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

96.97
/app/services/work_metadata_service.rb
1
# frozen_string_literal: true
2

3
# A place to move the logic to from the work controllers
4
#   Process the parameters and permissions to update a work
5
class WorkMetadataService
1✔
6
  attr_reader :params, :current_user
1✔
7

8
  # @params [User] current_user the user who is currently logged in
9
  # @param [HashWithIndifferentAccess] update_params values to update the work with
10
  def initialize(params:, current_user:)
1✔
11
    @params = params
38✔
12
    @current_user = current_user
38✔
13
  end
14

15
  # creates or finds the work for the new submission form based on the parameters
16
  #
17
  # @returns the new or updated work
18
  def work_for_new_submission
1✔
19
    if params[:id].present?
20✔
NEW
20
      Work.find(params[:id])
×
21
    else
22
      group = Group.find_by(code: params[:group_code]) || current_user.default_group
20✔
23
      Work.new(created_by_user_id: current_user.id, group_id: group.id)
20✔
24
    end
25
  end
26

27
  # generates or load the work for a new submission based on the parameters
28
  #
29
  # @returns the new or updated work
30
  def new_submission
1✔
31
    if params[:id].present?
18✔
32
      update_work
1✔
33
    else
34
      draft_work
17✔
35
    end
36
  end
37

38
  def self.file_location_url(work)
1✔
39
    if work.files_location == "file_upload"
15✔
40
      Rails.application.routes.url_helpers.work_file_upload_path(work)
6✔
41
    else
42
      Rails.application.routes.url_helpers.work_file_other_path(work)
9✔
43
    end
44
  end
45

46
private
1✔
47

48
  def update_work
1✔
49
    work = Work.find(params[:id])
1✔
50
    update_params = { group: group_code, resource: FormToResourceService.convert(params, work) }
1✔
51
    WorkCompareService.update_work(work:, update_params:, current_user:)
1✔
52
    work
1✔
53
  end
54

55
  def draft_work
1✔
56
    group_id = group_code.id
17✔
57
    work = Work.new(created_by_user_id: current_user.id, group_id:)
17✔
58
    work.resource = FormToResourceService.convert(params, work)
17✔
59
    if work.valid_to_draft
17✔
60
      work.draft!(current_user)
16✔
61
    end
62
    work
14✔
63
  end
64

65
  def group_code
1✔
66
    @group_code ||= Group.find_by(code: params[:group_code]) || current_user.default_group
18✔
67
  end
68
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