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

pulibrary / pdc_describe / 7ae96b6b-0a64-4479-9fa1-8ba6526e2c87

20 Mar 2024 12:42PM UTC coverage: 30.068% (-66.2%) from 96.266%
7ae96b6b-0a64-4479-9fa1-8ba6526e2c87

Pull #1701

circleci

leefaisonr
makes it so that links open in new window
Pull Request #1701: Update language on submission form

1019 of 3389 relevant lines covered (30.07%)

0.4 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✔
15
    Work.all.each do |work|
×
16
      resource_before = work.resource.dup
×
17
      RENAMED_PPPL_SUBCOMMUNITIES.each do |renamed_subcommunity|
×
18
        sc = work.resource.subcommunities
×
19
        next unless sc.include? renamed_subcommunity[:old]
×
20
        puts "Updating work #{work.id}" if commandline
×
21
        work.resource.subcommunities = new_subcommunities(sc, renamed_subcommunity)
×
22
      end
23
      work.save
×
24
      resource_after = work.resource
×
25
      resource_compare = ResourceCompareService.new(resource_before, resource_after)
×
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✔
33
    new_subcommunities = []
×
34
    sc.each do |subcommunity|
×
35
      new_subcommunities << if subcommunity == renamed_subcommunity[:old]
×
36
                              renamed_subcommunity[:new]
×
37
                            else
38
                              subcommunity
×
39
                            end
40
    end
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