active-fedora 5.0.0.rc3 → 5.0.0.rc4
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/.gitmodules +1 -0
- data/Gemfile +0 -1
- data/active-fedora.gemspec +1 -1
- data/lib/active_fedora.rb +0 -1
- data/lib/active_fedora/base.rb +2 -40
- data/lib/active_fedora/datastreams.rb +4 -32
- data/lib/active_fedora/delegating.rb +2 -2
- data/lib/active_fedora/file_management.rb +6 -1
- data/lib/active_fedora/metadata_datastream_helper.rb +0 -1
- data/lib/active_fedora/named_relationships.rb +4 -0
- data/lib/active_fedora/nokogiri_datastream.rb +2 -4
- data/lib/active_fedora/qualified_dublin_core_datastream.rb +0 -2
- data/lib/active_fedora/relationships.rb +19 -2
- data/lib/active_fedora/rels_ext_datastream.rb +1 -1
- data/lib/active_fedora/simple_datastream.rb +1 -3
- data/lib/active_fedora/version.rb +1 -1
- data/spec/integration/base_spec.rb +1 -26
- data/spec/integration/metadata_datastream_helper_spec.rb +1 -1
- data/spec/unit/base_datastream_management_spec.rb +0 -9
- data/spec/unit/base_extra_spec.rb +3 -40
- data/spec/unit/base_spec.rb +0 -55
- metadata +4 -10
- data/lib/active_fedora/metadata_datastream.rb +0 -272
- data/lib/ruby-fedora.rb +0 -12
- data/spec/integration/metadata_datastream_spec.rb +0 -66
- data/spec/unit/metadata_datastream_spec.rb +0 -392
data/lib/ruby-fedora.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
gem 'xml-simple'
|
3
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) unless
|
4
|
-
$LOAD_PATH.include?(File.dirname(__FILE__)) || $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
|
5
|
-
module Fedora #:nodoc:
|
6
|
-
end
|
7
|
-
#extended to remove facets dep
|
8
|
-
class Hash
|
9
|
-
def rekey!
|
10
|
-
self.each {|k,v| self[k.to_sym]=v; self.delete(k) unless self[k.to_sym]}
|
11
|
-
end
|
12
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveFedora::MetadataDatastream do
|
4
|
-
|
5
|
-
describe "changing the controlGroup of a datastream" do
|
6
|
-
before :all do
|
7
|
-
class Foo < ActiveFedora::Base
|
8
|
-
has_metadata :name => "stuff", :type => ActiveFedora::MetadataDatastream do |m|
|
9
|
-
m.field "alt_title", :string
|
10
|
-
end
|
11
|
-
end
|
12
|
-
obj = Foo.new()
|
13
|
-
obj.stuff.update_indexed_attributes({ [:alt_title] => {"0" => "Title"}} )
|
14
|
-
obj.save
|
15
|
-
|
16
|
-
#Update the object
|
17
|
-
obj2 = Foo.find(obj.pid)
|
18
|
-
obj2.stuff.controlGroup = 'M'
|
19
|
-
obj2.save
|
20
|
-
|
21
|
-
@obj = Foo.find(obj.pid)
|
22
|
-
end
|
23
|
-
|
24
|
-
after :all do
|
25
|
-
Object.send(:remove_const, :Foo)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should not change the datastream content" do
|
29
|
-
@obj.stuff.alt_title_values.should == ['Title']
|
30
|
-
end
|
31
|
-
end
|
32
|
-
describe "updating a datastream's content" do
|
33
|
-
before :all do
|
34
|
-
class Foo < ActiveFedora::Base
|
35
|
-
has_metadata :name => "properties", :type => ActiveFedora::MetadataDatastream do |m|
|
36
|
-
m.field "field1", :string
|
37
|
-
end
|
38
|
-
has_metadata :name => "stuff", :type => ActiveFedora::MetadataDatastream do |m|
|
39
|
-
m.field "alt_title", :string
|
40
|
-
end
|
41
|
-
end
|
42
|
-
obj = Foo.new()
|
43
|
-
obj.properties.update_indexed_attributes({ [:field1] => {"0" => "test value"}} )
|
44
|
-
obj.stuff.update_indexed_attributes({ [:alt_title] => {"0" => "Title"}} )
|
45
|
-
obj.save
|
46
|
-
|
47
|
-
#Update the object
|
48
|
-
obj2 = Foo.find(obj.pid)
|
49
|
-
obj2.stuff.update_indexed_attributes({ [:alt_title] => {"0" => "Moo Cow"}} )
|
50
|
-
obj2.save
|
51
|
-
|
52
|
-
@obj = Foo.find(obj.pid)
|
53
|
-
end
|
54
|
-
|
55
|
-
after :all do
|
56
|
-
Object.send(:remove_const, :Foo)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should have updated the one datastream" do
|
60
|
-
@obj.stuff.alt_title_values.should == ['Moo Cow']
|
61
|
-
end
|
62
|
-
it "should not have changed the other datastream" do
|
63
|
-
@obj.properties.field1_values.should == ['test value']
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,392 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'active_fedora'
|
4
|
-
require 'active_fedora/metadata_datastream'
|
5
|
-
|
6
|
-
# include ActiveFedora::Datastream
|
7
|
-
|
8
|
-
describe ActiveFedora::MetadataDatastream do
|
9
|
-
|
10
|
-
before(:all) do
|
11
|
-
@sample_fields = {:publisher => {:values => ["publisher1"], :type => :string},
|
12
|
-
:coverage => {:values => ["coverage1", "coverage2"], :type => :text},
|
13
|
-
:creation_date => {:values => "fake-date", :type => :date},
|
14
|
-
:mydate => {:values => "fake-date", :type => :date},
|
15
|
-
:empty_field => {:values => {}}
|
16
|
-
}
|
17
|
-
@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>")
|
18
|
-
end
|
19
|
-
|
20
|
-
before(:each) do
|
21
|
-
mock_inner = mock('inner object')
|
22
|
-
@test_object = ActiveFedora::Base.new
|
23
|
-
@mock_repo = mock('repository')
|
24
|
-
@mock_repo.stubs(:datastream).returns('')
|
25
|
-
@mock_repo.stubs(:datastream_dissemination=>'My Content', :config=>{})
|
26
|
-
mock_inner.stubs(:repository).returns(@mock_repo)
|
27
|
-
mock_inner.stubs(:pid)
|
28
|
-
@test_ds = ActiveFedora::MetadataDatastream.new(mock_inner, 'mdDs')
|
29
|
-
end
|
30
|
-
|
31
|
-
describe '#new' do
|
32
|
-
it 'should provide #new' do
|
33
|
-
ActiveFedora::MetadataDatastream.should respond_to(:new)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
it 'should provide .fields' do
|
39
|
-
@test_ds.should respond_to(:fields)
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '.save' do
|
43
|
-
it "should persist the product of .to_xml in fedora" do
|
44
|
-
@test_ds.field('coverage', :string)
|
45
|
-
@test_ds.expects(:new?).returns(true).times(3)
|
46
|
-
@mock_repo.expects(:datastream).with(:pid => nil, :dsid => 'mdDs').returns("")
|
47
|
-
@mock_repo.expects(:add_datastream)
|
48
|
-
#@test_ds.expects(:to_xml).returns("fake xml")
|
49
|
-
@test_ds.expects(:dirty?).returns(true)
|
50
|
-
@test_ds.update_attributes(:coverage=>"Hat")
|
51
|
-
@test_ds.serialize!
|
52
|
-
@test_ds.save
|
53
|
-
@test_ds.mimeType.should == 'text/xml'
|
54
|
-
@test_ds.content.should == "<?xml version=\"1.0\"?>\n<fields>\n <coverage>Hat</coverage>\n</fields>\n"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe ".update_indexed_attributes" do
|
59
|
-
|
60
|
-
before(:each) do
|
61
|
-
@test_ds.field "fubar", :string
|
62
|
-
@test_ds.field "swank", :text
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should apply submitted hash to corresponding datastream field values and mark the object dirty" do
|
66
|
-
@test_ds.should_not be_dirty
|
67
|
-
|
68
|
-
att= {"fubar"=>{"-1"=>"mork", "0"=>"york"}}
|
69
|
-
@test_ds.update_indexed_attributes(att)
|
70
|
-
@test_ds.fubar_values.should == ['mork', 'york']
|
71
|
-
@test_ds.fubar_values.should == ['mork', 'york']
|
72
|
-
|
73
|
-
att= {"fubar"=>{"0"=>"zork", "1"=>"tork", "2"=>'mangle'}}
|
74
|
-
@test_ds.update_indexed_attributes(att)
|
75
|
-
@test_ds.fubar_values.should == ['zork', 'tork', 'mangle']
|
76
|
-
|
77
|
-
att= {"fubar"=>{"0"=>"hork", "1"=>"tork", '-1'=>'dang'}}
|
78
|
-
result = @test_ds.update_indexed_attributes(att)
|
79
|
-
result.should == {"fubar"=>{"0"=>"hork", "1"=>"tork", '3'=>'dang'}}
|
80
|
-
@test_ds.fubar_values.should == ['hork', 'tork', 'mangle', 'dang']
|
81
|
-
|
82
|
-
@test_ds.should be_dirty
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should work for text fields" do
|
86
|
-
att= {"swank"=>{"-1"=>"mork", "1"=>"york"}}
|
87
|
-
result = @test_ds.update_indexed_attributes(att)
|
88
|
-
result.should == {"swank"=>{"1"=>"york", "0"=>"mork"}}
|
89
|
-
@test_ds.swank_values.should == ['mork', 'york']
|
90
|
-
att= {"swank"=>{"-1"=>"dork"}}
|
91
|
-
result2 = @test_ds.update_indexed_attributes(att)
|
92
|
-
result2.should == {"swank"=>{"2"=>"dork"}}
|
93
|
-
@test_ds.swank_values.should == ['mork', 'york', 'dork']
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should do nothing if there is no accessor corresponding to the given field key" do
|
97
|
-
xml_before = @test_ds.to_xml
|
98
|
-
@test_ds.update_indexed_attributes( { "style"=>"the style" } ).should == {}
|
99
|
-
@test_ds.to_xml.should == xml_before
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should return the new index of any added values" do
|
103
|
-
@test_ds.swank_values = ["my_val1","my_val2"]
|
104
|
-
result = @test_ds.update_indexed_attributes "swank"=>{"-1"=>"mork"}
|
105
|
-
result.should == {"swank"=>{"2"=>"mork"}}
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should deal gracefully with adding new values at explicitly declared indexes" do
|
109
|
-
@test_ds.fubar_values = ["all", "for", "the"]
|
110
|
-
att = {"fubar"=>{"3"=>'glory'}}
|
111
|
-
result = @test_ds.update_indexed_attributes(att)
|
112
|
-
result.should == {"fubar"=>{"3"=>"glory"}}
|
113
|
-
@test_ds.fubar_values.should == ["all", "for", "the", "glory"]
|
114
|
-
|
115
|
-
@test_ds.fubar_values = []
|
116
|
-
result = @test_ds.update_indexed_attributes(att)
|
117
|
-
result.should == {"fubar"=>{"0"=>"glory"}}
|
118
|
-
@test_ds.fubar_values.should == ["glory"]
|
119
|
-
end
|
120
|
-
|
121
|
-
it "should allow deleting of values and should delete values so that to_xml does not return emtpy nodes" do
|
122
|
-
att= {"fubar"=>{"-1"=>"mork", "0"=>"york", "1"=>"mangle"}}
|
123
|
-
@test_ds.update_indexed_attributes(att)
|
124
|
-
@test_ds.fubar_values.should == ['mork', 'york', 'mangle']
|
125
|
-
rexml = REXML::Document.new(@test_ds.to_xml)
|
126
|
-
#puts rexml.root.elements.each {|el| el.to_s}
|
127
|
-
#puts rexml.root.elements.to_a.inspect
|
128
|
-
rexml.root.elements.to_a.length.should == 3
|
129
|
-
@test_ds.update_indexed_attributes({"fubar"=>{"1"=>""}})
|
130
|
-
@test_ds.fubar_values.should == ['mork', 'mangle']
|
131
|
-
rexml = REXML::Document.new(@test_ds.to_xml)
|
132
|
-
rexml.root.elements.to_a.length.should == 2
|
133
|
-
@test_ds.update_indexed_attributes({"fubar"=>{"0"=>:delete}})
|
134
|
-
@test_ds.fubar_values.should == ['mangle']
|
135
|
-
rexml = REXML::Document.new(@test_ds.to_xml)
|
136
|
-
rexml.root.elements.to_a.length.should == 1
|
137
|
-
|
138
|
-
@test_ds.fubar_values = ["val1", nil, "val2"]
|
139
|
-
@test_ds.update_indexed_attributes({"fubar"=>{"1"=>""}})
|
140
|
-
@test_ds.fubar_values.should == ["val1", "val2"]
|
141
|
-
end
|
142
|
-
|
143
|
-
it "should not get tripped up by field names wrapped in arrays" do
|
144
|
-
att = {[:fubar]=>{"0"=>"eco3bv"}}
|
145
|
-
@test_ds.update_indexed_attributes(att)
|
146
|
-
@test_ds.fubar_values.should == ['eco3bv']
|
147
|
-
end
|
148
|
-
|
149
|
-
end
|
150
|
-
|
151
|
-
describe ".get_values" do
|
152
|
-
it "should call the _values method corresponding to the field_name" do
|
153
|
-
@test_ds.expects(:abstract_values).returns(["val1", "val2"])
|
154
|
-
@test_ds.get_values(:abstract).should == ["val1", "val2"]
|
155
|
-
end
|
156
|
-
it "should return a default value if one is supplied" do
|
157
|
-
@test_ds.stubs(:abstract_values).returns([])
|
158
|
-
@test_ds.get_values(:abstract, "default value").should == "default value"
|
159
|
-
@test_ds.get_values(:abstract, nil).should == nil
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
describe '.to_xml' do
|
164
|
-
it "should provide .to_xml" do
|
165
|
-
@test_ds.should respond_to(:to_xml)
|
166
|
-
end
|
167
|
-
it 'should output the fields hash as XML' do
|
168
|
-
@test_ds.expects(:fields).returns(@sample_fields)
|
169
|
-
returned_xml = XmlSimple.xml_in(@test_ds.to_xml)
|
170
|
-
returned_xml.should == @sample_xml
|
171
|
-
end
|
172
|
-
|
173
|
-
it 'should accept an optional Nokogiri::XML Document as an argument and insert its fields into that (mocked test)' do
|
174
|
-
doc = Nokogiri::XML::Document.parse("<test_rexml/>")
|
175
|
-
Nokogiri::XML::Builder.expects(:with).with(doc.root).returns(doc.root)
|
176
|
-
result = @test_ds.to_xml(doc)
|
177
|
-
end
|
178
|
-
|
179
|
-
it 'should accept an optional Nokogiri::XML Document as an argument and insert its fields into that (functional test)' do
|
180
|
-
@test_ds.expects(:fields).returns(@sample_fields)
|
181
|
-
doc = Nokogiri::XML::Document.parse("<test_rexml/>")
|
182
|
-
result = @test_ds.to_xml(doc)
|
183
|
-
XmlSimple.xml_in(doc.to_s).should == @sample_xml
|
184
|
-
XmlSimple.xml_in(result).should == @sample_xml
|
185
|
-
end
|
186
|
-
|
187
|
-
it 'should add to root of Nokogiri::XML::Documents, but add directly to the elements if a REXML::Element is passed in' do
|
188
|
-
doc = Nokogiri::XML::Document.parse("<test_document/>")
|
189
|
-
el = Nokogiri::XML::Node.new("test_element", Nokogiri::XML::Document.new)
|
190
|
-
Nokogiri::XML::Builder.expects(:with).with(doc.root).returns(doc.root)
|
191
|
-
Nokogiri::XML::Builder.expects(:with).with(el).returns(el)
|
192
|
-
@test_ds.to_xml(doc)
|
193
|
-
@test_ds.to_xml(el)
|
194
|
-
end
|
195
|
-
|
196
|
-
end
|
197
|
-
|
198
|
-
describe '#field' do
|
199
|
-
|
200
|
-
before(:each) do
|
201
|
-
class SpecDatastream < ActiveFedora::MetadataDatastream
|
202
|
-
def initialize(inner_object, dsid)
|
203
|
-
super
|
204
|
-
field :publisher, :string
|
205
|
-
field :coverage, :text
|
206
|
-
field :creation_date, :date
|
207
|
-
field :mydate, :date
|
208
|
-
field :mycomplicated_field, :string, :multiple=>false, :encoding=>'LCSH', :element_attrs=>{:foo=>:bar, :baz=>:bat}
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
after(:each) do
|
214
|
-
Object.send(:remove_const, :SpecDatastream)
|
215
|
-
end
|
216
|
-
|
217
|
-
it 'should add corresponding field to the @fields hash and set the field :type ' do
|
218
|
-
sds = SpecDatastream.new(nil, nil)
|
219
|
-
sds.fields.should_not have_key(:bio)
|
220
|
-
sds.field :bio, :text
|
221
|
-
sds.fields.should have_key(:bio)
|
222
|
-
sds.fields[:bio].should have_key(:type)
|
223
|
-
sds.fields[:bio][:type].should == :text
|
224
|
-
sds.fields[:mycomplicated_field][:element_attrs].should == {:foo=>:bar, :baz=>:bat}
|
225
|
-
end
|
226
|
-
|
227
|
-
it "should insert custom element attrs into the xml stream" do
|
228
|
-
sds = SpecDatastream.new(@test_object.inner_object, nil)
|
229
|
-
sds.stubs(:content=>'')
|
230
|
-
sds.mycomplicated_field_values='foo'
|
231
|
-
sds.fields[:mycomplicated_field][:element_attrs].should == {:foo=>:bar, :baz=>:bat}
|
232
|
-
expected_xml = '<fields><mycomplicated_field baz=\'bat\' foo=\'bar\'>foo</mycomplicated_field></fields>'
|
233
|
-
XmlSimple.xml_in(sds.to_xml).should == XmlSimple.xml_in(expected_xml)
|
234
|
-
end
|
235
|
-
|
236
|
-
it "should add getters and setters and appenders with field name" do
|
237
|
-
local_test_ds = SpecDatastream.new(@test_object.inner_object, nil)
|
238
|
-
local_test_ds.stubs(:content=>'')
|
239
|
-
local_test_ds.should respond_to(:publisher_values)
|
240
|
-
local_test_ds.should respond_to(:publisher_append)
|
241
|
-
local_test_ds.should respond_to(:publisher_values=)
|
242
|
-
local_test_ds.publisher_values.class.should == Array
|
243
|
-
local_test_ds.should respond_to(:coverage_values)
|
244
|
-
local_test_ds.should respond_to(:coverage_values=)
|
245
|
-
local_test_ds.should respond_to(:coverage_append)
|
246
|
-
local_test_ds.should respond_to(:creation_date_values)
|
247
|
-
local_test_ds.should respond_to(:creation_date_append)
|
248
|
-
local_test_ds.should respond_to(:creation_date_values=)
|
249
|
-
local_test_ds.should respond_to(:mydate_values)
|
250
|
-
local_test_ds.should respond_to(:mydate_append)
|
251
|
-
local_test_ds.should respond_to(:mydate_values=)
|
252
|
-
end
|
253
|
-
|
254
|
-
it "should track field values at instance level, not at class level" do
|
255
|
-
local_test_ds1 = SpecDatastream.new(@test_object.inner_object, nil)
|
256
|
-
local_test_ds1.stubs(:content=>'')
|
257
|
-
local_test_ds2 = SpecDatastream.new(@test_object.inner_object, nil)
|
258
|
-
local_test_ds2.stubs(:content=>'')
|
259
|
-
local_test_ds1.publisher_values = ["publisher1", "publisher2"]
|
260
|
-
local_test_ds2.publisher_values = ["publisherA", "publisherB"]
|
261
|
-
|
262
|
-
local_test_ds2.publisher_values.should == ["publisherA", "publisherB"]
|
263
|
-
local_test_ds1.publisher_values.should == ["publisher1", "publisher2"]
|
264
|
-
end
|
265
|
-
|
266
|
-
it "should allow you to add field values using <<" do
|
267
|
-
local_test_ds1 = SpecDatastream.new(@test_object.inner_object, nil)
|
268
|
-
local_test_ds1.stubs(:content=>'')
|
269
|
-
local_test_ds1.publisher_values << "publisher1"
|
270
|
-
local_test_ds1.publisher_values.should == ["publisher1"]
|
271
|
-
end
|
272
|
-
|
273
|
-
it "should create setter that always turns non-arrays into arrays" do
|
274
|
-
local_test_ds = SpecDatastream.new(@test_object.inner_object, nil)
|
275
|
-
local_test_ds.stubs(:content=>'')
|
276
|
-
local_test_ds.publisher_values = "Foo"
|
277
|
-
local_test_ds.publisher_values.should == ["Foo"]
|
278
|
-
end
|
279
|
-
|
280
|
-
it "should create setter that sets datastream.dirty? to true" do
|
281
|
-
local_test_ds = SpecDatastream.new(@test_object.inner_object, nil)
|
282
|
-
local_test_ds.stubs(:content=>'')
|
283
|
-
local_test_ds.should_not be_dirty
|
284
|
-
local_test_ds.publisher_values = "Foo"
|
285
|
-
local_test_ds.should be_dirty
|
286
|
-
|
287
|
-
# Note: If you use << to append values, the datastream will not be marked as dirty!
|
288
|
-
#local_test_ds.dirty = false
|
289
|
-
|
290
|
-
#local_test_ds.should_not be_dirty
|
291
|
-
#local_test_ds.publisher_values << "Foo"
|
292
|
-
#local_test_ds.should be_dirty
|
293
|
-
end
|
294
|
-
|
295
|
-
it "should add any extra opts to the field hash" do
|
296
|
-
local_test_ds = SpecDatastream.new(nil, nil)
|
297
|
-
local_test_ds.field "myfield", :string, :foo => "foo", :bar => "bar"
|
298
|
-
local_test_ds.fields[:myfield].should have_key(:foo)
|
299
|
-
local_test_ds.fields[:myfield][:foo].should == "foo"
|
300
|
-
local_test_ds.fields[:myfield].should have_key(:bar)
|
301
|
-
local_test_ds.fields[:myfield][:bar].should == "bar"
|
302
|
-
end
|
303
|
-
|
304
|
-
end
|
305
|
-
|
306
|
-
describe ".to_solr" do
|
307
|
-
|
308
|
-
after(:all) do
|
309
|
-
# Revert to default mappings after running tests
|
310
|
-
ActiveFedora::SolrService.load_mappings
|
311
|
-
end
|
312
|
-
|
313
|
-
it "should provide .to_solr and return a SolrDocument" do
|
314
|
-
@test_ds.should respond_to(:to_solr)
|
315
|
-
@test_ds.to_solr.should be_kind_of(Hash)
|
316
|
-
end
|
317
|
-
|
318
|
-
it "should optionally allow you to provide the Solr::Document to add fields to and return that document when done" do
|
319
|
-
doc = Hash.new
|
320
|
-
@test_ds.to_solr(doc).should equal(doc)
|
321
|
-
end
|
322
|
-
|
323
|
-
it "should iterate through @fields hash" do
|
324
|
-
@test_ds.expects(:fields).returns(@sample_fields)
|
325
|
-
solr_doc = @test_ds.to_solr
|
326
|
-
|
327
|
-
solr_doc["publisher_t"].should == ["publisher1"]
|
328
|
-
solr_doc["coverage_t"].sort.should == ["coverage1", "coverage2"]
|
329
|
-
solr_doc["creation_date_dt"].should == ["fake-date"]
|
330
|
-
solr_doc["mydate_dt"].should == ["fake-date"]
|
331
|
-
|
332
|
-
solr_doc["empty_field_t"].should be_nil
|
333
|
-
end
|
334
|
-
|
335
|
-
it 'should append create keys in format field_name + _ + field_type' do
|
336
|
-
@test_ds.stubs(:fields).returns(@sample_fields)
|
337
|
-
|
338
|
-
#should have these
|
339
|
-
|
340
|
-
@test_ds.to_solr["publisher_t"].should_not be_nil
|
341
|
-
@test_ds.to_solr["coverage_t"].should_not be_nil
|
342
|
-
@test_ds.to_solr["creation_date_dt"].should_not be_nil
|
343
|
-
|
344
|
-
#should NOT have these
|
345
|
-
@test_ds.to_solr["narrator"].should be_nil
|
346
|
-
@test_ds.to_solr["title"].should be_nil
|
347
|
-
@test_ds.to_solr["empty_field"].should be_nil
|
348
|
-
|
349
|
-
end
|
350
|
-
|
351
|
-
it "should use Solr mappings to generate field names" do
|
352
|
-
ActiveFedora::SolrService.load_mappings(File.join(File.dirname(__FILE__), "..", "..", "config", "solr_mappings_af_0.1.yml"))
|
353
|
-
@test_ds.stubs(:fields).returns(@sample_fields)
|
354
|
-
solr_doc = @test_ds.to_solr
|
355
|
-
|
356
|
-
#should have these
|
357
|
-
|
358
|
-
solr_doc["publisher_field"].should == ["publisher1"]
|
359
|
-
solr_doc["coverage_field"].sort.should == ["coverage1", "coverage2"]
|
360
|
-
solr_doc["creation_date_date"].should == ["fake-date"]
|
361
|
-
solr_doc["mydate_date"].should == ["fake-date"]
|
362
|
-
|
363
|
-
solr_doc["publisher_t"].should be_nil
|
364
|
-
solr_doc["coverage_t"].should be_nil
|
365
|
-
solr_doc["creation_date_dt"].should be_nil
|
366
|
-
|
367
|
-
# Reload default mappings
|
368
|
-
ActiveFedora::SolrService.load_mappings
|
369
|
-
end
|
370
|
-
|
371
|
-
it 'should append _dt to dates' do
|
372
|
-
ActiveFedora::SolrService.load_mappings
|
373
|
-
@test_ds.expects(:fields).returns(@sample_fields).at_least_once
|
374
|
-
|
375
|
-
@test_ds.to_solr["creation_date_dt"].should_not be_nil
|
376
|
-
@test_ds.to_solr["mydate_dt"].should_not be_nil
|
377
|
-
|
378
|
-
#should NOT have these
|
379
|
-
|
380
|
-
@test_ds.to_solr["mydate"].should be_nil
|
381
|
-
@test_ds.to_solr["creation_date_date"].should be_nil
|
382
|
-
end
|
383
|
-
|
384
|
-
end
|
385
|
-
|
386
|
-
describe '.fields' do
|
387
|
-
it "should return a Hash" do
|
388
|
-
@test_ds.fields.should be_instance_of(Hash)
|
389
|
-
end
|
390
|
-
end
|
391
|
-
|
392
|
-
end
|