active-fedora 3.0.7 → 3.1.0.pre1

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.
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
@@ -5,16 +5,26 @@ describe ActiveFedora::Base do
5
5
  describe "first level delegation" do
6
6
  class BarStream2 < ActiveFedora::NokogiriDatastream
7
7
  set_terminology do |t|
8
- t.root(:path=>"first", :xmlns=>"urn:foobar")
9
- t.duck()
8
+ t.root(:path=>"animals", :xmlns=>"urn:zoobar")
9
+ t.waterfowl do
10
+ t.ducks do
11
+ t.duck
12
+ end
13
+ end
14
+ t.donkey()
10
15
  t.cow()
11
16
  end
12
17
 
13
18
  def self.xml_template
14
- Nokogiri::XML::Document.parse '<first xmlns="urn:foobar">
15
- <duck></duck>
19
+ Nokogiri::XML::Document.parse '<animals xmlns="urn:zoobar">
20
+ <waterfowl>
21
+ <ducks>
22
+ <duck/>
23
+ </ducks>
24
+ </waterfowl>
25
+ <donkey></donkey>
16
26
  <cow></cow>
17
- </first>'
27
+ </animals>'
18
28
  end
19
29
  end
20
30
 
@@ -33,8 +43,9 @@ describe ActiveFedora::Base do
33
43
 
34
44
  has_metadata :type=>BarStream2, :name=>"xmlish"
35
45
  delegate :fubar, :to=>'withText', :unique=>true
36
- delegate :duck, :to=>'xmlish', :unique=>true
46
+ delegate :donkey, :to=>'xmlish', :unique=>true
37
47
  delegate :cow, :to=>'xmlish'
48
+ delegate :duck, :to=>'xmlish', :at=>[:waterfowl, :ducks]
38
49
  end
39
50
  before :each do
40
51
  @n = BarHistory2.new(:pid=>"monkey:99")
@@ -43,9 +54,9 @@ describe ActiveFedora::Base do
43
54
  @n.fubar="Quack"
44
55
  @n.fubar.should == "Quack"
45
56
  @n.withText.get_values(:fubar).first.should == 'Quack'
46
- @n.duck="Quack"
47
- @n.duck.should == "Quack"
48
- @n.xmlish.term_values(:duck).first.should == 'Quack'
57
+ @n.donkey="Bray"
58
+ @n.donkey.should == "Bray"
59
+ @n.xmlish.term_values(:donkey).first.should == 'Bray'
49
60
  end
50
61
  it "should return an array if not marked as unique" do
51
62
  ### Metadata datastream does not appear to support multiple value setting
@@ -53,6 +64,12 @@ describe ActiveFedora::Base do
53
64
  @n.cow.should == ["one", "two"]
54
65
  end
55
66
 
67
+ it "should be able to delegate deeply into the terminology" do
68
+ pending
69
+ @n.duck=["Quack", "Peep"]
70
+ @n.duck.should == ["Quack", "Peep"]
71
+ end
72
+
56
73
  end
57
74
  end
58
75
 
@@ -6,9 +6,8 @@ require 'active_fedora/metadata_datastream'
6
6
  describe ActiveFedora::Base do
7
7
 
8
8
  before(:each) do
9
- Fedora::Repository.instance.expects(:nextid).returns("__nextid__")
9
+ ActiveFedora::RubydoraConnection.instance.expects(:nextid).returns("__nextid__")
10
10
  @test_object = ActiveFedora::Base.new
11
- #Fedora::Repository.instance.delete(@test_object.inner_object)
12
11
  end
13
12
 
14
13
  describe ".metadata_streams" do
@@ -100,7 +99,10 @@ describe ActiveFedora::Base do
100
99
  it "should delete object from repository and index" do
101
100
  @test_object.stubs(:pid).returns("foo")
102
101
  ActiveFedora::SolrService.instance.conn.expects(:delete).with("foo")
103
- Fedora::Repository.instance.stubs(:delete).with(@test_object.inner_object)
102
+ #@test_object.inner_object.stubs(:delete)
103
+ mock_repository = mock('repo')
104
+ @test_object.inner_object.expects(:repository).returns(mock_repository)
105
+ mock_repository.expects :purge_object
104
106
  @test_object.expects(:inbound_relationships).returns({})
