rubydora 1.7.1 → 1.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  describe Rubydora::DigitalObject do
4
4
  before do
5
- @mock_repository = Rubydora::Fc3Service.new({})
5
+ @mock_api = Rubydora::Fc3Service.new({})
6
+ @mock_api.stub(:repository_profile, {"repositoryVersion" => "3.4"})
7
+ @mock_repository = Rubydora::Repository.new({}, @mock_api)
6
8
  end
7
9
  describe "profile" do
8
10
  before(:each) do
@@ -10,7 +12,7 @@ describe Rubydora::DigitalObject do
10
12
  end
11
13
 
12
14
  it "should convert object profile to a simple hash" do
13
- @mock_repository.should_receive(:object).with(:pid => 'pid').and_return("<objectProfile><a>1</a><b>2</b><objModels><model>3</model><model>4</model></objectProfile>")
15
+ @mock_api.should_receive(:object).with(:pid => 'pid').and_return("<objectProfile><a>1</a><b>2</b><objModels><model>3</model><model>4</model></objectProfile>")
14
16
  h = @object.profile
15
17
 
16
18
  h.should have_key("a")
@@ -23,28 +25,28 @@ describe Rubydora::DigitalObject do
23
25
  end
24
26
 
25
27
  it "should be frozen (to prevent modification)" do
26
- @mock_repository.should_receive(:object).with(:pid => 'pid').and_return("<objectProfile><a>1</a><b>2</b><objModels><model>3</model><model>4</model></objectProfile>")
28
+ @mock_api.should_receive(:object).with(:pid => 'pid').and_return("<objectProfile><a>1</a><b>2</b><objModels><model>3</model><model>4</model></objectProfile>")
27
29
  h = @object.profile
28
30
 
29
31
  expect { h['asdf'] = 'asdf' }.to raise_error
30
32
  end
31
33
 
32
34
  it "should return nil for empty profile fields" do
33
- @mock_repository.should_receive(:object).with(:pid => 'pid').and_return("<objectProfile><a></a></objectProfile>")
35
+ @mock_api.should_receive(:object).with(:pid => 'pid').and_return("<objectProfile><a></a></objectProfile>")
34
36
  @object.profile['a'].should be_nil
35
37
  end
36
38
 
37
39
  it "should throw exceptions that arise" do
38
- @mock_repository.should_receive(:object).with(:pid => 'pid').and_raise(Net::HTTPBadResponse)
40
+ @mock_api.should_receive(:object).with(:pid => 'pid').and_raise(Net::HTTPBadResponse)
39
41
  expect { @object.profile }.to raise_error(Net::HTTPBadResponse)
40
42
  end
41
43
  end
42
44
 
43
45
  describe "initialize" do
44
46
  before(:each) do
45
- @mock_repository.stub(:object) { raise RestClient::ResourceNotFound }
47
+ @mock_api.stub(:object) { raise RestClient::ResourceNotFound }
46
48
  end
47
- subject { Rubydora::DigitalObject.new 'pid', @mock_repository }
49
+ subject { Rubydora::DigitalObject.new 'pid', @mock_api }
48
50
 
49
51
  it "should load a DigitalObject instance" do
50
52
  expect(subject).to be_a_kind_of(Rubydora::DigitalObject)
@@ -60,15 +62,15 @@ describe Rubydora::DigitalObject do
60
62
 
61
63
  it "should call ingest on save" do
62
64
  subject.stub(:datastreams) { {} }
63
- expect(@mock_repository).to receive(:ingest).with(hash_including(:pid => 'pid')).and_return('pid')
65
+ expect(@mock_api).to receive(:ingest).with(hash_including(:pid => 'pid')).and_return('pid')
64
66
  subject.save
65
67
  end
66
68
 
67
69
  describe "without a provided pid" do
68
- subject { Rubydora::DigitalObject.new nil, @mock_repository }
70
+ subject { Rubydora::DigitalObject.new nil, @mock_api }
69
71
  it "should create a new Fedora object with a generated PID if no PID is provided" do
