active-fedora 3.0.7 → 3.1.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/.rvmrc +1 -1
  2. data/Gemfile.lock +39 -10
  3. data/History.txt +0 -4
  4. data/active-fedora.gemspec +4 -3
  5. data/lib/active_fedora.rb +9 -9
  6. data/lib/active_fedora/base.rb +92 -163
  7. data/lib/active_fedora/datastream.rb +59 -60
  8. data/lib/active_fedora/datastream_hash.rb +18 -0
  9. data/lib/active_fedora/metadata_datastream.rb +3 -2
  10. data/lib/active_fedora/metadata_datastream_helper.rb +3 -15
  11. data/lib/active_fedora/model.rb +3 -3
  12. data/lib/active_fedora/nokogiri_datastream.rb +305 -302
  13. data/lib/active_fedora/qualified_dublin_core_datastream.rb +24 -19
  14. data/lib/active_fedora/rels_ext_datastream.rb +39 -37
  15. data/lib/active_fedora/rubydora_connection.rb +40 -0
  16. data/lib/active_fedora/semantic_node.rb +1 -1
  17. data/lib/active_fedora/solr_service.rb +1 -1
  18. data/lib/active_fedora/version.rb +1 -1
  19. data/lib/ruby-fedora.rb +0 -8
  20. data/lib/tasks/active_fedora.rake +14 -9
  21. data/lib/tasks/active_fedora_dev.rake +23 -40
  22. data/spec/integration/base_loader_spec.rb +4 -21
  23. data/spec/integration/base_spec.rb +300 -310
  24. data/spec/integration/bug_spec.rb +9 -10
  25. data/spec/integration/datastream_spec.rb +12 -12
  26. data/spec/integration/metadata_datastream_helper_spec.rb +7 -10
  27. data/spec/integration/model_spec.rb +3 -2
  28. data/spec/integration/rels_ext_datastream_spec.rb +9 -15
  29. data/spec/spec_helper.rb +2 -29
  30. data/spec/unit/active_fedora_spec.rb +5 -5
  31. data/spec/unit/base_cma_spec.rb +0 -7
  32. data/spec/unit/base_datastream_management_spec.rb +8 -67
  33. data/spec/unit/base_delegate_spec.rb +26 -9
  34. data/spec/unit/base_extra_spec.rb +5 -3
  35. data/spec/unit/base_file_management_spec.rb +10 -17
  36. data/spec/unit/base_named_datastream_spec.rb +76 -199
  37. data/spec/unit/base_spec.rb +152 -69
  38. data/spec/unit/content_model_spec.rb +1 -1
  39. data/spec/unit/datastream_concurrency_spec.rb +5 -4
  40. data/spec/unit/datastream_spec.rb +28 -48
  41. data/spec/unit/has_many_collection_spec.rb +2 -0
  42. data/spec/unit/inheritance_spec.rb +6 -6
  43. data/spec/unit/metadata_datastream_spec.rb +12 -28
  44. data/spec/unit/model_spec.rb +10 -10
  45. data/spec/unit/nokogiri_datastream_spec.rb +31 -33
  46. data/spec/unit/qualified_dublin_core_datastream_spec.rb +15 -15
  47. data/spec/unit/rels_ext_datastream_spec.rb +35 -29
  48. data/spec/unit/rubydora_connection_spec.rb +26 -0
  49. data/spec/unit/semantic_node_spec.rb +12 -17
  50. data/spec/unit/solr_config_options_spec.rb +13 -14
  51. data/spec/unit/solr_service_spec.rb +14 -17
  52. metadata +59 -55
  53. data/lib/fedora/base.rb +0 -38
  54. data/lib/fedora/connection.rb +0 -218
  55. data/lib/fedora/datastream.rb +0 -67
  56. data/lib/fedora/fedora_object.rb +0 -161
  57. data/lib/fedora/formats.rb +0 -30
  58. data/lib/fedora/generic_search.rb +0 -71
  59. data/lib/fedora/repository.rb +0 -298
  60. data/spec/integration/datastreams_crud_spec.rb +0 -208
  61. data/spec/integration/fedora_object_spec.rb +0 -77
  62. data/spec/integration/repository_spec.rb +0 -301
  63. data/spec/integration/rf_fedora_object_spec.rb +0 -95
  64. data/spec/unit/connection_spec.rb +0 -25
  65. data/spec/unit/fedora_object_spec.rb +0 -74
  66. data/spec/unit/repository_spec.rb +0 -143
  67. data/spec/unit/rf_datastream_spec.rb +0 -63
