active-fedora 3.0.7 → 3.1.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/.rvmrc +1 -1
  2. data/Gemfile.lock +39 -10
  3. data/History.txt +0 -4
  4. data/active-fedora.gemspec +4 -3
  5. data/lib/active_fedora.rb +9 -9
  6. data/lib/active_fedora/base.rb +92 -163
  7. data/lib/active_fedora/datastream.rb +59 -60
  8. data/lib/active_fedora/datastream_hash.rb +18 -0
  9. data/lib/active_fedora/metadata_datastream.rb +3 -2
  10. data/lib/active_fedora/metadata_datastream_helper.rb +3 -15
  11. data/lib/active_fedora/model.rb +3 -3
  12. data/lib/active_fedora/nokogiri_datastream.rb +305 -302
  13. data/lib/active_fedora/qualified_dublin_core_datastream.rb +24 -19
  14. data/lib/active_fedora/rels_ext_datastream.rb +39 -37
  15. data/lib/active_fedora/rubydora_connection.rb +40 -0
  16. data/lib/active_fedora/semantic_node.rb +1 -1
  17. data/lib/active_fedora/solr_service.rb +1 -1
  18. data/lib/active_fedora/version.rb +1 -1
  19. data/lib/ruby-fedora.rb +0 -8
  20. data/lib/tasks/active_fedora.rake +14 -9
  21. data/lib/tasks/active_fedora_dev.rake +23 -40
  22. data/spec/integration/base_loader_spec.rb +4 -21
  23. data/spec/integration/base_spec.rb +300 -310
  24. data/spec/integration/bug_spec.rb +9 -10
  25. data/spec/integration/datastream_spec.rb +12 -12
  26. data/spec/integration/metadata_datastream_helper_spec.rb +7 -10
  27. data/spec/integration/model_spec.rb +3 -2
  28. data/spec/integration/rels_ext_datastream_spec.rb +9 -15
  29. data/spec/spec_helper.rb +2 -29
  30. data/spec/unit/active_fedora_spec.rb +5 -5
  31. data/spec/unit/base_cma_spec.rb +0 -7
  32. data/spec/unit/base_datastream_management_spec.rb +8 -67
  33. data/spec/unit/base_delegate_spec.rb +26 -9
  34. data/spec/unit/base_extra_spec.rb +5 -3
  35. data/spec/unit/base_file_management_spec.rb +10 -17
  36. data/spec/unit/base_named_datastream_spec.rb +76 -199
  37. data/spec/unit/base_spec.rb +152 -69
  38. data/spec/unit/content_model_spec.rb +1 -1
  39. data/spec/unit/datastream_concurrency_spec.rb +5 -4
  40. data/spec/unit/datastream_spec.rb +28 -48
  41. data/spec/unit/has_many_collection_spec.rb +2 -0
  42. data/spec/unit/inheritance_spec.rb +6 -6
  43. data/spec/unit/metadata_datastream_spec.rb +12 -28
  44. data/spec/unit/model_spec.rb +10 -10
  45. data/spec/unit/nokogiri_datastream_spec.rb +31 -33
  46. data/spec/unit/qualified_dublin_core_datastream_spec.rb +15 -15
  47. data/spec/unit/rels_ext_datastream_spec.rb +35 -29
  48. data/spec/unit/rubydora_connection_spec.rb +26 -0
  49. data/spec/unit/semantic_node_spec.rb +12 -17
  50. data/spec/unit/solr_config_options_spec.rb +13 -14
  51. data/spec/unit/solr_service_spec.rb +14 -17
  52. metadata +59 -55
  53. data/lib/fedora/base.rb +0 -38
  54. data/lib/fedora/connection.rb +0 -218
  55. data/lib/fedora/datastream.rb +0 -67
  56. data/lib/fedora/fedora_object.rb +0 -161
  57. data/lib/fedora/formats.rb +0 -30
  58. data/lib/fedora/generic_search.rb +0 -71
  59. data/lib/fedora/repository.rb +0 -298
  60. data/spec/integration/datastreams_crud_spec.rb +0 -208
  61. data/spec/integration/fedora_object_spec.rb +0 -77
  62. data/spec/integration/repository_spec.rb +0 -301
  63. data/spec/integration/rf_fedora_object_spec.rb +0 -95
  64. data/spec/unit/connection_spec.rb +0 -25
  65. data/spec/unit/fedora_object_spec.rb +0 -74
  66. data/spec/unit/repository_spec.rb +0 -143
  67. data/spec/unit/rf_datastream_spec.rb +0 -63
