active-fedora 5.1.0 → 5.2.0
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/active-fedora.gemspec +1 -2
- data/lib/active_fedora/datastreams.rb +14 -14
- data/lib/active_fedora/file_management.rb +5 -3
- data/lib/active_fedora/metadata_datastream_helper.rb +5 -1
- data/lib/active_fedora/nokogiri_datastream.rb +17 -4
- data/lib/active_fedora/rdf_datastream.rb +59 -36
- data/lib/active_fedora/relationships.rb +28 -11
- data/lib/active_fedora/version.rb +1 -1
- data/spec/config_helper.rb +3 -3
- data/spec/integration/base_spec.rb +15 -3
- data/spec/integration/bug_spec.rb +0 -3
- data/spec/integration/datastream_collections_spec.rb +9 -9
- data/spec/integration/datastream_spec.rb +1 -1
- data/spec/integration/full_featured_model_spec.rb +3 -4
- data/spec/integration/ntriples_datastream_spec.rb +0 -1
- data/spec/integration/rels_ext_datastream_spec.rb +12 -1
- data/spec/integration/semantic_node_spec.rb +10 -0
- data/spec/integration/solr_service_spec.rb +2 -2
- data/spec/spec_helper.rb +4 -7
- data/spec/support/mock_fedora.rb +10 -10
- data/spec/unit/active_fedora_spec.rb +8 -8
- data/spec/unit/association_proxy_spec.rb +2 -1
- data/spec/unit/base_cma_spec.rb +2 -2
- data/spec/unit/base_datastream_management_spec.rb +9 -9
- data/spec/unit/base_extra_spec.rb +25 -25
- data/spec/unit/base_file_management_spec.rb +32 -23
- data/spec/unit/base_spec.rb +94 -151
- data/spec/unit/callback_spec.rb +16 -11
- data/spec/unit/code_configurator_spec.rb +4 -4
- data/spec/unit/content_model_spec.rb +8 -8
- data/spec/unit/datastream_collections_spec.rb +23 -23
- data/spec/unit/datastream_spec.rb +7 -7
- data/spec/unit/datastreams_spec.rb +189 -304
- data/spec/unit/file_configurator_spec.rb +56 -56
- data/spec/unit/has_many_collection_spec.rb +1 -1
- data/spec/unit/model_spec.rb +51 -56
- data/spec/unit/nokogiri_datastream_spec.rb +24 -25
- data/spec/unit/ntriples_datastream_spec.rb +18 -27
- data/spec/unit/property_spec.rb +0 -2
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +1 -2
- data/spec/unit/rdfxml_rdf_datastream_spec.rb +1 -1
- data/spec/unit/relationship_graph_spec.rb +1 -1
- data/spec/unit/relationships_spec.rb +64 -52
- data/spec/unit/rels_ext_datastream_spec.rb +7 -7
- data/spec/unit/semantic_node_spec.rb +5 -5
- data/spec/unit/service_definitions_spec.rb +18 -16
- data/spec/unit/solr_config_options_spec.rb +6 -6
- data/spec/unit/solr_service_spec.rb +16 -16
- metadata +5 -21
@@ -1,20 +1,31 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveFedora::Base do
|
4
|
+
before(:all) do
|
5
|
+
@behavior = ActiveFedora::FileManagement.deprecation_behavior
|
6
|
+
ActiveFedora::FileManagement.deprecation_behavior = :silence
|
7
|
+
end
|
4
8
|
|
9
|
+
after :all do
|
10
|
+
ActiveFedora::FileManagement.deprecation_behavior = @behavior
|
11
|
+
end
|
12
|
+
|
5
13
|
before(:all) do
|
6
14
|
class FileMgmt < ActiveFedora::Base
|
7
15
|
include ActiveFedora::FileManagement
|
8
16
|
end
|
9
17
|
@base = FileMgmt.new
|
10
|
-
|
11
|
-
|
18
|
+
end
|
19
|
+
|
20
|
+
before(:each) do
|
21
|
+
@base.stub(:create_date).and_return("2008-07-02T05:09:42.015Z")
|
22
|
+
@base.stub(:modified_date).and_return("2008-09-29T21:21:52.892Z")
|
12
23
|
end
|
13
24
|
|
14
25
|
describe ".file_objects" do
|
15
26
|
it "should wrap .collection_members and .parts" do
|
16
|
-
@base.
|
17
|
-
@base.
|
27
|
+
@base.should_receive(:collection_members).and_return([])
|
28
|
+
@base.should_receive(:parts).and_return(["Foo"])
|
18
29
|
@base.file_objects
|
19
30
|
end
|
20
31
|
end
|
@@ -22,23 +33,23 @@ describe ActiveFedora::Base do
|
|
22
33
|
describe ".file_objects_append" do
|
23
34
|
it "should make the file object being appended assert isPartOf pointing back at the current object and save the child" do
|
24
35
|
mock_child = ActiveFedora::Base.new
|
25
|
-
mock_child.
|
26
|
-
mock_child.
|
36
|
+
mock_child.should_receive(:add_relationship).with(:is_part_of, @base)
|
37
|
+
mock_child.should_receive(:save)
|
27
38
|
@base.file_objects_append(mock_child)
|
28
39
|
end
|
29
40
|
it "should load the file object being appended if only a pid is provided and save the child" do
|
30
41
|
mock_child = mock("object")
|
31
|
-
mock_child.
|
32
|
-
mock_child.
|
33
|
-
ActiveFedora::Base.
|
42
|
+
mock_child.should_receive(:add_relationship).with(:is_part_of, @base)
|
43
|
+
mock_child.should_receive(:save)
|
44
|
+
ActiveFedora::Base.should_receive(:find).with("_PID_").and_return(mock_child)
|
34
45
|
@base.file_objects_append("_PID_")
|
35
46
|
end
|
36
47
|
end
|
37
48
|
|
38
49
|
describe ".parts" do
|
39
50
|
it "should search for both (outbound) has_part and (inbound) is_part_of relationships, removing duplicates" do
|
40
|
-
@base.
|
41
|
-
@base.
|
51
|
+
@base.should_receive(:parts_outbound).and_return(["A", "B"])
|
52
|
+
@base.should_receive(:parts_inbound).and_return(["B", "C"])
|
42
53
|
@base.parts.should == ["B", "C", "A"]
|
43
54
|
end
|
44
55
|
end
|
@@ -53,7 +64,7 @@ describe ActiveFedora::Base do
|
|
53
64
|
end
|
54
65
|
it "should assert hasCollectionMember for the given object/pid" do
|
55
66
|
mocko = mock("object")
|
56
|
-
@base.
|
67
|
+
@base.should_receive(:add_relationship).with(:has_collection_member, mocko)
|
57
68
|
@base.collection_members_append(mocko)
|
58
69
|
end
|
59
70
|
end
|
@@ -66,20 +77,18 @@ describe ActiveFedora::Base do
|
|
66
77
|
|
67
78
|
describe ".add_file_datastream" do
|
68
79
|
it "should create a new datastream with the file as its content" do
|
69
|
-
mock_file = mock(
|
70
|
-
|
71
|
-
|
72
|
-
@base.
|
80
|
+
mock_file = mock()
|
81
|
+
ds = mock()
|
82
|
+
@base.should_receive(:create_datastream).with(ActiveFedora::Datastream, nil, hash_including(:blob => mock_file)).and_return(ds)
|
83
|
+
@base.should_receive(:add_datastream).with(ds)
|
73
84
|
@base.add_file_datastream(mock_file)
|
74
85
|
end
|
75
86
|
it "should set :dsid and :label when supplied" do
|
76
|
-
mock_file =
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
@base.expects(:add_datastream).with(mock_ds)
|
82
|
-
@base.add_file_datastream(mock_file, :label => "My Label", :dsid => "__DSID__", :versionable => false)
|
87
|
+
mock_file = mock()
|
88
|
+
ds = mock()
|
89
|
+
@base.should_receive(:create_datastream).with(ActiveFedora::Datastream, 'Foo', hash_including(:dsLabel => 'My Label', :blob => mock_file)).and_return(ds)
|
90
|
+
@base.should_receive(:add_datastream).with(ds)
|
91
|
+
@base.add_file_datastream(mock_file, :label => 'My Label', :dsid => 'Foo')
|
83
92
|
end
|
84
93
|
|
85
94
|
end
|
data/spec/unit/base_spec.rb
CHANGED
@@ -10,25 +10,22 @@ describe ActiveFedora::Base do
|
|
10
10
|
context "When the repository is NOT sharded" do
|
11
11
|
subject {ActiveFedora::Base.connection_for_pid('foo:bar')}
|
12
12
|
before(:each) do
|
13
|
-
ActiveFedora.config.
|
13
|
+
ActiveFedora.config.stub(:sharded?).and_return(false)
|
14
14
|
ActiveFedora::Base.fedora_connection = {}
|
15
|
-
ActiveFedora.config.
|
15
|
+
ActiveFedora.config.stub(:credentials).and_return(:url=>'myfedora')
|
16
16
|
end
|
17
17
|
it { should be_kind_of Rubydora::Repository}
|
18
18
|
it "should be the standard connection" do
|
19
19
|
subject.client.url.should == 'myfedora'
|
20
20
|
end
|
21
21
|
describe "assign_pid" do
|
22
|
-
after do
|
23
|
-
ActiveFedora::RubydoraConnection.unstub(:new)
|
24
|
-
end
|
25
22
|
it "should use fedora to generate pids" do
|
26
23
|
# TODO: This juggling of Fedora credentials & establishing connections should be handled by an establish_fedora_connection method,
|
27
24
|
# possibly wrap it all into a fedora_connection method - MZ 06-05-2012
|
28
25
|
stubfedora = mock("Fedora")
|
29
|
-
stubfedora.
|
26
|
+
stubfedora.should_receive(:connection).and_return(mock("Connection", :next_pid =>"<pid>sample:newpid</pid>"))
|
30
27
|
# Should use ActiveFedora.config.credentials as a single hash rather than an array of shards
|
31
|
-
ActiveFedora::RubydoraConnection.
|
28
|
+
ActiveFedora::RubydoraConnection.should_receive(:new).with(ActiveFedora.config.credentials).and_return(stubfedora)
|
32
29
|
ActiveFedora::Base.assign_pid(ActiveFedora::Base.new.inner_object)
|
33
30
|
end
|
34
31
|
end
|
@@ -40,17 +37,17 @@ describe ActiveFedora::Base do
|
|
40
37
|
end
|
41
38
|
context "When the repository is sharded" do
|
42
39
|
before :each do
|
43
|
-
ActiveFedora.config.
|
40
|
+
ActiveFedora.config.stub(:sharded?).and_return(true)
|
44
41
|
ActiveFedora::Base.fedora_connection = {}
|
45
|
-
ActiveFedora.config.
|
42
|
+
ActiveFedora.config.stub(:credentials).and_return([{:url=>'shard1'}, {:url=>'shard2'} ])
|
46
43
|
end
|
47
44
|
describe "assign_pid" do
|
48
45
|
it "should always use the first shard to generate pids" do
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
ActiveFedora::Base.fedora_connection = {0 =>
|
46
|
+
stubhard1 = mock("Shard")
|
47
|
+
stubhard2 = mock("Shard")
|
48
|
+
stubhard1.should_receive(:connection).and_return(mock("Connection", :next_pid =>"<pid>sample:newpid</pid>"))
|
49
|
+
stubhard2.should_receive(:connection).never
|
50
|
+
ActiveFedora::Base.fedora_connection = {0 => stubhard1, 1 => stubhard2}
|
54
51
|
ActiveFedora::Base.assign_pid(ActiveFedora::Base.new.inner_object)
|
55
52
|
end
|
56
53
|
end
|
@@ -111,15 +108,15 @@ describe ActiveFedora::Base do
|
|
111
108
|
before(:each) do
|
112
109
|
@this_pid = increment_pid.to_s
|
113
110
|
stub_get(@this_pid)
|
114
|
-
Rubydora::Repository.any_instance.
|
115
|
-
ActiveFedora::Base.
|
111
|
+
Rubydora::Repository.any_instance.stub(:client).and_return(@mock_client)
|
112
|
+
ActiveFedora::Base.stub(:assign_pid).and_return(@this_pid)
|
116
113
|
|
117
114
|
@test_object = ActiveFedora::Base.new
|
118
115
|
end
|
119
116
|
|
120
117
|
after(:each) do
|
121
118
|
begin
|
122
|
-
ActiveFedora::SolrService.
|
119
|
+
ActiveFedora::SolrService.stub(:instance)
|
123
120
|
#@test_object.delete
|
124
121
|
rescue
|
125
122
|
end
|
@@ -129,14 +126,14 @@ describe ActiveFedora::Base do
|
|
129
126
|
describe '#new' do
|
130
127
|
it "should create an inner object" do
|
131
128
|
# for doing AFObject.new(params[:foo]) when nothing is in params[:foo]
|
132
|
-
Rubydora::DigitalObject.any_instance.
|
129
|
+
Rubydora::DigitalObject.any_instance.should_receive(:save).never
|
133
130
|
result = ActiveFedora::Base.new(nil)
|
134
131
|
result.inner_object.should be_kind_of(ActiveFedora::UnsavedDigitalObject)
|
135
132
|
end
|
136
133
|
|
137
134
|
it "should not save or get an pid on init" do
|
138
|
-
Rubydora::DigitalObject.any_instance.
|
139
|
-
ActiveFedora::Base.
|
135
|
+
Rubydora::DigitalObject.any_instance.should_receive(:save).never
|
136
|
+
ActiveFedora::Base.should_receive(:assign_pid).never
|
140
137
|
f = FooHistory.new
|
141
138
|
end
|
142
139
|
|
@@ -165,13 +162,13 @@ describe ActiveFedora::Base do
|
|
165
162
|
it "should have to_param once it's saved" do
|
166
163
|
|
167
164
|
@test_object.to_param.should be_nil
|
168
|
-
@test_object.inner_object.
|
165
|
+
@test_object.inner_object.stub(:new? => false)
|
169
166
|
@test_object.to_param.should == @test_object.pid
|
170
167
|
end
|
171
168
|
|
172
169
|
it "should have to_key once it's saved" do
|
173
170
|
@test_object.to_key.should be_nil
|
174
|
-
@test_object.inner_object.
|
171
|
+
@test_object.inner_object.stub(:new? => false)
|
175
172
|
@test_object.to_key.should == [@test_object.pid]
|
176
173
|
end
|
177
174
|
|
@@ -226,7 +223,7 @@ describe ActiveFedora::Base do
|
|
226
223
|
describe '.rels_ext' do
|
227
224
|
|
228
225
|
it 'should return the RelsExtDatastream object from the datastreams array' do
|
229
|
-
@test_object.
|
226
|
+
@test_object.stub(:datastreams => {"RELS-EXT" => "foo"})
|
230
227
|
@test_object.rels_ext.should == "foo"
|
231
228
|
end
|
232
229
|
end
|
@@ -244,7 +241,7 @@ describe ActiveFedora::Base do
|
|
244
241
|
|
245
242
|
it "should update the RELS-EXT datastream and set the datastream as dirty when relationships are added" do
|
246
243
|
mock_ds = mock("Rels-Ext")
|
247
|
-
mock_ds.
|
244
|
+
mock_ds.stub(:content_will_change!)
|
248
245
|
@test_object.datastreams["RELS-EXT"] = mock_ds
|
249
246
|
@test_object.add_relationship(:is_member_of, "info:fedora/demo:5")
|
250
247
|
@test_object.add_relationship(:is_member_of, "info:fedora/demo:10")
|
@@ -252,7 +249,7 @@ describe ActiveFedora::Base do
|
|
252
249
|
|
253
250
|
it 'should add a relationship to an object only if it does not exist already' do
|
254
251
|
next_pid = increment_pid.to_s
|
255
|
-
ActiveFedora::Base.
|
252
|
+
ActiveFedora::Base.stub(:assign_pid).and_return(next_pid)
|
256
253
|
stub_get(next_pid)
|
257
254
|
|
258
255
|
@test_object3 = ActiveFedora::Base.new
|
@@ -276,9 +273,9 @@ describe ActiveFedora::Base do
|
|
276
273
|
describe '#remove_relationship' do
|
277
274
|
it 'should remove a relationship from the relationships hash' do
|
278
275
|
@test_object3 = ActiveFedora::Base.new()
|
279
|
-
@test_object3.
|
276
|
+
@test_object3.stub(:pid=>'7')
|
280
277
|
@test_object4 = ActiveFedora::Base.new()
|
281
|
-
@test_object4.
|
278
|
+
@test_object4.stub(:pid=>'8')
|
282
279
|
@test_object.add_relationship(:has_part,@test_object3)
|
283
280
|
@test_object.add_relationship(:has_part,@test_object4)
|
284
281
|
#check both are there
|
@@ -314,104 +311,27 @@ describe ActiveFedora::Base do
|
|
314
311
|
end
|
315
312
|
|
316
313
|
describe '.save' do
|
317
|
-
it "should
|
318
|
-
|
319
|
-
|
320
|
-
@test_object.
|
321
|
-
@test_object.
|
322
|
-
stub_get(@this_pid, nil, true)
|
323
|
-
@test_object.save.should == true
|
324
|
-
@test_object.persisted?.should be true
|
314
|
+
it "should create a new record" do
|
315
|
+
@test_object.stub(:new_record? => true)
|
316
|
+
@test_object.should_receive(:create)
|
317
|
+
@test_object.should_receive(:update_index)
|
318
|
+
@test_object.save
|
325
319
|
end
|
326
320
|
|
327
|
-
it "should
|
328
|
-
|
329
|
-
|
330
|
-
@test_object.
|
331
|
-
@test_object.save
|
332
|
-
|
333
|
-
|
334
|
-
end
|
335
|
-
|
336
|
-
it "should call .save on any datastreams that are dirty" do
|
337
|
-
stub_ingest(@this_pid)
|
338
|
-
stub_add_ds(@this_pid, ['withText2', 'withText', 'RELS-EXT'])
|
339
|
-
to = FooHistory.new
|
340
|
-
to.expects(:update_index)
|
341
|
-
|
342
|
-
to.datastreams["someData"].stubs(:changed?).returns(true)
|
343
|
-
to.datastreams["someData"].stubs(:new_object?).returns(true)
|
344
|
-
to.datastreams["someData"].expects(:save)
|
345
|
-
to.expects(:refresh)
|
346
|
-
FooHistory.expects(:assign_pid).with(to.inner_object).returns(@this_pid)
|
347
|
-
to.save
|
348
|
-
end
|
349
|
-
it "should call .save on any datastreams that are new" do
|
350
|
-
stub_ingest(@this_pid)
|
351
|
-
stub_add_ds(@this_pid, ['RELS-EXT'])
|
352
|
-
ds = ActiveFedora::Datastream.new(@test_object.inner_object, 'ds_to_add')
|
353
|
-
ds.content = "DS CONTENT"
|
354
|
-
@test_object.add_datastream(ds)
|
355
|
-
ds.expects(:save)
|
356
|
-
@test_object.instance_variable_set(:@new_object, false)
|
357
|
-
@test_object.expects(:refresh)
|
358
|
-
@test_object.expects(:update_index)
|
359
|
-
@test_object.save
|
360
|
-
end
|
361
|
-
it "should not call .save on any datastreams that are not dirty" do
|
362
|
-
stub_ingest(@this_pid)
|
363
|
-
@test_object = FooHistory.new
|
364
|
-
@test_object.expects(:update_index)
|
365
|
-
@test_object.expects(:refresh)
|
366
|
-
|
367
|
-
@test_object.datastreams["someData"].should_not be_nil
|
368
|
-
@test_object.datastreams['someData'].stubs(:changed?).returns(false)
|
369
|
-
@test_object.datastreams['someData'].stubs(:new?).returns(false)
|
370
|
-
@test_object.datastreams['someData'].expects(:save).never
|
371
|
-
@test_object.datastreams['withText2'].expects(:save)
|
372
|
-
@test_object.datastreams['withText'].expects(:save)
|
373
|
-
@test_object.datastreams['RELS-EXT'].expects(:save)
|
374
|
-
FooHistory.expects(:assign_pid).with(@test_object.inner_object).returns(@this_pid)
|
375
|
-
@test_object.save
|
376
|
-
end
|
377
|
-
it "should update solr index with all metadata if any SimpleDatastreams have changed" do
|
378
|
-
stub_ingest(@this_pid)
|
379
|
-
stub_add_ds(@this_pid, ['ds1', 'RELS-EXT'])
|
380
|
-
|
381
|
-
dirty_ds = ActiveFedora::SimpleDatastream.new(@test_object.inner_object, 'ds1')
|
382
|
-
rels_ds = ActiveFedora::RelsExtDatastream.new(@test_object.inner_object, 'RELS-EXT')
|
383
|
-
rels_ds.model = @test_object
|
384
|
-
@test_object.add_datastream(rels_ds)
|
385
|
-
@test_object.add_datastream(dirty_ds)
|
386
|
-
@test_object.expects(:update_index)
|
387
|
-
|
388
|
-
@test_object.save
|
389
|
-
end
|
390
|
-
it "should update solr index with all metadata if any RDFDatastreams have changed" do
|
391
|
-
stub_ingest(@this_pid)
|
392
|
-
stub_add_ds(@this_pid, ['ds1', 'RELS-EXT'])
|
393
|
-
|
394
|
-
dirty_ds = ActiveFedora::NtriplesRDFDatastream.new(@test_object.inner_object, 'ds1')
|
395
|
-
rels_ds = ActiveFedora::RelsExtDatastream.new(@test_object.inner_object, 'RELS-EXT')
|
396
|
-
rels_ds.model = @test_object
|
397
|
-
@test_object.add_datastream(rels_ds)
|
398
|
-
@test_object.add_datastream(dirty_ds)
|
399
|
-
@test_object.expects(:update_index)
|
400
|
-
|
401
|
-
@test_object.save
|
321
|
+
it "should update an existing record" do
|
322
|
+
@test_object.stub(:new_record? => false)
|
323
|
+
@test_object.should_receive(:update)
|
324
|
+
@test_object.should_receive(:update_index)
|
325
|
+
@test_object.save
|
402
326
|
end
|
403
327
|
end
|
404
328
|
|
405
329
|
describe "#create" do
|
406
|
-
before do
|
407
|
-
stub_ingest(@this_pid)
|
408
|
-
stub_add_ds(@this_pid, ['someData', 'withText', 'withText2', 'RELS-EXT'])
|
409
|
-
end
|
410
330
|
it "should build a new record and save it" do
|
411
|
-
|
331
|
+
obj = mock()
|
332
|
+
obj.should_receive(:save)
|
333
|
+
FooHistory.should_receive(:new).and_return(obj)
|
412
334
|
@hist = FooHistory.create(:fubar=>'ta', :swank=>'da')
|
413
|
-
@hist.fubar.should == ['ta']
|
414
|
-
@hist.swank.should == ['da']
|
415
335
|
end
|
416
336
|
|
417
337
|
end
|
@@ -454,11 +374,11 @@ describe ActiveFedora::Base do
|
|
454
374
|
describe ".adapt_to_cmodel" do
|
455
375
|
subject { FooHistory.new }
|
456
376
|
it "should cast when a cmodel is found" do
|
457
|
-
ActiveFedora::ContentModel.
|
377
|
+
ActiveFedora::ContentModel.should_receive(:known_models_for).with( subject).and_return([FooAdaptation])
|
458
378
|
subject.adapt_to_cmodel.should be_kind_of FooAdaptation
|
459
379
|
end
|
460
380
|
it "should not cast when a cmodel is same as the class" do
|
461
|
-
ActiveFedora::ContentModel.
|
381
|
+
ActiveFedora::ContentModel.should_receive(:known_models_for).with( subject).and_return([FooHistory])
|
462
382
|
subject.adapt_to_cmodel.should === subject
|
463
383
|
end
|
464
384
|
end
|
@@ -474,8 +394,8 @@ describe ActiveFedora::Base do
|
|
474
394
|
end
|
475
395
|
|
476
396
|
it "should add pid, system_create_date and system_modified_date from object attributes" do
|
477
|
-
@test_object.
|
478
|
-
@test_object.
|
397
|
+
@test_object.should_receive(:create_date).and_return("2012-03-04T03:12:02Z")
|
398
|
+
@test_object.should_receive(:modified_date).and_return("2012-03-07T03:12:02Z")
|
479
399
|
solr_doc = @test_object.to_solr
|
480
400
|
solr_doc["system_create_dt"].should eql("2012-03-04T03:12:02Z")
|
481
401
|
solr_doc["system_modified_dt"].should eql("2012-03-07T03:12:02Z")
|
@@ -502,8 +422,8 @@ describe ActiveFedora::Base do
|
|
502
422
|
it "should use mappings.yml to decide names of solr fields" do
|
503
423
|
cdate = "2008-07-02T05:09:42Z"
|
504
424
|
mdate = "2009-07-07T23:37:18Z"
|
505
|
-
@test_object.
|
506
|
-
@test_object.
|
425
|
+
@test_object.stub(:create_date).and_return(cdate)
|
426
|
+
@test_object.stub(:modified_date).and_return(mdate)
|
507
427
|
solr_doc = @test_object.to_solr
|
508
428
|
solr_doc["system_create_dt"].should eql(cdate)
|
509
429
|
solr_doc["system_modified_dt"].should eql(mdate)
|
@@ -522,23 +442,23 @@ describe ActiveFedora::Base do
|
|
522
442
|
end
|
523
443
|
|
524
444
|
it "should call .to_solr on all SimpleDatastreams and NokogiriDatastreams, passing the resulting document to solr" do
|
525
|
-
mock1 = mock("ds1", :to_solr)
|
526
|
-
mock2 = mock("ds2", :to_solr)
|
527
|
-
ngds = mock("ngds", :to_solr)
|
528
|
-
ngds.
|
529
|
-
mock1.
|
530
|
-
mock2.
|
445
|
+
mock1 = mock("ds1", :to_solr => {})
|
446
|
+
mock2 = mock("ds2", :to_solr => {})
|
447
|
+
ngds = mock("ngds", :to_solr => {})
|
448
|
+
ngds.should_receive(:solrize_profile)
|
449
|
+
mock1.should_receive(:solrize_profile)
|
450
|
+
mock2.should_receive(:solrize_profile)
|
531
451
|
|
532
|
-
@test_object.
|
533
|
-
@test_object.
|
452
|
+
@test_object.should_receive(:datastreams).twice.and_return({:ds1 => mock1, :ds2 => mock2, :ngds => ngds})
|
453
|
+
@test_object.should_receive(:solrize_relationships)
|
534
454
|
@test_object.to_solr
|
535
455
|
end
|
536
456
|
it "should call .to_solr on all RDFDatastreams, passing the resulting document to solr" do
|
537
|
-
mock = mock("ds1", :to_solr)
|
538
|
-
mock.
|
457
|
+
mock = mock("ds1", :to_solr => {})
|
458
|
+
mock.should_receive(:solrize_profile)
|
539
459
|
|
540
|
-
@test_object.
|
541
|
-
@test_object.
|
460
|
+
@test_object.should_receive(:datastreams).twice.and_return({:ds1 => mock})
|
461
|
+
@test_object.should_receive(:solrize_relationships)
|
542
462
|
@test_object.to_solr
|
543
463
|
end
|
544
464
|
|
@@ -546,7 +466,7 @@ describe ActiveFedora::Base do
|
|
546
466
|
@test_object.add_relationship(:has_collection_member, "info:fedora/foo:member")
|
547
467
|
rels_ext = @test_object.rels_ext
|
548
468
|
rels_ext.should be_changed
|
549
|
-
@test_object.
|
469
|
+
@test_object.should_receive(:solrize_relationships)
|
550
470
|
@test_object.to_solr
|
551
471
|
end
|
552
472
|
|
@@ -554,7 +474,7 @@ describe ActiveFedora::Base do
|
|
554
474
|
|
555
475
|
describe ".label" do
|
556
476
|
it "should return the label of the inner object" do
|
557
|
-
@test_object.inner_object.
|
477
|
+
@test_object.inner_object.should_receive(:label).and_return("foo label")
|
558
478
|
@test_object.label.should == "foo label"
|
559
479
|
end
|
560
480
|
end
|
@@ -571,7 +491,7 @@ describe ActiveFedora::Base do
|
|
571
491
|
describe "get_values_from_datastream" do
|
572
492
|
it "should look up the named datastream and call get_values with the given pointer/field_name" do
|
573
493
|
mock_ds = mock("Datastream", :get_values=>["value1", "value2"])
|
574
|
-
@test_object.
|
494
|
+
@test_object.stub(:datastreams).and_return({"ds1"=>mock_ds})
|
575
495
|
@test_object.get_values_from_datastream("ds1", "--my xpath--").should == ["value1", "value2"]
|
576
496
|
end
|
577
497
|
end
|
@@ -587,9 +507,9 @@ describe ActiveFedora::Base do
|
|
587
507
|
"properties"=>{ "notes"=>"foo" }
|
588
508
|
}
|
589
509
|
m = FooHistory.new
|
590
|
-
m.
|
591
|
-
mock_desc_metadata.
|
592
|
-
mock_properties.
|
510
|
+
m.stub(:datastreams).and_return(mock_ds_hash)
|
511
|
+
mock_desc_metadata.should_receive(:update_indexed_attributes).with( ds_values_hash['descMetadata'] )
|
512
|
+
mock_properties.should_receive(:update_indexed_attributes).with( ds_values_hash['properties'] )
|
593
513
|
m.update_datastream_attributes( ds_values_hash )
|
594
514
|
end
|
595
515
|
it "should not do anything and should return an empty hash if the specified datastream does not exist" do
|
@@ -610,9 +530,9 @@ pending "This is broken, and deprecated. I don't want to fix it - jcoyne"
|
|
610
530
|
m = FooHistory.new
|
611
531
|
att= {"fubar"=> '1234', "baz" =>'stuff'}
|
612
532
|
|
613
|
-
m.
|
614
|
-
m.
|
615
|
-
m.
|
533
|
+
m.should_receive(:fubar=).with('1234')
|
534
|
+
m.should_receive(:baz=).with('stuff')
|
535
|
+
m.should_receive(:save)
|
616
536
|
m.update_attributes(att)
|
617
537
|
end
|
618
538
|
end
|
@@ -622,9 +542,9 @@ pending "This is broken, and deprecated. I don't want to fix it - jcoyne"
|
|
622
542
|
m = FooHistory.new
|
623
543
|
att= {"fubar"=>{"-1"=>"mork", "0"=>"york", "1"=>"mangle"}}
|
624
544
|
|
625
|
-
m.datastreams['someData'].
|
626
|
-
m.datastreams["withText"].
|
627
|
-
m.datastreams['withText2'].
|
545
|
+
m.datastreams['someData'].should_receive(:update_indexed_attributes)
|
546
|
+
m.datastreams["withText"].should_receive(:update_indexed_attributes)
|
547
|
+
m.datastreams['withText2'].should_receive(:update_indexed_attributes)
|
628
548
|
m.update_indexed_attributes(att)
|
629
549
|
end
|
630
550
|
it "should take a :datastreams argument" do
|
@@ -647,7 +567,18 @@ pending "This is broken, and deprecated. I don't want to fix it - jcoyne"
|
|
647
567
|
end
|
648
568
|
|
649
569
|
describe '#relationships_by_name' do
|
650
|
-
|
570
|
+
before(:all) do
|
571
|
+
@behavior = ActiveFedora::Relationships.deprecation_behavior
|
572
|
+
@c_behavior = ActiveFedora::Relationships::ClassMethods.deprecation_behavior
|
573
|
+
ActiveFedora::Relationships.deprecation_behavior = :silence
|
574
|
+
ActiveFedora::Relationships::ClassMethods.deprecation_behavior = :silence
|
575
|
+
end
|
576
|
+
|
577
|
+
after :all do
|
578
|
+
ActiveFedora::Relationships.deprecation_behavior = @behavior
|
579
|
+
ActiveFedora::Relationships::ClassMethods.deprecation_behavior = @c_behavior
|
580
|
+
end
|
581
|
+
|
651
582
|
before do
|
652
583
|
class MockNamedRelationships < ActiveFedora::Base
|
653
584
|
include ActiveFedora::FileManagement
|
@@ -659,7 +590,7 @@ pending "This is broken, and deprecated. I don't want to fix it - jcoyne"
|
|
659
590
|
|
660
591
|
it 'should return current relationships by name' do
|
661
592
|
next_pid = increment_pid.to_s
|
662
|
-
ActiveFedora::Base.
|
593
|
+
ActiveFedora::Base.stub(:assign_pid).and_return(next_pid)
|
663
594
|
stub_get(next_pid)
|
664
595
|
@test_object2 = MockNamedRelationships.new
|
665
596
|
@test_object2.add_relationship(:has_model, MockNamedRelationships.to_class_uri)
|
@@ -680,6 +611,18 @@ pending "This is broken, and deprecated. I don't want to fix it - jcoyne"
|
|
680
611
|
|
681
612
|
|
682
613
|
describe '#create_relationship_name_methods' do
|
614
|
+
before(:all) do
|
615
|
+
@behavior = ActiveFedora::Relationships.deprecation_behavior
|
616
|
+
@c_behavior = ActiveFedora::Relationships::ClassMethods.deprecation_behavior
|
617
|
+
ActiveFedora::Relationships.deprecation_behavior = :silence
|
618
|
+
ActiveFedora::Relationships::ClassMethods.deprecation_behavior = :silence
|
619
|
+
end
|
620
|
+
|
621
|
+
after :all do
|
622
|
+
ActiveFedora::Relationships.deprecation_behavior = @behavior
|
623
|
+
ActiveFedora::Relationships::ClassMethods.deprecation_behavior = @c_behavior
|
624
|
+
end
|
625
|
+
|
683
626
|
before do
|
684
627
|
class MockCreateNamedRelationshipMethodsBase < ActiveFedora::Base
|
685
628
|
include ActiveFedora::Relationships
|
@@ -690,7 +633,7 @@ pending "This is broken, and deprecated. I don't want to fix it - jcoyne"
|
|
690
633
|
|
691
634
|
it 'should append and remove using helper methods for each outbound relationship' do
|
692
635
|
next_pid = increment_pid.to_s
|
693
|
-
ActiveFedora::Base.
|
636
|
+
ActiveFedora::Base.stub(:assign_pid).and_return(next_pid)
|
694
637
|
stub_get(next_pid)
|
695
638
|
@test_object2 = MockCreateNamedRelationshipMethodsBase.new
|
696
639
|
@test_object2.should respond_to(:testing_append)
|
@@ -716,7 +659,7 @@ pending "This is broken, and deprecated. I don't want to fix it - jcoyne"
|
|
716
659
|
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_part), RDF::URI.new('info:fedora/demo:12'))
|
717
660
|
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:conforms_to), "AnInterface")
|
718
661
|
|
719
|
-
@test_object.
|
662
|
+
@test_object.should_receive(:relationships).and_return(graph)
|
720
663
|
solr_doc = @test_object.solrize_relationships
|
721
664
|
solr_doc["is_member_of_s"].should == ["info:fedora/demo:10"]
|
722
665
|
solr_doc["is_part_of_s"].should == ["info:fedora/demo:11"]
|