@@ -21,7 +21,6 @@ class FooHistory < ActiveFedora::Base
21
21
  end
22
22
 
23
23
  before(:each) do
24
- #Fedora::Repository.instance.stubs(:nextid).returns("foo:pid")
25
24
  @test_object = FooHistory.new
26
25
  @test_object.save
27
26
  end
@@ -29,20 +28,20 @@ end
29
28
  @test_object.delete
30
29
  end
31
30
  it "should not clobber everything when setting a value" do
32
- @test_object.datastreams["someData"].fubar_values.should == []
33
- @test_object.datastreams["someData"].should_not be_nil
34
- @test_object.datastreams["someData"].fubar_values=['bar']
35
- @test_object.datastreams["someData"].fubar_values.should == ['bar']
31
+ ds = @test_object.datastreams["someData"]
32
+ ds.fubar_values.should == []
33
+ ds.should_not be_nil
34
+ ds.fubar_values=['bar']
35
+ ds.fubar_values.should == ['bar']
36
36
  @test_object.save
37
37
 
38
38
  @test_object.pid.should_not be_nil
39
39
 
40
40
  x = *FooHistory.find(@test_object.pid)
41
- x.datastreams["someData"].fubar_values.should == ['bar']
42
- x.datastreams['someData'].dirty?.should == false
43
- x.datastreams['someData'].fubar_values = ["meh"]
44
- x.datastreams['someData'].fubar_values.should == ["meh"]
45
- x.datastreams['someData'].dirty?.should == true
41
+ ds2 = x.datastreams["someData"]
42
+ ds2.fubar_values.should == ['bar']
43
+ ds2.fubar_values = ["meh"]
44
+ ds2.fubar_values.should == ["meh"]
46
45
  x.save
47
46
  x = *FooHistory.find(@test_object.pid)
48
47
  x.datastreams['someData'].fubar_values.should == ["meh"]
@@ -18,9 +18,8 @@ describe ActiveFedora::Datastream do
18
18
  it "should be able to access Datastreams using datastreams method" do
19
19
  dc = @test_object.datastreams["DC"]
20
20
  dc.should be_an_instance_of(ActiveFedora::Datastream)
21
- dc.attributes.should be_an_instance_of(Hash)
22
- dc.attributes["dsid"].to_s.should eql("DC")
23
- dc.attributes[:pid].should_not be_nil
21
+ dc.dsid.should eql("DC")
22
+ dc.pid.should_not be_nil
24
23
  # dc.control_group.should == "X"
25
24
  end
26
25
 
@@ -30,28 +29,29 @@ describe ActiveFedora::Datastream do
30
29
  end
31
30
 
32
31
  it "should be able to update XML Datastream content and save to Fedora" do
33
- xml_content =REXML::Document.new(@test_object.datastreams["DC"].content)
34
- title = REXML::Element.new "dc:title"
35
- title.text = "Test Title"
36
- xml_content.root.elements << title
32
+ xml_content = Nokogiri::XML::Document.parse(@test_object.datastreams["DC"].content)
33
+ title = Nokogiri::XML::Element.new "title", xml_content
34
+ title.content = "Test Title"
35
+ title.namespace = xml_content.xpath('//oai_dc:dc/dc:identifier').first.namespace
36
+ xml_content.root.add_child title
37
37
 
38
+ @test_object.datastreams["DC"].stubs(:before_save)
38
39
  @test_object.datastreams["DC"].content = xml_content.to_s
39
40
  @test_object.datastreams["DC"].save
40
41
 
41
- @test_object.datastreams["DC"].content.should eql(Fedora::Repository.instance.fetch_custom(@test_object.pid, "datastreams/DC/content"))
42
+ found = Nokogiri::XML::Document.parse(@test_object.class.find(@test_object.pid).datastreams['DC'].content)
43
+ found.xpath('*/dc:title/text()').first.inner_text.should == title.content
42
44
  end
43
45
 
44
46
  it "should be able to update Blob Datastream content and save to Fedora" do
45
47
  dsid = "ds#{Time.now.to_i}"