105
107
  @test_object.delete
106
108
  end
@@ -5,7 +5,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
5
5
  describe ActiveFedora::Base do
6
6
 
7
7
  before(:each) do
8
- Fedora::Repository.stubs(:instance).returns(stub_everything())
9
8
  @base = ActiveFedora::Base.new
10
9
  @base.stubs(:create_date).returns("2008-07-02T05:09:42.015Z")
11
10
  @base.stubs(:modified_date).returns("2008-09-29T21:21:52.892Z")
@@ -81,27 +80,21 @@ describe ActiveFedora::Base do
81
80
 
82
81
  describe ".add_file_datastream" do
83
82
  it "should create a new datastream with the file as its content" do
84
- mock_file = mock("File")
85
- mock_ds = mock("Datastream")
86
- ActiveFedora::Datastream.expects(:new).with(:dsLabel => "", :controlGroup => 'M', :blob=>mock_file).returns(mock_ds)
83
+ mock_file = mock("File", :path=>'foo')
84
+ mock_ds = stub_everything("Datastream")
85
+ ActiveFedora::Datastream.expects(:new).with(@base.inner_object, 'DS1').returns(mock_ds)
87
86
  @base.expects(:add_datastream).with(mock_ds)
88
87
  @base.add_file_datastream(mock_file)
89
88
  end
90
- it "should apply filename argument to the datastream label if it is provided" do
91
- mock_file = mock("File")
92
- mock_ds = mock("Datastream")
93
- ActiveFedora::Datastream.expects(:new).with(:dsLabel => "My Label", :controlGroup => 'M', :blob=>mock_file).returns(mock_ds)
94
- @base.expects(:add_datastream).with(mock_ds)
95
- @base.add_file_datastream(mock_file, :label => "My Label")
96
- end
97
- it "should use :dsid if provided" do
98
- mock_file = mock("File")
99
- mock_ds = mock("Datastream")
100
- mock_ds.expects(:dsid=).with("__DSID__")
101
- ActiveFedora::Datastream.expects(:new).with(:dsLabel => "My Label", :controlGroup => 'M', :blob=>mock_file).returns(mock_ds)
89
+ it "should set :dsid and :label when supplied" do
90
+ mock_file = stub("File", :path=>'foo')
91
+ mock_ds = stub_everything("Datastream")
92
+ mock_ds.expects(:dsid=).with('__DSID__')
93
+ mock_ds.expects(:dsLabel=).with('My Label')
94
+ ActiveFedora::Datastream.expects(:new).with(@base.inner_object, 'DS1').returns(mock_ds)
102
95
  @base.expects(:add_datastream).with(mock_ds)
103
96
  @base.add_file_datastream(mock_file, :label => "My Label", :dsid => "__DSID__")
104
97
  end
105
98
 
106
99
  end
107
- end
100
+ end
@@ -12,9 +12,7 @@ describe ActiveFedora::Base do
12
12
  end
13
13
 
14
14
  before(:each) do
15
- Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
16
15
  @test_object = ActiveFedora::Base.new
17
- @test_object.new_object = true
18
16
  end
19
17
 
20
18
  after(:each) do
@@ -45,7 +43,6 @@ describe ActiveFedora::Base do
45
43
  end
46
44
 
47
45
  it 'should return an array of datastream names defined by has_datastream' do
48
- Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
49
46
  @test_object2 = MockDatastreamNames.new
50
47
  @test_object2.datastream_names.should == ["thumbnail","EAD"]
51
48
  end
@@ -64,7 +61,6 @@ describe ActiveFedora::Base do
64
61
  end
65
62
 
66
63
  it 'should add a named datastream to a fedora object' do
67
- Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
68
64
  @test_object2 = MockAddNamedDatastream.new
69
65
  f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
70
66
  f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
@@ -91,9 +87,9 @@ describe ActiveFedora::Base do
91
87
  @test_object2.add_named_datastream("thumbnail",{:content_type=>"image/jpeg",:file=>f})
