active-fedora 5.0.0.rc3 → 5.0.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,7 @@ require 'active-fedora'
4
4
  require "rexml/document"
5
5
 
6
6
  class MockMetaHelperSolr < ActiveFedora::Base
7
- has_metadata :name => "properties", :type => ActiveFedora::MetadataDatastream do |m|
7
+ has_metadata :name => "properties", :type => ActiveFedora::SimpleDatastream do |m|
8
8
  m.field "holding_id", :string
9
9
  end
10
10
 
@@ -54,13 +54,4 @@ describe ActiveFedora::Base do
54
54
  @test_object.add_datastream(ds, :prefix => "FOO")
55
55
  end
56
56
  end
57
-
58
-
59
- describe 'add' do
60
- it "should call .add_datastream" do
61
- @test_object.expects(:add_datastream)
62
- @test_object.add(stub("datastream").stub_everything)
63
- end
64
- end
65
-
66
57
  end
@@ -13,14 +13,14 @@ describe ActiveFedora::Base do
13
13
  mock_mds1 = mock("metadata ds1")
14
14
  mock_mds2 = mock("metadata ds2")
15
15
  mock_fds = mock("file ds")
16
- mock_fds.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(false)
16
+ mock_fds.expects(:kind_of?).with(ActiveFedora::RDFDatastream).returns(false)
17
17
  mock_ngds = mock("nokogiri ds")
