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

pulibrary / pdc_describe / 31a62f9e-3a5b-4033-a3e3-effd2d651737

pending completion
31a62f9e-3a5b-4033-a3e3-effd2d651737

Pull #962

circleci

Hector Correa
Fixes tests for S3 query service (and a couple of code duplications from a merge?)
Pull Request #962: Fetch pre-curation files from directly from AWS

35 of 35 new or added lines in 4 files covered. (100.0%)

1821 of 1864 relevant lines covered (97.69%)

149.32 hits per line

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

97.3
/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
92✔
12
      @related_identifier_type = related_identifier_type
92✔
13
      @relation_type = relation_type
92✔
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?
92✔
18
        @related_identifier_type = ::Datacite::Mapping::RelatedIdentifierType.find do |obj|
1✔
19
          ::PDCMetadata.fuzzy_match(obj, related_identifier_type)
2✔
20
        end.value
21
      end
22
      unless relation_type.blank? || valid_relation_type?
92✔
23
        @relation_type = ::Datacite::Mapping::RelationType.find do |obj|
2✔
24
          ::PDCMetadata.fuzzy_match(obj, relation_type)
2✔
25
        end.value
26
      end
27

28
      @errors = []
92✔
29
    end
30

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

43
    def value
1✔
44
      @related_identifier
1✔
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, related_identifier_type: related_identifier_type, relation_type: relation_type)
5✔
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)
101✔
59
      end
60

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

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

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