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
@@ -7,19 +7,20 @@ require 'ftools'
7
7
  describe ActiveFedora::Datastream do
8
8
 
9
9
  before(:each) do
10
- Fedora::Repository.instance.expects(:nextid).returns("foo")
11
10
  @test_object = ActiveFedora::Base.new
12
- @test_datastream = ActiveFedora::Datastream.new(:pid=>@test_object.pid, :dsid=>'abcd', :blob=>StringIO.new("hi there"))
11
+ @test_datastream = ActiveFedora::Datastream.new(@test_object.inner_object, 'abcd')
12
+ @test_datastream.content = 'hi there'
13
13
  end
14
14
 
15
15
  it "should provide #last_modified_in_repository" do
16
+ pending
16
17
  @test_datastream.should respond_to(:last_modified_in_repository)
17
18
  end
18
19
 
19
20
  it 'should update @last_modified when #save or #content is called' do
20
21
  pending
21
- Fedora::Repository.any_instance.stubs(:save)
22
- Fedora::Repository.any_instance.stubs(:fetch_custom)
22
+ # ActiveFedora::Repository.any_instance.stubs(:save)
23
+ # ActiveFedora::Repository.any_instance.stubs(:fetch_custom)
23
24
  @test_datastream.expects(:last_modified=).times(2)
24
25
  @test_datastream.expects(:last_modified_in_repository).times(3)
25
26
  @test_datastream.save
@@ -7,29 +7,10 @@ require 'ftools'
7
7
  describe ActiveFedora::Datastream do
8
8
 
9
9
  before(:each) do
10
- Fedora::Repository.instance.expects(:nextid).returns("foo")
11
10
  @test_object = ActiveFedora::Base.new
12
- @test_datastream = ActiveFedora::Datastream.new(:pid=>@test_object.pid, :dsid=>'abcd', :blob=>StringIO.new("hi there"))
13
- end
14
-
15
- it "should implement delete" do
16
- Fedora::Repository.instance.expects(:delete).with('foo/datastreams/abcd').returns(true).times(2)
17
- @test_datastream.delete.should == true
18
- ActiveFedora::Datastream.delete('foo', 'abcd').should == true
19
- end
20
-
21
- it "should set control_group" do
22
- xml=<<-EOF
23
- <?xml version="1.0" encoding="UTF-8"?>
24
- <foxml:datastream xmlns:foxml="foo" ID="Addelson_Frances19971114_FINAL.doc" STATE="A" CONTROL_GROUP="M" VERSIONABLE="true">
25
- <foxml:datastreamVersion ID="Addelson_Frances19971114_FINAL.doc.0" LABEL="Addelson_Frances19971114_FINAL.doc" CREATED="2008-11-19T18:18:46.631Z" MIMETYPE="application/msword">
26
- <foxml:contentLocation TYPE="INTERNAL_ID" REF="changeme:551+Addelson_Frances19971114_FINAL.doc+Addelson_Frances19971114_FINAL.doc.0"/>
27
- </foxml:datastreamVersion>
28
- </foxml:datastream>
29
- EOF
30
- n = ActiveFedora::Datastream.from_xml(ActiveFedora::Datastream.new, Nokogiri::XML::Document.parse(xml).root)
31
- n.control_group.should == 'M'
32
-
11
+ @test_datastream = ActiveFedora::Datastream.new(@test_object.inner_object, 'abcd')
12
+ #:pid=>@test_object.pid, :dsid=>'abcd', :blob=>StringIO.new("hi there"))
13
+ @test_datastream.content = "hi there"
33
14
  end
34
15
 
35
16
  it "should escape dots in to_param" do
@@ -45,7 +26,12 @@ describe ActiveFedora::Datastream do
45
26
 
46
27
  describe '#save' do
47
28
  it 'should call #before_save and #after_save' do