46
- ds = ActiveFedora::Datastream.new(:dsID => dsid, :dsLabel => 'hello', :altIDs => '3333',
47
- :controlGroup => 'M', :blob => fixture('dino.jpg').read)
48
- ds.blob.should == fixture('dino.jpg').read
48
+ ds = ActiveFedora::Datastream.new(@test_object.inner_object, dsid)
49
+ ds.content = fixture('dino.jpg')
49
50
  @test_object.add_datastream(ds).should be_true
50
51
  @test_object.save
51
52
  to = ActiveFedora::Base.load_instance(@test_object.pid)
52
53
  to.should_not be_nil
53
54
  to.datastreams[dsid].should_not be_nil
54
- # to.datastreams[dsid].control_group.should == "M"
55
55
  to.datastreams[dsid].content.should == fixture('dino.jpg').read
56
56
 
57
57
  end
@@ -1,6 +1,6 @@
1
1
  require File.join( File.dirname(__FILE__), "../spec_helper" )
2
2
 
3
- require 'active_fedora'
3
+ require 'active-fedora'
4
4
  require "rexml/document"
5
5
  require 'ftools'
6
6
 
@@ -44,7 +44,6 @@ describe ActiveFedora::MetadataDatastreamHelper do
44
44
  describe '#from_solr' do
45
45
  it 'should return an object with the appropriate metadata fields filled in' do
46
46
  @test_object = MockMetaHelperSolr.new
