active-fedora 5.1.0 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/active-fedora.gemspec +1 -2
  2. data/lib/active_fedora/datastreams.rb +14 -14
  3. data/lib/active_fedora/file_management.rb +5 -3
  4. data/lib/active_fedora/metadata_datastream_helper.rb +5 -1
  5. data/lib/active_fedora/nokogiri_datastream.rb +17 -4
  6. data/lib/active_fedora/rdf_datastream.rb +59 -36
  7. data/lib/active_fedora/relationships.rb +28 -11
  8. data/lib/active_fedora/version.rb +1 -1
  9. data/spec/config_helper.rb +3 -3
  10. data/spec/integration/base_spec.rb +15 -3
  11. data/spec/integration/bug_spec.rb +0 -3
  12. data/spec/integration/datastream_collections_spec.rb +9 -9
  13. data/spec/integration/datastream_spec.rb +1 -1
  14. data/spec/integration/full_featured_model_spec.rb +3 -4
  15. data/spec/integration/ntriples_datastream_spec.rb +0 -1
  16. data/spec/integration/rels_ext_datastream_spec.rb +12 -1
  17. data/spec/integration/semantic_node_spec.rb +10 -0
  18. data/spec/integration/solr_service_spec.rb +2 -2
  19. data/spec/spec_helper.rb +4 -7
  20. data/spec/support/mock_fedora.rb +10 -10
  21. data/spec/unit/active_fedora_spec.rb +8 -8
  22. data/spec/unit/association_proxy_spec.rb +2 -1
  23. data/spec/unit/base_cma_spec.rb +2 -2
  24. data/spec/unit/base_datastream_management_spec.rb +9 -9
  25. data/spec/unit/base_extra_spec.rb +25 -25
  26. data/spec/unit/base_file_management_spec.rb +32 -23
  27. data/spec/unit/base_spec.rb +94 -151
  28. data/spec/unit/callback_spec.rb +16 -11
  29. data/spec/unit/code_configurator_spec.rb +4 -4
  30. data/spec/unit/content_model_spec.rb +8 -8
  31. data/spec/unit/datastream_collections_spec.rb +23 -23
  32. data/spec/unit/datastream_spec.rb +7 -7
  33. data/spec/unit/datastreams_spec.rb +189 -304
  34. data/spec/unit/file_configurator_spec.rb +56 -56
  35. data/spec/unit/has_many_collection_spec.rb +1 -1
  36. data/spec/unit/model_spec.rb +51 -56
  37. data/spec/unit/nokogiri_datastream_spec.rb +24 -25
  38. data/spec/unit/ntriples_datastream_spec.rb +18 -27
  39. data/spec/unit/property_spec.rb +0 -2
  40. data/spec/unit/qualified_dublin_core_datastream_spec.rb +1 -2
  41. data/spec/unit/rdfxml_rdf_datastream_spec.rb +1 -1
  42. data/spec/unit/relationship_graph_spec.rb +1 -1
  43. data/spec/unit/relationships_spec.rb +64 -52
  44. data/spec/unit/rels_ext_datastream_spec.rb +7 -7
  45. data/spec/unit/semantic_node_spec.rb +5 -5
  46. data/spec/unit/service_definitions_spec.rb +18 -16
  47. data/spec/unit/solr_config_options_spec.rb +6 -6
  48. data/spec/unit/solr_service_spec.rb +16 -16
  49. metadata +5 -21
@@ -31,19 +31,24 @@ describe ActiveFedora::Base do
31
31
  end
32
32
 
33
33
  it "Should have after_initialize, before_save,after_save, before_create, after_create, after_update, before_update, before_destroy" do
34
- CallbackStub.any_instance.expects(:a_init).twice
35
- CallbackStub.any_instance.expects :b_create
36
- CallbackStub.any_instance.expects :a_create
37
- CallbackStub.any_instance.expects(:b_save).twice
38
- CallbackStub.any_instance.expects(:a_save).twice
39
- CallbackStub.any_instance.expects(:a_find)
40
- CallbackStub.any_instance.expects(:b_update)
41
- CallbackStub.any_instance.expects(:a_update)
42
- CallbackStub.any_instance.expects(:do_stuff)
43
- cb = CallbackStub.new
34
+ CallbackStub.any_instance.should_receive(:a_init)
35
+ CallbackStub.any_instance.should_receive :b_create
36
+ CallbackStub.any_instance.should_receive :a_create
37
+ CallbackStub.any_instance.should_receive(:b_save)
38
+ CallbackStub.any_instance.should_receive(:a_save)
39
+ cb = CallbackStub.new :pid => 'test:123'
44
40
  cb.save
41
+ end
42
+ it "Should have after_initialize, before_save,after_save, before_create, after_create, after_update, before_update, before_destroy" do
43
+ CallbackStub.any_instance.should_receive(:a_init)
44
+ CallbackStub.any_instance.should_receive(:b_save)
45
+ CallbackStub.any_instance.should_receive(:a_save)
46
+ CallbackStub.any_instance.should_receive(:a_find)
47
+ CallbackStub.any_instance.should_receive(:b_update)
48
+ CallbackStub.any_instance.should_receive(:a_update)
49
+ CallbackStub.any_instance.should_receive(:do_stuff)
45
50
 
46
- cb2 = CallbackStub.find(cb.pid)
51
+ cb2 = CallbackStub.find('test:123')
47
52
  cb2.save
48
53
 
49
54
  cb2.destroy
@@ -38,10 +38,10 @@ describe ActiveFedora::FileConfigurator do
38
38
  end
39
39
 
40
40
  it "should initialize from code" do