48
- Fedora::Repository.instance.stubs(:save)
29
+ @mock_repo = mock('repository')
30
+ @mock_repo.stubs(:add_datastream).with(:versionable => true, :pid => nil, :dsid => 'abcd', :controlGroup => 'M', :dsState => 'A', :content => 'hi there', :checksumType => 'DISABLED')
31
+ @mock_repo.expects(:datastream).with(:dsid => 'abcd', :pid => nil)
32
+ @test_object.inner_object.stubs(:repository).returns(@mock_repo)
33
+ @test_object.inner_object.stubs(:pid).returns(@pid)
34
+
49
35
  @test_datastream.stubs(:last_modified_in_repository)
50
36
  @test_datastream.expects(:before_save)
51
37
  @test_datastream.expects(:after_save)
@@ -53,21 +39,24 @@ describe ActiveFedora::Datastream do
53
39
  end
54
40
 
55
41
  it "should set @dirty to false" do
56
- Fedora::Repository.instance.stubs(:save)
57
- #@test_datastream.stubs(:last_modified_in_repository)
42
+ @mock_repo = mock('repository')
43
+ @mock_repo.stubs(:add_datastream).with(:versionable => true, :pid => @test_object.pid, :dsid => 'abcd', :controlGroup => 'M', :dsState => 'A', :content => 'hi there', :checksumType => 'DISABLED')
44
+ @mock_repo.expects(:datastream).with(:dsid => 'abcd', :pid => @test_object.pid)
45
+ @test_object.inner_object.stubs(:repository).returns(@mock_repo)
58
46
  @test_datastream.expects(:dirty=).with(false)
59
47
  @test_datastream.save
60
48
  end
61
49
  end
62
50
 
63
51
  describe '.content=' do
64
- it "should update the content and ng_xml, marking the datastream as dirty" do
52
+ it "should update the content and ng_xml, marking the datastream as changed" do
65
53
  sample_xml = "<foo><xmlelement/></foo>"
66
- @test_datastream.should_not be_dirty
67
- @test_datastream.blob.should_not be_equivalent_to(sample_xml)
54
+ @test_datastream.instance_variable_get(:@changed_attributes).clear
55
+ @test_datastream.should_not be_changed
56
+ @test_datastream.content.should_not be_equivalent_to(sample_xml)
68
57
  @test_datastream.content = sample_xml
69
- @test_datastream.should be_dirty
70
- @test_datastream.blob.should be_equivalent_to(sample_xml)
58
+ @test_datastream.should be_changed
59
+ @test_datastream.content.should be_equivalent_to(sample_xml)
71
60
  end
72
61
  end
73
62
 
@@ -79,18 +68,13 @@ describe ActiveFedora::Datastream do
79
68
  end
80
69
  end
81
70
 
82
- describe ".dsid=" do
83
- it "should set the datastream's dsid" do
84
- @test_datastream.dsid = "foodsid"
85
- @test_datastream.dsid.should == "foodsid"
86
- end
87
- end
88
-
89
- it "should have mime_type accessors and should allow you to pass :mime_type OR :mimeType as an argument to initialize block" do
90
- ds1 = ActiveFedora::Datastream.new(:mime_type=>"text/foo")
91
- ds1.mime_type.should == "text/foo"
92
- ds2 = ActiveFedora::Datastream.new(:mime_type=>"text/bar")
93
- ds2.mime_type.should == "text/bar"
71
+ it "should have mimeType accessors" do
72
+ ds1 = ActiveFedora::Datastream.new(nil, nil)#:mime_type=>"text/foo")
73
+ ds1.mimeType = "text/foo"
74
+ ds1.mimeType.should == "text/foo"
75
+ ds2 = ActiveFedora::Datastream.new(nil, nil)#:mime_type=>"text/bar")
76
+ ds2.mimeType = "text/bar"
77
+ ds2.mimeType.should == "text/bar"
94
78
  end
95
79
 
96
80
  describe ".size" do
@@ -119,17 +103,13 @@ describe ActiveFedora::Datastream do
119
103
  <dsChecksum>none</dsChecksum>
120
104
  </datastreamProfile>"
121
105
  EOS