@@ -27,9 +27,16 @@ describe ActiveFedora::Base do
27
27
  end
28
28
 
29
29
  before(:each) do
30
- Fedora::Repository.instance.stubs(:nextid).returns(increment_pid.to_s)
30
+ @mock_repo = mock("repository")
31
+ Rubydora::DigitalObject.any_instance.expects(:repository).returns(@mock_repo).at_least_once
32
+ @this_pid = increment_pid.to_s
33
+ ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(@this_pid)
34
+
35
+ @mock_repo.expects(:datastream).with{ |x| x[:dsid] == 'RELS-EXT'}.returns("").at_least_once #raises(RuntimeError, "Fake Not found")
36
+ @mock_repo.expects(:datastream).with{ |x| x[:dsid] == 'someData'}.returns("").at_least_once #raises(RuntimeError, "Fake Not found")
37
+ @mock_repo.expects(:datastream).with{ |x| x[:dsid] == 'withText2'}.returns("").at_least_once #raises(RuntimeError, "Fake Not found")
38
+ @mock_repo.expects(:datastream).with{ |x| x[:dsid] == 'withText'}.returns("").at_least_once #raises(RuntimeError, "Fake Not found")
31
39
  @test_object = ActiveFedora::Base.new
32
- @test_object.new_object = true
33
40
  @test_history = FooHistory.new
34
41
  end
35
42
 
@@ -43,16 +50,18 @@ describe ActiveFedora::Base do
43
50
 
44
51
  describe '#new' do
45
52
  it "should create a new inner object" do
46
- Fedora::Repository.instance.expects(:save).never
53
+ Rubydora::DigitalObject.any_instance.expects(:save).never
54
+ @mock_repo.expects(:datastreams).with(:pid => "test:1").returns("")
55
+
47
56
  result = ActiveFedora::Base.new(:pid=>"test:1")
48
- result.inner_object.should be_kind_of(Fedora::FedoraObject)
57
+ result.inner_object.should be_kind_of(Rubydora::DigitalObject)
49
58
  end
50
59
 
51
60
  it "should allow initialization with nil" do
52
61
  # for doing AFObject.new(params[:foo]) when nothing is in params[:foo]
53
- Fedora::Repository.instance.expects(:save).never
62
+ Rubydora::DigitalObject.any_instance.expects(:save).never
54
63
  result = ActiveFedora::Base.new(nil)
55
- result.inner_object.should be_kind_of(Fedora::FedoraObject)
64
+ result.inner_object.should be_kind_of(Rubydora::DigitalObject)
56
65
  end
57
66
 
58
67
  end
@@ -65,16 +74,21 @@ describe ActiveFedora::Base do
65
74
 
66
75
  ### Methods for ActiveModel::Conversions
67
76
  it "should have to_param once it's saved" do
77
+ @mock_repo.expects(:object).with(:pid => @this_pid).returns("")
78
+
68
79
  @test_object.to_param.should be_nil
69
80
  @test_object.expects(:create).returns(true)
70
81
  @test_object.save
82
+ @test_object.expects(:persisted?).returns(true).at_least_once
71
83
  @test_object.to_param.should == @test_object.pid
72
84
  end
73
85
 
74
86
  it "should have to_key once it's saved" do
87
+ @mock_repo.expects(:object).with(:pid => @this_pid).returns("")
75
88
  @test_object.to_key.should be_nil
76
89
  @test_object.expects(:create).returns(true)
77
90
  @test_object.save
91
+ @test_object.expects(:persisted?).returns(true).at_least_once
78
92
  @test_object.to_key.should == [@test_object.pid]
79
93
  end
80
94
 
@@ -98,22 +112,28 @@ describe ActiveFedora::Base do
98
112
 
99
113
  describe "has_metadata" do
100
114
  before :each do
