active-fedora 3.1.0.pre11 → 3.1.0.pre12

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,13 +17,6 @@ module ActiveFedora
17
17
 
18
18
  attr_accessor :internal_solr_doc
19
19
  attr_reader :ng_xml
20
-
21
- def initialize(digital_object, dsid)
22
- super
23
- self.class.from_xml(nil, self)
24
- end
25
-
26
-
27
20
 
28
21
  # Create an instance of this class based on xml content
29
22
  # @param [String, File, Nokogiri::XML::Node] xml the xml content to build from
@@ -64,7 +57,9 @@ module ActiveFedora
64
57
  end
65
58
 
66
59
 
67
- def to_xml(xml = self.ng_xml)
60
+ def to_xml(xml = nil)
61
+ ensure_xml_loaded
62
+ xml = self.ng_xml if xml.nil?
68
63
  ng_xml = self.ng_xml
69
64
  if ng_xml.respond_to?(:root) && ng_xml.root.nil? && self.class.respond_to?(:root_property_ref) && !self.class.root_property_ref.nil?
70
65
  ng_xml = self.class.generate(self.class.root_property_ref, "")
@@ -323,6 +318,12 @@ module ActiveFedora
323
318
  term_values(*field_key)
324
319
  end
325
320
 
321
+
322
+ def find_by_terms(*termpointer)
323
+ ensure_xml_loaded
324
+ super
325
+ end
326
+
326
327
  # Update values in the datastream's xml
327
328
  # This wraps {http://rdoc.info/gems/om/1.2.4/OM/XML/TermValueOperators#update_values-instance_method OM::TermValueOperators#update_values} so that returns an error if we have loaded from solr since datastreams loaded that way should be read-only
328
329
  #
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "3.1.0.pre11"
2
+ VERSION = "3.1.0.pre12"
3
3
  end
@@ -114,25 +114,6 @@ describe ActiveFedora::Base do
114
114
  @test_history.should be_kind_of(ActiveFedora::Base)
115
115
  end
116
116
 
117
- it "should reflect all of the metadata fields" do
118
- pending
119
- properties_ds = @test_history.datastreams["properties"]
120
- dublin_core_ds = @test_history.datastreams["dublin_core"]
121
-
122
- @properties_sample_values.each do |field, value|
123
- properties_ds.send("#{field.to_s}_values=",value)
124
- end
125
-
126
- @dublin_core_sample_values.each do |field, value|
127
- dublin_core_ds.send("#{field.to_s}_values=",[value])
128
- end
129
-
130
- @test_history.save
131
-
132
- retrieved_obj = OralHistory.find(@test_history.pid)
133
- retrieved_obj.inner_object.should_not be_new_object
134
-
135
- end
136
117
 
137
118
  it "should create proxies to all the datastreams" do
138
119
  properties_ds = @test_history.datastreams["properties"]
@@ -143,35 +124,6 @@ describe ActiveFedora::Base do
143
124
  OralHistory.new.should respond_to(:properties)
144
125
  end
145
126
 
146
- it "t1" do# should load all of the metadata fields from fedora xml" do
147
- pending
148
- properties_ds = @test_history.datastreams["properties"]
149
- dublin_core_ds = @test_history.datastreams["dublin_core"]
150
-
151
-
152
- @properties_sample_values.each do |field, value|
153
- properties_ds.send("#{field.to_s}_values=", [value])
154
- end
155
-
156
- @dublin_core_sample_values.each do |field, value|
157
- dublin_core_ds.send("#{field.to_s}_values=", [value])
158
- end
159
-
160
- @test_history.save
161
-
162
- @retrieved_history = OralHistory.find(@test_history.pid).first
163
- retrieved_properties_ds = @retrieved_history.datastreams["properties"]
164
- retrieved_dublin_core_ds = @retrieved_history.datastreams["dublin_core"]
165
- retrieved_properties_ds.should_not be_nil
166
- retrieved_dublin_core_ds.should_not be_nil
167
- @properties_sample_values.each do |field, value|
168
- retrieved_properties_ds.send("#{field.to_s}_values").should == [value]
169
- end
170
-
171
- @dublin_core_sample_values.each do |field, value|
172
- retrieved_dublin_core_ds.send("#{field.to_s}_values").should == [value]
173
- end
174
- end
175
127
 
