active-fedora 3.1.0.rc3 → 3.1.0.rc4
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.
- data/Gemfile.lock +4 -4
- data/Rakefile +2 -0
- data/active-fedora.gemspec +1 -1
- data/lib/active_fedora/base.rb +29 -10
- data/lib/active_fedora/datastream.rb +22 -28
- data/lib/active_fedora/datastream_hash.rb +5 -0
- data/lib/active_fedora/digital_object.rb +19 -0
- data/lib/active_fedora/model.rb +2 -2
- data/lib/active_fedora/rels_ext_datastream.rb +0 -15
- data/lib/active_fedora/semantic_node.rb +3 -3
- data/lib/active_fedora/version.rb +1 -1
- data/lib/tasks/active_fedora_dev.rake +1 -0
- data/spec/integration/base_spec.rb +2 -2
- data/spec/spec_helper.rb +3 -0
- data/spec/support/mock_fedora.rb +37 -0
- data/spec/unit/base_datastream_management_spec.rb +2 -1
- data/spec/unit/base_extra_spec.rb +5 -2
- data/spec/unit/base_named_datastream_spec.rb +1 -1
- data/spec/unit/base_spec.rb +90 -87
- data/spec/unit/content_model_spec.rb +3 -1
- data/spec/unit/datastream_spec.rb +7 -24
- data/spec/unit/nokogiri_datastream_spec.rb +1 -1
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +4 -0
- data/spec/unit/rels_ext_datastream_spec.rb +0 -27
- data/spec/unit/solr_config_options_spec.rb +2 -1
- metadata +81 -79
|
@@ -6,7 +6,9 @@ require 'active_fedora/metadata_datastream'
|
|
|
6
6
|
describe ActiveFedora::Base do
|
|
7
7
|
|
|
8
8
|
before(:each) do
|
|
9
|
+
stub_get('__nextid__')
|
|
9
10
|
ActiveFedora::RubydoraConnection.instance.expects(:nextid).returns("__nextid__")
|
|
11
|
+
Rubydora::Repository.any_instance.stubs(:client).returns(@mock_client)
|
|
10
12
|
@test_object = ActiveFedora::Base.new
|
|
11
13
|
end
|
|
12
14
|
|
|
@@ -71,16 +73,17 @@ describe ActiveFedora::Base do
|
|
|
71
73
|
# Actually uses self.to_solr internally to gather solr info from all metadata datastreams
|
|
72
74
|
mock1 = mock("ds1", :to_solr)
|
|
73
75
|
mock2 = mock("ds2", :to_solr)
|
|
74
|
-
mock3 = mock("RELS-EXT"
|
|
76
|
+
mock3 = mock("RELS-EXT")
|
|
75
77
|
|
|
76
78
|
mock_datastreams = {:ds1 => mock1, :ds2 => mock2, :rels_ext => mock3}
|
|
77
79
|
mock_datastreams.values.each {|ds| ds.stubs(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(false)}
|
|
78
80
|
mock1.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(true)
|
|
79
81
|
mock2.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(true)
|
|
80
82
|
mock3.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(false)
|
|
81
|
-
mock3.expects(:kind_of?).with(ActiveFedora::RelsExtDatastream).returns(true)
|
|
83
|
+
#mock3.expects(:kind_of?).with(ActiveFedora::RelsExtDatastream).returns(true)
|
|
82
84
|
|
|
83
85
|
@test_object.expects(:datastreams).returns(mock_datastreams)
|
|
86
|
+
@test_object.expects(:solrize_relationships)
|
|
84
87
|
@test_object.update_index
|
|
85
88
|
end
|
|
86
89
|
|
|
@@ -243,7 +243,7 @@ describe ActiveFedora::Base do
|
|
|
243
243
|
it 'should create a datastream object from a string' do
|
|
244
244
|
ds = @test_object.create_datastream("ActiveFedora::Datastream", 'NAME', {:blob=>"My file data"})
|
|
245
245
|
ds.class.should == ActiveFedora::Datastream
|
|
246
|
-
ds.dsLabel.should ==
|
|
246
|
+
ds.dsLabel.should == nil
|
|
247
247
|
ds.mimeType.should == "application/octet-stream"
|
|
248
248
|
end
|
|
249
249
|
end
|
data/spec/unit/base_spec.rb
CHANGED
|
@@ -27,16 +27,11 @@ describe ActiveFedora::Base do
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
before(:each) do
|
|
30
|
-
@mock_repo = mock("repository")
|
|
31
|
-
ActiveFedora::DigitalObject.any_instance.expects(:repository).returns(@mock_repo).at_least_once
|
|
32
30
|
@this_pid = increment_pid.to_s
|
|
33
|
-
@
|
|
31
|
+
stub_get(@this_pid)
|
|
32
|
+
Rubydora::Repository.any_instance.stubs(:client).returns(@mock_client)
|
|
34
33
|
ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(@this_pid)
|
|
35
34
|
|
|
36
|
-
@mock_repo.expects(:datastream).with{ |x| x[:dsid] == 'RELS-EXT'}.returns("").at_least_once #raises(RuntimeError, "Fake Not found")
|
|
37
|
-
@mock_repo.expects(:datastream).with{ |x| x[:dsid] == 'someData'}.returns("").at_least_once #raises(RuntimeError, "Fake Not found")
|
|
38
|
-
@mock_repo.expects(:datastream).with{ |x| x[:dsid] == 'withText2'}.returns("").at_least_once #raises(RuntimeError, "Fake Not found")
|
|
39
|
-
@mock_repo.expects(:datastream).with{ |x| x[:dsid] == 'withText'}.returns("").at_least_once #raises(RuntimeError, "Fake Not found")
|
|
40
35
|
@test_object = ActiveFedora::Base.new
|
|
41
36
|
@test_history = FooHistory.new
|
|
42
37
|
end
|
|
@@ -52,7 +47,12 @@ describe ActiveFedora::Base do
|
|
|
52
47
|
describe '#new' do
|
|
53
48
|
it "should create a new inner object" do
|
|
54
49
|
Rubydora::DigitalObject.any_instance.expects(:save).never
|
|
55
|
-
|
|
50
|
+
#@mock_repo.expects(:datastreams).with(:pid => "test:1").returns("")
|
|
51
|
+
@mock_client.stubs(:[]).with("objects/test%3A1/datastreams?format=xml").returns(@getter)
|
|
52
|
+
['someData', 'withText', 'withText2', 'RELS-EXT'].each do |dsid|
|
|
53
|
+
@mock_client.stubs(:[]).with {|params| /objects\/test%3A1\/datastreams\/#{dsid}/.match(params)}.returns(@getter)
|
|
54
|
+
# @mock_client.stubs(:[]).with {|params| /objects\/test%3A1\/datastreams\/#{dsid}\/content/.match(params)}.returns(stub(:post=>'test:1'))
|
|
55
|
+
end
|
|
56
56
|
|
|
57
57
|
result = ActiveFedora::Base.new(:pid=>"test:1")
|
|
58
58
|
result.inner_object.should be_kind_of(Rubydora::DigitalObject)
|
|
@@ -75,24 +75,19 @@ describe ActiveFedora::Base do
|
|
|
75
75
|
|
|
76
76
|
### Methods for ActiveModel::Conversions
|
|
77
77
|
it "should have to_param once it's saved" do
|
|
78
|
-
|
|
78
|
+
|
|
79
79
|
@test_object.to_param.should be_nil
|
|
80
|
-
@test_object.expects(:
|
|
81
|
-
@test_object.save
|
|
82
|
-
@test_object.expects(:persisted?).returns(true).at_least_once
|
|
80
|
+
@test_object.inner_object.expects(:new?).returns(false).at_least_once
|
|
83
81
|
@test_object.to_param.should == @test_object.pid
|
|
84
82
|
end
|
|
85
83
|
|
|
86
84
|
it "should have to_key once it's saved" do
|
|
87
|
-
@mock_repo.expects(:object).raises(RuntimeError)
|
|
88
85
|
@test_object.to_key.should be_nil
|
|
89
|
-
@test_object.expects(:
|
|
90
|
-
@test_object.save
|
|
91
|
-
@test_object.expects(:persisted?).returns(true).at_least_once
|
|
86
|
+
@test_object.inner_object.expects(:new?).returns(false).at_least_once
|
|
92
87
|
@test_object.to_key.should == [@test_object.pid]
|
|
93
88
|
end
|
|
94
89
|
|
|
95
|
-
it "should have to_model" do
|
|
90
|
+
it "should have to_model when it's saved" do
|
|
96
91
|
@test_object.to_model.should be @test_object
|
|
97
92
|
end
|
|
98
93
|
### end ActiveModel::Conversions
|
|
@@ -112,16 +107,18 @@ describe ActiveFedora::Base do
|
|
|
112
107
|
|
|
113
108
|
describe "has_metadata" do
|
|
114
109
|
before :each do
|
|
115
|
-
@
|
|
116
|
-
@
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
@
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
110
|
+
@mock_client.stubs(:[]).with("objects/monkey%3A99/datastreams?format=xml").returns(@getter)
|
|
111
|
+
@mock_client.stubs(:[]).with("objects/monkey%3A99/datastreams/RELS-EXT/content").returns(@getter)
|
|
112
|
+
|
|
113
|
+
#Update record
|
|
114
|
+
@mock_client.stubs(:[]).with("objects/monkey%3A99").returns(stub('post', :post=>'monkey:99'))
|
|
115
|
+
#Update datastream
|
|
116
|
+
['someData', 'withText', 'withText2', 'RELS-EXT'].each do |dsid|
|
|
117
|
+
@mock_client.stubs(:[]).with {|params| /objects\/monkey%3A99\/datastreams\/#{dsid}/.match(params)}.returns(stub('post', :post=>'monkey:99', :get=>''))
|
|
118
|
+
end
|
|
123
119
|
|
|
124
120
|
@n = FooHistory.new(:pid=>"monkey:99")
|
|
121
|
+
@n.datastreams['RELS-EXT'].expects(:changed?).returns(true).at_least_once
|
|
125
122
|
@n.expects(:update_index)
|
|
126
123
|
@n.save
|
|
127
124
|
end
|
|
@@ -153,7 +150,6 @@ describe ActiveFedora::Base do
|
|
|
153
150
|
end
|
|
154
151
|
|
|
155
152
|
it "should add self.class as the :active_fedora_model" do
|
|
156
|
-
@mock_repo.expects(:object).with(:pid => @this_pid).returns("")
|
|
157
153
|
fields = @test_object.fields
|
|
158
154
|
fields[:active_fedora_model][:values].should eql([@test_object.class.inspect])
|
|
159
155
|
end
|
|
@@ -165,7 +161,6 @@ describe ActiveFedora::Base do
|
|
|
165
161
|
mock2.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(true)
|
|
166
162
|
|
|
167
163
|
@test_object.expects(:datastreams).returns({:ds1 => mock1, :ds2 => mock2})
|
|
168
|
-
@mock_repo.expects(:object).with(:pid => @this_pid).returns("")
|
|
169
164
|
@test_object.fields
|
|
170
165
|
end
|
|
171
166
|
end
|
|
@@ -219,7 +214,10 @@ describe ActiveFedora::Base do
|
|
|
219
214
|
end
|
|
220
215
|
|
|
221
216
|
it 'should add a relationship to an object only if it does not exist already' do
|
|
222
|
-
|
|
217
|
+
next_pid = increment_pid.to_s
|
|
218
|
+
ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(next_pid)
|
|
219
|
+
stub_get(next_pid)
|
|
220
|
+
|
|
223
221
|
@test_object3 = ActiveFedora::Base.new
|
|
224
222
|
@test_object.add_relationship(:has_part,@test_object3)
|
|
225
223
|
r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object3)
|
|
@@ -241,9 +239,13 @@ describe ActiveFedora::Base do
|
|
|
241
239
|
|
|
242
240
|
describe '#remove_relationship' do
|
|
243
241
|
it 'should remove a relationship from the relationships hash' do
|
|
244
|
-
|
|
242
|
+
next_pid = increment_pid.to_s
|
|
243
|
+
ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(next_pid)
|
|
244
|
+
stub_get(next_pid)
|
|
245
245
|
@test_object3 = ActiveFedora::Base.new
|
|
246
|
-
|
|
246
|
+
next_pid = increment_pid.to_s
|
|
247
|
+
ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(next_pid)
|
|
248
|
+
stub_get(next_pid)
|
|
247
249
|
@test_object4 = ActiveFedora::Base.new
|
|
248
250
|
@test_object.add_relationship(:has_part,@test_object3)
|
|
249
251
|
@test_object.add_relationship(:has_part,@test_object4)
|
|
@@ -273,14 +275,12 @@ describe ActiveFedora::Base do
|
|
|
273
275
|
|
|
274
276
|
|
|
275
277
|
it "should return true and set persisted if object and datastreams all save successfully" do
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
@
|
|
279
|
-
@mock_repo.expects(:add_datastream).with {|params| params[:dsid] == 'RELS-EXT'}
|
|
280
|
-
@test_object.persisted?.should be false
|
|
278
|
+
stub_ingest(@this_pid)
|
|
279
|
+
stub_add_ds(@this_pid, ['RELS-EXT'])
|
|
280
|
+
@test_object.persisted?.should be false
|
|
281
281
|
@test_object.expects(:update_index)
|
|
282
|
+
stub_get(@this_pid, true)
|
|
282
283
|
@test_object.save.should == true
|
|
283
|
-
@mock_repo.expects(:object).with(:pid => @this_pid).returns("<objectProfile><objOwnerId>fedoraAdmin</objOwnerId></objectProfile>")
|
|
284
284
|
@test_object.persisted?.should be true
|
|
285
285
|
end
|
|
286
286
|
|
|
@@ -301,16 +301,10 @@ describe ActiveFedora::Base do
|
|
|
301
301
|
end
|
|
302
302
|
|
|
303
303
|
it "should call .save on any datastreams that are dirty" do
|
|
304
|
+
stub_ingest(@test_object.pid)
|
|
305
|
+
stub_add_ds(@test_object.pid, ['withText2', 'withText', 'RELS-EXT'])
|
|
304
306
|
to = FooHistory.new
|
|
305
307
|
to.expects(:update_index)
|
|
306
|
-
@mock_repo.expects(:ingest).with(:pid => @this_pid).returns(@this_pid)
|
|
307
|
-
@mock_repo.expects(:object).with(:pid => @this_pid).raises(RuntimeError)
|
|
308
|
-
@mock_repo.expects(:datastreams).with(:pid => @this_pid).returns("")
|
|
309
|
-
|
|
310
|
-
@mock_repo.expects(:add_datastream).with {|params| params[:dsid] == 'withText2'}
|
|
311
|
-
@mock_repo.expects(:add_datastream).with {|params| params[:dsid] == 'withText'}
|
|
312
|
-
@mock_repo.expects(:add_datastream).with {|params| params[:dsid] == 'RELS-EXT'}
|
|
313
|
-
|
|
314
308
|
|
|
315
309
|
to.datastreams["someData"].stubs(:changed?).returns(true)
|
|
316
310
|
to.datastreams["someData"].stubs(:new_object?).returns(true)
|
|
@@ -319,28 +313,23 @@ describe ActiveFedora::Base do
|
|
|
319
313
|
to.save
|
|
320
314
|
end
|
|
321
315
|
it "should call .save on any datastreams that are new" do
|
|
316
|
+
stub_ingest(@test_object.pid)
|
|
317
|
+
stub_add_ds(@test_object.pid, ['RELS-EXT'])
|
|
322
318
|
ds = ActiveFedora::Datastream.new(@test_object.inner_object, 'ds_to_add')
|
|
323
319
|
ds.content = "DS CONTENT"
|
|
324
320
|
@test_object.add_datastream(ds)
|
|
325
321
|
ds.expects(:save)
|
|
326
322
|
@test_object.instance_variable_set(:@new_object, false)
|
|
327
323
|
@test_object.expects(:refresh)
|
|
328
|
-
@mock_repo.expects(:object).with(:pid => @this_pid).raises(RuntimeError).at_least_once
|
|
329
|
-
@mock_repo.expects(:ingest).with(:pid => @test_object.pid)
|
|
330
|
-
@mock_repo.expects(:datastreams).with(:pid => @test_object.pid).returns("")
|
|
331
|
-
@mock_repo.expects(:add_datastream).with{ |x| x[:dsid] = "RELS-EXT"}
|
|
332
324
|
@test_object.expects(:update_index)
|
|
333
325
|
@test_object.save
|
|
334
326
|
end
|
|
335
327
|
it "should not call .save on any datastreams that are not dirty" do
|
|
328
|
+
stub_ingest(@test_object.pid)
|
|
336
329
|
@test_object = FooHistory.new
|
|
337
330
|
@test_object.expects(:update_index)
|
|
338
331
|
@test_object.expects(:refresh)
|
|
339
332
|
|
|
340
|
-
@mock_repo.expects(:ingest).with(:pid => @test_object.pid)
|
|
341
|
-
|
|
342
|
-
@test_object.inner_object.expects(:new?).returns(true).twice
|
|
343
|
-
@test_object.inner_object.expects(:datastreams).returns({'someData'=>mock('obj', :changed? => false)})
|
|
344
333
|
@test_object.datastreams["someData"].should_not be_nil
|
|
345
334
|
@test_object.datastreams['someData'].stubs(:changed?).returns(false)
|
|
346
335
|
@test_object.datastreams['someData'].stubs(:new?).returns(false)
|
|
@@ -351,28 +340,21 @@ describe ActiveFedora::Base do
|
|
|
351
340
|
@test_object.save
|
|
352
341
|
end
|
|
353
342
|
it "should update solr index with all metadata if any MetadataDatastreams have changed" do
|
|
354
|
-
|
|
355
|
-
@
|
|
356
|
-
@
|
|
357
|
-
@mock_repo.expects(:datastream).with{ |x| x[:dsid] == 'ds1'}.returns("").at_least_once #raises(RuntimeError, "Fake Not found")
|
|
358
|
-
@test_object.inner_object.expects(:new?).returns(true).twice
|
|
359
|
-
@test_object.inner_object.expects(:datastreams).returns([])
|
|
360
|
-
@test_object.inner_object.expects(:pid).at_least_once
|
|
343
|
+
# rels_ds.expects(:new?).returns(false).twice
|
|
344
|
+
stub_ingest(@test_object.pid)
|
|
345
|
+
stub_add_ds(@test_object.pid, ['ds1', 'RELS-EXT'])
|
|
361
346
|
|
|
362
347
|
dirty_ds = ActiveFedora::MetadataDatastream.new(@test_object.inner_object, 'ds1')
|
|
363
348
|
rels_ds = ActiveFedora::RelsExtDatastream.new(@test_object.inner_object, 'RELS-EXT')
|
|
364
|
-
rels_ds.expects(:new?).returns(false)
|
|
365
349
|
rels_ds.model = @test_object
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
mock2.expects(:serialize!)
|
|
369
|
-
@test_object.stubs(:datastreams).returns({:ds1 => dirty_ds, :ds2 => mock2, 'RELS-EXT'=>rels_ds})
|
|
350
|
+
@test_object.add_datastream(rels_ds)
|
|
351
|
+
@test_object.add_datastream(dirty_ds)
|
|
370
352
|
@test_object.expects(:update_index)
|
|
371
|
-
@test_object.expects(:refresh)
|
|
372
353
|
|
|
373
354
|
@test_object.save
|
|
374
355
|
end
|
|
375
356
|
it "should NOT update solr index if no MetadataDatastreams have changed" do
|
|
357
|
+
pending ## Rels-ext is getting automatically added so we can't test this.
|
|
376
358
|
ActiveFedora::DigitalObject.any_instance.stubs(:save)
|
|
377
359
|
mock1 = mock("ds1")
|
|
378
360
|
mock1.expects( :changed?).returns(false).at_least_once
|
|
@@ -380,12 +362,6 @@ describe ActiveFedora::Base do
|
|
|
380
362
|
mock2 = mock("ds2")
|
|
381
363
|
mock2.expects( :changed?).returns(false).at_least_once
|
|
382
364
|
mock2.expects(:serialize!)
|
|
383
|
-
mock_rels_ext = mock("rels-ext")
|
|
384
|
-
mock_rels_ext.stubs(:dsid=>"RELS-EXT", :relationships=>{}, :add_relationship=>nil, :dirty= => nil)
|
|
385
|
-
mock_rels_ext.expects( :changed?).returns(false).at_least_once
|
|
386
|
-
mock_rels_ext.expects(:serialize!)
|
|
387
|
-
mock_rels_ext.expects(:model=).with(@test_object)
|
|
388
|
-
ActiveFedora::RelsExtDatastream.expects(:new).returns(mock_rels_ext)
|
|
389
365
|
@test_object.stubs(:datastreams).returns({:ds1 => mock1, :ds2 => mock2})
|
|
390
366
|
@test_object.expects(:update_index).never
|
|
391
367
|
@test_object.expects(:refresh)
|
|
@@ -400,8 +376,8 @@ describe ActiveFedora::Base do
|
|
|
400
376
|
|
|
401
377
|
rels_ext = ActiveFedora::RelsExtDatastream.new(@test_object.inner_object, 'RELS-EXT')
|
|
402
378
|
rels_ext.model = @test_object
|
|
403
|
-
rels_ext.expects(:changed?).returns(true).
|
|
404
|
-
rels_ext.expects(:save).returns(true)
|
|
379
|
+
rels_ext.expects(:changed?).returns(true).twice
|
|
380
|
+
rels_ext.expects(:save).returns(true)
|
|
405
381
|
rels_ext.expects(:serialize!)
|
|
406
382
|
clean_ds = mock("ds2")
|
|
407
383
|
clean_ds.stubs(:dirty? => false, :changed? => false, :new? => false)
|
|
@@ -436,7 +412,6 @@ describe ActiveFedora::Base do
|
|
|
436
412
|
ds2 = ActiveFedora::MetadataDatastream.new(@test_object.inner_object, 'ds2')
|
|
437
413
|
[ds1,ds2].each {|ds| ds.expects(:to_xml)}
|
|
438
414
|
|
|
439
|
-
@mock_repo.expects(:object).with(:pid => @this_pid).returns("")
|
|
440
415
|
@test_object.expects(:datastreams).returns({:ds1 => ds1, :ds2 => ds2})
|
|
441
416
|
@test_object.to_xml
|
|
442
417
|
end
|
|
@@ -478,7 +453,7 @@ describe ActiveFedora::Base do
|
|
|
478
453
|
end
|
|
479
454
|
|
|
480
455
|
it "should add self.class as the :active_fedora_model" do
|
|
481
|
-
@
|
|
456
|
+
stub_get_content(@this_pid, ['someData', 'withText2', 'withText'])
|
|
482
457
|
solr_doc = @test_history.to_solr
|
|
483
458
|
solr_doc["active_fedora_model_s"].should eql("FooHistory")
|
|
484
459
|
end
|
|
@@ -506,24 +481,21 @@ describe ActiveFedora::Base do
|
|
|
506
481
|
end
|
|
507
482
|
|
|
508
483
|
it "should call .to_solr on all MetadataDatastreams and NokogiriDatastreams, passing the resulting document to solr" do
|
|
509
|
-
@mock_repo.expects(:object).with(:pid => @this_pid).returns("")
|
|
510
484
|
mock1 = mock("ds1", :to_solr)
|
|
511
485
|
mock2 = mock("ds2", :to_solr)
|
|
512
|
-
ngds = mock("ngds"
|
|
486
|
+
ngds = mock("ngds")
|
|
513
487
|
mock1.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(true)
|
|
514
488
|
mock2.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(true)
|
|
515
|
-
ngds.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(false)
|
|
516
|
-
ngds.expects(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(true)
|
|
517
489
|
|
|
518
490
|
@test_object.expects(:datastreams).returns({:ds1 => mock1, :ds2 => mock2, :ngds => ngds})
|
|
491
|
+
@test_object.expects(:solrize_relationships)
|
|
519
492
|
@test_object.to_solr
|
|
520
493
|
end
|
|
521
|
-
it "should call .to_solr on the
|
|
522
|
-
@mock_repo.expects(:object).with(:pid => @this_pid).returns("")
|
|
494
|
+
it "should call .to_solr on the relationships rels-ext is dirty" do
|
|
523
495
|
@test_object.add_relationship(:has_collection_member, "info:fedora/foo:member")
|
|
524
496
|
rels_ext = @test_object.rels_ext
|
|
525
497
|
rels_ext.dirty?.should == true
|
|
526
|
-
|
|
498
|
+
@test_object.expects(:solrize_relationships)
|
|
527
499
|
@test_object.to_solr
|
|
528
500
|
end
|
|
529
501
|
|
|
@@ -545,7 +517,6 @@ describe ActiveFedora::Base do
|
|
|
545
517
|
|
|
546
518
|
describe ".label=" do
|
|
547
519
|
it "should set the label of the inner object" do
|
|
548
|
-
@mock_repo.expects(:object).with(:pid => @this_pid).returns("")
|
|
549
520
|
@test_object.label.should_not == "foo label"
|
|
550
521
|
@test_object.label = "foo label"
|
|
551
522
|
@test_object.label.should == "foo label"
|
|
@@ -555,12 +526,20 @@ describe ActiveFedora::Base do
|
|
|
555
526
|
it "should get a pid but not save on init" do
|
|
556
527
|
Rubydora::DigitalObject.any_instance.expects(:save).never
|
|
557
528
|
ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns('mooshoo:24')
|
|
529
|
+
@mock_client.stubs(:[]).with("objects/mooshoo%3A24/datastreams?format=xml").returns(@getter)
|
|
530
|
+
['someData', 'withText', 'withText2', 'RELS-EXT'].each do |dsid|
|
|
531
|
+
@mock_client.stubs(:[]).with {|params| /objects\/mooshoo%3A24\/datastreams\/#{dsid}/.match(params)}.returns(@getter)
|
|
532
|
+
end
|
|
558
533
|
f = FooHistory.new
|
|
559
534
|
f.pid.should_not be_nil
|
|
560
535
|
f.pid.should == 'mooshoo:24'
|
|
561
536
|
end
|
|
562
537
|
it "should not clobber a pid if i'm creating!" do
|
|
563
|
-
@
|
|
538
|
+
@mock_client.stubs(:[]).with("objects/numbnuts%3A1/datastreams?format=xml").returns(@getter)
|
|
539
|
+
|
|
540
|
+
['someData', 'withText', 'withText2', 'RELS-EXT'].each do |dsid|
|
|
541
|
+
@mock_client.stubs(:[]).with {|params| /objects\/numbnuts%3A1\/datastreams\/#{dsid}/.match(params)}.returns(@getter)
|
|
542
|
+
end
|
|
564
543
|
f = FooHistory.new(:pid=>'numbnuts:1')
|
|
565
544
|
f.pid.should == 'numbnuts:1'
|
|
566
545
|
|
|
@@ -591,7 +570,6 @@ describe ActiveFedora::Base do
|
|
|
591
570
|
m.update_datastream_attributes( ds_values_hash )
|
|
592
571
|
end
|
|
593
572
|
it "should not do anything and should return an empty hash if the specified datastream does not exist" do
|
|
594
|
-
@mock_repo.expects(:object).with(:pid => @this_pid).returns("")
|
|
595
573
|
ds_values_hash = {
|
|
596
574
|
"nonexistentDatastream"=>{ "notes"=>"foo" }
|
|
597
575
|
}
|
|
@@ -628,6 +606,9 @@ describe ActiveFedora::Base do
|
|
|
628
606
|
it "should take a :datastreams argument" do
|
|
629
607
|
att= {"fubar"=>{"-1"=>"mork", "0"=>"york", "1"=>"mangle"}}
|
|
630
608
|
m = FooHistory.new
|
|
609
|
+
['withText', 'someData', 'withText2'].each do |dsid|
|
|
610
|
+
@mock_client.stubs(:[]).with {|params| /objects\/#{@this_pid}\/datastreams\/#{dsid}\/content/.match(params)}.returns(stub('getter/setter', :get=>'', :post=>@this_pid))
|
|
611
|
+
end
|
|
631
612
|
m.update_indexed_attributes(att, :datastreams=>"withText")
|
|
632
613
|
m.should_not be_nil
|
|
633
614
|
m.datastreams['someData'].fubar_values.should == []
|
|
@@ -673,7 +654,9 @@ describe ActiveFedora::Base do
|
|
|
673
654
|
end
|
|
674
655
|
|
|
675
656
|
it 'should return current relationships by name' do
|
|
676
|
-
|
|
657
|
+
next_pid = increment_pid.to_s
|
|
658
|
+
ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(next_pid)
|
|
659
|
+
stub_get(next_pid)
|
|
677
660
|
@test_object2 = MockNamedRelationships.new
|
|
678
661
|
@test_object2.add_relationship(:has_model, ActiveFedora::ContentModel.pid_from_ruby_class(MockNamedRelationships))
|
|
679
662
|
@test_object.add_relationship(:has_model, ActiveFedora::ContentModel.pid_from_ruby_class(ActiveFedora::Base))
|
|
@@ -694,7 +677,9 @@ describe ActiveFedora::Base do
|
|
|
694
677
|
end
|
|
695
678
|
|
|
696
679
|
it 'should append and remove using helper methods for each outbound relationship' do
|
|
697
|
-
|
|
680
|
+
next_pid = increment_pid.to_s
|
|
681
|
+
ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(next_pid)
|
|
682
|
+
stub_get(next_pid)
|
|
698
683
|
@test_object2 = MockCreateNamedRelationshipMethodsBase.new
|
|
699
684
|
@test_object2.should respond_to(:testing_append)
|
|
700
685
|
@test_object2.should respond_to(:testing_remove)
|
|
@@ -710,4 +695,22 @@ describe ActiveFedora::Base do
|
|
|
710
695
|
@test_object2.relationships_by_name.should == {:self=>{"testing"=>[],"collection_members"=>[], "part_of"=>[], "parts_outbound"=>[]}}
|
|
711
696
|
end
|
|
712
697
|
end
|
|
698
|
+
|
|
699
|
+
describe ".solrize_relationships" do
|
|
700
|
+
it "should serialize the relationships into a Hash" do
|
|
701
|
+
graph = RDF::Graph.new
|
|
702
|
+
subject = RDF::URI.new "info:fedora/test:sample_pid"
|
|
703
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:is_member_of), RDF::URI.new('info:fedora/demo:10'))
|
|
704
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:is_part_of), RDF::URI.new('info:fedora/demo:11'))
|
|
705
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:has_part), RDF::URI.new('info:fedora/demo:12'))
|
|
706
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:conforms_to), "AnInterface")
|
|
707
|
+
|
|
708
|
+
@test_object.expects(:relationships).returns(graph)
|
|
709
|
+
solr_doc = @test_object.solrize_relationships
|
|
710
|
+
solr_doc["is_member_of_s"].should == ["info:fedora/demo:10"]
|
|
711
|
+
solr_doc["is_part_of_s"].should == ["info:fedora/demo:11"]
|
|
712
|
+
solr_doc["has_part_s"].should == ["info:fedora/demo:12"]
|
|
713
|
+
solr_doc["conforms_to_s"].should == ["AnInterface"]
|
|
714
|
+
end
|
|
715
|
+
end
|
|
713
716
|
end
|
|
@@ -20,7 +20,9 @@ describe ActiveFedora::ContentModel do
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
before(:each) do
|
|
23
|
-
|
|
23
|
+
stub_get('__nextid__')
|
|
24
|
+
ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns("__nextid__")
|
|
25
|
+
Rubydora::Repository.any_instance.stubs(:client).returns(@mock_client)
|
|
24
26
|
@test_cmodel = ActiveFedora::ContentModel.new
|
|
25
27
|
end
|
|
26
28
|
|
|
@@ -18,33 +18,15 @@ describe ActiveFedora::Datastream do
|
|
|
18
18
|
@test_datastream.to_param.should == 'foo%2ebar'
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
it 'should provide #save, #before_save and #after_save' do
|
|
22
|
-
@test_datastream.should respond_to(:save)
|
|
23
|
-
@test_datastream.should respond_to(:before_save)
|
|
24
|
-
@test_datastream.should respond_to(:after_save)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
21
|
describe '#save' do
|
|
28
|
-
it
|
|
29
|
-
@mock_repo = mock('repository')
|
|
30
|
-
@mock_repo.stubs(:add_datastream).with(:versionable => true, :pid => nil, :dsid => 'abcd', :controlGroup => 'M', :dsState => 'A', :content => 'hi there', :checksumType => 'DISABLED')
|
|
31
|
-
@mock_repo.expects(:datastream).with(:dsid => 'abcd', :pid => nil)
|
|
32
|
-
@test_object.inner_object.stubs(:repository).returns(@mock_repo)
|
|
33
|
-
@test_object.inner_object.stubs(:pid).returns(@pid)
|
|
34
|
-
|
|
35
|
-
@test_datastream.stubs(:last_modified_in_repository)
|
|
36
|
-
@test_datastream.expects(:before_save)
|
|
37
|
-
@test_datastream.expects(:after_save)
|
|
38
|
-
@test_datastream.save
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it "should set @dirty to false" do
|
|
22
|
+
it "should set dirty? to false" do
|
|
42
23
|
@mock_repo = mock('repository')
|
|
43
24
|
@mock_repo.stubs(:add_datastream).with(:versionable => true, :pid => @test_object.pid, :dsid => 'abcd', :controlGroup => 'M', :dsState => 'A', :content => 'hi there', :checksumType => 'DISABLED')
|
|
44
25
|
@mock_repo.expects(:datastream).with(:dsid => 'abcd', :pid => @test_object.pid)
|
|
45
26
|
@test_object.inner_object.stubs(:repository).returns(@mock_repo)
|
|
46
|
-
@test_datastream.
|
|
27
|
+
@test_datastream.dirty?.should be_true
|
|
47
28
|
@test_datastream.save
|
|
29
|
+
@test_datastream.dirty?.should be_false
|
|
48
30
|
end
|
|
49
31
|
end
|
|
50
32
|
|
|
@@ -61,10 +43,11 @@ describe ActiveFedora::Datastream do
|
|
|
61
43
|
end
|
|
62
44
|
|
|
63
45
|
describe ".dirty?" do
|
|
64
|
-
it "should return the value of the @dirty attribute" do
|
|
65
|
-
@test_datastream.
|
|
46
|
+
it "should return the value of the @dirty attribute or changed?" do
|
|
47
|
+
@test_datastream.expects(:changed?).returns(false)
|
|
48
|
+
@test_datastream.dirty?.should be_false
|
|
66
49
|
@test_datastream.dirty = "boo"
|
|
67
|
-
@test_datastream.dirty?.should
|
|
50
|
+
@test_datastream.dirty?.should be_true
|
|
68
51
|
end
|
|
69
52
|
end
|
|
70
53
|
|