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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c1d67cac1ae367e1a6edc359472c3f57f36155e
4
- data.tar.gz: bce49c46cff9e385341a183a82a6afee4dc06177
3
+ metadata.gz: da77038c15e029fe70bc14ba3b2fa9013606e66a
4
+ data.tar.gz: 59a3733d31c8cf61c4d4fe680037ae57a343cb0e
5
5
  SHA512:
6
- metadata.gz: e2decc6e34053a3099a97c9d00b899b213ce63a354618fde4675f8d6837ca6ef469324a104b9c1a87935f1b2c93a9871324f35169960457597a8e6bae404afaf
7
- data.tar.gz: 11620d32bc20315e596ff94c7101d3d36e46543415477685f2226edfd1ab0336e7b137bd6c8a1412d49d21145f8de4a5f8608dd085167f96bf7625cc558f4a26
6
+ metadata.gz: 8d63141d8f4cda552f720a20887419c90beb1a2e41b5b6c5bee08fda01d259b2286b85af4a45caa93576371d3498613d55a9d12cae2999dc97c278bf0cd37454
7
+ data.tar.gz: 131bd338a0a2190c604ce92b945f2e2a220f2beadbd94fe442e1b93a6435f1ab9d8c52a51ab6ebc377014315bbc47316ce81eea5fd285a37106d6eba50f6a7b6
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Ddr
2
2
  module Models
3
- VERSION = "2.0.0"
3
+ VERSION = "2.0.1"
4
4
  end
5
5
  end
@@ -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.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-05 00:00:00.000000000 Z
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.4.6
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