176
128
  it "should push all of the metadata fields into solr" do
177
129
  # TODO: test must test values using solr symbol names (ie. _field, _text and _date)
@@ -1,6 +1,8 @@
1
1
  ENV["environment"] ||= 'test'
2
2
  require 'active-fedora'
3
3
  require 'spec'
4
+ require 'equivalent-xml/rspec_matchers'
5
+
4
6
 
5
7
  logger.level = Logger::WARN if logger.respond_to? :level ###MediaShelf StubLogger doesn't have a level= method
6
8
 
@@ -9,7 +9,6 @@ describe ActiveFedora::NokogiriDatastream do
9
9
  :mydate => {:values => "fake-date", :type => :date},
10
10
  :empty_field => {:values => {}}
11
11
  }
12
- @sample_xml = XmlSimple.xml_in("<fields><coverage>coverage1</coverage><coverage>coverage2</coverage><creation_date>fake-date</creation_date><mydate>fake-date</mydate><publisher>publisher1</publisher></fields>")
13
12
  @sample_raw_xml = "<foo><xmlelement/></foo>"
14
13
  @solr_doc = {"id"=>"hydrange_article1","name_role_roleTerm_t"=>["creator","submitter","teacher"],"name_0_role_t"=>"\r\ncreator\r\nsubmitter\r\n","name_1_role_t"=>"\r\n teacher \r\n","name_0_role_0_roleTerm_t"=>"creator","name_0_role_1_roleTerm_t"=>"submitter","name_1_role_0_roleTerm_t"=>["teacher"]}
15
14
  end
@@ -43,7 +42,10 @@ describe ActiveFedora::NokogiriDatastream do
43
42
  end
44
43
  it "should initialize from #xml_template if no xml is provided" do
45
44
  ActiveFedora::NokogiriDatastream.expects(:xml_template).returns("<fake template/>")
46
- ActiveFedora::NokogiriDatastream.new(nil, nil).ng_xml.should be_equivalent_to("<fake template/>")
45
+ n = ActiveFedora::NokogiriDatastream.new(nil, nil)
46
+ n.expects(:content).returns('')
47
+ n.ensure_xml_loaded
48
+ n.ng_xml.should be_equivalent_to("<fake template/>")
47
49
  end
48
50
  end
49
51
 
@@ -88,14 +90,6 @@ describe ActiveFedora::NokogiriDatastream do
88
90
 
89
91
  ### Examples copied over form metadata_datastream_spec
90
92
 
91
- # it "should support single-value arguments (as opposed to a hash of values with array indexes as keys)" do
92
- # # In other words, { "fubar"=>"dork" } should have the same effect as { "fubar"=>{"0"=>"dork"} }
93
- # pending "this should be working, but for some reason, the updates don't stick"
94
- # result = @test_ds.update_indexed_attributes( { "fubar"=>"dork" } )
95
- # result.should == {"fubar"=>{"0"=>"dork"}}
96
- # @test_ds.fubar_values.should == ["dork"]
97
- # end
98
- #
99
93
  it "should work for text fields" do
100
94
  pending if ENV['HUDSON_BUILD'] == 'true' # This test fails en suite in hudson
101
95
  att= {[{"person"=>"0"},"description"]=>{"-1"=>"mork", "1"=>"york"}}
@@ -113,43 +107,7 @@ describe ActiveFedora::NokogiriDatastream do
113
107
  result = @mods_ds.update_indexed_attributes [{"title_info"=>"0"},"main_title"]=>{"-1"=>"mork"}
114
108
  result.should == {"title_info_0_main_title"=>{"2"=>"mork"}}