70
- @mock_repository.should_receive(:ingest).with(hash_including(:pid => nil)).and_return('pid')
71
- @mock_repository.should_receive(:datastreams).with(hash_including(:pid => 'pid')).and_raise(RestClient::ResourceNotFound)
72
+ @mock_api.should_receive(:ingest).with(hash_including(:pid => nil)).and_return('pid')
73
+ @mock_api.should_receive(:datastreams).with(hash_including(:pid => 'pid')).and_raise(RestClient::ResourceNotFound)
72
74
  subject.save
73
75
  subject.pid.should == 'pid'
74
76
  end
@@ -77,29 +79,29 @@ describe Rubydora::DigitalObject do
77
79
 
78
80
  describe "create" do
79
81
  it "should call the Fedora REST API to create a new object" do
80
- @mock_repository.should_receive(:ingest).with(instance_of(Hash)).and_return("pid")
81
- obj = Rubydora::DigitalObject.create "pid", { :a => 1, :b => 2}, @mock_repository
82
+ @mock_api.should_receive(:ingest).with(instance_of(Hash)).and_return("pid")
83
+ obj = Rubydora::DigitalObject.create "pid", { :a => 1, :b => 2}, @mock_api
82
84
  obj.should be_a_kind_of(Rubydora::DigitalObject)
83
85
  end
84
86
 
85
87
  it "should return a new object with the Fedora response pid when no pid is provided" do
86
- @mock_repository.should_receive(:ingest).with(instance_of(Hash)).and_return("pid")
87
- obj = Rubydora::DigitalObject.create "new", { :a => 1, :b => 2}, @mock_repository
88
+ @mock_api.should_receive(:ingest).with(instance_of(Hash)).and_return("pid")
89
+ obj = Rubydora::DigitalObject.create "new", { :a => 1, :b => 2}, @mock_api
88
90
  obj.should be_a_kind_of(Rubydora::DigitalObject)
89
91
  obj.pid.should == "pid"
90
92
  end
91
93
  end
92
94
 
93
- describe "retreive" do
94
- before(:each) do
95
- @mock_repository.stub :datastreams do |hash|
96
- "<objectDatastreams><datastream dsid='a'></datastream>><datastream dsid='b'></datastream>><datastream dsid='c'></datastream></objectDatastreams>"
95
+ describe "retreive datastreams" do
96
+ describe "without profiles (fedora < 3.6)" do
97
+ before(:each) do
98
+ @mock_api.stub :datastreams do |hash|
99
+ "<objectDatastreams><datastream dsid='a'></datastream><datastream dsid='b'></datastream><datastream dsid='c'></datastream></objectDatastreams>"
100
+ end
101
+ @object = Rubydora::DigitalObject.new 'pid', @mock_api
102
+ @object.stub(:new_record? => false)
97
103
  end
98
- @object = Rubydora::DigitalObject.new 'pid', @mock_repository
99
- @object.stub(:new_record? => false)
100
- end
101
104
 
102
- describe "datastreams" do
103
105
  it "should provide a hash populated by the existing datastreams" do
104
106
 
105
107
  @object.datastreams.should have_key("a")
@@ -108,7 +110,7 @@ describe Rubydora::DigitalObject do
108
110
  end
109
111
 
110
112
  it "should allow other datastreams to be added" do
111
- @mock_repository.should_receive(:datastream).with(:pid => 'pid', :dsid => 'z').and_raise(RestClient::ResourceNotFound)
113
+ @mock_api.should_receive(:datastream).with(:pid => 'pid', :dsid => 'z').and_raise(RestClient::ResourceNotFound)
112
114
 
113
115
  @object.datastreams.length.should == 3
114
116
 
@@ -127,29 +129,92 @@ describe Rubydora::DigitalObject do
127
129
 
128
130
  it "should provide a way to override the type of datastream object to use" do
129
131
  class MyCustomDatastreamClass < Rubydora::Datastream; end
130
- object = Rubydora::DigitalObject.new 'pid', @mock_repository
132
+ object = Rubydora::DigitalObject.new 'pid', @mock_api
131
133
  object.stub(:datastream_object_for) do |dsid|
132
134
  MyCustomDatastreamClass.new(self, dsid)
133
135
  end