92
88
  #check dslabel set from either opt[label] or opt[blob].original_file_name
93
89
  @test_object2.add_named_datastream("high",{:content_type=>"image/jpeg",:blob=>f2, :label=>"my_image"})
94
- @test_object2.high.first.attributes[:dsLabel].should == "my_image"
90
+ @test_object2.high.first.dsLabel.should == "my_image"
95
91
  @test_object2.add_named_datastream("high",{:content_type=>"image/jpeg",:blob=>f2})
96
- @test_object2.high.first.attributes[:dsLabel].should == "dino.jpg"
92
+ @test_object2.high.first.dsLabel.should == "dino.jpg"
97
93
  #check opt[content_type] must be set or opt[blob] responds to content_type, already checking if content_type option set above
98
94
  f.expects(:content_type).returns("image/jpeg")
99
95
  @test_object2.add_named_datastream("thumbnail",{:file=>f})
@@ -128,16 +124,15 @@ describe ActiveFedora::Base do
128
124
  end
129
125
  raise "Did not raise exception with dsid that does not conform to prefix" unless had_exception
130
126
  #if prefix not set check uses name in CAPS and dsid uses prefix
131
- @test_object2.high.first.attributes[:prefix].should == "HIGH"
127
+ #@test_object2.high.first.attributes[:prefix].should == "HIGH"
132
128
  @test_object2.high.first.dsid.match(/HIGH[0-9]/)
133
129
  #check datastreams added with other right properties
134
- @test_object2.high.first.attributes[:controlGroup].should == "M"
135
- @test_object2.high.first.attributes[:type].should == "ActiveFedora::Datastream"
130
+ @test_object2.high.first.controlGroup.should == "M"
136
131
 
137
132
  #check external datastream
138
133
  @test_object2.add_named_datastream("external",{:dsLocation=>"http://myreasource.com"})
139
134
  #check dslocation goes to dslabel
140
- @test_object2.external.first.attributes[:dsLabel].should == "http://myreasource.com"
135
+ @test_object2.external.first.dsLabel.should == "http://myreasource.com"
141
136
  #check datastreams added to fedora (may want to stub this at first)
142
137
 
143
138
  end
@@ -155,16 +150,21 @@ describe ActiveFedora::Base do
155
150
  end
156
151
 
157
152
  it 'should add a datastream as controlGroup M with blob set to file' do
158
- Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
159
153
  @test_object2 = MockAddNamedFileDatastream.new
160
154
  f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
161
155
  #these normally supplied in multi-part post request
162
156
  f.stubs(:original_filename).returns("minivan.jpg")
163
157
  f.stubs(:content_type).returns("image/jpeg")
164
158
  @test_object2.add_named_file_datastream("thumbnail",f)
165
- @test_object2.thumbnail.first.attributes.should == {:type=>"ActiveFedora::Datastream",
166
- :prefix=>"THUMB", :content_type=>"image/jpeg", :dsid=>"THUMB1", :dsID=>"THUMB1",
167
- :pid=>@test_object2.pid, :mimeType=>"image/jpeg", :controlGroup=>"M", :dsLabel=>"minivan.jpg", :name=>"thumbnail"}
159
+ thumb = @test_object2.thumbnail.first
160
+ thumb.class.should == ActiveFedora::Datastream
161
+ thumb.mimeType.should == "image/jpeg"
162
+ thumb.dsid.should == "THUMB1"
163
+ thumb.controlGroup.should == "M"
164
+ thumb.dsLabel.should == "minivan.jpg"
165
+ #thumb.name.should == "thumbnail"
166
+ # :prefix=>"THUMB", :content_type=>"image/jpeg", :dsid=>"THUMB1", :dsID=>"THUMB1",
167
+ # :pid=>@test_object2.pid, :mimeType=>"image/jpeg", :controlGroup=>"M", :dsLabel=>"minivan.jpg", :name=>"thumbnail"}
168
168
 
169
169
  end
170
170
  end
@@ -179,7 +179,6 @@ describe ActiveFedora::Base do
179
179
  end
180
180
 
181
181
  it 'should update a datastream and not increment the dsid' do
