ddr-models 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ddr/models/base.rb +45 -0
- data/lib/ddr/models/version.rb +1 -1
- data/spec/support/shared_examples_for_ddr_models.rb +97 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da77038c15e029fe70bc14ba3b2fa9013606e66a
|
4
|
+
data.tar.gz: 59a3733d31c8cf61c4d4fe680037ae57a343cb0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d63141d8f4cda552f720a20887419c90beb1a2e41b5b6c5bee08fda01d259b2286b85af4a45caa93576371d3498613d55a9d12cae2999dc97c278bf0cd37454
|
7
|
+
data.tar.gz: 131bd338a0a2190c604ce92b945f2e2a220f2beadbd94fe442e1b93a6435f1ab9d8c52a51ab6ebc377014315bbc47316ce81eea5fd285a37106d6eba50f6a7b6
|
data/lib/ddr/models/base.rb
CHANGED
@@ -60,6 +60,51 @@ module Ddr
|
|
60
60
|
Ddr::Auth::LegacyAuthorization.new(self)
|
61
61
|
end
|
62
62
|
|
63
|
+
# Moves the first (descriptive metadata) identifier into
|
64
|
+
# (administrative metadata) local_id according to the following
|
65
|
+
# rubric:
|
66
|
+
#
|
67
|
+
# No existing local_id:
|
68
|
+
# - Set local_id to first identifier value
|
69
|
+
# - Remove first identifier value
|
70
|
+
#
|
71
|
+
# Existing local_id:
|
72
|
+
# Same as first identifier value
|
73
|
+
# - Remove first identifier value
|
74
|
+
# Not same as first identifier value
|
75
|
+
# :replace option is true
|
76
|
+
# - Set local_id to first identifier value
|
77
|
+
# - Remove first identifier value
|
78
|
+
# :replace option is false
|
79
|
+
# - Do nothing
|
80
|
+
#
|
81
|
+
# Returns true or false depending on whether the object was
|
82
|
+
# changed by this method
|
83
|
+
def move_first_identifier_to_local_id(replace: true)
|
84
|
+
moved = false
|
85
|
+
identifiers = identifier.to_a
|
86
|
+
first_id = identifiers.shift
|
87
|
+
if first_id
|
88
|
+
if local_id.blank?
|
89
|
+
self.local_id = first_id
|
90
|
+
self.identifier = identifiers
|
91
|
+
moved = true
|
92
|
+
else
|
93
|
+
if local_id == first_id
|
94
|
+
self.identifier = identifiers
|
95
|
+
moved = true
|
96
|
+
else
|
97
|
+
if replace
|
98
|
+
self.local_id = first_id
|
99
|
+
self.identifier = identifiers
|
100
|
+
moved = true
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
moved
|
106
|
+
end
|
107
|
+
|
63
108
|
end
|
64
109
|
end
|
65
110
|
end
|
data/lib/ddr/models/version.rb
CHANGED
@@ -24,4 +24,101 @@ RSpec.shared_examples "a DDR model" do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
describe "move first desc metadata identifier to local id" do
|
28
|
+
let(:local_id) { 'locl001' }
|
29
|
+
let(:identifiers) { [ 'id001', 'id002' ] }
|
30
|
+
context "no desc metadata identifiers" do
|
31
|
+
context "local id present" do
|
32
|
+
before { subject.local_id = local_id }
|
33
|
+
it "should not change the local id" do
|
34
|
+
result = subject.move_first_identifier_to_local_id
|
35
|
+
expect(result).to be false
|
36
|
+
expect(subject.local_id).to eq(local_id)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
context "one desc metadata identifier" do
|
41
|
+
before { subject.identifier = Array(identifiers.first) }
|
42
|
+
context "local id not present" do
|
43
|
+
it "should set the local id and remove the identifier" do
|
44
|
+
result = subject.move_first_identifier_to_local_id
|
45
|
+
expect(result).to be true
|
46
|
+
expect(subject.local_id).to eq(identifiers.first)
|
47
|
+
expect(subject.identifier).to be_empty
|
48
|
+
end
|
49
|
+
end
|
50
|
+
context "local id present" do
|
51
|
+
before { subject.local_id = local_id }
|
52
|
+
context "replace option is true" do
|
53
|
+
it "should set the local id and remove the identifier" do
|
54
|
+
result = subject.move_first_identifier_to_local_id
|
55
|
+
expect(result).to be true
|
56
|
+
expect(subject.local_id).to eq(identifiers.first)
|
57
|
+
expect(subject.identifier).to be_empty
|
58
|
+
end
|
59
|
+
end
|
60
|
+
context "replace option is false" do
|
61
|
+
context "local id matches first identifier" do
|
62
|
+
before { subject.identifier = Array(local_id) }
|
63
|
+
it "should remove the identifier" do
|
64
|
+
result = subject.move_first_identifier_to_local_id(replace: false)
|
65
|
+
expect(result).to be true
|
66
|
+
expect(subject.local_id).to eq(local_id)
|
67
|
+
expect(subject.identifier).to be_empty
|
68
|
+
end
|
69
|
+
end
|
70
|
+
context "local id does not match first identifier" do
|
71
|
+
it "should not change the local id and not remove the identifier" do
|
72
|
+
result = subject.move_first_identifier_to_local_id(replace: false)
|
73
|
+
expect(result).to be false
|
74
|
+
expect(subject.local_id).to eq(local_id)
|
75
|
+
expect(subject.identifier).to eq(Array(identifiers.first))
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
context "more than one desc metadata identifer" do
|
82
|
+
before { subject.identifier = identifiers }
|
83
|
+
context "local id not present" do
|
84
|
+
it "should set the local id and remove the identifier" do
|
85
|
+
result = subject.move_first_identifier_to_local_id
|
86
|
+
expect(result).to be true
|
87
|
+
expect(subject.local_id).to eq(identifiers.first)
|
88
|
+
expect(subject.identifier).to eq(Array(identifiers.last))
|
89
|
+
end
|
90
|
+
end
|
91
|
+
context "local id present" do
|
92
|
+
before { subject.local_id = local_id }
|
93
|
+
context "replace option is true" do
|
94
|
+
it "should set the local id and remove the identifier" do
|
95
|
+
result = subject.move_first_identifier_to_local_id
|
96
|
+
expect(result).to be true
|
97
|
+
expect(subject.local_id).to eq(identifiers.first)
|
98
|
+
expect(subject.identifier).to eq(Array(identifiers.last))
|
99
|
+
end
|
100
|
+
end
|
101
|
+
context "replace option is false" do
|
102
|
+
context "local id matches first identifier" do
|
103
|
+
before { subject.identifier = [ local_id, identifiers.last ] }
|
104
|
+
it "should remove the identifier" do
|
105
|
+
result = subject.move_first_identifier_to_local_id(replace: false)
|
106
|
+
expect(result).to be true
|
107
|
+
expect(subject.local_id).to eq(local_id)
|
108
|
+
expect(subject.identifier).to eq(Array(identifiers.last))
|
109
|
+
end
|
110
|
+
end
|
111
|
+
context "local id does not match first identifier" do
|
112
|
+
it "should not change the local id and not remove the identifier" do
|
113
|
+
result = subject.move_first_identifier_to_local_id(replace: false)
|
114
|
+
expect(result).to be false
|
115
|
+
expect(subject.local_id).to eq(local_id)
|
116
|
+
expect(subject.identifier).to eq(identifiers)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
27
124
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ddr-models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Coble
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-08-
|
12
|
+
date: 2015-08-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -627,7 +627,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
627
627
|
version: '0'
|
628
628
|
requirements: []
|
629
629
|
rubyforge_project:
|
630
|
-
rubygems_version: 2.
|
630
|
+
rubygems_version: 2.2.2
|
631
631
|
signing_key:
|
632
632
|
specification_version: 4
|
633
633
|
summary: Models used in the Duke Digital Repository
|