115
+ @mock_repo.expects(:datastreams).with(:pid => "monkey:99").returns("")
116
+ @mock_repo.expects(:object).with(:pid => "monkey:99").returns("")
117
+ @mock_repo.expects(:ingest).with(:pid => "monkey:99").returns("monkey:99")
118
+ @mock_repo.expects(:datastream_dissemination).with(:dsid => 'someData',:pid => 'monkey:99').returns('asdf')
119
+ @mock_repo.expects(:add_datastream).with {|params| params[:dsid] == 'someData'}
120
+ @mock_repo.expects(:datastream_dissemination).with(:dsid => 'withText',:pid => 'monkey:99').returns('asdf')
121
+ @mock_repo.expects(:add_datastream).with {|params| params[:dsid] == 'withText'}
122
+ @mock_repo.expects(:datastream_dissemination).with(:dsid => 'withText2',:pid => 'monkey:99').returns('asdf')
123
+ @mock_repo.expects(:add_datastream).with {|params| params[:dsid] == 'withText2'}
124
+ @mock_repo.expects(:datastream_dissemination).with(:dsid => 'RELS-EXT',:pid => 'monkey:99').returns('asdf')
125
+ @mock_repo.expects(:add_datastream).with {|params| params[:dsid] == 'RELS-EXT'}
126
+
101
127
  @n = FooHistory.new(:pid=>"monkey:99")
128
+ @n.expects(:update_index)
102
129
  @n.save
103
130
  end
104
131
 
105
- after :each do
106
- begin
107
- @n.delete
108
- rescue
109
- end
110
- end
111
-
112
132
  it "should create specified datastreams with specified fields" do
113
133
  @n.datastreams["someData"].should_not be_nil
114
134
  @n.datastreams["someData"].fubar_values='bar'
115
135
  @n.datastreams["someData"].fubar_values.should == ['bar']
116
- @n.datastreams["withText2"].label.should == "withLabel"
136
+ @n.datastreams["withText2"].dsLabel.should == "withLabel"
117
137
  end
118
138
 
119
139
  end
@@ -136,6 +156,7 @@ describe ActiveFedora::Base do
136
156
  end
137
157
 
138
158
  it "should add self.class as the :active_fedora_model" do
159
+ @mock_repo.expects(:object).with(:pid => @this_pid).returns("")
139
160
  fields = @test_object.fields
140
161
  fields[:active_fedora_model][:values].should eql([@test_object.class.inspect])
141
162
  end
@@ -147,6 +168,7 @@ describe ActiveFedora::Base do
147
168
  mock2.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(true)
148
169
 
149
170
  @test_object.expects(:datastreams).returns({:ds1 => mock1, :ds2 => mock2})
171
+ @mock_repo.expects(:object).with(:pid => @this_pid).returns("")
150
172
  @test_object.fields
151
173
  end
152
174
  end
@@ -168,15 +190,6 @@ describe ActiveFedora::Base do
168
190
  end
169
191
 
170
192
  describe '.rels_ext' do
171
- it 'should create the RELS-EXT datastream if it doesnt exist' do
172
- mocker = mock("rels-ext")
173
- ActiveFedora::RelsExtDatastream.expects(:new).returns(mocker)
174
- @test_object.expects(:add_datastream).with(mocker)
175
- # Make sure the RELS-EXT datastream does not exist yet
176
- @test_object.datastreams["RELS-EXT"].should == nil
177
- @test_object.rels_ext
178
- # Assume that @test_object.add_datastream actually does its job and adds the datastream to the datastreams array. Not testing that here.
179
- end
180
193
 
181
194
  it 'should return the RelsExtDatastream object from the datastreams array' do
182
195
  @test_object.expects(:datastreams).returns({"RELS-EXT" => "foo"}).at_least_once
@@ -212,7 +225,7 @@ describe ActiveFedora::Base do
212
225
  end
213
226
 
214
227
  it 'should add a relationship to an object only if it does not exist already' do
215
- Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
228
+ ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(increment_pid.to_s)
216
229
  @test_object3 = ActiveFedora::Base.new
217
230
  @test_object.add_relationship(:has_part,@test_object3)
218
231
  r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object3)
@@ -234,9 +247,9 @@ describe ActiveFedora::Base do
234
247
 
235
248
  describe '#remove_relationship' do
236
249
  it 'should remove a relationship from the relationships hash' do
237
- Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
250
+ ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(increment_pid.to_s)
238
251
  @test_object3 = ActiveFedora::Base.new
239
- Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
252
+ ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(increment_pid.to_s)
240
253
  @test_object4 = ActiveFedora::Base.new