122
- Fedora::Repository.instance.expects(:fetch_custom).with(@test_object.pid, "datastreams/#{@test_datastream.dsid}").returns(ds_profile)
123
- @test_datastream.expects(:new_object?).returns(false)
124
- @test_datastream.attributes.fetch(:dsSize,nil).should be_nil
106
+ @test_datastream.expects(:repository).returns(@mock_repo)
107
+ @mock_repo.expects(:datastream).with(:dsid => 'abcd', :pid => @test_object.pid).returns(ds_profile)
125
108
  @test_datastream.size.should == "9999"
126
- @test_datastream.attributes.fetch(:dsSize,nil).should_not be_nil
127
109
  end
128
110
 
129
111
  it "should default to an empty string if ds has not been saved" do
130
- @test_datastream.attributes.fetch(:dsSize,nil).should be_nil
131
112
  @test_datastream.size.should be_nil
132
- @test_datastream.attributes.fetch(:dsSize,nil).should be_nil
133
113
  end
134
114
  end
135
115
 
@@ -17,9 +17,11 @@ describe ActiveFedora::Associations::HasManyAssociation do
17
17
  end
18
18
 
19
19
  it "should build" do
20
+ class Foo; end
20
21
  @owner = stub(:new_record? => false)
21
22
  @assoc = ActiveFedora::Associations::HasManyAssociation.new(@owner, @reflection)
22
23
  @assoc.should respond_to :build
24
+ Object.send(:remove_const, :Foo)
23
25
 
24
26
  end
25
27
 
@@ -7,7 +7,7 @@ require 'active_fedora/qualified_dublin_core_datastream'
7
7
 
8
8
  describe ActiveFedora::Base do
9
9
  before(:each) do
10
- Fedora::Repository.instance.stubs(:nextid).returns("_nextid_")
10
+ #Fedora::Repository.instance.stubs(:nextid).returns("_nextid_")
11
11
  class Foo < ActiveFedora::Base
12
12
  has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"foostream" do|m|
13
13
  m.field "foostream", :string
@@ -25,11 +25,11 @@ describe ActiveFedora::Base do
25
25
 
26
26
  it "doesn't overwrite stream specs" do
27
27
  f = Foo.new
28
- f.datastreams.size.should == 2 #doesn't get dc until saved
29
- streams = f.datastreams.values.map(&:class).sort
30
- # streams.pop.name.should == "ActiveFedora::Datastream" #dc isn't here till saved
31
- streams.pop.name.should == "ActiveFedora::MetadataDatastream"
32
- streams.pop.name.should == "ActiveFedora::QualifiedDublinCoreDatastream"
28
+ f.datastreams.size.should == 3
29
+ streams = f.datastreams.values.map{|x| x.class.to_s}.sort
30
+ streams.pop.should == "ActiveFedora::RelsExtDatastream"
31
+ streams.pop.should == "ActiveFedora::QualifiedDublinCoreDatastream"
32
+ streams.pop.should == "ActiveFedora::MetadataDatastream"
33
33
  end
34
34
 
35
35
  it "should work for multiple types" do
@@ -18,7 +18,8 @@ describe ActiveFedora::MetadataDatastream do
18
18
  end
19
19
 
20
20
  before(:each) do
21
- @test_ds = ActiveFedora::MetadataDatastream.new
21
+ @test_object = ActiveFedora::Base.new
22
+ @test_ds = ActiveFedora::MetadataDatastream.new(@test_object.inner_object, 'mdDs')
22
23
  end
23
24
 
24
25
  after(:each) do
@@ -39,12 +40,6 @@ describe ActiveFedora::MetadataDatastream do
39
40
  it "should provide .save" do
40
41
  @test_ds.should respond_to(:save)
41
42
  end
42
- it "should persist the product of .to_xml in fedora" do
43
- Fedora::Repository.instance.expects(:save)
44
- @test_ds.expects(:to_xml).returns("fake xml")
45
- @test_ds.expects(:blob=).with("fake xml")
46
- @test_ds.save
47
- end
48
43
  end
49
44
 
50
45
  describe ".update_indexed_attributes" do
@@ -201,22 +196,11 @@ describe ActiveFedora::MetadataDatastream do
201
196
 
202
197
  end
203
198
 
