active-fedora 3.1.6 → 3.2.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile.lock +22 -22
  3. data/History.txt +9 -3
  4. data/active-fedora.gemspec +3 -3
  5. data/config/predicate_mappings.yml +1 -0
  6. data/config/service_mappings.yml +9 -0
  7. data/lib/active_fedora.rb +7 -1
  8. data/lib/active_fedora/base.rb +84 -30
  9. data/lib/active_fedora/datastream.rb +4 -1
  10. data/lib/active_fedora/datastream_collections.rb +304 -293
  11. data/lib/active_fedora/metadata_datastream.rb +2 -24
  12. data/lib/active_fedora/metadata_datastream_helper.rb +32 -5
  13. data/lib/active_fedora/named_relationships.rb +95 -0
  14. data/lib/active_fedora/nested_attributes.rb +1 -1
  15. data/lib/active_fedora/predicates.rb +76 -0
  16. data/lib/active_fedora/reflection.rb +9 -1
  17. data/lib/active_fedora/relationship.rb +1 -0
  18. data/lib/active_fedora/relationship_graph.rb +152 -0
  19. data/lib/active_fedora/relationships_helper.rb +32 -41
  20. data/lib/active_fedora/rels_ext_datastream.rb +3 -10
  21. data/lib/active_fedora/semantic_node.rb +47 -203
  22. data/lib/active_fedora/service_definitions.rb +89 -0
  23. data/lib/active_fedora/unsaved_digital_object.rb +40 -0
  24. data/lib/active_fedora/version.rb +1 -1
  25. data/spec/integration/base_spec.rb +106 -309
  26. data/spec/integration/datastream_collections_spec.rb +135 -0
  27. data/spec/integration/rels_ext_datastream_spec.rb +14 -35
  28. data/spec/integration/semantic_node_spec.rb +6 -10
  29. data/spec/unit/base_datastream_management_spec.rb +0 -3
  30. data/spec/unit/base_extra_spec.rb +5 -9
  31. data/spec/unit/base_spec.rb +103 -57
  32. data/spec/unit/{base_named_datastream_spec.rb → datastream_collections_spec.rb} +107 -150
  33. data/spec/unit/metadata_datastream_spec.rb +0 -1
  34. data/spec/unit/nokogiri_datastream_spec.rb +0 -1
  35. data/spec/unit/predicates_spec.rb +64 -0
  36. data/spec/unit/qualified_dublin_core_datastream_spec.rb +0 -7
  37. data/spec/unit/relationship_graph_spec.rb +95 -0
  38. data/spec/unit/relationship_spec.rb +4 -4
  39. data/spec/unit/relationships_helper_spec.rb +43 -104
  40. data/spec/unit/rels_ext_datastream_spec.rb +6 -6
  41. data/spec/unit/semantic_node_spec.rb +27 -116
  42. data/spec/unit/service_definitions_spec.rb +52 -0
  43. data/spec/unit/solr_config_options_spec.rb +1 -1
  44. metadata +35 -17
@@ -1,45 +1,50 @@
1
1
  require 'spec_helper'
2
- require "active_fedora"
3
2
 
4
- # Some tentative extensions to ActiveFedora::Base
5
3
 
6
- describe ActiveFedora::Base do
7
-
8
- @@last_pid = 0
9
-
10
- def increment_pid
11
- @@last_pid += 1
12
- end
13
-
14
- before(:each) do
15
- @test_object = ActiveFedora::Base.new
16
- end
4
+ DEPRECATION_MSG = "Deprecation: DatastreamCollections will not be included by default in the next version. To use has_datastream add 'include ActiveFedora::DatastreamCollections' to your model"
17
5
 
18
- after(:each) do
19
- begin
20
- @test_object.delete
21
- rescue
22
- end
23
-
24
- begin
25
- @test_object2.delete
26
- rescue
6
+ describe ActiveFedora::DatastreamCollections do
7
+ describe '.has_datastream' do
8
+ before(:all) do
9
+ ActiveSupport::Deprecation.expects(:warn).with(DEPRECATION_MSG)
10
+
11
+ class MockHasDatastream < ActiveFedora::Base
12
+ has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
13
+ has_datastream :name=>"EAD", :type=>ActiveFedora::Datastream, :mimeType=>"application/xml", :controlGroup=>'M'
14
+ has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
15
+ end
27
16
  end
28
17
 