115
109
  end
116
- #
117
- # it "should return accurate response when multiple values have been added in a single run" do
118
- # pending
119
- # att= {"swank"=>{"-1"=>"mork", "0"=>"york"}}
120
- # @test_ds.update_indexed_attributes(att).should == {"swank"=>{"0"=>"york", "1"=>"mork"}}
121
- # end
122
-
123
- # it "should deal gracefully with adding new values at explicitly declared indexes" do
124
- # @mods_ds.update_indexed_attributes([:journal, :title]=>["all", "for", "the"]
125
- # att = {"fubar"=>{"3"=>'glory'}}
126
- # result = @test_ds.update_indexed_attributes(att)
127
- # result.should == {"fubar"=>{"3"=>"glory"}}
128
- # @test_ds.fubar_values.should == ["all", "for", "the", "glory"]
129
- #
130
- # @test_ds.fubar_values = []
131
- # result = @test_ds.update_indexed_attributes(att)
132
- # result.should == {"fubar"=>{"0"=>"glory"}}
133
- # @test_ds.fubar_values.should == ["glory"]
134
- # end
135
- #
136
- # it "should allow deleting of values and should delete values so that to_xml does not return emtpy nodes" do
137
- # att= {[{"person"=>"0"},"description"]=>{"-1"=>"mork", "0"=>"york", "1"=>"mangle"}}
138
- # @mods_ds.update_indexed_attributes(att)
139
- # @mods_ds.fubar_values.should == ['mork', 'york', 'mangle']
140
- # rexml = REXML::Document.new(@test_ds.to_xml)
141
- # #puts rexml.root.elements.each {|el| el.to_s}
142
- # #puts rexml.root.elements.to_a.inspect
143
- # rexml.root.elements.to_a.length.should == 3
144
- # @mods_ds.update_indexed_attributes({[{"person"=>"0"},"description"]=>{"1"=>""}})
145
- # @mods_ds.fubar_values.should == ['mork', 'mangle']
146
- # rexml = REXML::Document.new(@test_ds.to_xml)
147
- # rexml.root.elements.to_a.length.should == 2
148
- # @mods_ds.update_indexed_attributes({[{"person"=>"0"},"description"]=>{"0"=>:delete}})
149
- # @mods_ds.fubar_values.should == ['mangle']
150
- # rexml = REXML::Document.new(@test_ds.to_xml)
151
- # rexml.root.elements.to_a.length.should == 1
152
- # end
110
+
153
111
  it "should allow deleting of values and should delete values so that to_xml does not return emtpy nodes" do
154
112
  pending if ENV['HUDSON_BUILD'] == 'true' # This test fails en suite in hudson
155
113
  att= {[{"person"=>"0"},"description"]=>{"0"=>"york", "1"=>"mangle","2"=>"mork"}}
@@ -191,20 +149,6 @@ describe ActiveFedora::NokogiriDatastream do
191
149
  @mods_ds.expects(:term_values).with("--my xpath--").returns(["abstract1", "abstract2"])
192
150
  @mods_ds.get_values("--my xpath--").should == ["abstract1", "abstract2"]
193
151
  end
194
- it "should assume field_names that are symbols or arrays are pointers to accessors declared in this datastreams model" do
195
- pending "This shouldn't be necessary -- OX::XML::PropertyValueOpertators.property_values deals with it internally..."
196
- ActiveFedora::NokogiriDatastream.expects(:accessor_xpath).with(:abstract).returns("--abstract xpath--")
197
- ActiveFedora::NokogiriDatastream.expects(:accessor_xpath).with(*[{:person=>1}]).returns("--person xpath--")
198
- ActiveFedora::NokogiriDatastream.expects(:accessor_xpath).with(*[{:person=>1},{:role=>1},:text]).returns("--person role text xpath--")
199
-
200
- @mods_ds.expects(:property_values).with("--abstract xpath--").returns(["abstract1", "abstract2"])
201
- @mods_ds.expects(:property_values).with("--person xpath--").returns(["person1", "person2"])
202
- @mods_ds.expects(:property_values).with("--person role text xpath--").returns(["text1"])
203
-
204
- @mods_ds.get_values(:abstract).should == ["abstract1", "abstract2"]
205
- @mods_ds.get_values([{:person=>1}]).should == ["person1", "person2"]
206
- @mods_ds.get_values([{:person=>1},{:role=>1},:text]).should == ["text1"]
207
- end
208
152
  end