134
136
 
135
137
  object.datastreams['asdf'].should be_a_kind_of(MyCustomDatastreamClass)
136
138
  end
137
-
138
139
  end
140
+ describe "with profiles (fedora >= 3.6)" do
141
+ before(:each) do
142
+ @mock_api.stub :datastreams do |hash|
143
+ "<objectDatastreams>
144
+ <datastreamProfile dsID='a'><dsLabel>Test label</dsLabel></datastreamProfile>
145
+ <datastreamProfile dsID='b'></datastreamProfile>
146
+ <datastreamProfile dsID='c'></datastreamProfile>
147
+ </objectDatastreams>"
148
+ end
149
+ @object = Rubydora::DigitalObject.new 'pid', @mock_api
150
+ @object.stub(:new_record? => false)
151
+ end
152
+
153
+ it "should provide a hash populated by the existing datastreams" do
154
+ @object.datastreams.should have_key("a")
155
+ @object.datastreams.should have_key("b")
156
+ @object.datastreams.should have_key("c")
157
+ end
158
+ it "should load the profile attributes" do
159
+ expect(@object['a'].label).to eq 'Test label'
160
+ end
161
+ it "should not set the new datastream as changed" do
162
+ expect(@object['a']).to_not be_changed
163
+ end
164
+ end
165
+ end
166
+
167
+ describe "retrieved with batch ds profiles" do
168
+ before(:each) do
169
+ @mock_api.stub(:datastreams).and_return <<-XML
170
+ <objectDatastreams>
171
+ <datastreamProfile pid="pid" dsID="a">
172
+ <dsLocation>some:uri</dsLocation>
173
+ <dsLabel>label</dsLabel>
174
+ <dsChecksumValid>true</dsChecksumValid>
175
+ </datastreamProfile>
176
+ <datastreamProfile pid="pid" dsID="b">
177
+ <dsLocation>some:uri</dsLocation>
178
+ <dsLabel>label</dsLabel>
179
+ <dsChecksumValid>true</dsChecksumValid>
180
+ </datastreamProfile>
181
+ <datastreamProfile pid="pid" dsID="c">
182
+ <dsLocation>some:uri</dsLocation>
183
+ <dsLabel>label</dsLabel>
184
+ <dsChecksumValid>true</dsChecksumValid>
185
+ </datastreamProfile>
186
+ </objectDatastreams>
187
+ XML
188
+ @object = Rubydora::DigitalObject.new 'pid', @mock_api
189
+ @object.stub(:new_record? => false)
190
+ end
191
+ describe "datastreams" do
192
+ it "should provide a hash populated by the existing datastreams" do
139
193
 
194
+ @object.datastreams.should have_key("a")
195
+ @object.datastreams["a"].new?.should be_false
196
+ @object.datastreams["a"].changed?.should be_false
197
+ @object.datastreams.should have_key("b")
198
+ @object.datastreams["b"].new?.should be_false
199
+ @object.datastreams["b"].changed?.should be_false
200
+ @object.datastreams.should have_key("c")
201
+ @object.datastreams["c"].new?.should be_false
202
+ @object.datastreams["c"].changed?.should be_false
203
+ end
204
+ end
140
205
  end
141
206
 
142
207
  describe "update" do
143
208
 
144
209
  before(:each) do
