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

pulibrary / pdc_describe / 9dbcf7a4-1c56-4510-9614-74ad5a22cff6

31 Jul 2024 02:46PM UTC coverage: 1.08% (-95.1%) from 96.17%
9dbcf7a4-1c56-4510-9614-74ad5a22cff6

push

circleci

jrgriffiniii
wip

52 of 4814 relevant lines covered (1.08%)

0.01 hits per line

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

0.0
/app/services/work_compare_service.rb
1
# frozen_string_literal: true
2

3
class WorkCompareService
×
4
  attr_reader :differences
×
5

6
  class << self
×
7
    # Updates a work with the parameters and logs any changes
8
    # @param [Work] work work to be updated
9
    # @param [HashWithIndifferentAccess] update_params values to update the work with
10
    # @param [] current_user user currently logged into the system
11
    # @return [Boolean] true if update occured; false if update had errors
12
    def update_work(work:, update_params:, current_user:)
×
13
      work_before = work.dup
×
14
      if work.update(update_params)
×
15
        work_compare = new(work_before, work)
×
16
        work.log_changes(work_compare, current_user.id)
×
17
        true
×
18
      else
×
19
        false
×
20
      end
×
21
    end
×
22
  end
×
23

24
  def initialize(before, after)
×
25
    @before = before
×
26
    @after = after
×
27
    @differences = {}
×
28
    compare_works
×
29
  end
×
30

31
  def identical?
×
32
    @differences == {}
×
33
  end
×
34

35
  private
×
36

37
    def resource_compare_service
×
38
      @resource_compare_service ||= ResourceCompareService.new(@before.resource, @after.resource)
×
39
    end
×
40

41
    def compare_works
×
42
      # Compare the group
43
      if @before.group != @after.group
×
44
        before_value = @before.group
×
45
        after_value = @after.group
×
46
        @differences[:group] = [{ action: :changed, from: before_value.title, to: after_value.title }]
×
47
      end
×
48

49
      @differences = @differences.merge(resource_compare_service.differences)
×
50
    end
×
51
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