209
153
 
210
154
  describe '#from_xml' do
@@ -214,12 +158,6 @@ describe ActiveFedora::NokogiriDatastream do
214
158
  Hydra::ModsArticleDatastream.from_xml(mods_xml,tmpl).ng_xml.root.to_xml.should == mods_xml.root.to_xml
215
159
  tmpl.dirty?.should be_false
216
160
  end
217
- it "should work when foxml datastream xml is passed in" do
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"
219
- hydrangea_article_foxml = Nokogiri::XML::Document.parse( fixture("hydrangea_fixture_mods_article1.foxml.xml") )
220
- ds_xml = hydrangea_article_foxml.at_xpath("//foxml:datastream[@ID='descMetadata']")
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
222
- end
223
161
  end
224
162
 
225
163
 
@@ -272,34 +210,29 @@ describe ActiveFedora::NokogiriDatastream do
272
210
  end
273
211
 
274
212
  it "should ng_xml.to_xml" do
275
- @test_ds.ng_xml.expects(:to_xml).returns("xml")
276
- @test_ds.to_xml.should == "xml"
213
+ @test_ds.expects(:ng_xml).returns(Nokogiri::XML::Document.parse("<text_document/>")).twice
214
+ @test_ds.to_xml.should == "<text_document/>\n"
277
215
  end
278
216
 
279
217
  it 'should accept an optional Nokogiri::XML Document as an argument and insert its fields into that (mocked test)' do
280
218
  doc = Nokogiri::XML::Document.parse("<test_document/>")
281
- doc.root.expects(:add_child).with(@test_ds.ng_xml.root)
219
+ doc.root.expects(:add_child)#.with(@test_ds.ng_xml.root)
282
220
  @test_ds.to_xml(doc)
283
221
  end
284
222
 
285
223
  it 'should accept an optional Nokogiri::XML Document as an argument and insert its fields into that (functional test)' do
286
- expected_result = XmlSimple.xml_in("<test_document><foo/><test_xml/></test_document>")
224
+ expected_result = "<test_document><foo/><test_xml/></test_document>"
287
225
  doc = Nokogiri::XML::Document.parse("<test_document><foo/></test_document>")
288
226
  result = @test_ds.to_xml(doc)
289
- XmlSimple.xml_in(doc.to_s).should == expected_result
290
- XmlSimple.xml_in(result).should == expected_result
227
+ doc.should be_equivalent_to expected_result
228
+ result.should be_equivalent_to expected_result
291
229
  end
292
230
 
293
231
  it 'should add to root of Nokogiri::XML::Documents, but add directly to the elements if a Nokogiri::XML::Node is passed in' do
294
- mock_new_node = mock("new node")
295
- mock_new_node.stubs(:to_xml).returns("foo")
296
-
297
232
  doc = Nokogiri::XML::Document.parse("<test_document/>")
298
233
  el = Nokogiri::XML::Node.new("test_element", Nokogiri::XML::Document.new)
299
- doc.root.expects(:add_child).with(@test_ds.ng_xml.root).returns(mock_new_node)
300
- el.expects(:add_child).with(@test_ds.ng_xml.root).returns(mock_new_node)
301
- @test_ds.to_xml(doc).should
302
- @test_ds.to_xml(el)
234
+ @test_ds.to_xml(doc).should be_equivalent_to "<test_document><test_xml/></test_document>"
235
+ @test_ds.to_xml(el).should be_equivalent_to "<test_element/>"
303
236
  end
304
237
 