145
- @mock_repository.stub(:object) { <<-XML
210
+ @mock_api.stub(:object) { <<-XML
146
211
  <objectProfile>
147
212
  <objLabel>label</objLabel>
148
213
  </objectProfile>
149
214
  XML
150
215
  }
151
216
 
152
- @object = Rubydora::DigitalObject.new 'pid', @mock_repository
217
+ @object = Rubydora::DigitalObject.new 'pid', @mock_api
153
218
  end
154
219
 
155
220
  it "should not say changed if the value is set the same" do
@@ -164,30 +229,31 @@ describe Rubydora::DigitalObject do
164
229
 
165
230
  describe "save" do
166
231
  before(:each) do
167
- @mock_repository.stub(:object) { <<-XML
232
+ @original_modified = "2011-01-02:05:15:45.1Z"
233
+ @mock_api.stub(:object) { <<-XML
168
234
  <objectProfile>
169
- <not>empty</not>
235
+ <objLastModDate>2011-01-02:05:15:45.100Z</objLastModDate>
170
236
  </objectProfile>
171
237
  XML
172
238
  }
173
239
 
174
- @object = Rubydora::DigitalObject.new 'pid', @mock_repository
240
+ @object = Rubydora::DigitalObject.new 'pid', @mock_api
175
241
  end
176
242
 
177
243
  describe "saving an object's datastreams" do
178
244
  before do
179
245
  @new_ds = double(Rubydora::Datastream)
180
- @new_ds.stub(:new? => true, :changed? => true, :content_changed? => true, :content => 'XXX')
246
+ @new_ds.stub(:new? => true, :changed? => true, :content_changed? => true, :content => 'XXX', :dsCreateDate => '12345')
181
247
  @new_empty_ds = double(Rubydora::Datastream)
182
- @new_empty_ds.stub(:new? => true, :changed? => false, :content_changed? => false, :content => nil)
248
+ @new_empty_ds.stub(:new? => true, :changed? => false, :content_changed? => false, :content => nil, :dsCreateDate => '12345')
183
249
  @existing_ds = double(Rubydora::Datastream)
184
- @existing_ds.stub(:new? => false, :changed? => false, :content_changed? => false, :content => 'YYY')
250
+ @existing_ds.stub(:new? => false, :changed? => false, :content_changed? => false, :content => 'YYY', :dsCreateDate => '12345')
185
251
  @changed_attr_ds = double(Rubydora::Datastream)
186
- @changed_attr_ds.stub(:new? => false, :changed? => true, :content_changed? => false, :content => 'YYY')
252
+ @changed_attr_ds.stub(:new? => false, :changed? => true, :content_changed? => false, :content => 'YYY', :dsCreateDate => '12345')
187
253
  @changed_ds = double(Rubydora::Datastream)
188
- @changed_ds.stub(:new? => false, :changed? => true, :content_changed? => true, :content => 'ZZZ')
254
+ @changed_ds.stub(:new? => false, :changed? => true, :content_changed? => true, :content => 'ZZZ', :dsCreateDate => '2012-01-02:05:15:45.100Z')
189
255
  @changed_empty_ds = double(Rubydora::Datastream)
190
- @changed_empty_ds.stub(:new? => false, :changed? => true, :content_changed? => true, :content => nil)
256
+ @changed_empty_ds.stub(:new? => false, :changed? => true, :content_changed? => true, :content => nil, :dsCreateDate => '12345')
191
257
 
192
258
  end
193
259
  it "should save a new datastream with content" do
@@ -200,6 +266,8 @@ describe Rubydora::DigitalObject do
200
266
  @object.stub(:datastreams) { { :changed_ds => @changed_ds } }
201
267
  @changed_ds.should_receive(:save)
202
268
  @object.save
269
+ # object date should be canonicalized and updated
270
+ @object.lastModifiedDate.should == '2012-01-02:05:15:45.1Z'
203
271
  end
204
272
 
205
273
  it "should save a datastream whose attributes have changed" do
@@ -230,34 +298,51 @@ describe Rubydora::DigitalObject do
230
298
  it "should save all changed attributes" do
231
299
  @object.label = "asdf"
232
300
  @object.should_receive(:datastreams).and_return({})
233
- @mock_repository.should_receive(:modify_object).with(hash_including(:pid => 'pid'))
301
+ @mock_api.should_receive(:modify_object).with(hash_including(:pid => 'pid'))
302
+ @object.save
303
+ expect(@object).to_not be_changed, "#{@object.changes.inspect}"
304
+ end
305
+
306
+ it "updates the modification time" do
307
+ ds = double(Rubydora::Datastream)
308
+ ds.stub(:changed? => false)
309
+ @object.stub(:datastreams) { { :ds => ds } }
310
+
311
+ @object.lastModifiedDate.should == @original_modified
312
+ mod_time = "2012-01-02:05:15:00.1Z"
313
+ @mock_api.should_receive(:modify_object).and_return(mod_time)
314
+
315
+ @object.label = "asdf"
234
316
  @object.save
317
+ @object.lastModifiedDate.should == mod_time
318
+ expect(@object).to_not be_changed, "#{@object.changes.inspect}"
235
319
  end
320
+
236
321
  end
237
322
 
238
323
  describe "delete" do
239
324
  before(:each) do
240
- @object = Rubydora::DigitalObject.new 'pid', @mock_repository
325
+ @object = Rubydora::DigitalObject.new 'pid', @mock_api
241
326
  end
242
327
 
243
328
  it "should call the Fedora REST API" do
244
- @mock_repository.should_receive(:purge_object).with({:pid => 'pid'})
329
+ @mock_api.should_receive(:purge_object).with({:pid => 'pid'})
245
330
  @object.delete
246
331
  end
247
332
  end
248
333
 
249
334
  describe "models" do
250
335
  before(:each) do
251
- @mock_repository.stub(:object) { <<-XML
336
+ @mock_api.stub(:object) { <<-XML
252
337
  <objectProfile>
253
338
  </objectProfile>
254
339
  XML
255
340
  }
256
- @object = Rubydora::DigitalObject.new 'pid', @mock_repository
341
+ @object = Rubydora::DigitalObject.new 'pid', @mock_api
257
342
  end
258
343
 
259
344
  it "should add models to fedora" do
260
- @mock_repository.should_receive(:add_relationship) do |params|
345
+ @mock_api.should_receive(:add_relationship) do |params|
261
346
  params.should have_key(:subject)
262
347
  params[:predicate].should == 'info:fedora/fedora-system:def/model#hasModel'
263
348
  params[:object].should == 'asdf'
@@ -267,7 +352,7 @@ describe Rubydora::DigitalObject do
267
352
 
268
353
  it "should remove models from fedora" do
269
354
  @object.stub(:profile).and_return({"objModels" => ['asdf']})
270
- @mock_repository.should_receive(:purge_relationship) do |params|
355
+ @mock_api.should_receive(:purge_relationship) do |params|
271
356
  params.should have_key(:subject)
272
357
  params[:predicate].should == 'info:fedora/fedora-system:def/model#hasModel'
273
358
  params[:object].should == 'asdf'
@@ -277,8 +362,8 @@ describe Rubydora::DigitalObject do
277
362
 
278
363
  it "should be able to handle complete model replacemenet" do
279
364
  @object.stub(:profile).and_return({"objModels" => ['asdf']})
280
- @mock_repository.should_receive(:add_relationship).with(instance_of(Hash))
281
- @mock_repository.should_receive(:purge_relationship).with(instance_of(Hash))
365
+ @mock_api.should_receive(:add_relationship).with(instance_of(Hash))
366
+ @mock_api.should_receive(:purge_relationship).with(instance_of(Hash))
282
367
  @object.models = '1234'
283
368
 
284
369
  end
@@ -286,60 +371,60 @@ describe Rubydora::DigitalObject do
286
371
 
287
372
  describe "relations" do
288
373
  before(:each) do
289
- @mock_repository.stub(:object) { <<-XML
374
+ @mock_api.stub(:object) { <<-XML
290
375
  <objectProfile>
291
376
  </objectProfile>
292
377
  XML
293
378
  }
294
- @object = Rubydora::DigitalObject.new 'pid', @mock_repository
379
+ @object = Rubydora::DigitalObject.new 'pid', @mock_api
295
380
  end
296
381
 
297
382
  it "should fetch related objects using sparql" do
298
- @mock_repository.should_receive(:find_by_sparql_relationship).with('info:fedora/pid', 'info:fedora/fedora-system:def/relations-external#hasPart').and_return([1])
383
+ @mock_api.should_receive(:find_by_sparql_relationship).with('info:fedora/pid', 'info:fedora/fedora-system:def/relations-external#hasPart').and_return([1])
299
384
  @object.parts.should == [1]
300
385
  end
301
386
 
302
387
  it "should add related objects" do
303
- @mock_repository.should_receive(:add_relationship) do |params|
388
+ @mock_api.should_receive(:add_relationship) do |params|
304
389
  params.should have_key(:subject)
305
390
  params[:predicate].should == 'info:fedora/fedora-system:def/relations-external#hasPart'
306
391
  params[:object].should == 'asdf'
307
392
  end
308
393
  @mock_object = double(Rubydora::DigitalObject)
309
394
  @mock_object.should_receive(:fqpid).and_return('asdf')
310
- @mock_repository.should_receive(:find_by_sparql_relationship).with('info:fedora/pid', 'info:fedora/fedora-system:def/relations-external#hasPart').and_return([])
395
+ @mock_api.should_receive(:find_by_sparql_relationship).with('info:fedora/pid', 'info:fedora/fedora-system:def/relations-external#hasPart').and_return([])
311
396
  @object.parts << @mock_object
312
397
  end
313
398
 
314
399
  it "should remove related objects" do
315
- @mock_repository.should_receive(:purge_relationship) do |params|
400
+ @mock_api.should_receive(:purge_relationship) do |params|
316
401
  params.should have_key(:subject)
317
402
  params[:predicate].should == 'info:fedora/fedora-system:def/relations-external#hasPart'
318
403
  params[:object].should == 'asdf'
319
404
  end
320
405
  @mock_object = double(Rubydora::DigitalObject)
321
406
  @mock_object.should_receive(:fqpid).and_return('asdf')
322
- @mock_repository.should_receive(:find_by_sparql_relationship).with('info:fedora/pid', 'info:fedora/fedora-system:def/relations-external#hasPart').and_return([@mock_object])
407
+ @mock_api.should_receive(:find_by_sparql_relationship).with('info:fedora/pid', 'info:fedora/fedora-system:def/relations-external#hasPart').and_return([@mock_object])
323
408
  @object.parts.delete(@mock_object)
324
409
  end
325
410
  end
326
411
 
327
412
  describe "versions" do
328
413
  before(:each) do
329
- @mock_repository.stub(:object) { <<-XML
414
+ @mock_api.stub(:object) { <<-XML
330
415
  <objectProfile>
331
416
  </objectProfile>
332
417
  XML
333
418
  }
334
419
 
335
- @mock_repository.stub(:object_versions) { <<-XML
420
+ @mock_api.stub(:object_versions) { <<-XML
336
421
  <fedoraObjectHistory>
337
422
  <objectChangeDate>2011-09-26T20:41:02.450Z</objectChangeDate>
338
423
  <objectChangeDate>2011-10-11T21:17:48.124Z</objectChangeDate>
339
424
  </fedoraObjectHistory>
340
425
  XML
341
426
  }
342
- @object = Rubydora::DigitalObject.new 'pid', @mock_repository
427
+ @object = Rubydora::DigitalObject.new 'pid', @mock_api
343
428
  end
344
429
 
345
430
  it "should have a list of previous versions" do
@@ -352,7 +437,7 @@ describe Rubydora::DigitalObject do
352
437
  end
353
438
 
354
439
  it "should lookup content of datastream using the asOfDateTime parameter" do
355
- @mock_repository.should_receive(:datastreams).with(hash_including(:asOfDateTime => '2011-09-26T20:41:02.450Z')).and_return('')
440
+ @mock_api.should_receive(:datastreams).with(hash_including(:asOfDateTime => '2011-09-26T20:41:02.450Z')).and_return('')
356
441
  Rubydora::Datastream.should_receive(:new).with(anything, 'my_ds', hash_including(:asOfDateTime => '2011-09-26T20:41:02.450Z'))
357
442
  ds = @object.versions.first['my_ds']
358
443
  end
@@ -361,7 +446,7 @@ describe Rubydora::DigitalObject do
361
446
 
362
447
  describe "to_api_params" do
363
448
  before(:each) do
364
- @object = Rubydora::DigitalObject.new 'pid', @mock_repository
449
+ @object = Rubydora::DigitalObject.new 'pid', @mock_api
365
450
  end
366
451
  it "should compile parameters to hash" do
367
452
  @object.send(:to_api_params).should == {}
@@ -369,7 +454,7 @@ describe Rubydora::DigitalObject do
369
454
  end
370
455
 
371
456
  shared_examples "an object attribute" do
372
- subject { Rubydora::DigitalObject.new 'pid', @mock_repository }
457
+ subject { Rubydora::DigitalObject.new 'pid', @mock_api }
373
458
 
374
459
  describe "getter" do
375
460
  it "should return the value" do
@@ -383,7 +468,7 @@ describe Rubydora::DigitalObject do
383
468
  end
384
469
 
385
470
  it "should fall-back to the set of default attributes" do
386
- @mock_repository.should_receive(:object).with(:pid=>"pid").and_raise(RestClient::ResourceNotFound)
471
+ @mock_api.should_receive(:object).with(:pid=>"pid").and_raise(RestClient::ResourceNotFound)
387
472
  Rubydora::DigitalObject::OBJ_DEFAULT_ATTRIBUTES.should_receive(:[]).with(method.to_sym) { 'zxcv'}
388
473
  subject.send(method).should == 'zxcv'
389
474
  end
@@ -394,7 +479,7 @@ describe Rubydora::DigitalObject do
394
479
  subject.stub(:datastreams => [])
395
480
  end
396
481
  it "should mark the object as changed after setting" do
397
- @mock_repository.should_receive(:object).with(:pid=>"pid").and_raise(RestClient::ResourceNotFound)
482
+ @mock_api.should_receive(:object).with(:pid=>"pid").and_raise(RestClient::ResourceNotFound)
398
483
  subject.send("#{method}=", 'new_value')
399
484
  subject.should be_changed
400
485
  end
@@ -405,8 +490,8 @@ describe Rubydora::DigitalObject do
405
490
  end
406
491
 
407
492
  it "should appear in the save request" do
408
- @mock_repository.should_receive(:ingest).with(hash_including(method.to_sym => 'new_value'))
409
- @mock_repository.should_receive(:object).with(:pid=>"pid").and_raise(RestClient::ResourceNotFound)
493
+ @mock_api.should_receive(:ingest).with(hash_including(method.to_sym => 'new_value'))
494
+ @mock_api.should_receive(:object).with(:pid=>"pid").and_raise(RestClient::ResourceNotFound)
410
495
  subject.send("#{method}=", 'new_value')
411
496
  subject.save
412
497
  end
@@ -414,7 +499,7 @@ describe Rubydora::DigitalObject do
414
499
  end
415
500
 
416
501
  describe "#state" do
417
- subject { Rubydora::DigitalObject.new 'pid', @mock_repository }
502
+ subject { Rubydora::DigitalObject.new 'pid', @mock_api }
418
503
 
419
504
  describe "getter" do
420
505
  it "should return the value" do
@@ -428,7 +513,7 @@ describe Rubydora::DigitalObject do
428
513
  end
429
514
 
430
515
  it "should fall-back to the set of default attributes" do
431
- @mock_repository.should_receive(:object).with(:pid=>"pid").and_raise(RestClient::ResourceNotFound)
516
+ @mock_api.should_receive(:object).with(:pid=>"pid").and_raise(RestClient::ResourceNotFound)
432
517
  Rubydora::DigitalObject::OBJ_DEFAULT_ATTRIBUTES.should_receive(:[]).with(:state) { 'zxcv'}
433
518
  subject.state.should == 'zxcv'
434
519
  end
@@ -439,7 +524,7 @@ describe Rubydora::DigitalObject do
439
524
  subject.stub(:datastreams => [])
440
525
  end
441
526
  it "should mark the object as changed after setting" do
442
- @mock_repository.should_receive(:object).with(:pid=>"pid").and_raise(RestClient::ResourceNotFound)
527
+ @mock_api.should_receive(:object).with(:pid=>"pid").and_raise(RestClient::ResourceNotFound)
443
528
  subject.state= 'D'
444
529
  subject.should be_changed
445
530
  end
@@ -455,8 +540,8 @@ describe Rubydora::DigitalObject do
455
540
  end
456
541
 
457
542
  it "should appear in the save request" do
458
- @mock_repository.should_receive(:ingest).with(hash_including(:state => 'A'))
459
- @mock_repository.should_receive(:object).with(:pid=>"pid").and_raise(RestClient::ResourceNotFound)
543
+ @mock_api.should_receive(:ingest).with(hash_including(:state => 'A'))
544
+ @mock_api.should_receive(:object).with(:pid=>"pid").and_raise(RestClient::ResourceNotFound)
460
545
  subject.state='A'
461
546
  subject.save
462
547
  end
@@ -72,10 +72,11 @@ describe "Integration testing against a live Fedora repository", :integration =>
72
72
  obj.label.should == 'asdf'
73
73
  obj.label = 'qwerty'
74
74
  obj.save
75
-
75
+ # get 'cached' lastModifiedDate
76
+ e_date = obj.lastModifiedDate
76
77
  obj = @repository.find('test:3')
77
78
  obj.label.should == 'qwerty'
78
-
79
+ obj.lastModifiedDate.should == e_date
79
80
  end
80
81
 
81
82
  describe "datastream stuff" do
@@ -120,6 +121,15 @@ describe "Integration testing against a live Fedora repository", :integration =>
120
121
  ds.controlGroup.should == "M"
121
122
  ds.size.should be > 100
122
123
  end
124
+
125
+ it "should not mark existing datastreams as changed on load" do
126
+ obj = @repository.find('fedora-system:ContentModel-3.0')
127
+ obj.datastreams.each do |k,v|
128
+ v.changed?.should be_false
129
+ v.new?.should be_false
130
+ end
131
+ end
132
+
123
133
  end
124
134
 
125
135
  it "should delete datastreams" do
@@ -135,6 +145,7 @@ describe "Integration testing against a live Fedora repository", :integration =>
135
145
  obj.save
136
146
 
137
147
  obj.datastreams["new_ds"].new?.should == false
148
+ obj.datastreams["new_ds"].changed?.should == false
138
149
  obj.datastreams["empty_ds"].new?.should == true
139
150
  end
140
151
 
@@ -164,6 +175,18 @@ describe "Integration testing against a live Fedora repository", :integration =>
164
175
  ds.content
165
176
  end
166
177
 
178
+ it "should cache object's lastModifiedDate from ds changes" do
179
+ @repository.ping.should == true
180
+ obj = @repository.find_or_initialize('test:1')
181
+ obj.save
182
+ obj.label = "abc"
183
+ obj.datastreams["my_ds"].content = "XXX"
184
+ obj.save
185
+ obj.label = "123"
186
+ obj.save
187
+ end
188
+
189
+
167
190
  describe "with transactions" do
168
191
  it "should work on ingest" do
169
192
  @repository.find('transactions:1').delete rescue nil
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rubydora::ProfileParser do
4
+ describe ".canonicalize_date_string" do
5
+ it "should correctly trim trailing zeroes in w3c date lexical representations" do
6
+ test_cases = {
7
+ "2014-02-13T19:44:30.630Z" => "2014-02-13T19:44:30.63Z",
8
+ "2014-02-13T19:44:30.600Z" => "2014-02-13T19:44:30.6Z",
9
+ "2014-02-13T19:44:30.000Z" => "2014-02-13T19:44:30Z",
10
+ "2014-02-13T19:44:30.01Z" => "2014-02-13T19:44:30.01Z",
11
+ "2014-02-13T19:44:30.001Z" => "2014-02-13T19:44:30.001Z",
12
+ "2014-02-13T20:40:43.470Z" => "2014-02-13T20:40:43.47Z"
13
+ }
14
+ test_cases.each do |input, expected|
15
+ actual = Rubydora::ProfileParser.canonicalize_date_string( input)
16
+ actual.should == expected
17
+ end
18
+ end
19
+ end
20
+ end
@@ -100,4 +100,11 @@ describe Rubydora::Repository do
100
100
  end
101
101
  end
102
102
 
103
+ describe "delegation of methods to api" do
104
+ it "should delegate :datastream_url" do
105
+ @repository.api.should_receive(:datastream_url).with("foo:bar", "descMetadata", {})
106
+ @repository.datastream_url("foo:bar", "descMetadata", {})
107
+ end
108
+ end
109
+
103
110
  end