29
- begin
30
- @test_object3.delete
31
- rescue
18
+ it 'should cache a definition of named datastream and create helper methods to add/remove/access them' do
19
+ @test_object2 = MockHasDatastream.new
20
+ #prefix should default to name in caps if not specified in has_datastream call
21
+ @test_object2.named_datastreams_desc.should == {"thumbnail"=>{:name=>"thumbnail",:prefix => "THUMB",
22
+ :type=>"ActiveFedora::Datastream", :mimeType=>"image/jpeg",
23
+ :controlGroup=>'M'},
24
+ "EAD"=> {:name=>"EAD", :prefix=>"EAD",
25
+ :type=>"ActiveFedora::Datastream", :mimeType=>"application/xml",
26
+ :controlGroup=>'M' },
27
+ "external"=> {:name=>"external", :prefix=>"EXTERNAL",
28
+ :type=>"ActiveFedora::Datastream", :controlGroup=>'E' }}
29
+ @test_object2.should respond_to(:thumbnail_append)
30
+ @test_object2.should respond_to(:thumbnail_file_append)
31
+ @test_object2.should respond_to(:thumbnail)
32
+ @test_object2.should respond_to(:thumbnail_ids)
33
+ @test_object2.should respond_to(:ead_append)
34
+ @test_object2.should respond_to(:ead_file_append)
35
+ @test_object2.should respond_to(:EAD)
36
+ @test_object2.should respond_to(:EAD_ids)
37
+ @test_object2.should respond_to(:external)
38
+ @test_object2.should respond_to(:external_ids)
32
39
  end
33
40
  end
34
-
35
- it 'should provide #datastream_names' do
36
- @test_object.should respond_to(:datastream_names)
37
- end
38
-
39
41
  describe '#datastream_names' do
40
- class MockDatastreamNames < ActiveFedora::Base
41
- has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
42
- has_datastream :name=>"EAD", :type=>ActiveFedora::Datastream, :mimeType=>"application/xml", :controlGroup=>'M'
42
+ before(:all) do
43
+ ActiveSupport::Deprecation.expects(:warn).with(DEPRECATION_MSG)
44
+ class MockDatastreamNames < ActiveFedora::Base
45
+ has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
46
+ has_datastream :name=>"EAD", :type=>ActiveFedora::Datastream, :mimeType=>"application/xml", :controlGroup=>'M'
47
+ end
43
48
  end
44
49
 
45
50
  it 'should return an array of datastream names defined by has_datastream' do
@@ -48,19 +53,18 @@ describe ActiveFedora::Base do
48
53
  end
49
54
  end
50
55
 
51
- it 'should provide #add_named_datastream' do
52
- @test_object.should respond_to(:add_named_datastream)
53
- end
54
-
55
56
  describe '#add_named_datastream' do
56
- class MockAddNamedDatastream < ActiveFedora::Base
57
- has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
58
- has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
59
- has_datastream :name=>"anymime", :type=>ActiveFedora::Datastream, :controlGroup=>'M'
60
- has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
57
+ before(:all) do
58
+ ActiveSupport::Deprecation.expects(:warn).with(DEPRECATION_MSG)
59
+ class MockAddNamedDatastream < ActiveFedora::Base
60
+ has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
61
+ has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
62
+ has_datastream :name=>"anymime", :type=>ActiveFedora::Datastream, :controlGroup=>'M'
63
+ has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
64
+ end
61
65
  end
62
-
63
66
  before do
67
+
64
68
  @test_object2 = MockAddNamedDatastream.new
65
69
  @f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
66
70
  @f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
@@ -140,15 +144,14 @@ describe ActiveFedora::Base do
140
144
  end
141
145
  end
142
146
 
143
- it 'should provide #add_named_file_datastream' do
144
- @test_object.should respond_to(:add_named_file_datastream)
145
- end
146
-
147
147
  describe '#add_named_file_datastream' do
148
- class MockAddNamedFileDatastream < ActiveFedora::Base
149
- has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
150
- has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
151
- has_datastream :name=>"anymime", :type=>ActiveFedora::Datastream, :controlGroup=>'M'
148
+ before do
149
+ ActiveSupport::Deprecation.expects(:warn).with(DEPRECATION_MSG)
150
+ class MockAddNamedFileDatastream < ActiveFedora::Base
151
+ has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
152
+ has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
153
+ has_datastream :name=>"anymime", :type=>ActiveFedora::Datastream, :controlGroup=>'M'
154
+ end
152
155
  end
153
156
 