305
238
  end
@@ -15,8 +15,8 @@ describe ActiveFedora::QualifiedDublinCoreDatastream do
15
15
 
16
16
  before(:each) do
17
17
  ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns("_nextid_")
18
- ActiveFedora::QualifiedDublinCoreDatastream.any_instance.expects(:content).at_least_once
19
18
  @test_ds = ActiveFedora::QualifiedDublinCoreDatastream.new(nil, nil)
19
+ @test_ds.stubs(:content).returns('')
20
20
 
21
21
  end
22
22
  it "from_xml should parse everything correctly" do
@@ -64,6 +64,7 @@ describe ActiveFedora::QualifiedDublinCoreDatastream do
64
64
  it "should have identity in and out" do
65
65
  sample = fixture('oh_qdc.xml')
66
66
  tmpl = OralHistorySampleModel.new.datastreams['dublin_core']
67
+ tmpl.expects(:content).returns('')
67
68
  x1 = Nokogiri::XML::Document.parse(sample).xpath('/wrapper/foxml:datastream/foxml:datastreamVersion/foxml:xmlContent/dc').first.to_xml
68
69
  z = ActiveFedora::QualifiedDublinCoreDatastream.from_xml(x1, tmpl)
69
70
  y = ActiveFedora::QualifiedDublinCoreDatastream.from_xml(z.to_dc_xml, tmpl)
@@ -72,6 +73,7 @@ describe ActiveFedora::QualifiedDublinCoreDatastream do
72
73
 
73
74
  it "should handle arbitrary attribs" do
74
75
  tmpl = OralHistorySampleModel.new.datastreams['dublin_core']
76
+ tmpl.expects(:content).returns('')
75
77
  tmpl.field :mycomplicated, :string, :xml_node=>'alt', :element_attrs=>{:foo=>'bar'}
76
78
  tmpl.mycomplicated_values='fubar'
77
79
  tmpl.to_dc_xml.should == '<dc xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\' xmlns:dcterms=\'http://purl.org/dc/terms/\'><dcterms:alt foo=\'bar\'>fubar</dcterms:alt></dc>'
@@ -83,7 +85,9 @@ describe ActiveFedora::QualifiedDublinCoreDatastream do
83
85
  it "should parse dcterms and dcelements from xml" do
84
86
  doc = Nokogiri::XML::Document.parse(File.open( File.dirname(__FILE__)+'/../fixtures/changeme155.xml') )
85
87
  stream = doc.xpath('//foxml:datastream[@ID=\'dublin_core\']/foxml:datastreamVersion/foxml:xmlContent/dc')
86
- n = ActiveFedora::QualifiedDublinCoreDatastream.from_xml(stream.to_xml, ActiveFedora::QualifiedDublinCoreDatastream.new(nil, nil))
88
+ ds = ActiveFedora::QualifiedDublinCoreDatastream.new(nil, nil)
89
+ ds.expects(:content).returns('')
90
+ n = ActiveFedora::QualifiedDublinCoreDatastream.from_xml(stream.to_xml, ds)
87
91
  n.spatial_values.should == ["Boston [7013445]", "Dorchester [7013575]", "Roxbury [7015002]"]
88
92
  n.title_values.should == ["Oral history with Frances Addelson, 1997 November 14"]
89
93
  n.dirty?.should == false
@@ -1,7 +1,5 @@
1
1
  require File.join( File.dirname(__FILE__), "../spec_helper" )
2
2
 
3
- require 'equivalent-xml'
4
-
5
3
  describe ActiveFedora::RelsExtDatastream do
6
4
 
7
5
  before(:all) do
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-fedora
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1923832015
4
+ hash: 1923832001
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 3
8
8
  - 1
9
9
  - 0
10
10
  - pre
11
- - 11
12
- version: 3.1.0.pre11
11
+ - 12
12
+ version: 3.1.0.pre12
13
13
  platform: ruby
14
14
  authors:
15
15
  - Matt Zumwalt