41
- YAML.expects(:load).never
42
- File.expects(:exists?).never
43
- File.expects(:read).never
44
- File.expects(:open).never
41
+ YAML.should_receive(:load).never
42
+ File.should_receive(:exists?).never
43
+ File.should_receive(:read).never
44
+ File.should_receive(:open).never
45
45
  ActiveFedora.init(@config_params)
46
46
  ActiveFedora.fedora_config.credentials.should == @config_params[:fedora_config]
47
47
  ActiveFedora.solr_config.should == @config_params[:solr_config]
@@ -20,8 +20,8 @@ describe ActiveFedora::ContentModel do
20
20
 
21
21
  before(:each) do
22
22
  stub_get('__nextid__')
23
- ActiveFedora::Base.stubs(:assign_pid).returns("__nextid__")
24
- Rubydora::Repository.any_instance.stubs(:client).returns(@mock_client)
23
+ ActiveFedora::Base.stub(:assign_pid).and_return("__nextid__")
24
+ Rubydora::Repository.any_instance.stub(:client).and_return(@mock_client)
25
25
  @test_cmodel = ActiveFedora::ContentModel.new
26
26
  end
27
27
 
@@ -54,12 +54,12 @@ describe ActiveFedora::ContentModel do
54
54
  describe "models_asserted_by" do
55
55
  it "should return an array of all of the content models asserted by the given object" do
56
56
  mock_object = mock("ActiveFedora Object")
57
- mock_object.expects(:relationships).with(:has_model).returns(["info:fedora/fedora-system:ServiceDefinition-3.0", "info:fedora/afmodel:SampleModel", "info:fedora/afmodel:NonDefinedModel"])
57
+ mock_object.should_receive(:relationships).with(:has_model).and_return(["info:fedora/fedora-system:ServiceDefinition-3.0", "info:fedora/afmodel:SampleModel", "info:fedora/afmodel:NonDefinedModel"])
58
58
  ActiveFedora::ContentModel.models_asserted_by(mock_object).should == ["info:fedora/fedora-system:ServiceDefinition-3.0", "info:fedora/afmodel:SampleModel", "info:fedora/afmodel:NonDefinedModel"]
59
59
  end
60
60
  it "should return an empty array if the object doesn't have a RELS-EXT datastream" do
61
61
  mock_object = mock("ActiveFedora Object")
62
- mock_object.expects(:relationships).with(:has_model).returns([])
62
+ mock_object.should_receive(:relationships).with(:has_model).and_return([])
63
63
  ActiveFedora::ContentModel.models_asserted_by(mock_object).should == []
64
64
  end
65
65
  end
@@ -67,23 +67,23 @@ describe ActiveFedora::ContentModel do
67
67
  describe "known_models_asserted_by" do
68
68
  it "should figure out the applicable models to load" do
69
69
  mock_object = mock("ActiveFedora Object")
70
- mock_object.expects(:relationships).with(:has_model).returns(["info:fedora/fedora-system:ServiceDefinition-3.0", "info:fedora/afmodel:SampleModel", "info:fedora/afmodel:NonDefinedModel"])
70
+ mock_object.should_receive(:relationships).with(:has_model).and_return(["info:fedora/fedora-system:ServiceDefinition-3.0", "info:fedora/afmodel:SampleModel", "info:fedora/afmodel:NonDefinedModel"])
71
71
  ActiveFedora::ContentModel.known_models_for(mock_object).should == [SampleModel]
72
72
  end
73
73
  it "should support namespaced models" do
74
74
  pending "This is harder than it looks."
75
75
  mock_object = mock("ActiveFedora Object")
76
- mock_object.expects(:relationships).with(:has_model).returns(["info:fedora/afmodel:Sample_NamespacedModel"])
76
+ mock_object.should_receive(:relationships).with(:has_model).and_return(["info:fedora/afmodel:Sample_NamespacedModel"])
77
77
  ActiveFedora::ContentModel.known_models_for(mock_object).should == [Sample::NamespacedModel]
78
78
  end
79
79
  it "should default to using ActiveFedora::Base as the model" do
80
80
  mock_object = mock("ActiveFedora Object")
81
- mock_object.expects(:relationships).with(:has_model).returns(["info:fedora/afmodel:NonDefinedModel"])
81
+ mock_object.should_receive(:relationships).with(:has_model).and_return(["info:fedora/afmodel:NonDefinedModel"])
82
82
  ActiveFedora::ContentModel.known_models_for(mock_object).should == [ActiveFedora::Base]
83
83
  end
84
84
  it "should still work even if the object doesn't have a RELS-EXT datastream" do
85
85
  mock_object = mock("ActiveFedora Object")
86
- mock_object.expects(:relationships).with(:has_model).returns([])
86
+ mock_object.should_receive(:relationships).with(:has_model).and_return([])
87
87
  ActiveFedora::ContentModel.known_models_for(mock_object).should == [ActiveFedora::Base]
88
88
  end
89
89
  end
@@ -65,8 +65,8 @@ describe ActiveFedora::DatastreamCollections do
65
65
  @test_object2 = MockAddNamedDatastream.new
66
66
  @f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
67
67
  @f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
68
- @f.stubs(:content_type).returns("image/jpeg")
69
- @f2.stubs(:original_filename).returns("dino.jpg")
68
+ @f.stub(:content_type).and_return("image/jpeg")
69
+ @f2.stub(:original_filename).and_return("dino.jpg")
70
70
  end
71
71
 
72
72
  it 'cannot add a datastream with name that does not exist' do
@@ -96,7 +96,7 @@ describe ActiveFedora::DatastreamCollections do
96
96
  end
97
97
 
98
98
  it "should check the file for a content type" do
99
- @f.expects(:content_type).returns("image/jpeg")
99
+ @f.should_receive(:content_type).and_return("image/jpeg")
100
100
  @test_object2.add_named_datastream("thumbnail",{:file=>@f})