182
- Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
183
182
  @test_object2 = MockUpdateNamedDatastream.new
184
183
  f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
185
184
  f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
@@ -207,38 +206,39 @@ describe ActiveFedora::Base do
207
206
  #check datastream is updated in place without new dsid
208
207
  @test_object2.thumbnail.size.should == 1
209
208
  @test_object2.thumbnail_ids == ["THUMB1"]
210
- @test_object2.thumbnail.first.attributes.should == {:type=>"ActiveFedora::Datastream",
211
- :content_type=>"image/jpeg",
212
- :prefix=>"THUMB", :mimeType=>"image/jpeg",
213
- :controlGroup=>"M", :dsid=>"THUMB1",
214
- :pid=>@test_object2.pid, :dsID=>"THUMB1",
215
- :name=>"thumbnail", :dsLabel=>"minivan.jpg"}
216
- @test_object2.thumbnail.first.blob.should == f
209
+ thumb1 = @test_object2.thumbnail.first
210
+ thumb1.dsid.should == 'THUMB1'
211
+ thumb1.pid.should == @test_object2.pid
212
+ thumb1.dsLabel.should == 'minivan.jpg'
213
+ f.rewind
214
+ @test_object2.thumbnail.first.content.should == f.read
217
215
  @test_object2.update_named_datastream("thumbnail",{:file=>f2,:dsid=>"THUMB1"})
218
216
  @test_object2.thumbnail.size.should == 1
219
217
  @test_object2.thumbnail_ids == ["THUMB1"]
220
- @test_object2.thumbnail.first.attributes.should == {:type=>"ActiveFedora::Datastream",
221
- :content_type=>"image/jpeg",
222
- :prefix=>"THUMB", :mimeType=>"image/jpeg",
223
- :controlGroup=>"M", :dsid=>"THUMB1",
224
- :pid=>@test_object2.pid, :dsID=>"THUMB1",
225
- :name=>"thumbnail", :dsLabel=>"dino.jpg"}
226
- @test_object2.thumbnail.first.blob.should == f2
218
+ # @test_object2.thumbnail.first.attributes.should == {:type=>"ActiveFedora::Datastream",
219
+ # :content_type=>"image/jpeg",
220
+ # :prefix=>"THUMB", :mimeType=>"image/jpeg",
221
+ # :controlGroup=>"M", :dsid=>"THUMB1",
222
+ # :pid=>@test_object2.pid, :dsID=>"THUMB1",
223
+ # :name=>"thumbnail", :dsLabel=>"dino.jpg"}
224
+ thumb1 = @test_object2.thumbnail.first
225
+ thumb1.dsid.should == 'THUMB1'
226
+ thumb1.pid.should == @test_object2.pid
227
+ thumb1.dsLabel.should == 'dino.jpg'
228
+ f2.rewind
229
+ @test_object2.thumbnail.first.content.should == f2.read
227
230
  end
228
231
  end
229
232
 
230
- it 'should provide #create_datastream' do
231
- @test_object.should respond_to(:create_datastream)
232
- end
233
-
234
233
  describe '#create_datastream' do
235
234
  it 'should create a datastream object using the type of object supplied in the string (does reflection)' do
236
235
  f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
237
236
  f.stubs(:content_type).returns("image/jpeg")
238
237
  f.stubs(:original_filename).returns("minivan.jpg")
239
- ds = @test_object.create_datastream("ActiveFedora::Datastream",{:blob=>f})
238
+ ds = @test_object.create_datastream("ActiveFedora::Datastream", 'NAME', {:blob=>f})
240
239
  ds.class.should == ActiveFedora::Datastream
241
- ds.blob.should == f
240
+ ds.dsLabel.should == "minivan.jpg"
241
+ ds.mimeType.should == "image/jpeg"
242
242
  end
243
243
  end
244
244
 
@@ -252,7 +252,6 @@ describe ActiveFedora::Base do
252
252
  end
253
253
 
254
254
  it 'should return true if a named datastream exists in model' do
255
- Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
256
255
  @test_object2 = MockIsNamedDatastream.new