204
- describe '.set_blob_for_save' do
205
- it "should provide .set_blob_for_save" do
206
- @test_ds.should respond_to(:set_blob_for_save)
207
- end
208
-
209
- it "should set the blob to to_xml" do
210
- @test_ds.expects(:blob=).with(@test_ds.to_xml)
211
- @test_ds.set_blob_for_save
212
- end
213
- end
214
-
215
199
  describe '#field' do
216
200
 
217
201
  before(:each) do
218
202
  class SpecDatastream < ActiveFedora::MetadataDatastream
219
- def initialize
203
+ def initialize(inner_object, dsid)
220
204
  super
221
205
  field :publisher, :string
222
206
  field :coverage, :text
@@ -232,7 +216,7 @@ describe ActiveFedora::MetadataDatastream do
232
216
  end
233
217
 
234
218
  it 'should add corresponding field to the @fields hash and set the field :type ' do
235
- sds = SpecDatastream.new
219
+ sds = SpecDatastream.new(nil, nil)
236
220
  sds.fields.should_not have_key(:bio)
237
221
  sds.field :bio, :text
238
222
  sds.fields.should have_key(:bio)
@@ -242,7 +226,7 @@ describe ActiveFedora::MetadataDatastream do
242
226
  end
243
227
 
244
228
  it "should insert custom element attrs into the xml stream" do
245
- sds = SpecDatastream.new
229
+ sds = SpecDatastream.new(nil, nil)
246
230
  sds.mycomplicated_field_values='foo'
247
231
  sds.fields[:mycomplicated_field][:element_attrs].should == {:foo=>:bar, :baz=>:bat}
248
232
  expected_xml = '<fields><mycomplicated_field baz=\'bat\' foo=\'bar\'>foo</mycomplicated_field></fields>'
@@ -250,7 +234,7 @@ describe ActiveFedora::MetadataDatastream do
250
234
  end
251
235
 
252
236
  it "should add getters and setters and appenders with field name" do
253
- local_test_ds = SpecDatastream.new
237
+ local_test_ds = SpecDatastream.new(nil, nil)
254
238
  local_test_ds.should respond_to(:publisher_values)
255
239
  local_test_ds.should respond_to(:publisher_append)
256
240
  local_test_ds.should respond_to(:publisher_values=)
@@ -267,8 +251,8 @@ describe ActiveFedora::MetadataDatastream do
267
251
  end
268
252
 
269
253
  it "should track field values at instance level, not at class level" do
270
- local_test_ds1 = SpecDatastream.new
271
- local_test_ds2 = SpecDatastream.new
254
+ local_test_ds1 = SpecDatastream.new(nil, nil)
255
+ local_test_ds2 = SpecDatastream.new(nil, nil)
272
256
  local_test_ds1.publisher_values = ["publisher1", "publisher2"]
273
257
  local_test_ds2.publisher_values = ["publisherA", "publisherB"]
274
258
 
@@ -277,19 +261,19 @@ describe ActiveFedora::MetadataDatastream do
277
261
  end
278
262
 
279
263
  it "should allow you to add field values using <<" do
280
- local_test_ds1 = SpecDatastream.new
264
+ local_test_ds1 = SpecDatastream.new(nil, nil)
281
265
  local_test_ds1.publisher_values << "publisher1"
282
266
  local_test_ds1.publisher_values.should == ["publisher1"]
283
267
  end
284
268
 
285
269
  it "should create setter that always turns non-arrays into arrays" do
286
- local_test_ds = SpecDatastream.new
270
+ local_test_ds = SpecDatastream.new(nil, nil)
287
271
  local_test_ds.publisher_values = "Foo"
288
272
  local_test_ds.publisher_values.should == ["Foo"]
289
273
  end
290
274
 
291
275
  it "should create setter that sets datastream.dirty? to true" do
292
- local_test_ds = SpecDatastream.new
276
+ local_test_ds = SpecDatastream.new(nil, nil)
293
277
  local_test_ds.should_not be_dirty
294
278
  local_test_ds.publisher_values = "Foo"
295
279
  local_test_ds.should be_dirty
@@ -303,7 +287,7 @@ describe ActiveFedora::MetadataDatastream do
303
287
  end
304
288
 