241
254
  @test_object.add_relationship(:has_part,@test_object3)
242
255
  @test_object.add_relationship(:has_part,@test_object4)
@@ -268,14 +281,22 @@ describe ActiveFedora::Base do
268
281
 
269
282
 
270
283
  it "should return true and set persisted if object and datastreams all save successfully" do
284
+ @mock_repo.expects(:datastream_dissemination).with(:dsid => 'RELS-EXT',:pid => @this_pid).returns('asdf')
285
+
286
+ @mock_repo.expects(:ingest).with(:pid => @this_pid).returns(@this_pid)
287
+ @mock_repo.expects(:object).with(:pid => @this_pid).returns("")
288
+ @mock_repo.expects(:datastreams).with(:pid => @this_pid).returns("")
289
+ @mock_repo.expects(:add_datastream).with {|params| params[:dsid] == 'RELS-EXT'}
271
290
  @test_object.persisted?.should be false
272
- @test_object.expects(:create).returns(true)
291
+ @test_object.expects(:update_index)
273
292
  @test_object.save.should == true
293
+ @mock_repo.expects(:object).with(:pid => @this_pid).returns("<objectProfile><objOwnerId>fedoraAdmin</objOwnerId></objectProfile>")
274
294
  @test_object.persisted?.should be true
275
295
  end
276
296
 
277
297
 
278
298
  it "should raise an exception if object fails to save" do
299
+ pending # Not using Fedora::Repository anymore
279
300
  server_response = mock("Server Error")
280
301
  Fedora::Repository.instance.expects(:save).with(@test_object.inner_object).raises(Fedora::ServerError, server_response)
281
302
  lambda {@test_object.save}.should raise_error(Fedora::ServerError)
@@ -283,6 +304,7 @@ describe ActiveFedora::Base do
283
304
  end
284
305
 
285
306
  it "should raise an exception if any of the datastreams fail to save" do
307
+ pending # Not using Fedora::Repository anymore
286
308
  Fedora::Repository.instance.expects(:save).with(@test_object.inner_object).returns(true)
287
309
  Fedora::Repository.instance.expects(:save).with(kind_of(ActiveFedora::RelsExtDatastream)).raises(Fedora::ServerError, mock("Server Error"))
288
310
  lambda {@test_object.save}.should raise_error(Fedora::ServerError)
@@ -291,71 +313,124 @@ describe ActiveFedora::Base do
291
313
  it "should call .save on any datastreams that are dirty" do
292
314
  to = FooHistory.new
293
315
  to.expects(:update_index)
294
- Fedora::Repository.instance.expects(:save).with(to.inner_object)
295
- Fedora::Repository.instance.expects(:save).with(kind_of(ActiveFedora::RelsExtDatastream))
296
- Fedora::Repository.instance.expects(:save).with(to.datastreams["withText"])
297
- Fedora::Repository.instance.expects(:save).with(to.datastreams["withText2"])
298
- to.datastreams["someData"].stubs(:dirty?).returns(true)
316
+ @mock_repo.expects(:ingest).with(:pid => @this_pid).returns(@this_pid)
317
+ @mock_repo.expects(:object).with(:pid => @this_pid).returns("")
318
+ @mock_repo.expects(:datastreams).with(:pid => @this_pid).returns("")
319
+ @mock_repo.expects(:datastream_dissemination).with(:dsid => 'withText',:pid => @this_pid).returns('asdf')
320
+ @mock_repo.expects(:datastream_dissemination).with(:dsid => 'withText2',:pid => @this_pid).returns('asdf')
321
+ @mock_repo.expects(:datastream_dissemination).with(:dsid => 'RELS-EXT',:pid => @this_pid).returns('asdf')
322
+ @mock_repo.expects(:datastream_dissemination).with(:dsid => 'someData',:pid => @this_pid).returns('asdf')
323
+
324
+ @mock_repo.expects(:add_datastream).with {|params| params[:dsid] == 'withText2'}
325
+ @mock_repo.expects(:add_datastream).with {|params| params[:dsid] == 'withText'}
326
+ @mock_repo.expects(:add_datastream).with {|params| params[:dsid] == 'RELS-EXT'}
327
+
328
+
329
+ to.datastreams["someData"].stubs(:changed?).returns(true)
299
330
  to.datastreams["someData"].stubs(:new_object?).returns(true)