154
157
  it 'should add a datastream as controlGroup M with blob set to file' do
@@ -170,14 +173,13 @@ describe ActiveFedora::Base do
170
173
 
171
174
  end
172
175
  end
173
-
174
- it 'should provide #update_named_datastream' do
175
- @test_object.should respond_to(:update_named_datastream)
176
- end
177
-
176
+
178
177
  describe '#update_named_datastream' do
179
- class MockUpdateNamedDatastream < ActiveFedora::Base
180
- has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
178
+ before do
179
+ ActiveSupport::Deprecation.expects(:warn).with(DEPRECATION_MSG)
180
+ class MockUpdateNamedDatastream < ActiveFedora::Base
181
+ has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
182
+ end
181
183
  end
182
184
 
183
185
  it 'should update a datastream and not increment the dsid' do
@@ -231,32 +233,29 @@ describe ActiveFedora::Base do
231
233
  @test_object2.thumbnail.first.content.should == f2.read
232
234
  end
233
235
  end
234
-
235
- describe '#create_datastream' do
236
- it 'should create a datastream object using the type of object supplied in the string (does reflection)' do
237
- f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
238
- f.stubs(:content_type).returns("image/jpeg")
239
- f.stubs(:original_filename).returns("minivan.jpg")
240
- ds = @test_object.create_datastream("ActiveFedora::Datastream", 'NAME', {:blob=>f})
241
- ds.class.should == ActiveFedora::Datastream
242
- ds.dsLabel.should == "minivan.jpg"
243
- ds.mimeType.should == "image/jpeg"
236
+ describe '#named_datastreams_desc' do
237
+
238
+ before do
239
+ ActiveSupport::Deprecation.expects(:warn).with(DEPRECATION_MSG)
240
+ class MockNamedDatastreamsDesc < ActiveFedora::Base
241
+ has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
242
+ end
244
243
  end
245
- it 'should create a datastream object from a string' do
246
- ds = @test_object.create_datastream("ActiveFedora::Datastream", 'NAME', {:blob=>"My file data"})
247
- ds.class.should == ActiveFedora::Datastream
248
- ds.dsLabel.should == nil
249
- ds.mimeType.should == "application/octet-stream"
244
+
245
+ it 'should intialize a value to an empty hash and then not modify afterward' do
246
+ @test_object2 = MockNamedDatastreamsDesc.new
247
+ @test_object2.named_datastreams_desc.should == {"thumbnail"=>{:name=>"thumbnail",:prefix => "THUMB",
248
+ :type=>"ActiveFedora::Datastream", :mimeType=>"image/jpeg",
249
+ :controlGroup=>'M'}}
250
250
  end
251
251
  end
252
-
253
- it 'should provide #is_named_datastream?' do
254
- @test_object.should respond_to(:is_named_datastream?)
255
- end
256
-
252
+
257
253
  describe '#is_named_datastream?' do
258
- class MockIsNamedDatastream < ActiveFedora::Base
259
- has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
254
+ before do
255
+ ActiveSupport::Deprecation.expects(:warn).with(DEPRECATION_MSG)
256
+ class MockIsNamedDatastream < ActiveFedora::Base
257
+ has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
258
+ end
260
259
  end
261
260
 
262
261
  it 'should return true if a named datastream exists in model' do
@@ -266,15 +265,15 @@ describe ActiveFedora::Base do
266
265
  end
267
266
  end
268
267
 
269
- it 'should provide #named_datastreams' do
270
- @test_object.should respond_to(:named_datastreams)
271
- end
272
268
 
273
269
  describe '#named_datastreams' do
274
- class MockNamedDatastreams < ActiveFedora::Base
275
- has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
276
- has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
277
- has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
270
+ before do
271
+ ActiveSupport::Deprecation.expects(:warn).with(DEPRECATION_MSG)
272
+ class MockNamedDatastreams < ActiveFedora::Base
273
+ has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
274
+ has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
275
+ has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
276
+ end
278
277
  end
279
278
 
280
279
  it 'should return a hash of datastream names to arrays of datastreams' do
@@ -316,15 +315,15 @@ describe ActiveFedora::Base do
316
315
  end
317
316
 
318
317
 
319
- it 'should provide #named_datastreams_ids' do
320
- @test_object.should respond_to(:named_datastreams_ids)
321
- end
322
-
318
+
323
319
  describe '#named_datastreams_ids' do
