• 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

19.05
/app/services/work_update_metadata_service.rb
1
# frozen_string_literal: true
2

3
# A service to update metadata across PDC Describe
4
class WorkUpdateMetadataService
1✔
5
  RENAMED_PPPL_SUBCOMMUNITIES = [
6
    {
1✔
7
      old: "Plasma Science & Technology",
8
      new: "Discovery Plasma Science"
9
    }
10
  ].freeze
11

12
  # For each renamed pppl subcommunity, traverse all of the works
13
  # and update the value
14
  def self.update_pppl_subcommunities(user, commandline: false)
1✔
UNCOV
15
    Work.all.each do |work|
×
UNCOV
16
      resource_before = work.resource.dup
×
UNCOV
17
      RENAMED_PPPL_SUBCOMMUNITIES.each do |renamed_subcommunity|
×
UNCOV
18
        sc = work.resource.subcommunities
×
UNCOV
19
        next unless sc.include? renamed_subcommunity[:old]
×
UNCOV
20
        puts "Updating work #{work.id}" if commandline
×
UNCOV
21
        work.resource.subcommunities = new_subcommunities(sc, renamed_subcommunity)
×
22
      end
UNCOV
23
      work.save
×
UNCOV
24
      resource_after = work.resource
×
UNCOV
25
      resource_compare = ResourceCompareService.new(resource_before, resource_after)
×
UNCOV
26
      WorkActivity.add_work_activity(work.id, resource_compare.differences.to_json, user.id, activity_type: WorkActivity::CHANGES)
×
27
    end
28
  end
29

30
  # Given a list of subcommunities, and a Hash from RENAMED_PPPL_SUBCOMMUNITIES,
31
  # replace all instances of :old with :new
32
  def self.new_subcommunities(sc, renamed_subcommunity)
1✔
UNCOV
33
    new_subcommunities = []
×
UNCOV
34
    sc.each do |subcommunity|
×
UNCOV
35
      new_subcommunities << if subcommunity == renamed_subcommunity[:old]
×
UNCOV
36
                              renamed_subcommunity[:new]
×
37
                            else
UNCOV
38
                              subcommunity
×
39
                            end
40
    end
UNCOV
41
    new_subcommunities
×
42
  end
43
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