300
331
  to.datastreams["someData"].expects(:save)
301
332
  to.expects(:refresh)
302
333
  to.save
303
334
  end
304
335
  it "should call .save on any datastreams that are new" do
305
- ds = ActiveFedora::Datastream.new(:dsid => 'ds_to_add')
336
+ @mock_repo.expects(:datastream_dissemination).with(:dsid => 'ds_to_add',:pid => @this_pid).returns('asdf')
337
+ @mock_repo.expects(:datastream_dissemination).with(:dsid => 'RELS-EXT',:pid => @this_pid).returns('asdf')
338
+ ds = ActiveFedora::Datastream.new(@test_object.inner_object, 'ds_to_add')
339
+ ds.content = "DS CONTENT"
306
340
  @test_object.add_datastream(ds)
307
341
  ds.expects(:save)
308
342
  @test_object.instance_variable_set(:@new_object, false)
309
- Fedora::Repository.instance.expects(:save).with(@test_object.inner_object)
310
- #Fedora::Repository.instance.expects(:save).with(kind_of(ActiveFedora::RelsExtDatastream))
311
343
  @test_object.expects(:refresh)
344
+ @mock_repo.expects(:object).with(:pid => @this_pid).returns("").at_least_once
345
+ @mock_repo.expects(:ingest).with(:pid => @test_object.pid)
346
+ @mock_repo.expects(:datastreams).with(:pid => @test_object.pid).returns("")
347
+ @mock_repo.expects(:add_datastream).with{ |x| x[:dsid] = "RELS-EXT"}
348
+ @test_object.expects(:update_index)
312
349
  @test_object.save
313
350
  end
314
351
  it "should not call .save on any datastreams that are not dirty" do
315
352
  @test_object = FooHistory.new
316
353
  @test_object.expects(:update_index)
317
354
  @test_object.expects(:refresh)
318
- @test_object.dc.should be_nil #heh, haven't saved it yet!
319
- Fedora::Repository.instance.expects(:save).with(@test_object.inner_object)
320
- Fedora::Repository.instance.expects(:save).with(kind_of(ActiveFedora::RelsExtDatastream))
321
- Fedora::Repository.instance.expects(:save).with(@test_object.datastreams["withText"])
322
- Fedora::Repository.instance.expects(:save).with(@test_object.datastreams["withText2"])
355
+
356
+ @mock_repo.expects(:ingest).with(:pid => @test_object.pid)
357
+
358
+ @test_object.inner_object.expects(:new?).returns(true).twice
359
+ @test_object.inner_object.expects(:datastreams).returns({'someData'=>mock('obj', :changed? => false)})
360
+ @mock_repo.expects(:datastream_dissemination).with(:dsid => 'someData',:pid => @test_object.pid).returns('asdf')
361
+ @mock_repo.expects(:datastream_dissemination).with(:dsid => 'withText',:pid => @test_object.pid).returns('asdf')
362
+ @mock_repo.expects(:datastream_dissemination).with(:dsid => 'withText2',:pid => @test_object.pid).returns('asdf')
363
+ @mock_repo.expects(:datastream_dissemination).with(:dsid => 'RELS-EXT',:pid => @test_object.pid).returns('asdf')
323
364
  @test_object.datastreams["someData"].should_not be_nil
324
- @test_object.datastreams['someData'].stubs(:dirty?).returns(false)
325
- @test_object.datastreams['someData'].stubs(:new_object?).returns(false)
365
+ @test_object.datastreams['someData'].stubs(:changed?).returns(false)
366
+ @test_object.datastreams['someData'].stubs(:new?).returns(false)
326
367
  @test_object.datastreams['someData'].expects(:save).never
368
+ @test_object.datastreams['withText2'].expects(:save)
369
+ @test_object.datastreams['withText'].expects(:save)
370
+ @test_object.datastreams['RELS-EXT'].expects(:save)
327
371
  @test_object.save
328
372
  end
329
373
  it "should update solr index with all metadata if any MetadataDatastreams have changed" do