324
- class MockNamedDatastreamsIds < ActiveFedora::Base
325
- has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
326
- has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
327
- has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
320
+ before do
321
+ ActiveSupport::Deprecation.expects(:warn).with(DEPRECATION_MSG)
322
+ class MockNamedDatastreamsIds < ActiveFedora::Base
323
+ has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
324
+ has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
325
+ has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
326
+ end
328
327
  end
329
328
 
330
329
  it 'should provide a hash of datastreams names to array of datastream ids' do
@@ -342,28 +341,14 @@ describe ActiveFedora::Base do
342
341
  end
343
342
  end
344
343
 
345
- #
346
- # Class level methods
347
- #
348
- describe '#named_datastreams_desc' do
349
-
350
- class MockNamedDatastreamsDesc < ActiveFedora::Base
351
- has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
352
- end
353
-
354
- it 'should intialize a value to an empty hash and then not modify afterward' do
355
- @test_object.named_datastreams_desc.should == {}
356
- @test_object2 = MockNamedDatastreamsDesc.new
357
- @test_object2.named_datastreams_desc.should == {"thumbnail"=>{:name=>"thumbnail",:prefix => "THUMB",
358
- :type=>"ActiveFedora::Datastream", :mimeType=>"image/jpeg",
359
- :controlGroup=>'M'}}
360
- end
361
- end
362
344
 
363
345
  describe '#create_named_datastream_finders' do
364
- class MockCreateNamedDatastreamFinder < ActiveFedora::Base
365
- has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
366
- has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
346
+ before do
347
+ ActiveSupport::Deprecation.expects(:warn).with(DEPRECATION_MSG)
348
+ class MockCreateNamedDatastreamFinder < ActiveFedora::Base
349
+ has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
350
+ has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
351
+ end
367
352
  end
368
353
 
369
354
  it 'should create helper methods to get named datastreams or dsids' do
@@ -398,10 +383,13 @@ describe ActiveFedora::Base do
398
383
  end
399
384
 
400
385
  describe '#create_named_datastream_update_methods' do
401
- class MockCreateNamedDatastreamUpdateMethods < ActiveFedora::Base
402
- has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
403
- has_datastream :name=>"EAD", :type=>ActiveFedora::Datastream, :mimeType=>"application/xml", :controlGroup=>'M'
404
- has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
386
+ before do
387
+ ActiveSupport::Deprecation.expects(:warn).with(DEPRECATION_MSG)
388
+ class MockCreateNamedDatastreamUpdateMethods < ActiveFedora::Base
389
+ has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
390
+ has_datastream :name=>"EAD", :type=>ActiveFedora::Datastream, :mimeType=>"application/xml", :controlGroup=>'M'
391
+ has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
392
+ end
405
393
  end
406
394
 
407
395
  it 'should create append method for each has_datastream entry' do
@@ -433,35 +421,4 @@ describe ActiveFedora::Base do
433
421
  t3_external1.controlGroup == 'E'
434
422
  end
435
423
  end
436
-
437
- describe '#has_datastream' do
438
- class MockHasDatastream < ActiveFedora::Base
439
- has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
440
- has_datastream :name=>"EAD", :type=>ActiveFedora::Datastream, :mimeType=>"application/xml", :controlGroup=>'M'
441
- has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
442
- end
443
-
444
- it 'should cache a definition of named datastream and create helper methods to add/remove/access them' do
445
- @test_object2 = MockHasDatastream.new
446
- #prefix should default to name in caps if not specified in has_datastream call
447
- @test_object2.named_datastreams_desc.should == {"thumbnail"=>{:name=>"thumbnail",:prefix => "THUMB",
448
- :type=>"ActiveFedora::Datastream", :mimeType=>"image/jpeg",
449
- :controlGroup=>'M'},
450
- "EAD"=> {:name=>"EAD", :prefix=>"EAD",
451
- :type=>"ActiveFedora::Datastream", :mimeType=>"application/xml",
452
- :controlGroup=>'M' },
453
- "external"=> {:name=>"external", :prefix=>"EXTERNAL",
454
- :type=>"ActiveFedora::Datastream", :controlGroup=>'E' }}
455
- @test_object2.should respond_to(:thumbnail_append)
456
- @test_object2.should respond_to(:thumbnail_file_append)
457
- @test_object2.should respond_to(:thumbnail)
458
- @test_object2.should respond_to(:thumbnail_ids)
459
- @test_object2.should respond_to(:ead_append)
460
- @test_object2.should respond_to(:ead_file_append)
461
- @test_object2.should respond_to(:EAD)
462
- @test_object2.should respond_to(:EAD_ids)
463
- @test_object2.should respond_to(:external)
464
- @test_object2.should respond_to(:external_ids)
465
- end
466
- end
467
424
  end