305
289
  it "should add any extra opts to the field hash" do
306
- local_test_ds = SpecDatastream.new
290
+ local_test_ds = SpecDatastream.new(nil, nil)
307
291
  local_test_ds.field "myfield", :string, :foo => "foo", :bar => "bar"
308
292
  local_test_ds.fields[:myfield].should have_key(:foo)
309
293
  local_test_ds.fields[:myfield][:foo].should == "foo"
@@ -19,7 +19,7 @@ describe ActiveFedora::Model do
19
19
  end
20
20
 
21
21
  before(:each) do
22
- Fedora::Repository.instance.stubs(:nextid).returns('_nextid_')
22
+ ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns('_nextid_')
23
23
  @test_instance = SpecModel::Basic.new
24
24
  @property = stub("myproperty", :name => "mock_prop", :instance_variable_name => "@mock_prop")
25
25
  SpecModel::Basic.extend(ActiveFedora::Model)
@@ -105,8 +105,8 @@ describe ActiveFedora::Model do
105
105
  mock_result.expects(:hits).returns([{"id" => "changeme:30"}, {"id" => "changeme:22"}])
106
106
  mock_solr.expects(:query).with('has_model_s:info\\:fedora/afmodel\\:SpecModel\:\:Basic', :rows=>1001).returns(mock_result)
107
107
  ActiveFedora::SolrService.expects(:instance).returns(mock("SolrService", :conn => mock_solr))
108
- Fedora::Repository.instance.expects(:find_model).with("changeme:30", SpecModel::Basic).returns("Fake Object1")
109
- Fedora::Repository.instance.expects(:find_model).with("changeme:22", SpecModel::Basic).returns("Fake Object2")
108
+ ActiveFedora::RubydoraConnection.instance.expects(:find_model).with("changeme:30", SpecModel::Basic).returns("Fake Object1")
109
+ ActiveFedora::RubydoraConnection.instance.expects(:find_model).with("changeme:22", SpecModel::Basic).returns("Fake Object2")
110
110
  SpecModel::Basic.find(:all, :rows=>1001).should == ["Fake Object1", "Fake Object2"]
111
111
  end
112
112
 
@@ -116,7 +116,7 @@ describe ActiveFedora::Model do
116
116
  mock_result.expects(:hits).returns([{"id" => "changeme:30"}])
117
117
  mock_solr.expects(:query).with('id:changeme\:30').returns(mock_result)
118
118
  ActiveFedora::SolrService.expects(:instance).returns(mock("SolrService", :conn => mock_solr))
119
- Fedora::Repository.instance.expects(:find_model).with("changeme:30", SpecModel::Basic).returns("Fake Object")
119
+ ActiveFedora::RubydoraConnection.instance.expects(:find_model).with("changeme:30", SpecModel::Basic).returns("Fake Object")
120
120
 
121
121
  SpecModel::Basic.find("changeme:30").should == "Fake Object"
122
122
  end
@@ -126,7 +126,7 @@ describe ActiveFedora::Model do
126
126
  mock_result = mock("MockResult")
127
127
  mock_result.expects(:hits).returns([{"id" => "changeme:30"}])
128
128
  mock_solr.expects(:query).with('id:changeme\:30').returns(mock_result)
129
- Fedora::Repository.instance.expects(:find_model).with("changeme:30", SpecModel::Basic).returns("fake object")
129
+ ActiveFedora::RubydoraConnection.instance.expects(:find_model).with("changeme:30", SpecModel::Basic).returns("fake object")
130
130
 
131
131
  ActiveFedora::SolrService.expects(:instance).returns(mock("SolrService", :conn => mock_solr))
132
132
 
@@ -136,15 +136,15 @@ describe ActiveFedora::Model do
136
136
  describe"(:pid => xxx)" do
137
137
  it "should pull the inner object from fedora if it already exists in fedora" do
138
138
  pending
139
- Fedora::Repository.instance.expects(:save).never
139
+ ActiveFedora::RubydoraConnection.instance.expects(:save).never
140
140
  mock_obj = mock("Fedora Object")
