Skip to content

Commit 6ebb2aa

Browse files
Merge pull request #22 from datacite/add-constants-relation-types-specs
Add constants relation_types specs
2 parents dbc2a0f + 44c2f3a commit 6ebb2aa

File tree

3 files changed

+101
-3
lines changed

3 files changed

+101
-3
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ Style/StringLiteralsInInterpolation:
3030

3131
Layout/SpaceInsideHashLiteralBraces:
3232
Enabled: true
33+
34+
RSpec/ExampleLength:
35+
Enabled: false

app/models/concerns/relation_type_handler.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@
44
# Method is only invoked via a before_validation callback in the events model.
55

66
module RelationTypeHandler
7-
include RelationTypes
87
extend ActiveSupport::Concern
98

109
def set_source_and_target_doi!
1110
return if subj_id.blank? || obj_id.blank?
1211

1312
case relation_type_id
14-
when *REFERENCE_RELATION_TYPES
13+
when *RelationTypes::REFERENCE_RELATION_TYPES
1514
self.source_doi = DoiUtilities.uppercase_doi_from_url(subj_id)
1615
self.target_doi = DoiUtilities.uppercase_doi_from_url(obj_id)
1716
self.source_relation_type_id = "references"
1817
self.target_relation_type_id = "citations"
19-
when *CITATION_RELATION_TYPES
18+
when *RelationTypes::CITATION_RELATION_TYPES
2019
self.source_doi = DoiUtilities.uppercase_doi_from_url(obj_id)
2120
self.target_doi = DoiUtilities.uppercase_doi_from_url(subj_id)
2221
self.source_relation_type_id = "references"
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# frozen_string_literal: true
2+
3+
require "rails_helper"
4+
5+
RSpec.describe("RelationType") do
6+
describe "Constants" do
7+
it "defines REFERENCE_RELATION_TYPES correctly" do
8+
expected = ["cites", "is-supplemented-by", "references"]
9+
10+
expect(RelationTypes::REFERENCE_RELATION_TYPES).to(eq(expected))
11+
end
12+
13+
it "defines CITATION_RELATION_TYPES correctly" do
14+
expected = ["is-cited-by", "is-supplement-to", "is-referenced-by"]
15+
16+
expect(RelationTypes::CITATION_RELATION_TYPES).to(eq(expected))
17+
end
18+
19+
it "defines INCLUDED_RELATION_TYPES as the union of REFERENCE_RELATION_TYPES and CITATION_RELATION_TYPES" do
20+
expected = RelationTypes::REFERENCE_RELATION_TYPES | RelationTypes::CITATION_RELATION_TYPES
21+
22+
expect(RelationTypes::INCLUDED_RELATION_TYPES).to(eq(expected))
23+
end
24+
25+
it "defines PART_RELATION_TYPES correctly" do
26+
expected = ["is-part-of", "has-part"]
27+
28+
expect(RelationTypes::PART_RELATION_TYPES).to(eq(expected))
29+
end
30+
31+
it "defines NEW_RELATION_TYPES correctly" do
32+
expected = ["is-reply-to", "is-translation-of", "is-published-in"]
33+
34+
expect(RelationTypes::NEW_RELATION_TYPES).to(eq(expected))
35+
end
36+
37+
it "defines RELATIONS_RELATION_TYPES correctly" do
38+
expected = [
39+
"compiles",
40+
"is-compiled-by",
41+
"documents",
42+
"is-documented-by",
43+
"has-metadata",
44+
"is-metadata-for",
45+
"is-derived-from",
46+
"is-source-of",
47+
"reviews",
48+
"is-reviewed-by",
49+
"requires",
50+
"is-required-by",
51+
"continues",
52+
"is-coutinued-by",
53+
"has-version",
54+
"is-version-of",
55+
"has-part",
56+
"is-part-of",
57+
"is-variant-from-of",
58+
"is-original-form-of",
59+
"is-identical-to",
60+
"obsoletes",
61+
"is-obsolete-by",
62+
"is-new-version-of",
63+
"is-previous-version-of",
64+
"describes",
65+
"is-described-by",
66+
]
67+
68+
expect(RelationTypes::RELATIONS_RELATION_TYPES).to(eq(expected))
69+
end
70+
71+
it "defines ALL_RELATION_TYPES as the union of all relation types" do
72+
expected = (
73+
RelationTypes::RELATIONS_RELATION_TYPES |
74+
RelationTypes::NEW_RELATION_TYPES |
75+
RelationTypes::CITATION_RELATION_TYPES |
76+
RelationTypes::REFERENCE_RELATION_TYPES
77+
).uniq
78+
79+
expect(RelationTypes::ALL_RELATION_TYPES).to(match_array(expected))
80+
end
81+
82+
it "defines OTHER_RELATION_TYPES correctly" do
83+
expected = (
84+
RelationTypes::RELATIONS_RELATION_TYPES | RelationTypes::NEW_RELATION_TYPES
85+
) - RelationTypes::INCLUDED_RELATION_TYPES - RelationTypes::PART_RELATION_TYPES
86+
87+
expect(RelationTypes::OTHER_RELATION_TYPES).to(match_array(expected))
88+
end
89+
90+
it "defines RELATED_SOURCE_IDS correctly" do
91+
expected = ["datacite-related", "datacite-crossref", "crossref"]
92+
93+
expect(RelationTypes::RELATED_SOURCE_IDS).to(eq(expected))
94+
end
95+
end
96+
end

0 commit comments

Comments
 (0)