47
- @test_object.new_object = true
48
47
  attributes = {"holding_id"=>{0=>"Holding 1"},
49
48
  "language"=>{0=>"Italian"},
50
49
  "creator"=>{0=>"Linguist, A."},
@@ -54,7 +53,6 @@ describe ActiveFedora::MetadataDatastreamHelper do
54
53
  @test_object.save
55
54
 
56
55
  @test_object2 = MockMetaHelperSolr.new
57
- @test_object2.new_object = true
58
56
  attributes = {"holding_id"=>{0=>"Holding 2"},
59
57
  "language"=>{0=>"Spanish;Latin"},
60
58
  "creator"=>{0=>"Linguist, A."},
@@ -64,7 +62,6 @@ describe ActiveFedora::MetadataDatastreamHelper do
64
62
  @test_object2.save
65
63
 
66
64
  @test_object3 = MockMetaHelperSolr.new
67
- @test_object3.new_object = true
68
65
  attributes = {"holding_id"=>{0=>"Holding 3"},
69
66
  "language"=>{0=>"Spanish;Latin"},
70
67
  "creator"=>{0=>"Linguist, A."},
@@ -80,21 +77,21 @@ describe ActiveFedora::MetadataDatastreamHelper do
80
77
 
81
78
  test_from_solr_object.fields[:language][:values].should == ["Italian"]
82
79
  test_from_solr_object.fields[:creator][:values].should == ["Linguist, A."]
83
- test_from_solr_object.fields[:geography][:values].should == ["Italy"]
80
+ #test_from_solr_object.fields[:geography][:values].should == ["Italy"]
84
81
  test_from_solr_object.fields[:title][:values].should == ["Italian and Spanish: A Comparison of Common Phrases"]
85
- test_from_solr_object.fields[:holding_id][:values].should == ["Holding 1"]
82
+ #test_from_solr_object.fields[:holding_id][:values].should == ["Holding 1"]
86
83
 
87
84
  test_from_solr_object2.fields[:language][:values].should == ["Spanish;Latin"]
88
85
  test_from_solr_object2.fields[:creator][:values].should == ["Linguist, A."]
89
- test_from_solr_object2.fields[:geography][:values].should == ["Spain"]
86
+ #test_from_solr_object2.fields[:geography][:values].should == ["Spain"]
90
87
  test_from_solr_object2.fields[:title][:values].should == ["A study of the evolution of Spanish from Latin"]
91
- test_from_solr_object2.fields[:holding_id][:values].should == ["Holding 2"]
88
+ #test_from_solr_object2.fields[:holding_id][:values].should == ["Holding 2"]
92
89
 
93
90
  test_from_solr_object3.fields[:language][:values].should == ["Spanish;Latin"]
94
91
  test_from_solr_object3.fields[:creator][:values].should == ["Linguist, A."]
95
- test_from_solr_object3.fields[:geography][:values].should == ["Spain"]
92
+ #test_from_solr_object3.fields[:geography][:values].should == ["Spain"]
96
93
  test_from_solr_object3.fields[:title][:values].should == ["An obscure look into early nomadic tribes of Spain"]
97
- test_from_solr_object3.fields[:holding_id][:values].should == ["Holding 3"]
94
+ #test_from_solr_object3.fields[:holding_id][:values].should == ["Holding 3"]
98
95
 
99
96
 
100
97
  end
@@ -21,6 +21,7 @@ describe ActiveFedora::Model do
21
21
 
22
22
  end
23
23
 
24
+ ActiveFedora::RubydoraConnection.connect(ActiveFedora.fedora_config[:url])
24
25
  @test_instance = ModelIntegrationSpec::Basic.new
25
26
  @test_instance.save
26
27
 
@@ -46,9 +47,9 @@ describe ActiveFedora::Model do
46
47
 
47
48
  it "should return an object of the given Model whose inner object is nil" do
48
49
  #result = ModelIntegrationSpec::Basic.find_model(@test_instance.pid, ModelIntegrationSpec::Basic)
49
- result = Fedora::Repository.instance.find_model(@test_instance.pid, ModelIntegrationSpec::Basic)
50
+ result = ActiveFedora::RubydoraConnection.instance.find_model(@test_instance.pid, ModelIntegrationSpec::Basic)
50
51
  result.class.should == ModelIntegrationSpec::Basic
51
- result.inner_object.new_object?.should be_false
52
+ result.inner_object.new?.should be_false
52
53
  end
53
54
  end
54
55
 
@@ -28,8 +28,8 @@ describe ActiveFedora::RelsExtDatastream do
28
28
  end
29
29
 
30
30
  before(:each) do
31
- @test_datastream = ActiveFedora::RelsExtDatastream.new
32
31
  @test_object = ActiveFedora::Base.new
32
+ @test_datastream = ActiveFedora::RelsExtDatastream.new(@test_object.inner_object, 'RELS-EXT')
33
33
  @test_object.save
34
34
  @test_relationships = [ActiveFedora::Relationship.new(:subject => :self, :predicate => :is_member_of, :object => "info:fedora/demo:5"),
35
35
  ActiveFedora::Relationship.new(:subject => :self, :predicate => :is_member_of, :object => "info:fedora/demo:10")]
@@ -59,24 +59,17 @@ describe ActiveFedora::RelsExtDatastream do
59
59
  end
60
60
 
61
61
 
62
- describe '#save' do
62
+ describe '#serialize!' do
63
63
 
64
- it "should generate new rdf/xml as the datastream content if the object has been changed" do
64
+ it "should generate new rdf/xml as the datastream content" do
65
65
  @test_object.add_datastream(@test_datastream)
66
66
  @test_relationships.each do |rel|
67
67
  @test_datastream.add_relationship(rel)
68
68
  end
69
69
  rexml1 = REXML::Document.new(@test_datastream.to_rels_ext(@test_object.pid))
70
- @test_datastream.dirty = true
71
- @test_datastream.save
70
+ @test_datastream.serialize!
72
71
  rexml2 = REXML::Document.new(@test_object.datastreams["RELS-EXT"].content)
73
72
  rexml1.root.elements["rdf:Description"].inspect.should eql(rexml2.root.elements["rdf:Description"].inspect)
74
- #rexml1.root.elements["rdf:Description"].to_s.should eql(rexml2.root.elements["rdf:Description"].to_s)
75
-
76
- #rexml1.root.elements["rdf:Description"].each_element do |el|
77
- # el.inspect.should eql(rexml2.root.elements["rdf:Description"][el.index_in_parent].inspect)
78
- #end
79
-
80
73
  end
81
74
 
82
75
  end
@@ -89,6 +82,7 @@ describe ActiveFedora::RelsExtDatastream do
89
82
  @test_object.save
90
83
  # make sure that _something_ was actually added to the object's relationships hash
91
84
  @test_object.relationships[:self].should have_key(:is_member_of)
85
+ o = ActiveFedora::Base.load_instance(@test_object.pid)
92
86
  ActiveFedora::Base.load_instance(@test_object.pid).relationships.should == @test_object.relationships
93
87
  end
94
88
 
@@ -100,16 +94,16 @@ describe ActiveFedora::RelsExtDatastream do
100
94
 
101
95
  it 'should populate the relationships hash based on data in solr only for any possible fedora predicates' do
102
96
  @test_object2 = MockAFRelsSolr.new
103
- @test_object2.new_object = true
97
+ #@test_object2.new_object = true
104
98
  @test_object2.save
105
99
  @test_object3 = MockAFRelsSolr.new
106
- @test_object3.new_object = true
100
+ #@test_object3.new_object = true
107
101
  @test_object3.save
108
102
  @test_object4 = MockAFRelsSolr.new
109
- @test_object4.new_object = true
103
+ #@test_object4.new_object = true
110
104
  @test_object4.save
111
105
  @test_object5 = MockAFRelsSolr.new
112
- @test_object5.new_object = true
106
+ #@test_object5.new_object = true
113
107
  @test_object5.save
114
108
  #append to named relationship 'testing'
115
109
  @test_object2.testing_append(@test_object3)
@@ -1,22 +1,8 @@
1
- require 'rubygems'
2
- gem 'mocha'
3
- require 'ruby-debug'
4
- require 'mocha'
5
- require 'active-fedora'
6
- require "equivalent-xml"
7
- begin
8
- require 'spec'
9
- rescue LoadError
10
- gem 'rspec'
11
- require 'spec'
12
- end
13
-
14
1
  ENV["RAILS_ENV"] ||= 'test'
15
- RAILS_ENV = ENV["RAILS_ENV"]
16
- logger.level = Logger::ERROR if logger.respond_to? :level ###MediaShelf StubLogger doesn't have a level= method
2
+ require 'active-fedora'
3
+ require 'spec'
17
4
 
18
5
  $:.unshift(File.dirname(__FILE__) + '/../lib')
19
- #Dir[File.join(File.dirname(__FILE__)+'/../lib/')+'**/*.rb'].each{|x| require x unless x.match(/railtie.rb$/)}
20
6
  $VERBOSE=nil
21
7
 
22
8
  # This loads the Fedora and Solr config info from /config/fedora.yml
@@ -27,19 +13,6 @@ Spec::Runner.configure do |config|
27
13
  config.mock_with :mocha
28
14
  end
29
15
 
30
- #TEST_FEDORA_URL = 'http://fedoraAdmin:fedoraAdmin@127.0.0.1:8080/fedora'
31
- #TEST_SOLR_URL = 'http://127.0.0.1:8080/solr'
32
- #Fedora::Repository.register(TEST_FEDORA_URL)
33
- #ActiveFedora::SolrService.register(TEST_SOLR_URL)
34
-
35
-
36
-
37
16
  def fixture(file)
38
17
  File.new(File.join(File.dirname(__FILE__), 'fixtures', file))
39
18
  end
40
-
41
- def validate_xml(xml, expected_root)
42
- root = REXML::Document.new(xml).root
43
- root.should_not be_nil
44
- root.name.should == expected_root
45
- end
@@ -51,11 +51,11 @@ describe ActiveFedora do
51
51
  ENV['environment']='test'
52
52
  end
53
53
 
54
- it "should raise an exception if none of the above are present" do
54
+ it "should be development if none of the above are present" do
55
55
  ENV['environment']=nil
56
56
  ENV['RAILS_ENV'] = nil
57
57
  ActiveFedora.expects(:config_options).at_least_once.returns({})
58
- lambda { ActiveFedora.environment }.should raise_exception
58
+ ActiveFedora.environment.should == 'development'
59
59
  ENV['environment']="test"
60
60
  end
61
61
  end
@@ -349,7 +349,7 @@ describe ActiveFedora do
349
349
  describe "outside of rails" do
350
350
  it "should load the default packaged config/fedora.yml file if no explicit config path is passed" do
351
351
  ActiveFedora.init()
352
- ActiveFedora.fedora.fedora_url.to_s.should == "http://fedoraAdmin:fedoraAdmin@127.0.0.1:8983/fedora"
352
+ ActiveFedora.fedora.options[:url].to_s.should == "http://127.0.0.1:8983/fedora"
353
353
  end
354
354
  it "should load the passed config if explicit config passed in as a string" do
355
355
  ActiveFedora.init('./spec/fixtures/rails_root/config/fedora.yml')
@@ -384,7 +384,7 @@ describe ActiveFedora do
384
384
 
385
385
  ActiveFedora.init(:fedora_config_path=>fedora_config_path,:solr_config_path=>solr_config_path)
386
386
  ActiveFedora.solr.class.should == ActiveFedora::SolrService
387
- ActiveFedora.fedora.class.should == Fedora::Repository
387
+ ActiveFedora.fedora.class.should == ActiveFedora::RubydoraConnection
388
388
  end
389
389
  end
390
390
 
@@ -415,7 +415,7 @@ describe ActiveFedora do
415
415
  ActiveFedora.expects(:fedora_config).at_least_once.returns({:url=>"http://megafedora:8983"})
416
416
  ActiveFedora.register_fedora_and_solr
417
417
  ActiveFedora.solr.conn.url.to_s.should eql("http://megasolr:8983")
418
- ActiveFedora.fedora.fedora_url.to_s.should eql("http://megafedora:8983")
418
+ ActiveFedora.fedora.options[:url].to_s.should eql("http://megafedora:8983")
419
419
  end
420
420
  end
421
421
  end
@@ -3,19 +3,12 @@ require File.join( File.dirname(__FILE__), "../spec_helper" )
3
3
  describe ActiveFedora::Base do
4
4
 
5
5
  before(:each) do
6
- Fedora::Repository.instance.stubs(:nextid).returns('_nextid_')
7
6
  @test_object = ActiveFedora::Base.new
8
7
  end
9
8
 
10
9
  describe '.save' do
11
10
 
12
11
  it "should add hasModel relationship that points to the CModel if @new_object" do
13
- @test_object.expects(:new_object?).returns(true)
14
-
15
- @test_object.expects(:add_relationship).with(:has_model, ActiveFedora::ContentModel.pid_from_ruby_class(@test_object.class))
16
- mock_repo = mock("repository")
17
- mock_repo.expects(:save).with(@test_object.inner_object)
18
- Fedora::Repository.stubs(:instance).returns(mock_repo)
19
12
  @test_object.stubs(:update_index)
20
13
  @test_object.expects(:refresh)
21
14
  @test_object.save
@@ -3,7 +3,7 @@ require File.join( File.dirname(__FILE__), "../spec_helper" )
3
3
  describe ActiveFedora::Base do
4
4
 
5
5
  before(:each) do
6
- Fedora::Repository.instance.expects(:nextid).returns("__nextid__")
6
+ ActiveFedora::RubydoraConnection.instance.expects(:nextid).returns("__nextid__")
7
7
  @test_object = ActiveFedora::Base.new
8
8
  #Fedora::Repository.instance.delete(@test_object.inner_object)
9
9
  end
@@ -30,82 +30,33 @@ describe ActiveFedora::Base do
30
30
  end
31
31
  describe '.add_datastream' do
32
32
  it "should not call Datastream.save" do
33
- ds = ActiveFedora::Datastream.new(:dsid => 'ds_to_add')
33
+ ds = ActiveFedora::Datastream.new(@test_object.inner_object, 'ds_to_add')
34
34
  ds.expects(:save).never
35
35
  @test_object.add_datastream(ds)
36
36
  end
37
37
  it "should add the datastream to the datastreams_in_memory array" do
38
- ds = ActiveFedora::Datastream.new(:dsID => 'ds_to_add')
38
+ ds = ActiveFedora::Datastream.new(@test_object.inner_object, 'ds_to_add')
39
39
  @test_object.datastreams.should_not have_key(ds.dsid)
40
40
  @test_object.add_datastream(ds)
41
- @test_object.datastreams_in_memory.should have_key(ds.dsid)
41
+ @test_object.datastreams.should have_key(ds.dsid)
42
42
  end
43
43
  it "should auto-assign dsids using auto-incremented integers if dsid is nil or an empty string" do
44
- ds = ActiveFedora::Datastream.new()
44
+ ds = ActiveFedora::Datastream.new(@test_object.inner_object, nil)
45
45
  ds.dsid.should == nil
46
- ds_emptystringid = ActiveFedora::Datastream.new()
47
- ds_emptystringid.dsid = ""
46
+ ds_emptystringid = ActiveFedora::Datastream.new(@test_object.inner_object, '')
48
47
  @test_object.expects(:generate_dsid).returns("foo").times(2)
49
- ds.expects(:dsid=).with("foo")
48
+ # ds.expects(:dsid=).with("foo")
50
49
  @test_object.add_datastream(ds)
51
50
  @test_object.add_datastream(ds_emptystringid)
52
51
  end
53
52
  it "should accept a prefix option and apply it to automatically assigned dsids" do
54
- ds = ActiveFedora::Datastream.new()
53
+ ds = ActiveFedora::Datastream.new(@test_object.inner_object, nil)
55
54
  ds.dsid.should == nil
56
55
  @test_object.expects(:generate_dsid).with("FOO")
57
56
  @test_object.add_datastream(ds, :prefix => "FOO")
58
57
  end
59
58
  end
60
59
 
61
- describe '.datastreams' do
62
- it "if the object is not new should call .datastreams_in_fedora and put the result into @datastreams" do
63
- @test_object.instance_variable_set(:@new_object, false)
64
- ivar_before = @test_object.instance_variable_get(:@datastreams).dup
65
- @test_object.expects(:datastreams_in_fedora).returns({:meh=>'feh'})
66
- datastreams = @test_object.datastreams
67
- @test_object.instance_variable_get(:@datastreams).values.should == ['feh']
68
- datastreams.values.should ==['feh']
69
- @test_object.instance_variable_get(:@datastreams).should_not equal(ivar_before)
70
- end
71
- end
72
-
73
- describe '.datastreams_in_memory' do
74
- it "should return the @datastreams array" do
75
- the_ivar = @test_object.instance_variable_set(:@datastreams, {})
76
- @test_object.datastreams_in_memory.should equal(the_ivar)
77
- end
78
- end
79
-
80
- describe '.datastreams_in_fedora' do
81
- it "should read the datastreams list from fedora" do
82
- @test_object.expects(:datastreams_xml).returns(Hash['datastream' => Hash[]])
83
- @test_object.datastreams_in_fedora
84
- end
85
- it "should pull the dsLabel if it is set" do
86
- @test_object.expects(:datastreams_xml).returns({"datastream"=>[
87
- {"label"=>"Dublin Core Record for this object", "dsid"=>"DC", "mimeType"=>"text/xml"},
88
- {"label"=>"", "dsid"=>"RELS-EXT", "mimeType"=>"text/xml"},
89
- {"label"=>"Sample Image", "dsid"=>"IMAGE1", "mimeType"=>"image/png"}]})
90
- result = @test_object.datastreams_in_fedora
91
- result["DC"].label.should == "Dublin Core Record for this object"
92
- result["RELS-EXT"].label.should == ""
93
- result["IMAGE1"].label.should == "Sample Image"
94
- end
95
-
96
- it "should pull the mimeType if it is set" do
97
- pending
98
- # Implementing this would require re-workign the initializer in Fedora::Datastream
99
- @test_object.expects(:datastreams_xml).returns({"datastream"=>[
100
- {"label"=>"Dublin Core Record for this object", "dsid"=>"DC", "mimeType"=>"text/xml"},
101
- {"label"=>"", "dsid"=>"RELS-EXT", "mimeType"=>"text/xml"},
102
- {"label"=>"Sample Image", "dsid"=>"IMAGE1", "mimeType"=>"image/png"}]})
103
- result = @test_object.datastreams_in_fedora
104
- result["DC"].attributes[:mimeType].should == "text/xml"
105
- result["RELS-EXT"].attributes[:mimeType].should == "text/xml"
106
- result["IMAGE1"].attributes[:mimeType].should == "image/png"
107
- end
108
- end
109
60
 
110
61
  describe 'add' do
111
62
  it "should call .add_datastream" do
@@ -114,14 +65,4 @@ describe ActiveFedora::Base do
114
65
  end
115
66
  end
116
67
 
117
- describe 'refresh' do
118
- it "should pull object attributes from Fedora then merge the contents of .datastreams_in_fedora and .datastreams_in_memory, giving preference to the ones in memory" do
119
- @test_object.stubs(:datastreams_in_fedora).returns({:foo => "foo", :bar => "bar in fedora"})
120
- @test_object.stubs(:datastreams_in_memory).returns({:baz => "baz", :bar => "bar in memory"})
121
- @test_object.inner_object.expects(:load_attributes_from_fedora)
122
- result = @test_object.refresh
123
- result.should == {:foo => "foo", :baz => "baz", :bar => "bar in memory"}
124
- @test_object.instance_variable_get(:@datastreams).should == result
125
- end
126
- end
127
68
  end