257
256
  @test_object2.is_named_datastream?("thumbnail").should == true
258
257
  @test_object2.is_named_datastream?("thumb").should == false
@@ -271,7 +270,6 @@ describe ActiveFedora::Base do
271
270
  end
272
271
 
273
272
  it 'should return a hash of datastream names to arrays of datastreams' do
274
- Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
275
273
  @test_object2 = MockNamedDatastreams.new
276
274
  f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg" ))
277
275
  f.stubs(:content_type).returns("image/jpeg")
@@ -288,102 +286,27 @@ describe ActiveFedora::Base do
288
286
  datastreams.keys.include?("high").should == true
289
287
  datastreams.keys.size.should == 3
290
288
  datastreams["thumbnail"].size.should == 1
291
- datastreams["thumbnail"].first.class.should == ActiveFedora::Datastream
292
- datastreams["thumbnail"].first.attributes.should == {:type=>"ActiveFedora::Datastream",
293
- :content_type=>"image/jpeg",
294
- :prefix=>"THUMB",
295
- :mimeType=>"image/jpeg",
296
- :controlGroup=>"M",
297
- :dsid=>"THUMB1",
298
- :pid=>@test_object2.pid,
299
- :dsID=>"THUMB1",
300
- :name=>"thumbnail", :dsLabel=>"minivan.jpg"}
301
- datastreams["thumbnail"].first.blob.should == f
289
+ datastreams["thumbnail"].first.dsid.should == 'THUMB1'
290
+ datastreams["thumbnail"].first.dsLabel.should == 'minivan.jpg'
291
+ datastreams["thumbnail"].first.controlGroup.should == "M"
292
+ f.rewind
293
+ datastreams["thumbnail"].first.content.should == f.read
294
+
302
295
  datastreams["external"].size.should == 1
303
- datastreams["external"].first.class.should == ActiveFedora::Datastream
304
- datastreams["external"].first.attributes.should == {:type=>"ActiveFedora::Datastream",
305
- :prefix=>"EXTERNAL",
306
- :controlGroup=>"E",
307
- :dsid=>"EXTERNAL1",
308
- :pid=>@test_object2.pid,
309
- :dsID=>"EXTERNAL1",
310
- :dsLocation=>"http://myresource.com",
311
- :name=>"external", :dsLabel=>"http://myresource.com"}
312
- datastreams["external"].first.blob.should == nil
296
+ datastreams["external"].first.dsid.should == "EXTERNAL1"
297
+ datastreams["external"].first.dsLocation.should == "http://myresource.com"
298
+ datastreams["external"].first.controlGroup.should == "E"
299
+ datastreams["external"].first.content.should == ""
300
+
313
301
  datastreams["high"].size.should == 1
314
- datastreams["high"].first.class.should == ActiveFedora::Datastream
315
- datastreams["high"].first.attributes.should == {:type=>"ActiveFedora::Datastream",
316
- :content_type=>"image/jpeg",
317
- :prefix=>"HIGH",
318
- :mimeType=>"image/jpeg",
319
- :controlGroup=>"M",
320
- :dsid=>"HIGH1",
321
- :pid=>@test_object2.pid,
322
- :dsID=>"HIGH1",
323
- :name=>"high", :dsLabel=>"dino.jpg"}
324
- datastreams["high"].first.blob.should == f2
302
+ datastreams["high"].first.dsLabel.should == 'dino.jpg'
303
+ datastreams["high"].first.controlGroup.should == "M"
304
+ datastreams["high"].first.dsid.should == "HIGH1"
305
+ f2.rewind
306
+ datastreams["high"].first.content.should == f2.read
325
307
  end
326
308
  end
327
309
 