330
- Fedora::Repository.instance.stubs(:save)
331
- dirty_ds = ActiveFedora::MetadataDatastream.new
332
- dirty_ds.expects(:dirty?).returns(true)
333
- dirty_ds.expects(:save).returns(true)
334
- mock2 = mock("ds2", :dirty? => false, :new_object? => false)
335
- @test_object.stubs(:datastreams_in_memory).returns({:ds1 => dirty_ds, :ds2 => mock2})
374
+ @mock_repo.expects(:ingest).with(:pid => nil)
375
+ @mock_repo.expects(:modify_datastream).with{ |x| x[:pid] == nil && x[:dsid] == 'RELS-EXT'}
376
+ @mock_repo.expects(:datastream_dissemination).with(:dsid => 'RELS-EXT',:pid => nil).returns('asdf')
377
+ @mock_repo.expects(:datastream_dissemination).with(:dsid => 'ds1',:pid => nil).returns('asdf')
378
+ @mock_repo.expects(:add_datastream).with {|params| params[:dsid] == 'ds1'}
379
+ @mock_repo.expects(:datastream).with{ |x| x[:dsid] == 'ds1'}.returns("").at_least_once #raises(RuntimeError, "Fake Not found")
380
+ @test_object.inner_object.expects(:new?).returns(true).twice
381
+ @test_object.inner_object.expects(:datastreams).returns([])
382
+ @test_object.inner_object.expects(:pid).at_least_once
383
+
384
+ dirty_ds = ActiveFedora::MetadataDatastream.new(@test_object.inner_object, 'ds1')
385
+ rels_ds = ActiveFedora::RelsExtDatastream.new(@test_object.inner_object, 'RELS-EXT')
386
+ rels_ds.expects(:new?).returns(false)
387
+ mock2 = mock("ds2")
388
+ mock2.stubs(:changed? => false)
389
+ mock2.expects(:serialize!)
390
+ @test_object.stubs(:datastreams).returns({:ds1 => dirty_ds, :ds2 => mock2, 'RELS-EXT'=>rels_ds})
336
391
  @test_object.expects(:update_index)
337
392
  @test_object.expects(:refresh)
338
393
 
339
394
  @test_object.save
340
395
  end
341
396
  it "should NOT update solr index if no MetadataDatastreams have changed" do
342
- Fedora::Repository.instance.stubs(:save)
343
- mock1 = mock("ds1", :dirty? => false, :new_object? => false)
344
- mock2 = mock("ds2", :dirty? => false, :new_object? => false)
345
- @test_object.stubs(:datastreams_in_memory).returns({:ds1 => mock1, :ds2 => mock2})
397
+ Rubydora::DigitalObject.any_instance.stubs(:save)
398
+ mock1 = mock("ds1")
399
+ mock1.expects( :changed?).returns(false).at_least_once
400
+ mock1.expects(:serialize!)
401
+ mock2 = mock("ds2")
402
+ mock2.expects( :changed?).returns(false).at_least_once
403
+ mock2.expects(:serialize!)
404
+ mock_rels_ext = mock("rels-ext")
405
+ mock_rels_ext.stubs(:dsid=>"RELS-EXT", :relationships=>{}, :add_relationship=>nil, :dirty= => nil)
406
+ mock_rels_ext.expects( :changed?).returns(false).at_least_once
407
+ mock_rels_ext.expects(:serialize!)
408
+ ActiveFedora::RelsExtDatastream.expects(:new).returns(mock_rels_ext)
409
+ @test_object.stubs(:datastreams).returns({:ds1 => mock1, :ds2 => mock2})
346
410
  @test_object.expects(:update_index).never
347
411
  @test_object.expects(:refresh)
348
412
  @test_object.instance_variable_set(:@new_object, false)
349
-
413
+
414
+ @mock_repo.expects(:object).with(:pid => @this_pid).returns("")
415
+
350
416
  @test_object.save
351
417
  end
352
418
  it "should update solr index if RELS-EXT datastream has changed" do
353
- Fedora::Repository.instance.stubs(:save)
354
- rels_ext = ActiveFedora::RelsExtDatastream.new
355
- rels_ext.expects(:dirty?).returns(true)
419
+ @mock_repo = mock('repository')
420
+ @mock_repo.expects(:ingest).with(:pid => @test_object.pid)
421
+ @test_object.inner_object.expects(:repository).returns(@mock_repo).at_least_once
422
+ @test_object.inner_object.expects(:new?).returns(true).twice
423
+
424
+ rels_ext = ActiveFedora::RelsExtDatastream.new(@test_object.inner_object, 'RELS-EXT')
425
+ rels_ext.expects(:relationships_are_dirty).returns(true).at_least_once
426
+ rels_ext.expects(:new?).returns(true)
356
427
  rels_ext.expects(:save).returns(true)