101
101
  end
102
102
 
@@ -105,7 +105,7 @@ describe ActiveFedora::DatastreamCollections do
105
105
  end
106
106
 
107
107
  it "should encsure mimetype and content type match" do
108
- @f.stubs(:content_type).returns("image/tiff")
108
+ @f.stub(:content_type).and_return("image/tiff")
109
109
  expect { @test_object2.add_named_datastream("thumbnail",{:file=>f}) }.to raise_error
110
110
  end
111
111
 
@@ -118,7 +118,7 @@ describe ActiveFedora::DatastreamCollections do
118
118
 
119
119
  it "should cgecj that a dsid forms to the prefix" do
120
120
  #if dsid supplied check that conforms to prefix
121
- @f.stubs(:content_type).returns("image/jpeg")
121
+ @f.stub(:content_type).and_return("image/jpeg")
122
122
  expect { @test_object2.add_named_datastream("thumbnail",{:file=>@f,:dsid=>"DS1"}) }.to raise_error
123
123
  end
124
124
 
@@ -155,8 +155,8 @@ describe ActiveFedora::DatastreamCollections do
155
155
  @test_object2 = MockAddNamedFileDatastream.new
156
156
  f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
157
157
  #these normally supplied in multi-part post request
158
- f.stubs(:original_filename).returns("minivan.jpg")
159
- f.stubs(:content_type).returns("image/jpeg")
158
+ f.stub(:original_filename).and_return("minivan.jpg")
159
+ f.stub(:content_type).and_return("image/jpeg")
160
160
  @test_object2.add_named_file_datastream("thumbnail",f)
161
161
  thumb = @test_object2.thumbnail.first
162
162
  thumb.class.should == ActiveFedora::Datastream
@@ -183,10 +183,10 @@ describe ActiveFedora::DatastreamCollections do
183
183
  @test_object2 = MockUpdateNamedDatastream.new
184
184
  f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
185
185
  f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
186
- f.stubs(:content_type).returns("image/jpeg")
187
- f.stubs(:original_filename).returns("minivan.jpg")
188
- f2.stubs(:content_type).returns("image/jpeg")
189
- f2.stubs(:original_filename).returns("dino.jpg")
186
+ f.stub(:content_type).and_return("image/jpeg")
187
+ f.stub(:original_filename).and_return("minivan.jpg")
188
+ f2.stub(:content_type).and_return("image/jpeg")
189
+ f2.stub(:original_filename).and_return("dino.jpg")
190
190
  #check raise exception if dsid not supplied
191
191
  @test_object2.add_named_datastream("thumbnail",{:file=>f})
192
192
  had_exception = false
@@ -273,11 +273,11 @@ describe ActiveFedora::DatastreamCollections do
273
273
  it 'should return a hash of datastream names to arrays of datastreams' do
274
274
  @test_object2 = MockNamedDatastreams.new
275
275
  f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg" ))
276
- f.stubs(:content_type).returns("image/jpeg")
277
- f.stubs(:original_filename).returns("minivan.jpg")
276
+ f.stub(:content_type).and_return("image/jpeg")
277
+ f.stub(:original_filename).and_return("minivan.jpg")
278
278
  f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
279
- f2.stubs(:content_type).returns("image/jpeg")
280
- f2.stubs(:original_filename).returns("dino.jpg")
279
+ f2.stub(:content_type).and_return("image/jpeg")
280
+ f2.stub(:original_filename).and_return("dino.jpg")
281
281
  @test_object2.thumbnail_file_append(f)
282
282
  @test_object2.high_file_append(f2)
283
283
  @test_object2.external_append({:dsLocation=>"http://myresource.com"})
@@ -319,11 +319,11 @@ describe ActiveFedora::DatastreamCollections do
319
319
  it 'should provide a hash of datastreams names to array of datastream ids' do
320
320
  @test_object2 = MockNamedDatastreamsIds.new
321
321
  f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg" ))
322
- f.stubs(:content_type).returns("image/jpeg")
323
- f.stubs(:original_filename).returns("minivan.jpg")
322
+ f.stub(:content_type).and_return("image/jpeg")
323
+ f.stub(:original_filename).and_return("minivan.jpg")
324
324
  f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
325
- f2.stubs(:content_type).returns("image/jpeg")
326
- f2.stubs(:original_filename).returns("dino.jpg")
325
+ f2.stub(:content_type).and_return("image/jpeg")
326
+ f2.stub(:original_filename).and_return("dino.jpg")
327
327
  @test_object2.thumbnail_file_append(f)
328
328
  @test_object2.high_file_append(f2)
329
329
  @test_object2.external_append({:dsLocation=>"http://myresource.com"})
@@ -349,8 +349,8 @@ describe ActiveFedora::DatastreamCollections do
349
349
  @test_object2.should respond_to(:high_ids)
350
350
  f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
351
351
  f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
352
- f2.stubs(:original_filename).returns("dino.jpg")
353
- f.stubs(:content_type).returns("image/jpeg")
352
+ f2.stub(:original_filename).and_return("dino.jpg")
353
+ f.stub(:content_type).and_return("image/jpeg")
354
354
  @test_object2.add_named_datastream("thumbnail",{:content_type=>"image/jpeg",:blob=>f, :label=>"testDS"})
355
355
  @test_object2.add_named_datastream("high",{:content_type=>"image/jpeg",:blob=>f2})
356
356
  @test_object2.add_named_datastream("high",{:content_type=>"image/jpeg",:blob=>f2})
@@ -388,8 +388,8 @@ describe ActiveFedora::DatastreamCollections do
388
388
  @test_object2.should respond_to(:thumbnail_append)