141
- Fedora::Repository.instance.expects(:find_objects).returns([mock_obj])
141
+ ActiveFedora::RubydoraConnection.instance.expects(:find_objects).returns([mock_obj])
142
142
  ActiveFedora::Base.new(:pid=>"test:1").inner_object.should equal(mock_obj)
143
143
  end
144
144
  it "should save the inner_object to fedora if it does not already exist" do
145
145
  pending
146
- Fedora::Repository.instance.expects(:save)
147
- Fedora::Repository.instance.expects(:find_objects).returns([])
146
+ ActiveFedora::RubydoraConnection.instance.expects(:save)
147
+ ActiveFedora::RubydoraConnection.instance.expects(:find_objects).returns([])
148
148
  ActiveFedora::Base.new(:pid=>"test:1")
149
149
  end
150
150
  end
@@ -179,7 +179,7 @@ describe ActiveFedora::Model do
179
179
  it "should use Repository.find_model to instantiate an object" do
180
180
  mock_repo = mock("repo")
181
181
  mock_repo.expects(:find_model).with("_PID_", SpecModel::Basic)
182
- Fedora::Repository.expects(:instance).returns(mock_repo)
182
+ ActiveFedora::RubydoraConnection.expects(:instance).returns(mock_repo)
183
183
  SpecModel::Basic.load_instance("_PID_")
184
184
  end
185
185
  end
@@ -15,7 +15,13 @@ describe ActiveFedora::NokogiriDatastream do
15
15
  end
16
16
 
17
17
  before(:each) do
18
- @test_ds = ActiveFedora::NokogiriDatastream.new(:blob=>"<test_xml/>")
18
+ mock_inner = mock('inner object')
19
+ @mock_repo = mock('repository')
20
+ @mock_repo.stubs(:datastream_dissemination=>'My Content')
21
+ mock_inner.stubs(:repository).returns(@mock_repo)
22
+ mock_inner.stubs(:pid)
23
+ @test_ds = ActiveFedora::NokogiriDatastream.new(mock_inner, "descMetadata")
24
+ @test_ds.content="<test_xml/>"
19
25
  end
20
26
 
21
27
  after(:each) do
@@ -31,12 +37,13 @@ describe ActiveFedora::NokogiriDatastream do
31
37
  @test_ds.ng_xml.should be_instance_of(Nokogiri::XML::Document)
32
38
  end
33
39
  it 'should load xml from blob if provided' do
34
- test_ds1 = ActiveFedora::NokogiriDatastream.new(:blob=>"<xml><foo/></xml>")
40
+ test_ds1 = ActiveFedora::NokogiriDatastream.new(nil, 'ds1')
41
+ test_ds1.content="<xml><foo/></xml>"
35
42
  test_ds1.ng_xml.to_xml.should == "<?xml version=\"1.0\"?>\n<xml>\n <foo/>\n</xml>\n"
36
43
  end
37
44
  it "should initialize from #xml_template if no xml is provided" do
38
45
  ActiveFedora::NokogiriDatastream.expects(:xml_template).returns("<fake template/>")
39
- ActiveFedora::NokogiriDatastream.new.ng_xml.should be_equivalent_to("<fake template/>")
46
+ ActiveFedora::NokogiriDatastream.new(nil, nil).ng_xml.should be_equivalent_to("<fake template/>")
40
47
  end
41
48
  end
42
49
 
@@ -49,7 +56,8 @@ describe ActiveFedora::NokogiriDatastream do
49
56
  describe ".update_indexed_attributes" do
50
57
 
51
58
  before(:each) do
52
- @mods_ds = Hydra::ModsArticleDatastream.new(:blob=>fixture(File.join("mods_articles","hydrangea_article1.xml")))
59
+ @mods_ds = Hydra::ModsArticleDatastream.new(nil, 'descMetadata')
60
+ @mods_ds.content=fixture(File.join("mods_articles","hydrangea_article1.xml")).read
53
61
  end
54
62
 
55
63
  it "should apply submitted hash to corresponding datastream field values" do
@@ -170,7 +178,8 @@ describe ActiveFedora::NokogiriDatastream do
170
178
  describe ".get_values" do
171
179
 