18
- mock_ngds.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(false)
18
+ mock_ngds.expects(:kind_of?).with(ActiveFedora::RDFDatastream).returns(false)
19
19
  mock_ngds.expects(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(true)
20
20
 
21
21
 
22
22
  [mock_mds1,mock_mds2].each do |ds|
23
- ds.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(false)
23
+ ds.expects(:kind_of?).with(ActiveFedora::RDFDatastream).returns(false)
24
24
  ds.expects(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(true)
25
25
  end
26
26
  mock_fds.stubs(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(false)
@@ -35,43 +35,6 @@ describe ActiveFedora::Base do
35
35
  end
36
36
  end
37
37
 
38
- describe ".file_streams" do
39
- #TODO move to datastreams_spec
40
- it "should return all of the datastreams from the object that are kinds of SimpleDatastreams" do
41
- mock_fds1 = mock("file ds", :dsid => "file1")
42
- mock_fds1.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(false)
43
- mock_fds1.expects(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(false)
44
- mock_fds2 = mock("file ds", :dsid => "file2")
45
- mock_fds2.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(false)
46
- mock_fds2.expects(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(false)
47
- mock_mds = mock("metadata ds")
48
- mock_mds.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(false)
49
- mock_mds.expects(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(true)
50
- @test_object.expects(:datastreams).returns({:foo => mock_fds1, :bar=> mock_fds2, :baz => mock_mds})
51
-
52
- result = @test_object.file_streams
53
- result.length.should == 2
54
- result.should include(mock_fds1)
55
- result.should include(mock_fds2)
56
-
57
- end
58
- it "should skip DC and RELS-EXT datastreams" do
59
- mock_fds1 = mock("file ds", :dsid => "foo")
60
- mock_fds1.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(false)
61
- mock_fds1.expects(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(false)
62
- dc = mock("DC")
63
- dc.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(false)
64
- dc.expects(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(true)
65
- rels_ext = mock("RELS-EXT")
66
- rels_ext.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(false)
67
- rels_ext.expects(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(true)
68
- @test_object.expects(:datastreams).returns({:foo => mock_fds1, :dc => dc, :rels_ext => rels_ext})
69
-
70
- result = @test_object.file_streams
71
- result.length.should == 1
72
- result.should include(mock_fds1)
73
- end
74
- end
75
38
 
76
39
  describe ".update_index" do
77
40
  before do
@@ -207,37 +207,6 @@ describe ActiveFedora::Base do
207
207
  end
208
208
  end
209
209
 
210
-
211
-
212
- describe ".fields" do
213
- it "should provide fields" do
214
- @test_object.should respond_to(:fields)
215
- end
216
- it "should add pid, system_create_date and system_modified_date from object attributes" do
217
- cdate = "2008-07-02T05:09:42.015Z"
218
- mdate = "2009-07-07T23:37:18.991Z"
219
- @test_object.expects(:create_date).returns(cdate)
220
- @test_object.expects(:modified_date).returns(mdate)
221
- fields = @test_object.fields
222
- fields[:system_create_date][:values].should eql([cdate])
223
- fields[:system_modified_date][:values].should eql([mdate])
224
- fields[:id][:values].should eql([@test_object.pid])
225
- end
226
-
227
- it "should add self.class as the :active_fedora_model" do
228
- fields = @test_object.fields
229
- fields[:active_fedora_model][:values].should eql([@test_object.class.inspect])
230
- end
231
-
232
- it "should call .fields on all SimpleDatastreams and return the resulting document" do
233
- mock1 = mock("ds1", :fields => {}, :class=>ActiveFedora::SimpleDatastream)
234
- mock2 = mock("ds2", :fields => {}, :class=>ActiveFedora::SimpleDatastream)
235
-
236
- @test_object.expects(:datastreams).returns({:ds1 => mock1, :ds2 => mock2})
237
- @test_object.fields
238
- end
239
- end
240
-
241
210
  it 'should provide #find' do
242
211
  ActiveFedora::Base.should respond_to(:find)
243
212
  end
@@ -534,30 +503,6 @@ describe ActiveFedora::Base do
534
503
  end
535
504
  end
536
505
 
537
- describe ".to_xml" do
538
- it "should provide .to_xml" do
539
- @test_object.should respond_to(:to_xml)
540
- end
541
-
542
- it "should add pid, system_create_date and system_modified_date from object attributes" do
543
- @test_object.expects(:create_date).returns("2012-03-06T03:12:02Z")
544
- @test_object.expects(:modified_date).returns("2012-03-07T03:12:02Z")
545
- solr_doc = @test_object.to_solr
546
- solr_doc["system_create_dt"].should eql("2012-03-06T03:12:02Z")
547
- solr_doc["system_modified_dt"].should eql("2012-03-07T03:12:02Z")
548
- solr_doc[:id].should eql("#{@test_object.pid}")
549
- end
550
-
551
- it "should call .to_xml on all SimpleDatastreams and return the resulting document" do
552
- ds1 = ActiveFedora::SimpleDatastream.new(@test_object.inner_object, 'ds1')
553
- ds2 = ActiveFedora::SimpleDatastream.new(@test_object.inner_object, 'ds2')
554
- [ds1,ds2].each {|ds| ds.expects(:to_xml)}
555
-
556
- @test_object.expects(:datastreams).returns({:ds1 => ds1, :ds2 => ds2})
557
- @test_object.to_xml
558
- end
559
- end
560
-
561
506
  describe ".to_solr" do
562
507
  after(:all) do
563
508
  # Revert to default mappings after running tests
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-fedora
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0.rc3
4
+ version: 5.0.0.rc4
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-11-15 00:00:00.000000000 Z
14
+ date: 2012-11-28 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rsolr
@@ -52,7 +52,7 @@ dependencies:
52
52
  requirements:
53
53
  - - ~>
54
54
  - !ruby/object:Gem::Version
55
- version: 2.0.0.rc6
55
+ version: 2.0.0.rc7
56
56
  type: :runtime
57
57
  prerelease: false
58
58
  version_requirements: !ruby/object:Gem::Requirement
@@ -60,7 +60,7 @@ dependencies:
60
60
  requirements:
61
61
  - - ~>
62
62
  - !ruby/object:Gem::Version
63
- version: 2.0.0.rc6
63
+ version: 2.0.0.rc7
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: activeresource
66
66
  requirement: !ruby/object:Gem::Requirement
@@ -361,7 +361,6 @@ files:
361
361
  - lib/active_fedora/fixture_exporter.rb
362
362
  - lib/active_fedora/fixture_loader.rb
363
363
  - lib/active_fedora/locale/en.yml
364
- - lib/active_fedora/metadata_datastream.rb
365
364
  - lib/active_fedora/metadata_datastream_helper.rb
366
365
  - lib/active_fedora/model.rb
367
366
  - lib/active_fedora/named_relationships.rb
@@ -388,7 +387,6 @@ files:
388
387
  - lib/active_fedora/unsaved_digital_object.rb
389
388
  - lib/active_fedora/validations.rb
390
389
  - lib/active_fedora/version.rb
391
- - lib/ruby-fedora.rb
392
390
  - lib/tasks/active_fedora.rake
393
391
  - lib/tasks/active_fedora_dev.rake
394
392
  - script/console
@@ -425,7 +423,6 @@ files:
425
423
  - spec/integration/datastreams_spec.rb
426
424
  - spec/integration/full_featured_model_spec.rb
427
425
  - spec/integration/metadata_datastream_helper_spec.rb
428
- - spec/integration/metadata_datastream_spec.rb
429
426
  - spec/integration/model_spec.rb
430
427
  - spec/integration/mods_article_integration_spec.rb
431
428
  - spec/integration/nested_attribute_spec.rb
@@ -502,7 +499,6 @@ files:
502
499
  - spec/unit/file_configurator_spec.rb
503
500
  - spec/unit/has_many_collection_spec.rb
504
501
  - spec/unit/inheritance_spec.rb
505
- - spec/unit/metadata_datastream_spec.rb
506
502
  - spec/unit/model_spec.rb
507
503
  - spec/unit/nokogiri_datastream_spec.rb
508
504
  - spec/unit/ntriples_datastream_spec.rb
@@ -578,7 +574,6 @@ test_files:
578
574
  - spec/integration/datastreams_spec.rb
579
575
  - spec/integration/full_featured_model_spec.rb
580
576
  - spec/integration/metadata_datastream_helper_spec.rb
581
- - spec/integration/metadata_datastream_spec.rb
582
577
  - spec/integration/model_spec.rb
583
578
  - spec/integration/mods_article_integration_spec.rb
584
579
  - spec/integration/nested_attribute_spec.rb
@@ -655,7 +650,6 @@ test_files:
655
650
  - spec/unit/file_configurator_spec.rb
656
651
  - spec/unit/has_many_collection_spec.rb
657
652
  - spec/unit/inheritance_spec.rb
658
- - spec/unit/metadata_datastream_spec.rb
659
653
  - spec/unit/model_spec.rb
660
654
  - spec/unit/nokogiri_datastream_spec.rb
661
655
  - spec/unit/ntriples_datastream_spec.rb
@@ -1,272 +0,0 @@
1
- module ActiveFedora
2
- # A legacy class that creates and updates simple xml documents
3
- # For much greater flexibility, use {ActiveFedora::NokogiriDatastream} instead.
4
- # @example The simple, flat xml structure used by these datastreams
5
- # <fields>
6
- # <title>Foo</title>
7
- # <author>Bar</author>
8
- # </fields>
9
- class MetadataDatastream < NokogiriDatastream
10
-
11
- # .to_solr (among other things) is provided by ActiveFedora::MetadataDatastreamHelper
12
- include ActiveFedora::MetadataDatastreamHelper
13
-
14
- def initialize(digital_object, dsid)
15
- ActiveSupport::Deprecation.warn("MetadataDatastream is deprecated and will be removed in a future release. Create a NokogiriDatastream to structure your data")
16
- super
17
- end
18
-
19
- def to_solr(solr_doc = Hash.new) # :nodoc:
20
- fields.each do |field_key, field_info|
21
- if field_info.has_key?(:values) && !field_info[:values].nil?
22
- field_symbol = ActiveFedora::SolrService.solr_name(field_key, field_info[:type])
23
- values = field_info[:values]
24
- values = [values] unless values.respond_to? :each
25
- values.each do |val|
26
- ::Solrizer::Extractor.insert_solr_field_value(solr_doc, field_symbol, val )
27
- end
28
- end
29
- end
30
-
31
- return solr_doc
32
- end
33
-
34
- # ** EXPERIMENTAL **
35
- #
36
- # This is utilized by ActiveFedora::Base.load_instance_from_solr to set
37
- # metadata values in this object using the Solr document passed in.
38
- # Any keys in the solr document that map to a metadata field key within a MetadataDatastream object
39
- # are set to the corresponding value. Any others are ignored. ActiveFedora::SolrService.solr_name
40
- # is used to map solr key to field key name.
41
- #
42
- # ====Warning
43
- # Solr must be synchronized with data in Fedora.
44
- # @content is initialized to the empty document template to satisfy #ensure_xml_loaded
45
- # (called from #update_attributes and #update_indexed_attributes)
46
- def from_solr(solr_doc)
47
- @content = self.to_xml
48
- self.xml_loaded = true
49
- fields.each do |field_key, field_info|
50
- field_symbol = ActiveFedora::SolrService.solr_name(field_key, field_info[:type])
51
- value = (solr_doc[field_symbol].nil? ? solr_doc[field_symbol.to_s]: solr_doc[field_symbol])
52
- unless value.nil?
53
- if value.is_a? Array
54
- update_attributes({field_key=>value})
55
- else
56
- update_indexed_attributes({field_key=>{0=>value}})
57
- end
58
- end
59
- end
60
- end
61
-
62
-
63
-
64
-
65
- def update_attributes(params={},opts={})
66
- result = params.dup
67
- params.each do |k,v|
68
- if v == :delete || v == "" || v == nil
69
- v = []
70
- end
71
- if self.fields.has_key?(k.to_sym)
72
- result[k] = set_value(k, v)
73
- else
74
- result.delete(k)
75
- end
76
- end
77
- return result
78
- end
79
-
80
- # An ActiveRecord-ism to udpate metadata values.
81
- #
82
- # The passed in hash must look like this :
83
- # {:name=>{"0"=>"a","1"=>"b"}}
84
- #
85
- # This will attempt to set the values for any field named fubar in the datastream.
86
- # If there is no field by that name, it returns an empty hash and doesn't change the object at all.
87
- # If there is a field by that name, it will set the values for field of name :name having the value [a,b]
88
- # and it returns a hash with the field name, value index, and the value as it was set.
89
- #
90
- # An index of -1 will insert a new value. any existing value at the relevant index
91
- # will be overwritten.
92
- #
93
- # As in update_attributes, this overwrites _all_ available fields by default.
94
- #
95
- # Example Usage:
96
- #
97
- # ds.update_attributes({:myfield=>{"0"=>"a","1"=>"b"},:myotherfield=>{"-1"=>"c"}})
98
- #
99
- def update_indexed_attributes(params={}, opts={})
100
- ensure_xml_loaded
101
-
102
- ##FIX this bug, it should delete it from a copy of params in case passed to another datastream for update since this will modify params
103
- ##for subsequent calls if updating more than one datastream in a single update_indexed_attributes call
104
- current_params = params.clone
105
-
106
- # remove any fields from params that this datastream doesn't recognize
107
- current_params.delete_if do |field_name,new_values|
108
- if field_name.kind_of?(Array) then field_name = field_name.first end
109
- !self.fields.include?(field_name.to_sym)
110
- end
111
-
112
- result = current_params.dup
113
- current_params.each do |field_name,new_values|
114
- if field_name.kind_of?(Array) then field_name = field_name.first end
115
-
116
- ##FIX this bug, it should delete it from a copy of params in case passed to another datastream for update
117
- #if field does not exist just skip it
118
- next if !self.fields.include?(field_name.to_sym)
119
- field_accessor_method = "#{field_name}_values"
120
-
121
- if new_values.kind_of?(Hash)
122
- result[field_name] = new_values.dup
123
-
124
- current_values = instance_eval(field_accessor_method)
125
-
126
- # current_values = get_values(field_name) # for some reason this leaves current_values unset?
127
-
128
- new_values.delete_if do |y,z|
129
- if current_values[y.to_i] and y.to_i > -1
130
- current_values[y.to_i]=z
131
- true
132
- else
133
- false
134
- end
135
- end
136
-
137
- new_values.keys.sort { |a,b| a.to_i <=> b.to_i }.each do |y|
138
- z = new_values[y]
139
- result[field_name].delete(y)
140
- current_values<<z #just append everything left
141
- new_array_index = current_values.length - 1
142
- result[field_name][new_array_index.to_s] = z
143
- end
144
- current_values.delete_if {|x| x == :delete || x == "" || x == nil}
145
- #set_value(field_name, current_values)
146
- instance_eval("#{field_accessor_method}=(current_values)") #write it back to the ds
147
- # result[field_name].delete("-1")
148
- else
149
- values = instance_eval("#{field_name}_values=(new_values)")
150
- result[field_name] = {"0"=>values}
151
- end
152
- self.dirty = true
153
- end
154
- return result
155
- end
156
-
157
-
158
- def get_values(field_name, default=[])
159
- ensure_xml_loaded
160
- field_accessor_method = "#{field_name}_values"
161
- if respond_to? field_accessor_method
162
- values = self.send(field_accessor_method)
163
- else
164
- values = []
165
- end
166
- if values.empty?
167
- if default.nil?
168
- return default
169
- else
170
- return default
171
- end
172
- else
173
- return values
174
- end
175
- end
176
-
177
- def set_value(field_name, values)
178
- ensure_xml_loaded
179
- field_accessor_method = "#{field_name}_values="
180
- if respond_to? field_accessor_method
181
- values = self.send(field_accessor_method, values)
182
- return self.send("#{field_name}_values")
183
- end
184
- end
185
-
186
- # Populate a MetadataDatastream object based on the "datastream" node from a FOXML file
187
- # @param [ActiveFedora::Datastream] tmpl the Datastream object that you are building
188
- # @param [Nokogiri::XML::Node] node the "foxml:datastream" node from a FOXML file. Assumes that the content of this datastream is that of an ActiveFedora MetadataDatastream (<fields>...</fields>)
189
- def self.from_xml(xml, tmpl) # :nodoc:
190
- node = Nokogiri::XML::Document.parse(xml)
191
- node.xpath("fields/node()").each do |f|
192
- tmpl.send("#{f.name}_append", f.text) unless f.class == Nokogiri::XML::Text
193
- end
194
- tmpl.send(:dirty=, false)
195
- tmpl
196
- end
197
-
198
- def to_xml(xml = Nokogiri::XML::Document.parse("<fields />")) #:nodoc:
199
- if xml.instance_of?(Nokogiri::XML::Builder)
200
- xml_insertion_point = xml.doc.root
201
- elsif xml.instance_of?(Nokogiri::XML::Document)
202
- xml_insertion_point = xml.root
203
- else
204
- xml_insertion_point = xml
205
- end
206
-
207
- builder = Nokogiri::XML::Builder.with(xml_insertion_point) do |xml|
208
- fields.each do |field,field_info|
209
- element_attrs = field_info[:element_attrs].nil? ? {} : field_info[:element_attrs]
210
- values = field_info[:values]
211
- values = [values] unless values.respond_to? :each
212
- values.each do |val|
213
- builder_arg = "xml.#{field}(val, element_attrs)"
214
- eval(builder_arg)
215
- end
216
- end
217
- end
218
- return builder.to_xml
219
- end
220
-
221
- # This method generates the various accessor and mutator methods on self for the datastream metadata attributes.
222
- # each field will have the 3 magic methods:
223
- # name_values=(arg)
224
- # name_values
225
- # name_append(arg)
226
- #
227
- #
228
- # Calling any of the generated methods marks self as dirty.
229
- #
230
- # 'tupe' is a datatype, currently :string, :text and :date are supported.
231
- #
232
- # opts is an options hash, which will affect the generation of the xml representation of this datastream.
233
- #
234
- # Currently supported modifiers:
235
- # For +QualifiedDublinCorDatastreams+:
236
- # :element_attrs =>{:foo=>:bar} - hash of xml element attributes
237
- # :xml_node => :nodename - The xml node to be used to represent this object (in dcterms namespace)
238
- # :encoding=>foo, or encodings_scheme - causes an xsi:type attribute to be set to 'foo'
239
- # :multiple=>true - mark this field as a multivalue field (on by default)
240
- #
241
- #At some point, these modifiers will be ported up to work for any +ActiveFedora::MetadataDatastream+.
242
- #
243
- #There is quite a good example of this class in use in spec/examples/oral_history.rb
244
- #
245
- #!! Careful: If you declare two fields that correspond to the same xml node without any qualifiers to differentiate them,
246
- #you will end up replicating the values in the underlying datastream, resulting in mysterious dubling, quadrupling, etc.
247
- #whenever you edit the field's values.
248
- def field(name, tupe, opts={})
249
- #TODO add term to terminology
250
- @fields[name.to_s.to_sym]={:type=>tupe, :values=>[]}.merge(opts)
251
- #eval <<-EOS
252
- (class << self; self; end).class_eval do
253
- define_method "#{name}_values=".to_sym do |arg|
254
- ensure_xml_loaded
255
- @fields["#{name.to_s}".to_sym][:values]=[arg].flatten
256
- self.dirty=true
257
- end
258
- define_method "#{name}_values".to_sym do
259
- ensure_xml_loaded
260
- @fields["#{name}".to_sym][:values]
261
- end
262
- define_method "#{name}_append".to_sym do |arg|
263
- ensure_xml_loaded
264
- @fields["#{name}".to_sym][:values] << arg
265
- self.dirty =true
266
- end
267
- end
268
- end
269
-
270
- end
271
-
272
- end