389
389
  @test_object2.should respond_to(:ead_append)
390
390
  f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
391
- f.stubs(:content_type).returns("image/jpeg")
392
- f.stubs(:original_filename).returns("minivan.jpg")
391
+ f.stub(:content_type).and_return("image/jpeg")
392
+ f.stub(:original_filename).and_return("minivan.jpg")
393
393
  @test_object2.thumbnail_file_append(f)
394
394
  t2_thumb1 = @test_object2.thumbnail.first
395
395
  t2_thumb1.mimeType.should == "image/jpeg"
@@ -14,7 +14,7 @@ describe ActiveFedora::Datastream do
14
14
  its(:metadata?) { should be_false}
15
15
 
16
16
  it "should escape dots in to_param" do
17
- @test_datastream.stubs(:dsid).returns('foo.bar')
17
+ @test_datastream.stub(:dsid).and_return('foo.bar')
18
18
  @test_datastream.to_param.should == 'foo%2ebar'
19
19
  end
20
20
 
@@ -64,10 +64,10 @@ describe ActiveFedora::Datastream do
64
64
  describe '#save' do
65
65
  it "should set changed" do
66
66
  mock_repo = mock('repository')
67
- mock_repo.stubs(:config).returns({})
68
- mock_repo.stubs(:add_datastream).with(:versionable => true, :pid => @test_object.pid, :dsid => 'abcd', :controlGroup => 'M', :dsState => 'A', :content => 'hi there')
69
- mock_repo.expects(:datastream).with(:dsid => 'abcd', :pid => @test_object.pid).returns('').at_least_once
70
- @test_object.inner_object.stubs(:repository).returns(mock_repo)
67
+ mock_repo.stub(:config).and_return({})
68
+ mock_repo.stub(:add_datastream).with(:versionable => true, :pid => @test_object.pid, :dsid => 'abcd', :controlGroup => 'M', :dsState => 'A', :content => 'hi there')
69
+ mock_repo.stub(:datastream).with(:dsid => 'abcd', :pid => @test_object.pid).and_return('')
70
+ @test_object.inner_object.stub(:repository).and_return(mock_repo)
71
71
  @test_datastream.save
72
72
  @test_datastream.should_not be_changed
73
73
  end
@@ -122,8 +122,8 @@ describe ActiveFedora::Datastream do
122
122
  EOS
123
123
 
124
124
  mock_repo = mock('repository', :config=>{})
125
- @test_object.inner_object.stubs(:repository).returns(mock_repo)
126
- mock_repo.expects(:datastream).with(:dsid => 'abcd', :pid => @test_object.pid).returns(ds_profile)
125
+ @test_object.inner_object.stub(:repository).and_return(mock_repo)
126
+ mock_repo.should_receive(:datastream).with(:dsid => 'abcd', :pid => @test_object.pid).and_return(ds_profile)
127
127
  @test_datastream.size.should == 9999
128
128
  end
129
129
 
@@ -1,358 +1,243 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ActiveFedora::Datastreams do
4
- before do
5
- @test_object = ActiveFedora::Base.new
6
- end
7
-
8
- it "should respond_to has_metadata" do
9
- ActiveFedora::Base.respond_to?(:has_metadata).should be_true
10
- end
4
+ subject { ActiveFedora::Base.new }
11
5
 
12
- describe ".metadata_streams" do
13
- it "should return all of the datastreams from the object that are kinds of SimpleDatastreams " do
14
- mock_mds1 = mock("metadata ds1")
15
- mock_mds2 = mock("metadata ds2")
16
- mock_fds = mock("file ds")
17
- mock_fds.expects(:metadata?).returns(false)
18
- mock_ngds = mock("nokogiri ds")
19
- mock_ngds.expects(:metadata?).returns(true)
20
-
21
- [mock_mds1,mock_mds2].each do |ds|
22
- ds.expects(:metadata?).returns(true)
6
+ describe '.has_metadata' do
7
+ before do
8
+ class FooHistory < ActiveFedora::Base
9
+ has_metadata :name => 'dsid'
10
+ has_metadata :name => 'complex_ds', :versionable => true, :autocreate => true, :type => 'Z', :label => 'My Label', :control_group => 'Z'
23
11
  end
24
-
25
- @test_object.expects(:datastreams).returns({:foo => mock_mds1, :bar => mock_mds2, :baz => mock_fds, :bork=>mock_ngds})
26
-
27
- result = @test_object.metadata_streams
28
- result.length.should == 3
29
- result.should include(mock_mds1)
30
- result.should include(mock_mds2)
31
- result.should include(mock_ngds)
12
+ end
13
+
14
+ it "should have a ds_specs entry" do
15
+ FooHistory.ds_specs.should have_key('dsid')
16
+ end
17
+
18
+ it "should have reasonable defaults" do
19
+ FooHistory.ds_specs['dsid'].should include(:autocreate => false)
20
+ end
21
+
22
+ it "should let you override defaults" do
23
+ FooHistory.ds_specs['complex_ds'].should include(:versionable => true, :autocreate => true, :type => 'Z', :label => 'My Label', :control_group => 'Z')
32
24
  end
33
25
  end
34
26
 
35
- describe "datastream_from_spec" do
36
- it "should accept versionable" do
37
- ds = @test_object.datastream_from_spec({:type=>ActiveFedora::Datastream, :versionable=>false}, 'test')
38
- ds.versionable.should be_false
39
- ds = @test_object.datastream_from_spec({:type=>ActiveFedora::Datastream, :versionable=>true}, 'test')
40
- ds.versionable.should be_true
27
+ describe '.has_file_datastream' do
28
+ before do
29
+ class FooHistory < ActiveFedora::Base
30
+ has_file_datastream :name => 'dsid'
31
+ end
41
32
  end