172
180
  before(:each) do
173
- @mods_ds = Hydra::ModsArticleDatastream.new(:blob=>fixture(File.join("mods_articles","hydrangea_article1.xml")))
181
+ @mods_ds = Hydra::ModsArticleDatastream.new(nil, 'modsDs')
182
+ @mods_ds.content=fixture(File.join("mods_articles","hydrangea_article1.xml")).read
174
183
  end
175
184
 
176
185
  it "should call lookup with field_name and return the text values from each resulting node" do
@@ -201,8 +210,9 @@ describe ActiveFedora::NokogiriDatastream do
201
210
  describe '#from_xml' do
202
211
  it "should work when a template datastream is passed in" do
203
212
  mods_xml = Nokogiri::XML::Document.parse( fixture(File.join("mods_articles", "hydrangea_article1.xml")) )
204
- tmpl = Hydra::ModsArticleDatastream.new
213
+ tmpl = Hydra::ModsArticleDatastream.new(nil, nil)
205
214
  Hydra::ModsArticleDatastream.from_xml(mods_xml,tmpl).ng_xml.root.to_xml.should == mods_xml.root.to_xml
215
+ tmpl.dirty?.should be_false
206
216
  end
207
217
  it "should work when foxml datastream xml is passed in" do
208
218
  pending "at least for now, just updated Base.deserialize to feed in the xml content rather than the foxml datstream xml. Possibly we can update MetadataDatstream to assume the same and leave it at that? -MZ 23-06-2010"
@@ -210,11 +220,6 @@ describe ActiveFedora::NokogiriDatastream do
210
220
  ds_xml = hydrangea_article_foxml.at_xpath("//foxml:datastream[@ID='descMetadata']")
211
221
  Hydra::ModsArticleDatastream.from_xml(ds_xml).ng_xml.to_xml.should == hydrangea_article_foxml.at_xpath("//foxml:datastream[@ID='descMetadata']/foxml:datastreamVersion[last()]/foxml:xmlContent").first_element_child.to_xml
212
222
  end
213
- it "should set @dirty to false" do
214
- hydrangea_article_foxml = Nokogiri::XML::Document.parse( fixture("hydrangea_fixture_mods_article1.foxml.xml") )
215
- ds_xml = hydrangea_article_foxml.at_xpath("//foxml:datastream[@ID='descMetadata']")
216
- Hydra::ModsArticleDatastream.from_xml(ds_xml).dirty?.should be_false
217
- end
218
223
  end
219
224
 
220
225
 
@@ -227,21 +232,22 @@ describe ActiveFedora::NokogiriDatastream do
227
232
  @test_ds.should respond_to(:save)
228
233
  end
229
234
  it "should persist the product of .to_xml in fedora" do
230
- Fedora::Repository.instance.expects(:save)
235
+ @test_ds.expects(:new?).returns(true)
236
+ @mock_repo.expects(:add_datastream).with(:pid => nil, :dsid => 'descMetadata', :checksumType => 'DISABLED', :versionable => true, :content => 'fake xml', :controlGroup => 'M', :dsState => 'A')
231
237
  @test_ds.expects(:to_xml).returns("fake xml")
232
- @test_ds.expects(:blob=).with("fake xml")
238
+ @test_ds.serialize!
233
239
  @test_ds.save
234
240
  end
235
241
  end
236
242
 
237
243
  describe '.content=' do
238
244
  it "should update the content and ng_xml, marking the datastream as dirty" do
239
- @test_ds.should_not be_dirty
240
- @test_ds.blob.should_not be_equivalent_to(@sample_raw_xml)
245
+ @test_ds.dirty = false # pretend it isn't dirty to show that content= does it
246
+ @test_ds.content.should_not be_equivalent_to(@sample_raw_xml)
241
247
  @test_ds.ng_xml.to_xml.should_not be_equivalent_to(@sample_raw_xml)
242
248
  @test_ds.content = @sample_raw_xml
243
249
  @test_ds.should be_dirty