357
- clean_ds = mock("ds2", :dirty? => false, :new_object? => false)
358
- @test_object.stubs(:datastreams_in_memory).returns({"RELS-EXT" => rels_ext, :clean_ds => clean_ds})
428
+ rels_ext.expects(:serialize!)
429
+ clean_ds = mock("ds2")
430
+ clean_ds.stubs(:dirty? => false, :changed? => false, :new? => false)
431
+ clean_ds.expects(:serialize!)
432
+ @test_object.inner_object.stubs(:datastreams).returns({"RELS-EXT" => rels_ext, :clean_ds => clean_ds})
433
+ @test_object.stubs(:datastreams).returns({"RELS-EXT" => rels_ext, :clean_ds => clean_ds})
359
434
  @test_object.instance_variable_set(:@new_object, false)
360
435
  @test_object.expects(:refresh)
361
436
  @test_object.expects(:update_index)
@@ -380,10 +455,11 @@ describe ActiveFedora::Base do
380
455
  end
381
456
 
382
457
  it "should call .to_xml on all MetadataDatastreams and return the resulting document" do
383
- ds1 = ActiveFedora::MetadataDatastream.new
384
- ds2 = ActiveFedora::MetadataDatastream.new
458
+ ds1 = ActiveFedora::MetadataDatastream.new(@test_object.inner_object, 'ds1')
459
+ ds2 = ActiveFedora::MetadataDatastream.new(@test_object.inner_object, 'ds2')
385
460
  [ds1,ds2].each {|ds| ds.expects(:to_xml)}
386
461
 
462
+ @mock_repo.expects(:object).with(:pid => @this_pid).returns("")
387
463
  @test_object.expects(:datastreams).returns({:ds1 => ds1, :ds2 => ds2})
388
464
  @test_object.to_xml
389
465
  end
@@ -425,6 +501,7 @@ describe ActiveFedora::Base do
425
501
  end
426
502
 
427
503
  it "should add self.class as the :active_fedora_model" do
504
+ @mock_repo.expects(:object).with(:pid => @this_pid).returns("")
428
505
  solr_doc = @test_history.to_solr
429
506
  solr_doc["active_fedora_model_s"].should eql("FooHistory")
430
507
  end
@@ -452,6 +529,7 @@ describe ActiveFedora::Base do
452
529
  end
453
530
 
454
531
  it "should call .to_solr on all MetadataDatastreams and NokogiriDatastreams, passing the resulting document to solr" do
532
+ @mock_repo.expects(:object).with(:pid => @this_pid).returns("")
455
533
  mock1 = mock("ds1", :to_solr)
456
534
  mock2 = mock("ds2", :to_solr)
457
535
  ngds = mock("ngds", :to_solr)
@@ -464,8 +542,9 @@ describe ActiveFedora::Base do
464
542
  @test_object.to_solr
465
543
  end
466
544
  it "should call .to_solr on the RELS-EXT datastream if it is dirty" do
545
+ @mock_repo.expects(:object).with(:pid => @this_pid).returns("")
467
546
  @test_object.add_relationship(:has_collection_member, "foo member")
468
- rels_ext = @test_object.datastreams_in_memory["RELS-EXT"]
547
+ rels_ext = @test_object.rels_ext
469
548
  rels_ext.dirty?.should == true
470
549
  rels_ext.expects(:to_solr)
471
550
  @test_object.to_solr
@@ -489,6 +568,7 @@ describe ActiveFedora::Base do
489
568
 
490
569
  describe ".label=" do
491
570
  it "should set the label of the inner object" do
571
+ @mock_repo.expects(:object).with(:pid => @this_pid).returns("")
492
572
  @test_object.label.should_not == "foo label"
493
573
  @test_object.label = "foo label"
494
574
  @test_object.label.should == "foo label"
@@ -496,14 +576,14 @@ describe ActiveFedora::Base do
496
576
  end
497
577
 
498
578
  it "should get a pid but not save on init" do
499
- Fedora::Repository.instance.expects(:save).never
500
- Fedora::Repository.instance.expects(:nextid).returns('mooshoo:24')
579
+ Rubydora::DigitalObject.any_instance.expects(:save).never
580
+ ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns('mooshoo:24')
501
581
  f = FooHistory.new