328
- it 'should provide #named_datastreams_attributes' do
329
- @test_object.should respond_to(:named_datastreams_attributes)
330
- end
331
-
332
- describe '#named_datastreams_attributes' do
333
- class MockNamedDatastreamsAttributes < ActiveFedora::Base
334
- has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
335
- has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
336
- has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
337
- end
338
-
339
- it 'should return a hash of datastream names to hash of dsid to attribute hashes' do
340
- Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
341
- @test_object2 = MockNamedDatastreamsAttributes.new
342
- f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg" ))
343
- f.stubs(:content_type).returns("image/jpeg")
344
- f.stubs(:original_filename).returns("minivan.jpg")
345
- f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
346
- f2.stubs(:content_type).returns("image/jpeg")
347
- f2.stubs(:original_filename).returns("dino.jpg")
348
- @test_object2.thumbnail_file_append(f)
349
- @test_object2.high_file_append(f2)
350
- @test_object2.external_append({:dsLocation=>"http://myresource.com"})
351
- datastreams_attr = @test_object2.named_datastreams_attributes
352
- datastreams_attr.keys.include?("thumbnail").should == true
353
- datastreams_attr.keys.include?("external").should == true
354
- datastreams_attr.keys.include?("high").should == true
355
- datastreams_attr.keys.size.should == 3
356
- datastreams_attr["thumbnail"].size.should == 1
357
- datastreams_attr["thumbnail"]["THUMB1"].should == {:type=>"ActiveFedora::Datastream",
358
- :content_type=>"image/jpeg",
359
- :prefix=>"THUMB",
360
- :mimeType=>"image/jpeg",
361
- :controlGroup=>"M",
362
- :dsid=>"THUMB1",
363
- :pid=>@test_object2.pid,
364
- :dsID=>"THUMB1",
365
- :name=>"thumbnail", :dsLabel=>"minivan.jpg"}
366
- datastreams_attr["external"].size.should == 1
367
- datastreams_attr["external"]["EXTERNAL1"].should == {:type=>"ActiveFedora::Datastream",
368
- :prefix=>"EXTERNAL",
369
- :controlGroup=>"E",
370
- :dsid=>"EXTERNAL1",
371
- :pid=>@test_object2.pid,
372
- :dsID=>"EXTERNAL1",
373
- :dsLocation=>"http://myresource.com",
374
- :name=>"external", :dsLabel=>"http://myresource.com"}
375
- datastreams_attr["high"].size.should == 1
376
- datastreams_attr["high"]["HIGH1"].should == {:type=>"ActiveFedora::Datastream",
377
- :content_type=>"image/jpeg",
378
- :prefix=>"HIGH",
379
- :mimeType=>"image/jpeg",
380
- :controlGroup=>"M",
381
- :dsid=>"HIGH1",
382
- :pid=>@test_object2.pid,
383
- :dsID=>"HIGH1",
384
- :name=>"high", :dsLabel=>"dino.jpg"}
385
- end
386
- end
387
310
 
388
311
  it 'should provide #named_datastreams_ids' do
389
312
  @test_object.should respond_to(:named_datastreams_ids)
@@ -397,7 +320,6 @@ describe ActiveFedora::Base do
397
320
  end
398
321
 
399
322
  it 'should provide a hash of datastreams names to array of datastream ids' do
400
- Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
401
323
  @test_object2 = MockNamedDatastreamsIds.new
402
324
  f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg" ))
403
325
  f.stubs(:content_type).returns("image/jpeg")
@@ -412,59 +334,6 @@ describe ActiveFedora::Base do
412
334
  end
413
335
  end
414
336
 