244
- @test_ds.blob.should be_equivalent_to(@sample_raw_xml)
250
+ @test_ds.content.should be_equivalent_to(@sample_raw_xml)
245
251
  @test_ds.ng_xml.to_xml.should be_equivalent_to(@sample_raw_xml)
246
252
  end
247
253
  end
@@ -254,7 +260,7 @@ describe ActiveFedora::NokogiriDatastream do
254
260
  @test_ds.ng_xml.to_xml.should be_equivalent_to(@sample_raw_xml)
255
261
  end
256
262
  it "should mark the datastream as dirty" do
257
- @test_ds.should_not be_dirty
263
+ @test_ds.dirty = false # pretend it isn't dirty to show that content= does it
258
264
  @test_ds.ng_xml = @sample_raw_xml
259
265
  @test_ds.should be_dirty
260
266
  end
@@ -298,17 +304,6 @@ describe ActiveFedora::NokogiriDatastream do
298
304
 
299
305
  end
300
306
 
301
- describe '.set_blob_for_save' do
302
- it "should provide .set_blob_for_save" do
303
- @test_ds.should respond_to(:set_blob_for_save)
304
- end
305
-
306
- it "should set the blob to to_xml" do
307
- @test_ds.expects(:blob=).with(@test_ds.to_xml)
308
- @test_ds.set_blob_for_save
309
- end
310
- end
311
-
312
307
  describe '.from_solr' do
313
308
  it "should set the internal_solr_doc attribute to the solr document passed in" do
314
309
  @test_ds.from_solr(@solr_doc)
@@ -318,7 +313,8 @@ describe ActiveFedora::NokogiriDatastream do
318
313
 
319
314
  describe '.get_values_from_solr' do
320
315
  before(:each) do
321
- @mods_ds = ActiveFedora::NokogiriDatastream.new(:blob=>fixture(File.join("mods_articles","hydrangea_article1.xml")))
316
+ @mods_ds = ActiveFedora::NokogiriDatastream.new(nil, nil)
317
+ @mods_ds.content=fixture(File.join("mods_articles","hydrangea_article1.xml")).read
322
318
  end
323
319
 
324
320
  it "should return empty array if internal_solr_doc not set" do
@@ -373,7 +369,8 @@ describe ActiveFedora::NokogiriDatastream do
373
369
 
374
370
  describe '.update_values' do
375
371
  before(:each) do
376
- @mods_ds = ActiveFedora::NokogiriDatastream.new(:blob=>fixture(File.join("mods_articles","hydrangea_article1.xml")))
372
+ @mods_ds = ActiveFedora::NokogiriDatastream.new(nil, nil)
373
+ @mods_ds.content= fixture(File.join("mods_articles","hydrangea_article1.xml")).read
377
374
  end
378
375
 
379
376
  it "should throw an exception if we have initialized the internal_solr_doc." do
@@ -394,8 +391,8 @@ describe ActiveFedora::NokogiriDatastream do
394
391
  end
395
392
 
396
393
  it "should set @dirty to true" do
397
- mods_ds = Hydra::ModsArticleDatastream.new(:blob=>fixture(File.join("mods_articles","hydrangea_article1.xml")))
398
- mods_ds.dirty?.should be_false
394
+ mods_ds = Hydra::ModsArticleDatastream.new(nil, nil)
395
+ mods_ds.content=fixture(File.join("mods_articles","hydrangea_article1.xml")).read
399
396
  mods_ds.update_values([{":person"=>"0"}, "role", "text"]=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"})
400
397
  mods_ds.dirty?.should be_true
401
398
  end
@@ -404,7 +401,8 @@ describe ActiveFedora::NokogiriDatastream do
404
401
  describe '.term_values' do
405
402
 
406
403
  before(:each) do
407
- @mods_ds = ActiveFedora::NokogiriDatastream.new(:blob=>fixture(File.join("mods_articles","hydrangea_article1.xml")))
404
+ @mods_ds = ActiveFedora::NokogiriDatastream.new(nil, nil)
405
+ @mods_ds.content=fixture(File.join("mods_articles","hydrangea_article1.xml")).read
408
406
  end
409
407
 
410
408
  it "should call OM::XML::term_values if internal_solr_doc is not set and return values from xml" do