42
- it "should default versionable to true" do
43
- ds = @test_object.datastream_from_spec({:type=>ActiveFedora::Datastream}, 'test')
44
- ds.versionable.should be_true
33
+
34
+ it "should have reasonable defaults" do
35
+ FooHistory.ds_specs['dsid'].should include(:type => ActiveFedora::Datastream, :label => 'File Datastream', :control_group => 'M')
45
36
  end
37
+ end
38
+
39
+ describe "#serialize_datastreams" do
40
+ it "should touch each datastream" do
41
+ m1 = mock()
42
+ m2 = mock()
46
43
 
44
+ m1.should_receive(:serialize!)
45
+ m2.should_receive(:serialize!)
46
+ subject.stub(:datastreams => { :m1 => m1, :m2 => m2})
47
+ subject.serialize_datastreams
48
+ end
47
49
  end
48
50
 
49
- describe "has_metadata" do
50
- @@last_pid = 0
51
- def increment_pid
52
- @@last_pid += 1
51
+ describe "#add_disseminator_location_to_datastreams" do
52
+ it "should infer dsLocations for E datastreams without hitting Fedora" do
53
+
54
+ mock_specs = {:e => { :disseminator => 'xyz' }}
55
+ mock_ds = mock(:controlGroup => 'E')
56
+ ActiveFedora::Base.stub(:ds_specs => mock_specs)
57
+ ActiveFedora.stub(:config_for_environment => { :url => 'http://localhost'})
58
+ subject.stub(:pid => 'test:1', :datastreams => {:e => mock_ds})
59
+ mock_ds.should_receive(:dsLocation=).with("http://localhost/objects/test:1/methods/xyz")
60
+ subject.add_disseminator_location_to_datastreams
53
61
  end
62
+ end
54
63
 
64
+ describe "#corresponding_datastream_name" do
55
65
  before(:each) do
56
- @this_pid = increment_pid.to_s
57
- stub_get(@this_pid)
58
- Rubydora::Repository.any_instance.stubs(:client).returns(@mock_client)
59
- ActiveFedora::Base.stubs(:assign_pid).returns(@this_pid)
60
- #ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(@this_pid)
66
+ subject.stub(:datastreams => { 'abc' => mock(), 'a_b_c' => mock(), 'a-b' => mock()})
61
67
  end
62
68
 
63
- describe "updates the spec" do
64
- before do
65
- class FooHistory < ActiveFedora::Base
66
- end
67
- end
68
- after do
69
- Object.send(:remove_const, :FooHistory)
70
- end
71
- subject { FooHistory}
72
- it "should update the ds_spec" do
73
- FooHistory.ds_specs.keys.should == ['RELS-EXT']
74
- FooHistory.has_metadata :type=>ActiveFedora::Datastream, :name=>'new_ds'
75
- FooHistory.ds_specs.keys.should include 'new_ds'
76
- end
77
- it "should be able to set a type" do
78
- FooHistory.has_metadata :type=>ActiveFedora::Datastream, :name=>'new_ds', :control_group=>'R'
79
- FooHistory.ds_specs['new_ds'][:control_group].should == 'R'
80
- end
81
- it "should be able to set versionable to false" do
82
- FooHistory.has_metadata :type=>ActiveFedora::Datastream, :name=>'new_ds', :versionable=>false
83
- FooHistory.has_file_datastream :type=>ActiveFedora::Datastream, :name=>'newer_ds', :versionable=>false
84
- FooHistory.ds_specs['new_ds'][:versionable].should be_false
85
- FooHistory.ds_specs['newer_ds'][:versionable].should be_false
86
- end
87
- it "should be able to set versionable to true" do
88
- FooHistory.has_metadata :type=>ActiveFedora::Datastream, :name=>'new_ds', :versionable=>true
89
- FooHistory.ds_specs['new_ds'][:versionable].should be_true
90
- end
91
- it "should not set versionable if it's not supplied" do
92
- FooHistory.has_metadata :type=>ActiveFedora::Datastream, :name=>'new_ds'
93
- FooHistory.ds_specs['new_ds'].keys.should_not include :versionable
94
- end
95
-
69
+ it "should use the name, if it exists" do
70
+ subject.corresponding_datastream_name('abc').should == 'abc'
96
71
  end
97
72
 
98
- describe "creates datastreams" do
99
- before(:each) do
100
- class FooHistory < ActiveFedora::Base
101
- has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"someData", :autocreate => true do |m|
102
- m.field "fubar", :string
103
- m.field "swank", :text
104
- end
105
- has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"withText2", :label=>"withLabel", :autocreate => true do |m|
106
- m.field "fubar", :text
107
- end
108
-
109
- has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"no_autocreate", :autocreate => false, :label=>"withLabel" do |m|
110
- m.field "fubar", :text
111
- end
112
- end
113
- stub_ingest(@this_pid)
114
- stub_add_ds(@this_pid, ['RELS-EXT', 'someData', 'withText', 'withText2','no_autocreate'])
115
-
116
- @n = FooHistory.new()
117
- FooHistory.stubs(:assign_pid).returns(@this_pid)
118
- @n.datastreams['RELS-EXT'].expects(:changed?).returns(true).at_least_once
119
- @n.expects(:update_index)
120
- end
73
+ it "should hash-erize underscores" do
74
+ subject.corresponding_datastream_name('a_b').should == 'a-b'
75
+ end
121
76
 