415
- it 'should provide #datastreams_attributes' do
416
- @test_object.should respond_to(:datastreams_attributes)
417
- end
418
-
419
- describe '#datastreams_attributes' do
420
- class MockDatastreamsAttributes < ActiveFedora::Base
421
- has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
422
- has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
423
- has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
424
- end
425
-
426
- it 'should return a hash of datastream ids to an attribute hash' do
427
- Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
428
- @test_object2 = MockDatastreamsAttributes.new
429
- f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg" ))
430
- f.stubs(:content_type).returns("image/jpeg")
431
- f.stubs(:original_filename).returns("minivan.jpg")
432
- f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
433
- f2.stubs(:content_type).returns("image/jpeg")
434
- f2.stubs(:original_filename).returns("dino.jpg")
435
- @test_object2.thumbnail_file_append(f)
436
- @test_object2.high_file_append(f2)
437
- @test_object2.external_append({:dsLocation=>"http://myresource.com"})
438
- datastreams_attr = @test_object2.datastreams_attributes
439
- datastreams_attr.should == {"THUMB1"=>{:type=>"ActiveFedora::Datastream",
440
- :content_type=>"image/jpeg",
441
- :prefix=>"THUMB",
442
- :mimeType=>"image/jpeg",
443
- :controlGroup=>"M",
444
- :dsid=>"THUMB1",
445
- :pid=>@test_object2.pid,
446
- :dsID=>"THUMB1",
447
- :name=>"thumbnail", :dsLabel=>"minivan.jpg"},
448
- "EXTERNAL1"=>{:type=>"ActiveFedora::Datastream",
449
- :prefix=>"EXTERNAL",
450
- :controlGroup=>"E",
451
- :dsid=>"EXTERNAL1",
452
- :pid=>@test_object2.pid,
453
- :dsID=>"EXTERNAL1",
454
- :dsLocation=>"http://myresource.com",
455
- :name=>"external", :dsLabel=>"http://myresource.com"},
456
- "HIGH1"=>{:type=>"ActiveFedora::Datastream",
457
- :content_type=>"image/jpeg",
458
- :prefix=>"HIGH",
459
- :mimeType=>"image/jpeg",
460
- :controlGroup=>"M",
461
- :dsid=>"HIGH1",
462
- :pid=>@test_object2.pid,
463
- :dsID=>"HIGH1",
464
- :name=>"high", :dsLabel=>"dino.jpg"}}
465
- end
466
- end
467
-
468
337
  #
469
338
  # Class level methods
470
339
  #
@@ -476,7 +345,6 @@ describe ActiveFedora::Base do
476
345
 
477
346
  it 'should intialize a value to an empty hash and then not modify afterward' do
478
347
  @test_object.named_datastreams_desc.should == {}
479
- Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
480
348
  @test_object2 = MockNamedDatastreamsDesc.new