@@ -44,7 +44,6 @@ describe ActiveFedora::MetadataDatastream do
44
44
  @mock_repo.expects(:datastream).with(:pid => nil, :dsid => 'mdDs')
45
45
  @mock_repo.expects(:add_datastream).with(:pid => nil, :dsid => 'mdDs', :checksumType => 'DISABLED', :versionable => true, :content => 'fake xml', :controlGroup => 'M', :dsState => 'A', :mimeType=>'text/xml')
46
46
  @test_ds.expects(:to_xml).returns("fake xml")
47
- @test_ds.expects(:dirty?).returns(true)
48
47
  @test_ds.serialize!
49
48
  @test_ds.save
50
49
  @test_ds.mimeType.should == 'text/xml'
@@ -43,7 +43,6 @@ describe ActiveFedora::NokogiriDatastream do
43
43
  it "should initialize from #xml_template if no xml is provided" do
44
44
  ActiveFedora::NokogiriDatastream.expects(:xml_template).returns("<fake template/>")
45
45
  n = ActiveFedora::NokogiriDatastream.new(nil, nil)
46
- n.expects(:content).returns('')
47
46
  n.ensure_xml_loaded
48
47
  n.ng_xml.should be_equivalent_to("<fake template/>")
49
48
  end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe ActiveFedora::Predicates do
5
+ it 'should provide .default_predicate_namespace' do
6
+ ActiveFedora::Predicates.default_predicate_namespace.should == 'info:fedora/fedora-system:def/relations-external#'
7
+ end
8
+
9
+ describe "#predicate_mappings" do
10
+
11
+ it 'should return a hash' do
12
+ ActiveFedora::Predicates.predicate_mappings.should be_kind_of Hash
13
+ end
14
+
15
+ it "should provide mappings to the fedora ontology via the info:fedora/fedora-system:def/relations-external default namespace mapping" do
16
+ ActiveFedora::Predicates.predicate_mappings.keys.include?(ActiveFedora::Predicates.default_predicate_namespace).should be_true
17
+ ActiveFedora::Predicates.predicate_mappings[ActiveFedora::Predicates.default_predicate_namespace].should be_kind_of Hash
18
+ end
19
+
20
+ it 'should provide predicate mappings for entire Fedora Relationship Ontology' do
21
+ desired_mappings = Hash[:is_member_of => "isMemberOf",
22
+ :has_member => "hasMember",
23
+ :is_part_of => "isPartOf",
24
+ :has_part => "hasPart",
25
+ :is_member_of_collection => "isMemberOfCollection",
26
+ :has_collection_member => "hasCollectionMember",
27
+ :is_constituent_of => "isConstituentOf",
28
+ :has_constituent => "hasConstituent",
29
+ :is_subset_of => "isSubsetOf",
30
+ :has_subset => "hasSubset",
31
+ :is_derivation_of => "isDerivationOf",
32
+ :has_derivation => "hasDerivation",
33
+ :is_dependent_of => "isDependentOf",
34
+ :has_dependent => "hasDependent",
35
+ :is_description_of => "isDescriptionOf",
36
+ :has_description => "hasDescription",
37
+ :is_metadata_for => "isMetadataFor",
38
+ :has_metadata => "hasMetadata",
39
+ :is_annotation_of => "isAnnotationOf",
40
+ :has_annotation => "hasAnnotation",
41
+ :has_equivalent => "hasEquivalent",
42
+ :conforms_to => "conformsTo",
43
+ :has_model => "hasModel"]
44
+ desired_mappings.each_pair do |k,v|
45
+ ActiveFedora::Predicates.predicate_mappings[ActiveFedora::Predicates.default_predicate_namespace].should have_key(k)
46
+ ActiveFedora::Predicates.predicate_mappings[ActiveFedora::Predicates.default_predicate_namespace][k].should == v
47
+ end
48
+ end
49
+ end
50
+
51
+ it 'should provide #predicate_lookup that maps symbols to common RELS-EXT predicates' do
52
+ ActiveFedora::Predicates.should respond_to(:predicate_lookup)
53
+ ActiveFedora::Predicates.predicate_lookup(:is_part_of).should == "isPartOf"
54
+ ActiveFedora::Predicates.predicate_lookup(:is_member_of).should == "isMemberOf"
55
+ ActiveFedora::Predicates.predicate_lookup("isPartOfCollection").should == "isPartOfCollection"
56
+ ActiveFedora::Predicates.predicate_config[:predicate_mapping].merge!({"some_namespace"=>{:has_foo=>"hasFOO"}})
57
+ ActiveFedora::Predicates.find_predicate(:has_foo).should == ["hasFOO","some_namespace"]
58
+ ActiveFedora::Predicates.predicate_lookup(:has_foo,"some_namespace").should == "hasFOO"
59
+ lambda { ActiveFedora::Predicates.predicate_lookup(:has_foo) }.should raise_error ActiveFedora::UnregisteredPredicateError
60
+ end
61
+
62
+
63
+
64
+ end
@@ -24,9 +24,6 @@ describe ActiveFedora::QualifiedDublinCoreDatastream do
24
24
  end