122
- after do
123
- Object.send(:remove_const, :FooHistory)
124
- end
77
+ it "should return nil if nothing matches" do
78
+ subject.corresponding_datastream_name('xyz').should be_nil
79
+ end
80
+ end
81
+
82
+ describe "#datastreams" do
83
+ it "should return the datastream hash proxy" do
84
+ subject.stub(:load_datastreams)
85
+ subject.datastreams.should be_a_kind_of(ActiveFedora::DatastreamHash)
86
+ end
87
+ end
125
88
 
126
- it "should respect autocreate => false" do
127
- @n.datastreams['no_autocreate'].expects(:save).never
128
- @n.save
129
- end
89
+ describe "#configure_datastream" do
90
+ it "should look up the ds_spec" do
91
+ mock_dsspec = { :type => nil }
92
+ subject.stub(:ds_specs => {'abc' => mock_dsspec})
93
+ subject.configure_datastream(mock(:dsid => 'abc'))
94
+ end
130
95
 
131
- it "should default to autocreating datastreams" do
132
- @n.datastreams['someData'].expects(:save).once
133
- @n.save
134
- end
96
+ it "should be ok if there is no ds spec" do
97
+ mock_dsspec = mock()
98
+ subject.stub(:ds_specs => {})
99
+ subject.configure_datastream(mock(:dsid => 'abc'))
100
+ end
135
101
 
136
- it "should create specified datastreams with specified fields" do
137
- @n.save
138
- @n.datastreams["someData"].should_not be_nil
139
- @n.datastreams["someData"].fubar='bar'
140
- @n.datastreams["someData"].fubar.should == ['bar']
141
- @n.datastreams["withText2"].dsLabel.should == "withLabel"
142
- end
102
+ it "should configure RelsExtDatastream" do
103
+ mock_dsspec = { :type => ActiveFedora::RelsExtDatastream }
104
+ subject.stub(:ds_specs => {'abc' => mock_dsspec})
105
+
106
+ ds = mock(:dsid => 'abc')
107
+ ds.should_receive(:model=).with(subject)
108
+
109
+ subject.configure_datastream(ds)
143
110
  end
144
111
 
112
+ it "should run a Proc" do
113
+ ds = mock(:dsid => 'abc')
114
+ @count = 0
115
+ mock_dsspec = { :block => lambda { |x| @count += 1 } }
116
+ subject.stub(:ds_specs => {'abc' => mock_dsspec})
145
117
 
146
- it "should create specified datastreams with appropriate control group" do
147
- ActiveFedora.stubs(:config_for_environment).returns(:url=>'sub_url')
148
- stub_ingest(@this_pid)
149
- stub_add_ds(@this_pid, ['RELS-EXT', 'DC', 'rightsMetadata', 'properties', 'descMetadata', 'UKETD_DC'])
150
- stub_get(@this_pid, ['RELS-EXT', 'DC', 'rightsMetadata', 'properties', 'descMetadata', 'UKETD_DC'])
151
- class UketdObject < ActiveFedora::Base
152
- has_metadata :name => "rightsMetadata", :label=>"Rights metadata", :type => ActiveFedora::NokogiriDatastream
153
-
154
- # Uses the Hydra MODS Article profile for tracking most of the descriptive metadata
155
- # TODO: define terminology for ETD
156
- has_metadata :name => "descMetadata", :label=>"MODS metadata", :control_group=>"M", :type => ActiveFedora::NokogiriDatastream
157
118
 
158
- has_metadata :name => "UKETD_DC", :label=>"UKETD_DC metadata", :control_group => "E", :disseminator=>"hull-sDef:uketdObject/getUKETDMetadata", :type => ActiveFedora::NokogiriDatastream
119
+ expect {
120
+ subject.configure_datastream(ds)
121
+ }.to change { @count }.by(1)
122
+ end
123
+ end
159
124
 
160
- has_metadata :name => "DC", :type => ActiveFedora::NokogiriDatastream, :label=>"DC admin metadata"
125
+ describe "#datastream_from_spec" do
126
+ it "should fetch the rubydora datastream" do
127
+ subject.inner_object.should_receive(:datastream_object_for).with('dsid', {})
128
+ subject.datastream_from_spec({}, 'dsid')
129
+ end
130
+ end
161
131
 
162
- # A place to put extra metadata values
163
- has_metadata :name => "properties", :label=>"Workflow properties", :type => ActiveFedora::SimpleDatastream do |m|
164
- m.field 'collection', :string
165
- m.field 'depositor', :string
166
- end
132
+ describe "#load_datastreams" do
133
+ it "should load and configure persisted datastreams and should add any datastreams left over in the ds specs" do
134
+ pending
135
+ end
136
+ end
167
137
 
168
- end
169
- @n = UketdObject.new()
170
- UketdObject.stubs(:assign_pid).returns(@this_pid)
171
- @n.save
172
- @n.datastreams["DC"].controlGroup.should eql("X")
173
- @n.datastreams["rightsMetadata"].controlGroup.should eql("X")
174
- @n.datastreams["properties"].controlGroup.should eql("X")
175
- @n.datastreams["descMetadata"].controlGroup.should eql("M")
176
- @n.datastreams["UKETD_DC"].controlGroup.should eql("E")
177
- @n.datastreams["UKETD_DC"].dsLocation.should == "sub_url/objects/#{@this_pid}/methods/hull-sDef:uketdObject/getUKETDMetadata"
178
- end
179
-
180
-
181
- context ":control_group => 'E'" do
182
- before do
183
- stub_get(@this_pid)
184
- stub_add_ds(@this_pid, ['RELS-EXT', 'externalDisseminator', 'externalUrl'])
185
- end
138
+ describe "#add_datastream" do
139
+ it "should add the datastream to the object" do
140
+ ds = mock(:dsid => 'Abc')
141
+ subject.add_datastream(ds)
142
+ subject.datastreams['Abc'].should == ds
143
+ end
186
144
 