481
349
  @test_object2.named_datastreams_desc.should == {"thumbnail"=>{:name=>"thumbnail",:prefix => "THUMB",
482
350
  :type=>"ActiveFedora::Datastream", :mimeType=>"image/jpeg",
@@ -491,7 +359,6 @@ describe ActiveFedora::Base do
491
359
  end
492
360
 
493
361
  it 'should create helper methods to get named datastreams or dsids' do
494
- Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
495
362
  @test_object2 = MockCreateNamedDatastreamFinder.new
496
363
  @test_object2.should respond_to(:thumbnail)
497
364
  @test_object2.should respond_to(:thumbnail_ids)
@@ -504,9 +371,15 @@ describe ActiveFedora::Base do
504
371
  @test_object2.add_named_datastream("thumbnail",{:content_type=>"image/jpeg",:blob=>f, :label=>"testDS"})
505
372
  @test_object2.add_named_datastream("high",{:content_type=>"image/jpeg",:blob=>f2})
506
373
  @test_object2.add_named_datastream("high",{:content_type=>"image/jpeg",:blob=>f2})
507
- @test_object2.thumbnail.first.attributes.should == {:type=>"ActiveFedora::Datastream",
508
- :prefix=>"THUMB", :content_type=>"image/jpeg", :dsid=>"THUMB1", :dsID=>"THUMB1",
509
- :pid=>@test_object2.pid, :mimeType=>"image/jpeg", :controlGroup=>"M", :dsLabel=>"testDS", :name=>"thumbnail", :label=>"testDS"}
374
+ t2_thumb1 = @test_object2.thumbnail.first
375
+ t2_thumb1.mimeType.should == "image/jpeg"
376
+ t2_thumb1.controlGroup.should == "M"
377
+ t2_thumb1.dsLabel.should == "testDS"
378
+ t2_thumb1.pid.should == @test_object2.pid
379
+ t2_thumb1.dsid.should == "THUMB1"
380
+ # :type=>"ActiveFedora::Datastream",
381
+ # :prefix=>"THUMB", :content_type=>"image/jpeg", :dsid=>"THUMB1", :dsID=>"THUMB1",
382
+ # :pid=>@test_object2.pid, :mimeType=>"image/jpeg", :controlGroup=>"M", :dsLabel=>"testDS", :name=>"thumbnail", :label=>"testDS"}
510
383
  @test_object2.thumbnail_ids.should == ["THUMB1"]
511
384
  @test_object2.high_ids.include?("HIGH1") == true
512
385
  @test_object2.high_ids.include?("HIGH2") == true
@@ -524,9 +397,7 @@ describe ActiveFedora::Base do
524
397
  end
525
398
 
526
399
  it 'should create append method for each has_datastream entry' do
527
- Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
528
400
  @test_object2 = MockCreateNamedDatastreamUpdateMethods.new
529
- Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
530
401
  @test_object3 = MockCreateNamedDatastreamUpdateMethods.new
531
402
  @test_object2.should respond_to(:thumbnail_append)
532
403
  @test_object2.should respond_to(:ead_append)
@@ -534,17 +405,24 @@ describe ActiveFedora::Base do
534
405
  f.stubs(:content_type).returns("image/jpeg")
535
406
  f.stubs(:original_filename).returns("minivan.jpg")
536
407
  @test_object2.thumbnail_file_append(f)
537
- @test_object2.thumbnail.first.attributes.should == {:type=>"ActiveFedora::Datastream",
538
- :prefix=>"THUMB", :content_type=>"image/jpeg", :dsid=>"THUMB1", :dsID=>"THUMB1",
539
- :pid=>@test_object2.pid, :mimeType=>"image/jpeg", :controlGroup=>"M", :dsLabel=>"minivan.jpg", :name=>"thumbnail"}
408
+ t2_thumb1 = @test_object2.thumbnail.first
409
+ t2_thumb1.mimeType.should == "image/jpeg"
410
+ t2_thumb1.dsLabel.should == "minivan.jpg"
411
+ t2_thumb1.pid.should == @test_object2.pid
412
+ t2_thumb1.dsid.should == "THUMB1"
540
413
  @test_object3.thumbnail_append({:file=>f})
541
- @test_object3.thumbnail.first.attributes.should == {:type=>"ActiveFedora::Datastream",
542
- :prefix=>"THUMB", :content_type=>"image/jpeg", :dsid=>"THUMB1", :dsID=>"THUMB1",
543
- :pid=>@test_object3.pid, :mimeType=>"image/jpeg", :controlGroup=>"M", :dsLabel=>"minivan.jpg", :name=>"thumbnail"}
414
+ t3_thumb1 = @test_object3.thumbnail.first
415
+ t3_thumb1.mimeType.should == "image/jpeg"
416
+ t3_thumb1.dsLabel.should == "minivan.jpg"
417
+ t3_thumb1.pid.should == @test_object3.pid
418
+ t3_thumb1.dsid.should == "THUMB1"
544
419
  @test_object3.external_append({:dsLocation=>"http://myresource.com"})
545
- @test_object3.external.first.attributes.should == {:type=>"ActiveFedora::Datastream",
546
- :prefix=>"EXTERNAL", :dsid=>"EXTERNAL1", :dsID=>"EXTERNAL1",
547
- :pid=>@test_object3.pid, :controlGroup=>"E", :dsLabel=>"http://myresource.com", :dsLocation=>"http://myresource.com", :name=>"external"}
420
+ t3_external1 = @test_object3.external.first
421
+ t3_external1.dsLabel.should == "http://myresource.com"
422
+ t3_external1.dsLocation.should == "http://myresource.com"
423
+ t3_external1.pid.should == @test_object3.pid
424
+ t3_external1.dsid.should == "EXTERNAL1"
425
+ t3_external1.controlGroup == 'E'
548
426
  end
549
427
  end
550
428
 
@@ -556,7 +434,6 @@ describe ActiveFedora::Base do
556
434
  end
557
435
 
558
436
  it 'should cache a definition of named datastream and create helper methods to add/remove/access them' do
559
- Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
560
437
  @test_object2 = MockHasDatastream.new
561
438
  #prefix should default to name in caps if not specified in has_datastream call
562
439
  @test_object2.named_datastreams_desc.should == {"thumbnail"=>{:name=>"thumbnail",:prefix => "THUMB",