active-fedora 1.1.4 → 1.1.5
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.
- data/README.textile +19 -0
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/active-fedora.gemspec +12 -2
- data/lib/active_fedora/base.rb +4 -0
- data/lib/hydra.rb +2 -0
- data/lib/hydra_libs/mods_datastream.rb +6 -0
- data/lib/hydra_libs/opinionated_mods_document.rb +2 -0
- data/spec/unit/mods_datastream_spec.rb +289 -0
- data/spec/unit/nokogiri_datastream_spec.rb +299 -0
- metadata +28 -9
data/README.textile
CHANGED
@@ -19,6 +19,25 @@ h2. Getting Started
|
|
19
19
|
|
20
20
|
The "ActiveFedora Console Tour":http://projects.mediashelf.us/wiki/active-fedora/Getting_Started gives you a brief tour through ActiveFedora's features on the command line.
|
21
21
|
|
22
|
+
h2. Testing
|
23
|
+
|
24
|
+
In order to run the RSpec tests, you need to have a copy of hydra-jetty running. To do this, download a working copy of hydra-jetty, cd into its root and run
|
25
|
+
<pre>java -jar start.jar</pre>
|
26
|
+
|
27
|
+
Then open a new terminal and import fedora's demo objects.
|
28
|
+
|
29
|
+
<pre>
|
30
|
+
export FEDORA_HOME=/path/to/hydra/jetty/fedora/default
|
31
|
+
$FEDORA_HOME/client/bin/fedora-ingest-demos.sh localhost 8983 fedoraAdmin fedoraAdmin http
|
32
|
+
<pre>
|
33
|
+
|
34
|
+
Now you're ready to run
|
35
|
+
|
36
|
+
<pre>
|
37
|
+
cd /wherever/active_fedora/is
|
38
|
+
rake spec
|
39
|
+
</pre>
|
40
|
+
|
22
41
|
h2. LICENSE:
|
23
42
|
|
24
43
|
Copyright (c) 2009-2010 Matt Zumwalt
|
data/Rakefile
CHANGED
@@ -20,6 +20,7 @@ begin
|
|
20
20
|
gem.add_dependency('xml-simple', '>= 1.0.12')
|
21
21
|
gem.add_dependency('mime-types', '>= 1.16')
|
22
22
|
gem.add_dependency('multipart-post')
|
23
|
+
gem.add_dependency('nokogiri')
|
23
24
|
|
24
25
|
gem.add_development_dependency "rspec", ">= 1.2.9"
|
25
26
|
gem.add_development_dependency "mocha", ">= 1.2.9"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.5
|
data/active-fedora.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{active-fedora}
|
8
|
-
s.version = "1.1.
|
8
|
+
s.version = "1.1.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Matt Zumwalt", "McClain Looney"]
|
12
|
-
s.date = %q{2010-05-
|
12
|
+
s.date = %q{2010-05-16}
|
13
13
|
s.description = %q{ActiveFedora provides for creating and managing objects in the Fedora Repository Architecture.}
|
14
14
|
s.email = %q{matt.zumwalt@yourmediashelf.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -208,6 +208,9 @@ Gem::Specification.new do |s|
|
|
208
208
|
"lib/fedora/formats.rb",
|
209
209
|
"lib/fedora/generic_search.rb",
|
210
210
|
"lib/fedora/repository.rb",
|
211
|
+
"lib/hydra.rb",
|
212
|
+
"lib/hydra_libs/mods_datastream.rb",
|
213
|
+
"lib/hydra_libs/opinionated_mods_document.rb",
|
211
214
|
"lib/ruby-fedora.rb",
|
212
215
|
"lib/util/class_level_inheritable_attributes.rb",
|
213
216
|
"script/console",
|
@@ -259,6 +262,8 @@ Gem::Specification.new do |s|
|
|
259
262
|
"spec/unit/inheritance_spec.rb",
|
260
263
|
"spec/unit/metadata_datastream_spec.rb",
|
261
264
|
"spec/unit/model_spec.rb",
|
265
|
+
"spec/unit/mods_datastream_spec.rb",
|
266
|
+
"spec/unit/nokogiri_datastream_spec.rb",
|
262
267
|
"spec/unit/property_spec.rb",
|
263
268
|
"spec/unit/qualified_dublin_core_datastream_spec.rb",
|
264
269
|
"spec/unit/relationship_spec.rb",
|
@@ -314,6 +319,8 @@ Gem::Specification.new do |s|
|
|
314
319
|
"spec/unit/inheritance_spec.rb",
|
315
320
|
"spec/unit/metadata_datastream_spec.rb",
|
316
321
|
"spec/unit/model_spec.rb",
|
322
|
+
"spec/unit/mods_datastream_spec.rb",
|
323
|
+
"spec/unit/nokogiri_datastream_spec.rb",
|
317
324
|
"spec/unit/property_spec.rb",
|
318
325
|
"spec/unit/qualified_dublin_core_datastream_spec.rb",
|
319
326
|
"spec/unit/relationship_spec.rb",
|
@@ -335,6 +342,7 @@ Gem::Specification.new do |s|
|
|
335
342
|
s.add_runtime_dependency(%q<xml-simple>, [">= 1.0.12"])
|
336
343
|
s.add_runtime_dependency(%q<mime-types>, [">= 1.16"])
|
337
344
|
s.add_runtime_dependency(%q<multipart-post>, [">= 0"])
|
345
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
338
346
|
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
339
347
|
s.add_development_dependency(%q<mocha>, [">= 1.2.9"])
|
340
348
|
s.add_development_dependency(%q<ruby-debug>, [">= 0"])
|
@@ -343,6 +351,7 @@ Gem::Specification.new do |s|
|
|
343
351
|
s.add_dependency(%q<xml-simple>, [">= 1.0.12"])
|
344
352
|
s.add_dependency(%q<mime-types>, [">= 1.16"])
|
345
353
|
s.add_dependency(%q<multipart-post>, [">= 0"])
|
354
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
346
355
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
347
356
|
s.add_dependency(%q<mocha>, [">= 1.2.9"])
|
348
357
|
s.add_dependency(%q<ruby-debug>, [">= 0"])
|
@@ -352,6 +361,7 @@ Gem::Specification.new do |s|
|
|
352
361
|
s.add_dependency(%q<xml-simple>, [">= 1.0.12"])
|
353
362
|
s.add_dependency(%q<mime-types>, [">= 1.16"])
|
354
363
|
s.add_dependency(%q<multipart-post>, [">= 0"])
|
364
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
355
365
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
356
366
|
s.add_dependency(%q<mocha>, [">= 1.2.9"])
|
357
367
|
s.add_dependency(%q<ruby-debug>, [">= 0"])
|
data/lib/active_fedora/base.rb
CHANGED
@@ -86,6 +86,10 @@ module ActiveFedora
|
|
86
86
|
end
|
87
87
|
@new_object = false
|
88
88
|
self.update_index if @metadata_is_dirty == true && ENABLE_SOLR_UPDATES
|
89
|
+
if defined?( Solrizer::Solrizer )
|
90
|
+
solrizer = Solrizer::Solrizer.new
|
91
|
+
solrizer.solrize( self )
|
92
|
+
end
|
89
93
|
@metadata_is_dirty == false
|
90
94
|
return result
|
91
95
|
end
|
data/lib/hydra.rb
ADDED
@@ -0,0 +1,289 @@
|
|
1
|
+
require File.join( File.dirname(__FILE__), "../spec_helper" )
|
2
|
+
|
3
|
+
require 'active_fedora'
|
4
|
+
require 'hydra'
|
5
|
+
|
6
|
+
describe ModsDatastream do
|
7
|
+
|
8
|
+
before(:all) do
|
9
|
+
@sample_fields = {:publisher => {:values => ["publisher1"], :type => :string},
|
10
|
+
:coverage => {:values => ["coverage1", "coverage2"], :type => :text},
|
11
|
+
:creation_date => {:values => "fake-date", :type => :date},
|
12
|
+
:mydate => {:values => "fake-date", :type => :date},
|
13
|
+
:empty_field => {:values => {}}
|
14
|
+
}
|
15
|
+
@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>")
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
before(:each) do
|
20
|
+
@test_ds = ModsDatastream.new
|
21
|
+
end
|
22
|
+
|
23
|
+
after(:each) do
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#new' do
|
27
|
+
it 'should provide #new' do
|
28
|
+
ModsDatastream.should respond_to(:new)
|
29
|
+
@test_ds.ng_xml.should be_instance_of(OpinionatedModsDocument)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
it 'should provide .fields' do
|
35
|
+
@test_ds.should respond_to(:fields)
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '.save' do
|
39
|
+
it "should provide .save" do
|
40
|
+
@test_ds.should respond_to(:save)
|
41
|
+
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
|
+
end
|
49
|
+
|
50
|
+
describe '.to_xml' do
|
51
|
+
it "should provide .to_xml" do
|
52
|
+
@test_ds.should respond_to(:to_xml)
|
53
|
+
end
|
54
|
+
it 'should output the fields hash as XML' do
|
55
|
+
@test_ds.expects(:fields).returns(@sample_fields)
|
56
|
+
#sample_rexml = REXML::Document.new(sample_xml)
|
57
|
+
#returned_rexml = REXML::Document.new(@test_ds.to_dc_xml)
|
58
|
+
#returned_rexml.to_s.should == sample_rexml.to_s
|
59
|
+
returned_xml = XmlSimple.xml_in(@test_ds.to_xml)
|
60
|
+
returned_xml.should == @sample_xml
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should accept an optional REXML Document as an argument and insert its fields into that' do
|
64
|
+
@test_ds.expects(:fields).returns(@sample_fields)
|
65
|
+
rexml = REXML::Document.new("<test_rexml/>")
|
66
|
+
rexml.root.elements.expects(:add).times(5)
|
67
|
+
result = @test_ds.to_xml(rexml)
|
68
|
+
end
|
69
|
+
it 'should accept an optional REXML Document as an argument and insert its fields into that' do
|
70
|
+
@test_ds.expects(:fields).returns(@sample_fields)
|
71
|
+
rexml = REXML::Document.new("<test_rexml/>")
|
72
|
+
result = @test_ds.to_xml(rexml)
|
73
|
+
XmlSimple.xml_in(rexml.to_s).should == @sample_xml
|
74
|
+
XmlSimple.xml_in(result).should == @sample_xml
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should add to root of REXML::Documents, but add directly to the elements if a REXML::Element is passed in' do
|
78
|
+
@test_ds.expects(:fields).returns(@sample_fields).times(2)
|
79
|
+
doc = REXML::Document.new("<test_document/>")
|
80
|
+
el = REXML::Element.new("<test_element/>")
|
81
|
+
doc.root.elements.expects(:add).times(5)
|
82
|
+
el.expects(:add).times(5)
|
83
|
+
@test_ds.to_xml(doc)
|
84
|
+
@test_ds.to_xml(el)
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '.set_blob_for_save' do
|
90
|
+
it "should provide .set_blob_for_save" do
|
91
|
+
@test_ds.should respond_to(:set_blob_for_save)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should set the blob to to_xml" do
|
95
|
+
@test_ds.expects(:blob=).with(@test_ds.to_xml)
|
96
|
+
@test_ds.set_blob_for_save
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '#field' do
|
101
|
+
|
102
|
+
before(:each) do
|
103
|
+
class SpecDatastream < ActiveFedora::MetadataDatastream
|
104
|
+
def initialize
|
105
|
+
super
|
106
|
+
field :publisher, :string
|
107
|
+
field :coverage, :text
|
108
|
+
field :creation_date, :date
|
109
|
+
field :mydate, :date
|
110
|
+
field :mycomplicated_field, :string, :multiple=>false, :encoding=>'LCSH', :element_attrs=>{:foo=>:bar, :baz=>:bat}
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
after(:each) do
|
116
|
+
Object.send(:remove_const, :SpecDatastream)
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should add corresponding field to the @fields hash and set the field :type ' do
|
120
|
+
sds = SpecDatastream.new
|
121
|
+
sds.fields.should_not have_key(:bio)
|
122
|
+
sds.field :bio, :text
|
123
|
+
sds.fields.should have_key(:bio)
|
124
|
+
sds.fields[:bio].should have_key(:type)
|
125
|
+
sds.fields[:bio][:type].should == :text
|
126
|
+
sds.fields[:mycomplicated_field][:element_attrs].should == {:foo=>:bar, :baz=>:bat}
|
127
|
+
end
|
128
|
+
|
129
|
+
# it "should insert custom element attrs into the xml stream" do
|
130
|
+
# sds = SpecDatastream.new
|
131
|
+
# sds.mycomplicated_field_values='foo'
|
132
|
+
# sds.fields[:mycomplicated_field][:element_attrs].should == {:foo=>:bar, :baz=>:bat}
|
133
|
+
# sds.to_xml.should == '<fields><mycomplicated_field baz=\'bat\' foo=\'bar\'>foo</mycomplicated_field></fields>'
|
134
|
+
# end
|
135
|
+
|
136
|
+
it "should add getters and setters and appenders with field name" do
|
137
|
+
local_test_ds = SpecDatastream.new
|
138
|
+
local_test_ds.should respond_to(:publisher_values)
|
139
|
+
local_test_ds.should respond_to(:publisher_append)
|
140
|
+
local_test_ds.should respond_to(:publisher_values=)
|
141
|
+
local_test_ds.publisher_values.class.should == Array
|
142
|
+
local_test_ds.should respond_to(:coverage_values)
|
143
|
+
local_test_ds.should respond_to(:coverage_values=)
|
144
|
+
local_test_ds.should respond_to(:coverage_append)
|
145
|
+
local_test_ds.should respond_to(:creation_date_values)
|
146
|
+
local_test_ds.should respond_to(:creation_date_append)
|
147
|
+
local_test_ds.should respond_to(:creation_date_values=)
|
148
|
+
local_test_ds.should respond_to(:mydate_values)
|
149
|
+
local_test_ds.should respond_to(:mydate_append)
|
150
|
+
local_test_ds.should respond_to(:mydate_values=)
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should track field values at instance level, not at class level" do
|
154
|
+
local_test_ds1 = SpecDatastream.new
|
155
|
+
local_test_ds2 = SpecDatastream.new
|
156
|
+
local_test_ds1.publisher_values = ["publisher1", "publisher2"]
|
157
|
+
local_test_ds2.publisher_values = ["publisherA", "publisherB"]
|
158
|
+
|
159
|
+
local_test_ds2.publisher_values.should == ["publisherA", "publisherB"]
|
160
|
+
local_test_ds1.publisher_values.should == ["publisher1", "publisher2"]
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should allow you to add field values using <<" do
|
164
|
+
local_test_ds1 = SpecDatastream.new
|
165
|
+
local_test_ds1.publisher_values << "publisher1"
|
166
|
+
local_test_ds1.publisher_values.should == ["publisher1"]
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should create setter that always turns non-arrays into arrays" do
|
170
|
+
local_test_ds = SpecDatastream.new
|
171
|
+
local_test_ds.publisher_values = "Foo"
|
172
|
+
local_test_ds.publisher_values.should == ["Foo"]
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should create setter that sets datastream.dirty? to true" do
|
176
|
+
local_test_ds = SpecDatastream.new
|
177
|
+
local_test_ds.should_not be_dirty
|
178
|
+
local_test_ds.publisher_values = "Foo"
|
179
|
+
local_test_ds.should be_dirty
|
180
|
+
|
181
|
+
# Note: If you use << to append values, the datastream will not be marked as dirty!
|
182
|
+
#local_test_ds.dirty = false
|
183
|
+
|
184
|
+
#local_test_ds.should_not be_dirty
|
185
|
+
#local_test_ds.publisher_values << "Foo"
|
186
|
+
#local_test_ds.should be_dirty
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should add any extra opts to the field hash" do
|
190
|
+
local_test_ds = SpecDatastream.new
|
191
|
+
local_test_ds.field "myfield", :string, :foo => "foo", :bar => "bar"
|
192
|
+
local_test_ds.fields[:myfield].should have_key(:foo)
|
193
|
+
local_test_ds.fields[:myfield][:foo].should == "foo"
|
194
|
+
local_test_ds.fields[:myfield].should have_key(:bar)
|
195
|
+
local_test_ds.fields[:myfield][:bar].should == "bar"
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
|
200
|
+
describe ".to_solr" do
|
201
|
+
|
202
|
+
after(:all) do
|
203
|
+
# Revert to default mappings after running tests
|
204
|
+
ActiveFedora::SolrService.load_mappings
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should provide .to_solr and return a SolrDocument" do
|
208
|
+
@test_ds.should respond_to(:to_solr)
|
209
|
+
@test_ds.to_solr.should be_kind_of(Solr::Document)
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should optionally allow you to provide the Solr::Document to add fields to and return that document when done" do
|
213
|
+
doc = Solr::Document.new
|
214
|
+
@test_ds.to_solr(doc).should equal(doc)
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should iterate through @fields hash" do
|
218
|
+
@test_ds.expects(:fields).returns(@sample_fields)
|
219
|
+
solr_doc = @test_ds.to_solr
|
220
|
+
|
221
|
+
solr_doc[:publisher_t].should == "publisher1"
|
222
|
+
solr_doc[:coverage_t].should == "coverage1"
|
223
|
+
solr_doc[:creation_date_dt].should == "fake-date"
|
224
|
+
solr_doc[:mydate_dt].should == "fake-date"
|
225
|
+
|
226
|
+
solr_doc[:empty_field_t].should be_nil
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should allow multiple values for a single field"
|
230
|
+
|
231
|
+
it 'should append create keys in format field_name + _ + field_type' do
|
232
|
+
@test_ds.stubs(:fields).returns(@sample_fields)
|
233
|
+
|
234
|
+
#should have these
|
235
|
+
|
236
|
+
@test_ds.to_solr[:publisher_t].should_not be_nil
|
237
|
+
@test_ds.to_solr[:coverage_t].should_not be_nil
|
238
|
+
@test_ds.to_solr[:creation_date_dt].should_not be_nil
|
239
|
+
|
240
|
+
#should NOT have these
|
241
|
+
@test_ds.to_solr[:narrator].should be_nil
|
242
|
+
@test_ds.to_solr[:title].should be_nil
|
243
|
+
@test_ds.to_solr[:empty_field].should be_nil
|
244
|
+
|
245
|
+
end
|
246
|
+
|
247
|
+
it "should use Solr mappings to generate field names" do
|
248
|
+
ActiveFedora::SolrService.load_mappings(File.join(File.dirname(__FILE__), "..", "..", "config", "solr_mappings_af_0.1.yml"))
|
249
|
+
@test_ds.stubs(:fields).returns(@sample_fields)
|
250
|
+
solr_doc = @test_ds.to_solr
|
251
|
+
|
252
|
+
#should have these
|
253
|
+
|
254
|
+
solr_doc[:publisher_field].should == "publisher1"
|
255
|
+
solr_doc[:coverage_field].should == "coverage1"
|
256
|
+
solr_doc[:creation_date_date].should == "fake-date"
|
257
|
+
solr_doc[:mydate_date].should == "fake-date"
|
258
|
+
|
259
|
+
solr_doc[:publisher_t].should be_nil
|
260
|
+
solr_doc[:coverage_t].should be_nil
|
261
|
+
solr_doc[:creation_date_dt].should be_nil
|
262
|
+
|
263
|
+
# Reload default mappings
|
264
|
+
ActiveFedora::SolrService.load_mappings
|
265
|
+
end
|
266
|
+
|
267
|
+
it 'should append _dt to dates' do
|
268
|
+
@test_ds.expects(:fields).returns(@sample_fields).at_least_once
|
269
|
+
|
270
|
+
#should have these
|
271
|
+
|
272
|
+
@test_ds.to_solr[:creation_date_dt].should_not be_nil
|
273
|
+
@test_ds.to_solr[:mydate_dt].should_not be_nil
|
274
|
+
|
275
|
+
#should NOT have these
|
276
|
+
|
277
|
+
@test_ds.to_solr[:mydate].should be_nil
|
278
|
+
@test_ds.to_solr[:creation_date_date].should be_nil
|
279
|
+
end
|
280
|
+
|
281
|
+
end
|
282
|
+
|
283
|
+
describe '.fields' do
|
284
|
+
it "should return a Hash" do
|
285
|
+
@test_ds.fields.should be_instance_of(Hash)
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
end
|
@@ -0,0 +1,299 @@
|
|
1
|
+
require File.join( File.dirname(__FILE__), "../spec_helper" )
|
2
|
+
|
3
|
+
|
4
|
+
describe ActiveFedora::NokogiriDatastream do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
@sample_fields = {:publisher => {:values => ["publisher1"], :type => :string},
|
8
|
+
:coverage => {:values => ["coverage1", "coverage2"], :type => :text},
|
9
|
+
:creation_date => {:values => "fake-date", :type => :date},
|
10
|
+
:mydate => {:values => "fake-date", :type => :date},
|
11
|
+
:empty_field => {:values => {}}
|
12
|
+
}
|
13
|
+
@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>")
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
before(:each) do
|
18
|
+
@test_ds = ActiveFedora::NokogiriDatastream.new
|
19
|
+
end
|
20
|
+
|
21
|
+
after(:each) do
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#new' do
|
25
|
+
it 'should provide #new' do
|
26
|
+
ActiveFedora::NokogiriDatastream.should respond_to(:new)
|
27
|
+
@test_ds.ng_xml.should be_instance_of(Nokogiri::XML::Document)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
it 'should provide .fields' do
|
33
|
+
@test_ds.should respond_to(:fields)
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '.save' do
|
37
|
+
it "should provide .save" do
|
38
|
+
@test_ds.should respond_to(:save)
|
39
|
+
end
|
40
|
+
it "should persist the product of .to_xml in fedora" do
|
41
|
+
Fedora::Repository.instance.expects(:save)
|
42
|
+
@test_ds.expects(:to_xml).returns("fake xml")
|
43
|
+
@test_ds.expects(:blob=).with("fake xml")
|
44
|
+
@test_ds.save
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '.to_xml' do
|
49
|
+
it "should provide .to_xml" do
|
50
|
+
@test_ds.should respond_to(:to_xml)
|
51
|
+
end
|
52
|
+
it 'should output the fields hash as XML' do
|
53
|
+
@test_ds.expects(:fields).returns(@sample_fields)
|
54
|
+
returned_xml = XmlSimple.xml_in(@test_ds.to_xml)
|
55
|
+
returned_xml.should == @sample_xml
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should accept an optional REXML Document as an argument and insert its fields into that' do
|
59
|
+
@test_ds.expects(:fields).returns(@sample_fields)
|
60
|
+
rexml = REXML::Document.new("<test_rexml/>")
|
61
|
+
rexml.root.elements.expects(:add).times(5)
|
62
|
+
result = @test_ds.to_xml(rexml)
|
63
|
+
end
|
64
|
+
it 'should accept an optional REXML Document as an argument and insert its fields into that' do
|
65
|
+
@test_ds.expects(:fields).returns(@sample_fields)
|
66
|
+
rexml = REXML::Document.new("<test_rexml/>")
|
67
|
+
result = @test_ds.to_xml(rexml)
|
68
|
+
XmlSimple.xml_in(rexml.to_s).should == @sample_xml
|
69
|
+
XmlSimple.xml_in(result).should == @sample_xml
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should add to root of REXML::Documents, but add directly to the elements if a REXML::Element is passed in' do
|
73
|
+
@test_ds.expects(:fields).returns(@sample_fields).times(2)
|
74
|
+
doc = REXML::Document.new("<test_document/>")
|
75
|
+
el = REXML::Element.new("<test_element/>")
|
76
|
+
doc.root.elements.expects(:add).times(5)
|
77
|
+
el.expects(:add).times(5)
|
78
|
+
@test_ds.to_xml(doc)
|
79
|
+
@test_ds.to_xml(el)
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '.set_blob_for_save' do
|
85
|
+
it "should provide .set_blob_for_save" do
|
86
|
+
@test_ds.should respond_to(:set_blob_for_save)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should set the blob to to_xml" do
|
90
|
+
@test_ds.expects(:blob=).with(@test_ds.to_xml)
|
91
|
+
@test_ds.set_blob_for_save
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe '#field' do
|
96
|
+
|
97
|
+
before(:each) do
|
98
|
+
class SpecDatastream < ActiveFedora::MetadataDatastream
|
99
|
+
def initialize
|
100
|
+
super
|
101
|
+
field :publisher, :string
|
102
|
+
field :coverage, :text
|
103
|
+
field :creation_date, :date
|
104
|
+
field :mydate, :date
|
105
|
+
field :mycomplicated_field, :string, :multiple=>false, :encoding=>'LCSH', :element_attrs=>{:foo=>:bar, :baz=>:bat}
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
after(:each) do
|
111
|
+
Object.send(:remove_const, :SpecDatastream)
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
describe ".values" do
|
116
|
+
it "should call ng_xml.values_for(field_name) OR call corresponding lookup method and build an array of values by calling .value on each node in the set"
|
117
|
+
end
|
118
|
+
|
119
|
+
describe ".values<<" do
|
120
|
+
it "should call corresponding builder method"
|
121
|
+
end
|
122
|
+
|
123
|
+
describe ".values=" do
|
124
|
+
it "should wipe out any existing nodes, use the corresponding builder, and insert new node(s) as the replacement"
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should add corresponding field to the @fields hash and set the field :type ' do
|
128
|
+
sds = SpecDatastream.new
|
129
|
+
sds.fields.should_not have_key(:bio)
|
130
|
+
sds.field :bio, :text
|
131
|
+
sds.fields.should have_key(:bio)
|
132
|
+
sds.fields[:bio].should have_key(:type)
|
133
|
+
sds.fields[:bio][:type].should == :text
|
134
|
+
sds.fields[:mycomplicated_field][:element_attrs].should == {:foo=>:bar, :baz=>:bat}
|
135
|
+
end
|
136
|
+
|
137
|
+
# it "should insert custom element attrs into the xml stream" do
|
138
|
+
# sds = SpecDatastream.new
|
139
|
+
# sds.mycomplicated_field_values='foo'
|
140
|
+
# sds.fields[:mycomplicated_field][:element_attrs].should == {:foo=>:bar, :baz=>:bat}
|
141
|
+
# sds.to_xml.should == '<fields><mycomplicated_field baz=\'bat\' foo=\'bar\'>foo</mycomplicated_field></fields>'
|
142
|
+
# end
|
143
|
+
|
144
|
+
it "should add getters and setters and appenders with field name" do
|
145
|
+
local_test_ds = SpecDatastream.new
|
146
|
+
local_test_ds.should respond_to(:publisher_values)
|
147
|
+
local_test_ds.should respond_to(:publisher_append)
|
148
|
+
local_test_ds.should respond_to(:publisher_values=)
|
149
|
+
local_test_ds.publisher_values.class.should == Array
|
150
|
+
local_test_ds.should respond_to(:coverage_values)
|
151
|
+
local_test_ds.should respond_to(:coverage_values=)
|
152
|
+
local_test_ds.should respond_to(:coverage_append)
|
153
|
+
local_test_ds.should respond_to(:creation_date_values)
|
154
|
+
local_test_ds.should respond_to(:creation_date_append)
|
155
|
+
local_test_ds.should respond_to(:creation_date_values=)
|
156
|
+
local_test_ds.should respond_to(:mydate_values)
|
157
|
+
local_test_ds.should respond_to(:mydate_append)
|
158
|
+
local_test_ds.should respond_to(:mydate_values=)
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should track field values at instance level, not at class level" do
|
162
|
+
local_test_ds1 = SpecDatastream.new
|
163
|
+
local_test_ds2 = SpecDatastream.new
|
164
|
+
local_test_ds1.publisher_values = ["publisher1", "publisher2"]
|
165
|
+
local_test_ds2.publisher_values = ["publisherA", "publisherB"]
|
166
|
+
|
167
|
+
local_test_ds2.publisher_values.should == ["publisherA", "publisherB"]
|
168
|
+
local_test_ds1.publisher_values.should == ["publisher1", "publisher2"]
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should allow you to add field values using <<" do
|
172
|
+
local_test_ds1 = SpecDatastream.new
|
173
|
+
local_test_ds1.publisher_values << "publisher1"
|
174
|
+
local_test_ds1.publisher_values.should == ["publisher1"]
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should create setter that always turns non-arrays into arrays" do
|
178
|
+
local_test_ds = SpecDatastream.new
|
179
|
+
local_test_ds.publisher_values = "Foo"
|
180
|
+
local_test_ds.publisher_values.should == ["Foo"]
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should create setter that sets datastream.dirty? to true" do
|
184
|
+
local_test_ds = SpecDatastream.new
|
185
|
+
local_test_ds.should_not be_dirty
|
186
|
+
local_test_ds.publisher_values = "Foo"
|
187
|
+
local_test_ds.should be_dirty
|
188
|
+
|
189
|
+
# Note: If you use << to append values, the datastream will not be marked as dirty!
|
190
|
+
#local_test_ds.dirty = false
|
191
|
+
|
192
|
+
#local_test_ds.should_not be_dirty
|
193
|
+
#local_test_ds.publisher_values << "Foo"
|
194
|
+
#local_test_ds.should be_dirty
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should add any extra opts to the field hash" do
|
198
|
+
local_test_ds = SpecDatastream.new
|
199
|
+
local_test_ds.field "myfield", :string, :foo => "foo", :bar => "bar"
|
200
|
+
local_test_ds.fields[:myfield].should have_key(:foo)
|
201
|
+
local_test_ds.fields[:myfield][:foo].should == "foo"
|
202
|
+
local_test_ds.fields[:myfield].should have_key(:bar)
|
203
|
+
local_test_ds.fields[:myfield][:bar].should == "bar"
|
204
|
+
end
|
205
|
+
|
206
|
+
end
|
207
|
+
|
208
|
+
describe ".to_solr" do
|
209
|
+
|
210
|
+
after(:all) do
|
211
|
+
# Revert to default mappings after running tests
|
212
|
+
ActiveFedora::SolrService.load_mappings
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should iterate through the class fields, calling .values on each and appending the values to the solr doc"
|
216
|
+
|
217
|
+
it "should provide .to_solr and return a SolrDocument" do
|
218
|
+
@test_ds.should respond_to(:to_solr)
|
219
|
+
@test_ds.to_solr.should be_kind_of(Solr::Document)
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should optionally allow you to provide the Solr::Document to add fields to and return that document when done" do
|
223
|
+
doc = Solr::Document.new
|
224
|
+
@test_ds.to_solr(doc).should equal(doc)
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should iterate through @fields hash" do
|
228
|
+
@test_ds.expects(:fields).returns(@sample_fields)
|
229
|
+
solr_doc = @test_ds.to_solr
|
230
|
+
|
231
|
+
solr_doc[:publisher_t].should == "publisher1"
|
232
|
+
solr_doc[:coverage_t].should == "coverage1"
|
233
|
+
solr_doc[:creation_date_dt].should == "fake-date"
|
234
|
+
solr_doc[:mydate_dt].should == "fake-date"
|
235
|
+
|
236
|
+
solr_doc[:empty_field_t].should be_nil
|
237
|
+
end
|
238
|
+
|
239
|
+
it "should allow multiple values for a single field"
|
240
|
+
|
241
|
+
it 'should append create keys in format field_name + _ + field_type' do
|
242
|
+
@test_ds.stubs(:fields).returns(@sample_fields)
|
243
|
+
|
244
|
+
#should have these
|
245
|
+
|
246
|
+
@test_ds.to_solr[:publisher_t].should_not be_nil
|
247
|
+
@test_ds.to_solr[:coverage_t].should_not be_nil
|
248
|
+
@test_ds.to_solr[:creation_date_dt].should_not be_nil
|
249
|
+
|
250
|
+
#should NOT have these
|
251
|
+
@test_ds.to_solr[:narrator].should be_nil
|
252
|
+
@test_ds.to_solr[:title].should be_nil
|
253
|
+
@test_ds.to_solr[:empty_field].should be_nil
|
254
|
+
|
255
|
+
end
|
256
|
+
|
257
|
+
it "should use Solr mappings to generate field names" do
|
258
|
+
ActiveFedora::SolrService.load_mappings(File.join(File.dirname(__FILE__), "..", "..", "config", "solr_mappings_af_0.1.yml"))
|
259
|
+
@test_ds.stubs(:fields).returns(@sample_fields)
|
260
|
+
solr_doc = @test_ds.to_solr
|
261
|
+
|
262
|
+
#should have these
|
263
|
+
|
264
|
+
solr_doc[:publisher_field].should == "publisher1"
|
265
|
+
solr_doc[:coverage_field].should == "coverage1"
|
266
|
+
solr_doc[:creation_date_date].should == "fake-date"
|
267
|
+
solr_doc[:mydate_date].should == "fake-date"
|
268
|
+
|
269
|
+
solr_doc[:publisher_t].should be_nil
|
270
|
+
solr_doc[:coverage_t].should be_nil
|
271
|
+
solr_doc[:creation_date_dt].should be_nil
|
272
|
+
|
273
|
+
# Reload default mappings
|
274
|
+
ActiveFedora::SolrService.load_mappings
|
275
|
+
end
|
276
|
+
|
277
|
+
it 'should append _dt to dates' do
|
278
|
+
@test_ds.expects(:fields).returns(@sample_fields).at_least_once
|
279
|
+
|
280
|
+
#should have these
|
281
|
+
|
282
|
+
@test_ds.to_solr[:creation_date_dt].should_not be_nil
|
283
|
+
@test_ds.to_solr[:mydate_dt].should_not be_nil
|
284
|
+
|
285
|
+
#should NOT have these
|
286
|
+
|
287
|
+
@test_ds.to_solr[:mydate].should be_nil
|
288
|
+
@test_ds.to_solr[:creation_date_date].should be_nil
|
289
|
+
end
|
290
|
+
|
291
|
+
end
|
292
|
+
|
293
|
+
describe '.fields' do
|
294
|
+
it "should return a Hash" do
|
295
|
+
@test_ds.fields.should be_instance_of(Hash)
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 1.1.
|
8
|
+
- 5
|
9
|
+
version: 1.1.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Matt Zumwalt
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-05-
|
18
|
+
date: 2010-05-16 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -72,9 +72,21 @@ dependencies:
|
|
72
72
|
type: :runtime
|
73
73
|
version_requirements: *id004
|
74
74
|
- !ruby/object:Gem::Dependency
|
75
|
-
name:
|
75
|
+
name: nokogiri
|
76
76
|
prerelease: false
|
77
77
|
requirement: &id005 !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
segments:
|
82
|
+
- 0
|
83
|
+
version: "0"
|
84
|
+
type: :runtime
|
85
|
+
version_requirements: *id005
|
86
|
+
- !ruby/object:Gem::Dependency
|
87
|
+
name: rspec
|
88
|
+
prerelease: false
|
89
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
78
90
|
requirements:
|
79
91
|
- - ">="
|
80
92
|
- !ruby/object:Gem::Version
|
@@ -84,11 +96,11 @@ dependencies:
|
|
84
96
|
- 9
|
85
97
|
version: 1.2.9
|
86
98
|
type: :development
|
87
|
-
version_requirements: *
|
99
|
+
version_requirements: *id006
|
88
100
|
- !ruby/object:Gem::Dependency
|
89
101
|
name: mocha
|
90
102
|
prerelease: false
|
91
|
-
requirement: &
|
103
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
92
104
|
requirements:
|
93
105
|
- - ">="
|
94
106
|
- !ruby/object:Gem::Version
|
@@ -98,11 +110,11 @@ dependencies:
|
|
98
110
|
- 9
|
99
111
|
version: 1.2.9
|
100
112
|
type: :development
|
101
|
-
version_requirements: *
|
113
|
+
version_requirements: *id007
|
102
114
|
- !ruby/object:Gem::Dependency
|
103
115
|
name: ruby-debug
|
104
116
|
prerelease: false
|
105
|
-
requirement: &
|
117
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
106
118
|
requirements:
|
107
119
|
- - ">="
|
108
120
|
- !ruby/object:Gem::Version
|
@@ -110,7 +122,7 @@ dependencies:
|
|
110
122
|
- 0
|
111
123
|
version: "0"
|
112
124
|
type: :development
|
113
|
-
version_requirements: *
|
125
|
+
version_requirements: *id008
|
114
126
|
description: ActiveFedora provides for creating and managing objects in the Fedora Repository Architecture.
|
115
127
|
email: matt.zumwalt@yourmediashelf.com
|
116
128
|
executables: []
|
@@ -312,6 +324,9 @@ files:
|
|
312
324
|
- lib/fedora/formats.rb
|
313
325
|
- lib/fedora/generic_search.rb
|
314
326
|
- lib/fedora/repository.rb
|
327
|
+
- lib/hydra.rb
|
328
|
+
- lib/hydra_libs/mods_datastream.rb
|
329
|
+
- lib/hydra_libs/opinionated_mods_document.rb
|
315
330
|
- lib/ruby-fedora.rb
|
316
331
|
- lib/util/class_level_inheritable_attributes.rb
|
317
332
|
- script/console
|
@@ -363,6 +378,8 @@ files:
|
|
363
378
|
- spec/unit/inheritance_spec.rb
|
364
379
|
- spec/unit/metadata_datastream_spec.rb
|
365
380
|
- spec/unit/model_spec.rb
|
381
|
+
- spec/unit/mods_datastream_spec.rb
|
382
|
+
- spec/unit/nokogiri_datastream_spec.rb
|
366
383
|
- spec/unit/property_spec.rb
|
367
384
|
- spec/unit/qualified_dublin_core_datastream_spec.rb
|
368
385
|
- spec/unit/relationship_spec.rb
|
@@ -441,6 +458,8 @@ test_files:
|
|
441
458
|
- spec/unit/inheritance_spec.rb
|
442
459
|
- spec/unit/metadata_datastream_spec.rb
|
443
460
|
- spec/unit/model_spec.rb
|
461
|
+
- spec/unit/mods_datastream_spec.rb
|
462
|
+
- spec/unit/nokogiri_datastream_spec.rb
|
444
463
|
- spec/unit/property_spec.rb
|
445
464
|
- spec/unit/qualified_dublin_core_datastream_spec.rb
|
446
465
|
- spec/unit/relationship_spec.rb
|