187
- after :each do
188
- # clean up test class
189
- Object.send(:remove_const, :MoreFooHistory)
190
- end
191
-
192
- it "should allow :control_group => 'E' with a :url option" do
193
- class MoreFooHistory < ActiveFedora::Base
194
- has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"externalDisseminator",:control_group => "E", :url => "http://exampl.com/mypic.jpg"
195
- end
196
- stub_ingest(@this_pid)
197
- @n = MoreFooHistory.new
198
- MoreFooHistory.stubs(:assign_pid).returns(@this_pid)
199
- @n.save
200
- @n.datastreams['externalDisseminator'].dsLocation.should == "http://exampl.com/mypic.jpg"
201
- end
202
-
203
- describe "control_group E without a url" do
204
- before do
205
- class MoreFooHistory < ActiveFedora::Base
206
- has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"externalDisseminator",:control_group => "E"
207
- end
208
- stub_ingest(@this_pid)
209
- @n = MoreFooHistory.new
210
- MoreFooHistory.stubs(:assign_pid).returns(@this_pid)
211
- end
212
- it "should allow :control_group => 'E' without a :url option" do
213
- @n.datastreams['externalDisseminator'].dsLocation.present?.should == false
214
- @n.save
215
- end
216
-
217
- it "should fail validation if a :url is not added before save" do
218
- @n.datastreams['externalDisseminator'].validate_content_present.should == false
219
- @n.save
220
- end
221
-
222
- it "should pass validation if a :url is added before save" do
223
- @n.datastreams['externalDisseminator'].dsLocation = "http://exampl.com/mypic.jpg"
224
- @n.datastreams['externalDisseminator'].validate_content_present.should == true
225
- @n.save
226
- end
227
- end
145
+ it "should mint a dsid" do
146
+ ds = ActiveFedora::Datastream.new
147
+ subject.add_datastream(ds).should == 'DS1'
228
148
  end
149
+ end
229
150
 
230
- context ":control_group => 'R'" do
231
- before do
232
- stub_get(@this_pid)
233
- stub_add_ds(@this_pid, ['RELS-EXT', 'externalDisseminator' ])
234
- end
235
-
236
- after :each do
237
- Object.send(:remove_const, :MoreFooHistory)
238
- end
239
-
240
- it "should allow :control_group => 'R' with a :url option" do
241
- stub_ingest(@this_pid)
242
- class MoreFooHistory < ActiveFedora::Base
243
- has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"externalDisseminator",:control_group => "R", :url => "http://exampl.com/mypic.jpg"
244
- end
245
- @n = MoreFooHistory.new
246
- MoreFooHistory.stubs(:assign_pid).returns(@this_pid)
247
- @n.save
248
- end
249
-
250
- describe "control_group R without url" do
251
- before do
252
- class MoreFooHistory < ActiveFedora::Base
253
- has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"externalDisseminator",:control_group => "R"
254
- end
255
- MoreFooHistory.stubs(:assign_pid).returns(@this_pid)
256
- stub_ingest(@this_pid)
257
- @n = MoreFooHistory.new
258
- end
259
- it "should allow :control_group => 'R' without a :url option" do
260
- @n.datastreams['externalDisseminator'].dsLocation.present?.should == false
261
- @n.save
262
- end
263
-
264
- it "should fail validation if a :url is not added before save" do
265
- @n.datastreams['externalDisseminator'].validate_content_present.should == false
266
- @n.save
267
- end
268
-
269
- it "should pass validation if a :url is added before save" do
270
- @n.datastreams['externalDisseminator'].dsLocation = "http://exampl.com/mypic.jpg"
271
- @n.datastreams['externalDisseminator'].validate_content_present.should == true
272
- @n.save
273
- end
274
- end
151
+ describe "#metadata_streams" do
152
+ it "should only be metadata datastreams" do
153
+ ds1 = mock(:metadata? => true)
154
+ ds2 = mock(:metadata? => true)
155
+ ds3 = mock(:metadata? => true)
156
+ relsextds = ActiveFedora::RelsExtDatastream.new
157
+ file_ds = mock(:metadata? => false)
158
+ subject.stub(:datastreams => {:a => ds1, :b => ds2, :c => ds3, :d => relsextds, :e => file_ds})
159
+ subject.metadata_streams.should include(ds1, ds2, ds3)
160
+ subject.metadata_streams.should_not include(relsextds)
161
+ subject.metadata_streams.should_not include(file_ds)
275
162
  end
276
163
  end
277
164
 
278
- describe "#create_datastream" do
279
- it 'should create a datastream object using the type of object supplied in the string (does reflection)' do
280
- f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
281
- f.stubs(:content_type).returns("image/jpeg")
282
- f.stubs(:original_filename).returns("minivan.jpg")
283
- ds = @test_object.create_datastream("ActiveFedora::Datastream", 'NAME', {:blob=>f})
284
- ds.class.should == ActiveFedora::Datastream
285
- ds.dsLabel.should == "minivan.jpg"
286
- ds.mimeType.should == "image/jpeg"
287
- end
288
- it 'should create a datastream object from a string' do
289
- ds = @test_object.create_datastream("ActiveFedora::Datastream", 'NAME', {:blob=>"My file data"})
290
- ds.class.should == ActiveFedora::Datastream
291
- ds.dsLabel.should == nil
292
- ds.mimeType.should == "application/octet-stream"
293
- end
294
-
295
- it 'should not set dsLocation if dsLocation is nil' do
296
- ActiveFedora::Datastream.any_instance.expects(:dsLocation=).never
297
- ds = @test_object.create_datastream("ActiveFedora::Datastream", 'NAME', {:dsLocation=>nil})
298
- end
299
-
300
- it 'should set attributes passed in onto the datastream' do
301
- ds = @test_object.create_datastream("ActiveFedora::Datastream", 'NAME', {:dsLocation=>"a1", :mimeType=>'image/png', :controlGroup=>'X', :dsLabel=>'My Label', :checksumType=>'SHA-1'})
302
- ds.location.should == 'a1'
303
- ds.mimeType.should == 'image/png'
304
- ds.controlGroup.should == 'X'
305
- ds.label.should == 'My Label'
306
- ds.checksumType.should == 'SHA-1'
165
+ describe "#generate_dsid" do
166
+ it "should create an autoincrementing dsid" do
167
+ subject.generate_dsid('FOO').should == 'FOO1'
168
+ end
169
+
170
+ it "should start from the highest existin dsid" do
171
+ subject.stub(:datastreams => {'FOO56' => mock()})
172
+ subject.generate_dsid('FOO').should == 'FOO57'
307
173
  end
