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

pulibrary / pdc_describe / 9091a1ae-29be-458c-984a-339d213919c4

12 Dec 2024 07:41PM UTC coverage: 26.434% (-69.7%) from 96.113%
9091a1ae-29be-458c-984a-339d213919c4

Pull #2000

circleci

jrgriffiniii
Removing integration with ActiveStorage
Pull Request #2000: Bump actionpack from 7.2.1.1 to 7.2.2.1

945 of 3575 relevant lines covered (26.43%)

0.35 hits per line

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

35.14
/app/models/pdc_metadata/related_object.rb
1
# frozen_string_literal: true
2
# Class for storing a related object
3
module PDCMetadata
1✔
4
  # let(:related_identifier) { "https://www.biorxiv.org/content/10.1101/545517v1" }
5
  # let(:related_identifier_type) { "arXiv" }
6
  # let(:relation_type) { "IsCitedBy" }
7
  class RelatedObject
1✔
8
    attr_accessor :related_identifier, :related_identifier_type, :relation_type, :errors
1✔
9

10
    def initialize(related_identifier:, related_identifier_type:, relation_type:)
1✔
11
      @related_identifier = related_identifier
×
12
      @related_identifier_type = related_identifier_type
×
13
      @relation_type = relation_type
×
14

15
      # TODO: Older records have a different format.
16
      # When we migrate these, then this can be removed.
17
      unless related_identifier_type.blank? || valid_related_identifier_type?
×
18
        @related_identifier_type = ::Datacite::Mapping::RelatedIdentifierType.find do |obj|
×
19
          ::PDCMetadata.fuzzy_match(obj, related_identifier_type)
×
20
        end.value
21
      end
22
      unless relation_type.blank? || valid_relation_type?
×
23
        @relation_type = ::Datacite::Mapping::RelationType.find do |obj|
×
24
          ::PDCMetadata.fuzzy_match(obj, relation_type)
×
25
        end.value
26
      end
27

28
      @errors = []
×
29
    end
30

31
    def valid?
1✔
32
      valid = related_identifier.present? && valid_related_identifier_type? && valid_relation_type?
×
33
      return valid if valid
×
34
      if related_identifier.blank?
×
35
        errors << "Related identifier is missing"
×
36
      else
37
        errors << "Related Identifier Type is missing or invalid for #{related_identifier}" unless valid_related_identifier_type?
×
38
        errors << "Relationship Type is missing or invalid for #{related_identifier}" unless valid_relation_type?
×
39
      end
40
      false
×
41
    end
42

43
    def value
1✔
44
      @related_identifier
×
45
    end
46

47
    def compare_value
1✔
48
      "#{related_identifier} ('#{relation_type}' relation #{related_identifier_type})"
×
49
    end
50

51
    def self.new_related_object(related_identifier, related_identifier_type, relation_type)
1✔
52
      RelatedObject.new(related_identifier:, related_identifier_type:, relation_type:)
×
53
    end
54

55
    private
1✔
56

57
      def valid_related_identifier_type?
1✔
58
        @valid_related_identifier_type ||= valid_type_values.include?(related_identifier_type)
×
59
      end
60

61
      def valid_relation_type?
1✔
62
        @valid_relation_type ||= valid_relationship_types.include?(relation_type)
×
63
      end
64

65
      def valid_type_values
1✔
66
        @valid_type_values ||= Datacite::Mapping::RelatedIdentifierType.map(&:value)
×
67
      end
68

69
      def valid_relationship_types
1✔
70
        @valid_relationship_types ||= Datacite::Mapping::RelationType.map(&:value)
×
71
      end
72
  end
73
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