502
582
  f.pid.should_not be_nil
503
583
  f.pid.should == 'mooshoo:24'
504
584
  end
505
585
  it "should not clobber a pid if i'm creating!" do
506
- FooHistory.any_instance.expects(:configure_defined_datastreams)
586
+ @mock_repo.expects(:datastreams).with(:pid => "numbnuts:1").returns("")
507
587
  f = FooHistory.new(:pid=>'numbnuts:1')
508
588
  f.pid.should == 'numbnuts:1'
509
589
 
@@ -512,7 +592,7 @@ describe ActiveFedora::Base do
512
592
  describe "get_values_from_datastream" do
513
593
  it "should look up the named datastream and call get_values with the given pointer/field_name" do
514
594
  mock_ds = mock("Datastream", :get_values=>["value1", "value2"])
515
- @test_object.stubs(:datastreams_in_memory).returns({"ds1"=>mock_ds})
595
+ @test_object.stubs(:datastreams).returns({"ds1"=>mock_ds})
516
596
  @test_object.get_values_from_datastream("ds1", "--my xpath--").should == ["value1", "value2"]
517
597
  end
518
598
  end
@@ -528,12 +608,13 @@ describe ActiveFedora::Base do
528
608
  "properties"=>{ "notes"=>"foo" }
529
609
  }
530
610
  m = FooHistory.new
531
- m.stubs(:datastreams_in_memory).returns(mock_ds_hash)
611
+ m.stubs(:datastreams).returns(mock_ds_hash)
532
612
  mock_desc_metadata.expects(:update_indexed_attributes).with( ds_values_hash['descMetadata'] )
533
613
  mock_properties.expects(:update_indexed_attributes).with( ds_values_hash['properties'] )
534
614
  m.update_datastream_attributes( ds_values_hash )
535
615
  end
536
616
  it "should not do anything and should return an empty hash if the specified datastream does not exist" do
617
+ @mock_repo.expects(:object).with(:pid => @this_pid).returns("")
537
618
  ds_values_hash = {
538
619
  "nonexistentDatastream"=>{ "notes"=>"foo" }
539
620
  }
@@ -562,7 +643,9 @@ describe ActiveFedora::Base do
562
643
  m = FooHistory.new
563
644
  att= {"fubar"=>{"-1"=>"mork", "0"=>"york", "1"=>"mangle"}}
564
645
 
565
- m.datastreams_in_memory.each_value {|ds| ds.expects(:update_indexed_attributes)}
646
+ m.datastreams['someData'].expects(:update_indexed_attributes)
647
+ m.datastreams["withText"].expects(:update_indexed_attributes)
648
+ m.datastreams['withText2'].expects(:update_indexed_attributes)
566
649
  m.update_indexed_attributes(att)
567
650
  end
568
651
  it "should take a :datastreams argument" do
@@ -613,7 +696,7 @@ describe ActiveFedora::Base do
613
696
  end
614
697
 
615
698
  it 'should return current relationships by name' do
616
- Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
699
+ ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(increment_pid.to_s)
617
700
  @test_object2 = MockNamedRelationships.new
618
701
  @test_object2.add_relationship(:has_model, ActiveFedora::ContentModel.pid_from_ruby_class(MockNamedRelationships))
619
702
  @test_object.add_relationship(:has_model, ActiveFedora::ContentModel.pid_from_ruby_class(ActiveFedora::Base))
@@ -634,7 +717,7 @@ describe ActiveFedora::Base do
634
717
  end
635
718
 
636
719
  it 'should append and remove using helper methods for each outbound relationship' do
637
- Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
720
+ ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(increment_pid.to_s)
638
721
  @test_object2 = MockCreateNamedRelationshipMethodsBase.new
639
722
  @test_object2.should respond_to(:testing_append)
640
723
  @test_object2.should respond_to(:testing_remove)
@@ -20,7 +20,7 @@ describe ActiveFedora::ContentModel do
20
20
  end
21
21
 
22
22
  before(:each) do
23
- Fedora::Repository.instance.stubs(:nextid).returns("_nextid_")
23
+ ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns("_nextid_")
24
24
  @test_cmodel = ActiveFedora::ContentModel.new
25
25
  end
26
26