308
174
  end
309
175
 
310
- describe ".has_file_datastream" do
311
- before do
312
- class FileDS < ActiveFedora::Datastream; end
313
- class FooHistory < ActiveFedora::Base
314
- has_file_datastream
315
- has_file_datastream :name=>"second", :label=>"Second file", :type=>FileDS, :control_group=>'X'
316
- end
176
+ describe "#dc" do
177
+ it "should be the DC datastream" do
178
+ m = mock
179
+ subject.stub(:datastreams => { 'DC' => m})
180
+ subject.dc.should == m
317
181
  end
318
- after do
319
- Object.send(:remove_const, :FooHistory)
320
- Object.send(:remove_const, :FileDS)
182
+ end
183
+
184
+
185
+ describe "#relsext" do
186
+ it "should be the RELS-EXT datastream" do
187
+ m = mock
188
+ subject.stub(:datastreams => { 'RELS-EXT' => m})
189
+ subject.rels_ext.should == m
321
190
  end
322
- it "Should add a line in ds_spec" do
323
- FooHistory.ds_specs['content'][:type].should == ActiveFedora::Datastream
324
- FooHistory.ds_specs['content'][:label].should == "File Datastream"
325
- FooHistory.ds_specs['content'][:control_group].should == "M"
326
- FooHistory.ds_specs['second'][:type].should == FileDS
327
- FooHistory.ds_specs['second'][:label].should == "Second file"
328
- FooHistory.ds_specs['second'][:control_group].should == "X"
191
+
192
+ it "should make one up otherwise" do
193
+ subject.stub(:datastreams => {})
194
+
195
+ subject.rels_ext.should be_a_kind_of(ActiveFedora::RelsExtDatastream)
329
196
  end
330
197
  end
331
198
 
332
199
  describe "#add_file_datastream" do
333
- before do
334
- @mock_file = mock('file')
200
+ # tested elsewhere :/
201
+ end
202
+
203
+ describe "#create_datastream" do
204
+ it "should mint a DSID" do
205
+ ds = subject.create_datastream(ActiveFedora::Datastream, nil, {})
206
+ ds.dsid.should == 'DS1'
335
207
  end
336
- it "should pass prefix" do
337
- stub_add_ds(@test_object.pid, ['content1'])
338
- @test_object.add_file_datastream(@mock_file, :prefix=>'content' )
339
- @test_object.datastreams.keys.should include 'content1'
208
+
209
+ it "should raise an argument error if the supplied dsid is nonsense" do
210
+ expect { subject.create_datastream(ActiveFedora::Datastream, 0) }.to raise_error(ArgumentError)
340
211
  end
341
- it "should pass dsid" do
342
- stub_add_ds(@test_object.pid, ['MY_DSID'])
343
- @test_object.add_file_datastream(@mock_file, :dsid=>'MY_DSID')
344
- @test_object.datastreams.keys.should include 'MY_DSID'
212
+
213
+ it "should try to get a mime type from the blob" do
214
+ mock_file = mock(:content_type => 'x-application/asdf')
215
+ ds = subject.create_datastream(ActiveFedora::Datastream, nil, {:blob => mock_file})
216
+ ds.mimeType.should == 'x-application/asdf'
345
217
  end
346
- it "without dsid or prefix" do
347
- stub_add_ds(@test_object.pid, ['DS1'])
348
- @test_object.add_file_datastream(@mock_file, {} )
349
- @test_object.datastreams.keys.should include 'DS1'
218
+
219
+ it "should provide a default mime type" do
220
+ mock_file = mock()
221
+ ds = subject.create_datastream(ActiveFedora::Datastream, nil, {:blob => mock_file})
222
+ ds.mimeType.should == 'application/octet-stream'
350
223
  end
351
- it "Should pass checksum Type" do
352
- stub_add_ds(@test_object.pid, ['DS1'])
353
- @test_object.add_file_datastream(@mock_file, {:checksumType=>'MD5'} )
354
- @test_object.datastreams['DS1'].checksumType.should == 'MD5'
224
+
225
+ it "should use the filename as a default label" do
226
+ mock_file = mock(:path => '/asdf/fdsa')
227
+ ds = subject.create_datastream(ActiveFedora::Datastream, nil, {:blob => mock_file})
228
+ ds.dsLabel.should == 'fdsa'
355
229
  end
356
230
  end
357
231
 
232
+ describe "#additional_attributes_for_external_and_redirect_control_groups" do
233
+ before(:all) do
234
+ @behavior = ActiveFedora::Datastreams.deprecation_behavior
235
+ ActiveFedora::Datastreams.deprecation_behavior = :silence
236
+ end
237
+
238
+ after :all do
239
+ ActiveFedora::Datastreams.deprecation_behavior = @behavior
240
+ end
241
+
242
+ end
358
243
  end