25
25
  it "from_xml should parse everything correctly" do
26
26
  #originally just tested that lcsh encoding and stuff worked, but the other stuff is worth testing
27
- stub_get("meh:leh", ['RELS-EXT', 'sensitive_passages', 'significant_passages', 'dublin_core', 'properties'])
28
- stub_get_content("meh:leh", ['dublin_core'])
29
- ActiveFedora::RubydoraConnection.instance.expects(:nextid).returns("meh:leh")
30
27
  tmpl = OralHistorySampleModel.new.datastreams['dublin_core']
31
28
 
32
29
  tmpl.expects(:subject_append).with('sh1')
@@ -69,7 +66,6 @@ describe ActiveFedora::QualifiedDublinCoreDatastream do
69
66
  it "should have identity in and out" do
70
67
  sample = fixture('oh_qdc.xml')
71
68
  tmpl = OralHistorySampleModel.new.datastreams['dublin_core']
72
- tmpl.expects(:content).returns('')
73
69
  x1 = Nokogiri::XML::Document.parse(sample).xpath('/wrapper/foxml:datastream/foxml:datastreamVersion/foxml:xmlContent/dc').first.to_xml
74
70
  z = ActiveFedora::QualifiedDublinCoreDatastream.from_xml(x1, tmpl)
75
71
  y = ActiveFedora::QualifiedDublinCoreDatastream.from_xml(z.to_dc_xml, tmpl)
@@ -78,7 +74,6 @@ describe ActiveFedora::QualifiedDublinCoreDatastream do
78
74
 
79
75
  it "should handle arbitrary attribs" do
80
76
  tmpl = OralHistorySampleModel.new.datastreams['dublin_core']
81
- tmpl.expects(:content).returns('')
82
77
  tmpl.field :mycomplicated, :string, :xml_node=>'alt', :element_attrs=>{:foo=>'bar'}
83
78
  tmpl.mycomplicated_values='fubar'
84
79
  Nokogiri::XML(tmpl.to_dc_xml).should be_equivalent_to('<dc xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\' xmlns:dcterms=\'http://purl.org/dc/terms/\'><dcterms:alt foo=\'bar\'>fubar</dcterms:alt></dc>')
@@ -90,7 +85,6 @@ describe ActiveFedora::QualifiedDublinCoreDatastream do
90
85
  doc = Nokogiri::XML::Document.parse(File.open( File.dirname(__FILE__)+'/../fixtures/changeme155.xml') )
91
86
  stream = doc.xpath('//foxml:datastream[@ID=\'dublin_core\']/foxml:datastreamVersion/foxml:xmlContent/dc')
92
87
  ds = ActiveFedora::QualifiedDublinCoreDatastream.new(nil, nil)
93
- ds.expects(:content).returns('')
94
88
  n = ActiveFedora::QualifiedDublinCoreDatastream.from_xml(stream.to_xml, ds)
95
89
  n.spatial_values.should == ["Boston [7013445]", "Dorchester [7013575]", "Roxbury [7015002]"]
96
90
  n.title_values.should == ["Oral history with Frances Addelson, 1997 November 14"]
@@ -135,7 +129,6 @@ describe ActiveFedora::QualifiedDublinCoreDatastream do
135
129
  it "should call .content= with to_dc_xml" do
136
130
  result = @test_ds.to_dc_xml
137
131
  @test_ds.expects(:content=).with(result)
138
- @test_ds.expects(:dirty?).returns(true)
139
132
  @test_ds.serialize!
140
133
  end
141
134
  end