active-fedora 5.4.0 → 5.5.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,9 +3,14 @@ require 'spec_helper'
3
3
  describe ActiveFedora::NtriplesRDFDatastream do
4
4
  before do
5
5
  class MyDatastream < ActiveFedora::NtriplesRDFDatastream
6
- register_vocabularies RDF::DC, RDF::FOAF, RDF::RDFS
7
6
  map_predicates do |map|
8
- map.title(:in => RDF::DC)
7
+ map.title(:in => RDF::DC) do |index|
8
+ index.as :searchable, :facetable, :displayable
9
+ end
10
+ map.date_uploaded(:to => "dateSubmitted", :in => RDF::DC) do |index|
11
+ index.type :date
12
+ index.as :searchable, :displayable, :sortable
13
+ end
9
14
  map.part(:to => "hasPart", :in => RDF::DC)
10
15
  map.based_near(:in => RDF::FOAF)
11
16
  map.related_url(:to => "seeAlso", :in => RDF::RDFS)
@@ -13,14 +18,16 @@ describe ActiveFedora::NtriplesRDFDatastream do
13
18
  end
14
19
  class RdfTest < ActiveFedora::Base
15
20
  has_metadata :name=>'rdf', :type=>MyDatastream
16
- delegate :based_near, :to=>'rdf'
17
- delegate :related_url, :to=>'rdf'
18
- delegate :part, :to=>'rdf'
21
+ delegate_to 'rdf', [:based_near, :related_url, :part, :date_uploaded]
19
22
  delegate :title, :to=>'rdf', :unique=>true
20
23
  end
21
24
  @subject = RdfTest.new
22
25
  end
23
26
 
27
+ subject {
28
+ @subject
29
+ }
30
+
24
31
  after do
25
32
  Object.send(:remove_const, :RdfTest)
26
33
  Object.send(:remove_const, :MyDatastream)
@@ -30,6 +37,48 @@ describe ActiveFedora::NtriplesRDFDatastream do
30
37
  @subject.save
31
38
  end
32
39
 
40
+ it "should save content properly upon save" do
41
+ foo = RdfTest.new(:pid=>'test:1') #Pid needs to match the subject in the loaded file
42
+ foo.title = 'Hamlet'
43
+ foo.save
44
+ foo.title.should == 'Hamlet'
45
+ foo.rdf.content = File.new('spec/fixtures/mixed_rdf_descMetadata.nt').read
46
+ foo.save
47
+ foo.title.should == 'Title of work'
48
+ end
49
+
50
+ it "should delegate as_json to the fields" do
51
+ @subject = RdfTest.new(title: "Title of work")
52
+ @subject.rdf.title.as_json.should == ["Title of work"]
53
+ @subject.rdf.title.to_json.should == "\[\"Title of work\"\]"
54
+ end
55
+
56
+ it "should solrize even when the object is not new" do
57
+ foo = RdfTest.new
58
+ foo.should_receive(:update_index).once
59
+ foo.title = "title1"
60
+ foo.save
61
+ foo = RdfTest.find(foo.pid)
62
+ foo.should_receive(:update_index).once
63
+ foo.title = "The Work2"
64
+ foo.save
65
+ end
66
+
67
+ it "should serialize dates" do
68
+ subject.date_uploaded = Date.parse('2012-11-02')
69
+ subject.date_uploaded.first.should be_kind_of Date
70
+ solr_document = subject.to_solr
71
+ solr_document["my_datastream__date_uploaded_dt"].should == ['2012-11-02T00:00:00Z']
72
+ end
73
+
74
+ it "should produce a solr document" do
75
+ @subject = RdfTest.new(title: "War and Peace")
76
+ solr_document = @subject.to_solr
77
+ solr_document["my_datastream__title_display"].should == ["War and Peace"]
78
+ solr_document["my_datastream__title_facet"].should == ["War and Peace"]
79
+ solr_document["my_datastream__title_t"].should == ["War and Peace"]
80
+ end
81
+
33
82
  it "should set and recall values" do
34
83
  @subject.title = 'War and Peace'
35
84
  @subject.rdf.should be_changed
@@ -149,7 +198,6 @@ describe ActiveFedora::NtriplesRDFDatastream do
149
198
  describe "term proxy methods" do
150
199
  before(:each) do
151
200
  class TitleDatastream < ActiveFedora::NtriplesRDFDatastream
152
- register_vocabularies RDF::DC
153
201
  map_predicates { |map| map.title(:in => RDF::DC) }
154
202
  end
155
203
  class Foobar < ActiveFedora::Base
@@ -54,7 +54,7 @@ module Hydra
54
54
  t.computing_id
55
55
  }
56
56
  # lookup :person, :first_name
57
- t.person(:ref=>:name, :attributes=>{:type=>"personal"}, :index_as=>[:facetable])
57
+ t.person(:ref=>:name, :attributes=>{:type=>"personal"}, :index_as=>[:facetable, :searchable])
58
58
  t.department(:proxy=>[:person,:description],:index_as=>[:facetable])
59
59
  t.organization(:ref=>:name, :attributes=>{:type=>"corporate"}, :index_as=>[:facetable])
60
60
  t.conference(:ref=>:name, :attributes=>{:type=>"conference"}, :index_as=>[:facetable])
@@ -92,6 +92,8 @@ describe ActiveFedora do
92
92
 
93
93
  describe "with no explicit config path" do
94
94
  it "should look for the file in the path defined at Rails.root" do
95
+ ActiveFedora::SolrService.stub(:load_mappings) #necessary or else it will load the solrizer config and it breaks other tests in the suite.
96
+
95
97
  stub_rails(:root=>File.join(File.dirname(__FILE__),"../fixtures/rails_root"))
96
98
  ActiveFedora.init()
97
99
  ActiveFedora.config.credentials[:url].should == "http://testhost.com:8983/fedora"
@@ -384,11 +384,6 @@ describe ActiveFedora::Base do
384
384
  end
385
385
 
386
386
  describe ".to_solr" do
387
- after(:all) do
388
- # Revert to default mappings after running tests
389
- ActiveFedora::SolrService.load_mappings
390
- end
391
-
392
387
  it "should provide .to_solr" do
393
388
  @test_object.should respond_to(:to_solr)
394
389
  end
@@ -419,26 +414,30 @@ describe ActiveFedora::Base do
419
414
  solr_doc["active_fedora_model_s"].should eql("FooHistory")
420
415
  end
421
416
 
422
- it "should use mappings.yml to decide names of solr fields" do
423
- cdate = "2008-07-02T05:09:42Z"
424
- mdate = "2009-07-07T23:37:18Z"
425
- @test_object.stub(:create_date).and_return(cdate)
426
- @test_object.stub(:modified_date).and_return(mdate)
427
- solr_doc = @test_object.to_solr
428
- solr_doc["system_create_dt"].should eql(cdate)
429
- solr_doc["system_modified_dt"].should eql(mdate)
430
- solr_doc[:id].should eql("#{@test_object.pid}")
431
- solr_doc["active_fedora_model_s"].should eql(@test_object.class.inspect)
432
-
433
- ActiveFedora::SolrService.load_mappings(File.join(File.dirname(__FILE__), "..", "..", "config", "solr_mappings_af_0.1.yml"))
434
- solr_doc = @test_object.to_solr
435
- [:system_create_dt, :system_modified_dt, :active_fedora_model_s].each do |fn|
436
- solr_doc[fn].should == nil
417
+ describe "using mappings.yml" do
418
+ before do
419
+ @old_mapper = ActiveFedora::SolrService.default_field_mapper.dup
420
+ ActiveFedora::SolrService.load_mappings(File.join(File.dirname(__FILE__), "..", "..", "config", "solr_mappings_af_0.1.yml"))
421
+ end
422
+ after do
423
+ ActiveFedora::SolrService.default_field_mapper = @old_mapper
424
+ end
425
+
426
+ it "should decide names of solr fields" do
427
+ cdate = "2008-07-02T05:09:42Z"
428
+ mdate = "2009-07-07T23:37:18Z"
429
+ @test_object.stub(:create_date).and_return(cdate)
430
+ @test_object.stub(:modified_date).and_return(mdate)
431
+
432
+ solr_doc = @test_object.to_solr
433
+ [:system_create_dt, :system_modified_dt, :active_fedora_model_s].each do |fn|
434
+ solr_doc[fn].should == nil
435
+ end
436
+ solr_doc["system_create_date"].should eql(cdate)
437
+ solr_doc["system_modified_date"].should eql(mdate)
438
+ solr_doc[:id].should eql("#{@test_object.pid}")
439
+ solr_doc["active_fedora_model_field"].should eql(@test_object.class.inspect)
437
440
  end
438
- solr_doc["system_create_date"].should eql(cdate)
439
- solr_doc["system_modified_date"].should eql(mdate)
440
- solr_doc[:id].should eql("#{@test_object.pid}")
441
- solr_doc["active_fedora_model_field"].should eql(@test_object.class.inspect)
442
441
  end
443
442
 
444
443
  it "should call .to_solr on all SimpleDatastreams and OmDatastreams, passing the resulting document to solr" do
@@ -145,6 +145,7 @@ describe ActiveFedora::FileConfigurator do
145
145
  subject.reset!
146
146
  end
147
147
  it "should load the file specified in fedora_config_path" do
148
+ subject.stub(:load_solrizer_config)
148
149
  subject.should_receive(:get_config_path).with(:fedora).and_return("/path/to/fedora.yml")
149
150
  subject.should_receive(:load_solr_config)
150
151
  IO.should_receive(:read).with("/path/to/fedora.yml").and_return("development:\n url: http://devfedora:8983\ntest:\n url: http://myfedora:8080")
@@ -153,6 +154,7 @@ describe ActiveFedora::FileConfigurator do
153
154
  end
154
155
 
155
156
  it "should allow sharding" do
157
+ subject.stub(:load_solrizer_config)
156
158
  subject.should_receive(:get_config_path).with(:fedora).and_return("/path/to/fedora.yml")
157
159
  subject.should_receive(:load_solr_config)
158
160
  IO.should_receive(:read).with("/path/to/fedora.yml").and_return("development:\n url: http://devfedora:8983\ntest:\n- url: http://myfedora:8080\n- url: http://myfedora:8081")
@@ -161,6 +163,7 @@ describe ActiveFedora::FileConfigurator do
161
163
  end
162
164
 
163
165
  it "should parse the file using ERb" do
166
+ subject.stub(:load_solrizer_config)
164
167
  subject.should_receive(:get_config_path).with(:fedora).and_return("/path/to/fedora.yml")
165
168
  subject.should_receive(:load_solr_config)
166
169
  IO.should_receive(:read).with("/path/to/fedora.yml").and_return("development:\n url: http://devfedora:<%= 8983 %>\ntest:\n url: http://myfedora:<%= 8081 %>")
@@ -174,6 +177,7 @@ describe ActiveFedora::FileConfigurator do
174
177
  subject.reset!
175
178
  end
176
179
  it "should load the file specified in solr_config_path" do
180
+ subject.stub(:load_solrizer_config)
177
181
  subject.should_receive(:get_config_path).with(:solr).and_return("/path/to/solr.yml")
178
182
  subject.should_receive(:load_fedora_config)
179
183
  IO.should_receive(:read).with("/path/to/solr.yml").and_return("development:\n default:\n url: http://devsolr:8983\ntest:\n default:\n url: http://mysolr:8080")
@@ -182,6 +186,7 @@ describe ActiveFedora::FileConfigurator do
182
186
  end
183
187
 
184
188
  it "should parse the file using ERb" do
189
+ subject.stub(:load_solrizer_config)
185
190
  subject.should_receive(:get_config_path).with(:solr).and_return("/path/to/solr.yml")
186
191
  subject.should_receive(:load_fedora_config)
187
192
  IO.should_receive(:read).with("/path/to/solr.yml").and_return("development:\n default:\n url: http://devsolr:<%= 8983 %>\ntest:\n default:\n url: http://mysolr:<%= 8081 %>")
@@ -246,6 +251,7 @@ describe ActiveFedora::FileConfigurator do
246
251
  subject.should respond_to(:solr_config_path)
247
252
  end
248
253
  it "loads a config from the current working directory as a second choice" do
254
+ subject.stub(:load_solrizer_config)
249
255
  Dir.stub(:getwd).and_return(@fake_rails_root)
250
256
  subject.init
251
257
  subject.get_config_path(:fedora).should eql("#{@fake_rails_root}/config/fedora.yml")
@@ -253,6 +259,7 @@ describe ActiveFedora::FileConfigurator do
253
259
  end
254
260
  it "loads the config that ships with this gem as a last choice" do
255
261
  Dir.stub(:getwd).and_return("/fake/path")
262
+ subject.stub(:load_solrizer_config)
256
263
  logger.should_receive(:warn).with("Using the default fedora.yml that comes with active-fedora. If you want to override this, pass the path to fedora.yml to ActiveFedora - ie. ActiveFedora.init(:fedora_config_path => '/path/to/fedora.yml') - or set Rails.root and put fedora.yml into \#{Rails.root}/config.").exactly(3).times
257
264
  subject.init
258
265
  expected_config = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "config"))
@@ -276,6 +283,7 @@ describe ActiveFedora::FileConfigurator do
276
283
  end
277
284
 
278
285
  it "loads a config from Rails.root as a first choice" do
286
+ subject.stub(:load_solrizer_config)
279
287
  subject.init
280
288
  subject.get_config_path(:fedora).should eql("#{Rails.root}/config/fedora.yml")
281
289
  subject.solr_config_path.should eql("#{Rails.root}/config/solr.yml")
@@ -9,7 +9,7 @@ describe ActiveFedora::NomDatastream do
9
9
  t.a :path => '//a', :accessor => lambda { |x| x.text }, :index => 'a_s'
10
10
  t.b :path => '//b', :index => 'b_s'
11
11
  end
12
- end
12
+ end
13
13
 
14
14
  MyNomDatastream.from_xml '<root><a>123</a><b><c>asdf</c></b></root>'
15
15
  }
@@ -23,4 +23,35 @@ describe ActiveFedora::NomDatastream do
23
23
  subject.to_solr['b_s'].should include('asdf')
24
24
  end
25
25
  end
26
+
27
+ describe "with options for .set_terminology" do
28
+ subject {
29
+ class TerminologyOptions < ActiveFedora::NomDatastream
30
+ set_terminology({
31
+ :namespaces => {
32
+ 'dc' => "http://purl.org/dc/elements/1.1/",
33
+ 'dcterms' => "http://purl.org/dc/terms/"
34
+ }
35
+ }) do |t|
36
+ t.a :path => 'a', :xmlns => 'dc', :accessor => lambda { |x| x.text }
37
+ end
38
+ end
39
+
40
+ TerminologyOptions.from_xml %(
41
+ <root
42
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
43
+ xmlns:dcterms="http://purl.org/dc/terms/"
44
+ >
45
+ <dc:a>123</dc:a>
46
+ <dcterms:a>not-part-of-a</dcterms:a>
47
+ <dcterms:b>abcd</dcterms:b>
48
+ </root>
49
+ )
50
+ }
51
+
52
+ it "should scope #a attribute to only the dc namespace" do
53
+ subject.a.should == ["123"]
54
+ end
55
+
56
+ end
26
57
  end
@@ -4,7 +4,6 @@ describe ActiveFedora::NtriplesRDFDatastream do
4
4
  describe "an instance with content" do
5
5
  before do
6
6
  class MyDatastream < ActiveFedora::NtriplesRDFDatastream
7
- register_vocabularies RDF::DC, RDF::FOAF, RDF::RDFS
8
7
  map_predicates do |map|
9
8
  map.created(:in => RDF::DC)
10
9
  map.title(:in => RDF::DC)
@@ -14,21 +13,11 @@ describe ActiveFedora::NtriplesRDFDatastream do
14
13
  map.related_url(:to => "seeAlso", :in => RDF::RDFS)
15
14
  end
16
15
  end
17
- class Foo < ActiveFedora::Base
18
- has_metadata :name => "descMetadata", :type => MyDatastream
19
- delegate :created, :to => :descMetadata
20
- delegate :title, :to => :descMetadata
21
- delegate :publisher, :to => :descMetadata
22
- delegate :based_near, :to => :descMetadata
23
- delegate :related_url, :to => :descMetadata
24
- end
25
- @object = Foo.new(:pid => 'test:1')
26
- @subject = @object.descMetadata
16
+ @subject = MyDatastream.new(stub('inner object', :pid=>'test:1', :new? =>true), 'descMetadata')
27
17
  @subject.content = File.new('spec/fixtures/mixed_rdf_descMetadata.nt').read
28
- @object.save
29
18
  end
30
19
  after do
31
- @object.delete
20
+ Object.send(:remove_const, :MyDatastream)
32
21
  end
33
22
  it "should have a subject" do
34
23
  @subject.rdf_subject.should == "info:fedora/test:1"
@@ -50,10 +39,6 @@ describe ActiveFedora::NtriplesRDFDatastream do
50
39
  @subject.related_url.should == ["http://google.com/"]
51
40
  end
52
41
 
53
- it "should delegate as_json to the fields" do
54
- @subject.title.as_json.should == ["Title of work"]
55
- @subject.title.to_json.should == "\[\"Title of work\"\]"
56
- end
57
42
 
58
43
  it "should return fields that are not TermProxies" do
59
44
  @subject.created.should be_kind_of Array
@@ -98,7 +83,6 @@ describe ActiveFedora::NtriplesRDFDatastream do
98
83
  describe "an instance with a custom subject" do
99
84
  before do
100
85
  class MyDatastream < ActiveFedora::NtriplesRDFDatastream
101
- register_vocabularies RDF::DC, RDF::FOAF, RDF::RDFS
102
86
  rdf_subject { |ds| "info:fedora/#{ds.pid}/content" }
103
87
  map_predicates do |map|
104
88
  map.created(:in => RDF::DC)
@@ -126,7 +110,6 @@ describe ActiveFedora::NtriplesRDFDatastream do
126
110
  describe "a new instance" do
127
111
  before(:each) do
128
112
  class MyDatastream < ActiveFedora::NtriplesRDFDatastream
129
- register_vocabularies RDF::DC
130
113
  map_predicates do |map|
131
114
  map.publisher(:in => RDF::DC)
132
115
  end
@@ -149,7 +132,6 @@ describe ActiveFedora::NtriplesRDFDatastream do
149
132
  describe "solr integration" do
150
133
  before(:all) do
151
134
  class MyDatastream < ActiveFedora::NtriplesRDFDatastream
152
- register_vocabularies RDF::DC, RDF::FOAF, RDF::RDFS
153
135
  map_predicates do |map|
154
136
  map.created(:in => RDF::DC) do |index|
155
137
  index.as :sortable, :displayable
@@ -177,33 +159,16 @@ describe ActiveFedora::NtriplesRDFDatastream do
177
159
  end
178
160
  before(:each) do
179
161
  @subject.stub(:pid => 'test:1')
180
- @subject.stub(:new? => false)
181
- @sample_fields = {:my_datastream__publisher => {:values => ["publisher1"], :type => :string, :behaviors => [:facetable, :sortable, :searchable, :displayable]},
182
- :my_datastream__based_near => {:values => ["coverage1", "coverage2"], :type => :text, :behaviors => [:displayable, :facetable, :searchable]},
183
- :my_datastream__created => {:values => "fake-date", :type => :date, :behaviors => [:sortable, :displayable]},
184
- :my_datastream__title => {:values => "fake-title", :type => :text, :behaviors => [:searchable, :displayable, :sortable]},
185
- :my_datastream__related_url => {:values => "http://example.org/", :type =>:string, :behaviors => [:searchable]},
186
- :my_datastream__empty_field => {:values => [], :type => :string, :behaviors => [:searchable]}
187
- }
188
- end
189
- after(:all) do
190
- # Revert to default mappings after running tests
191
- ActiveFedora::SolrService.load_mappings
192
162
  end
193
163
  it "should provide .to_solr and return a SolrDocument" do
194
164
  @subject.should respond_to(:to_solr)
195
165
  @subject.to_solr.should be_kind_of(Hash)
196
166
  end
197
- it "should provide .fields and return a Hash" do
198
- @subject.should respond_to(:fields)
199
- @subject.fields.should be_kind_of(Hash)
200
- end
201
167
  it "should optionally allow you to provide the Solr::Document to add fields to and return that document when done" do
202
168
  doc = Hash.new
203
169
  @subject.to_solr(doc).should == doc
204
170
  end
205
171
  it "should iterate through @fields hash" do
206
- @subject.should_receive(:fields).and_return(@sample_fields)
207
172
  solr_doc = @subject.to_solr
208
173
  solr_doc["my_datastream__publisher_t"].should == ["publisher1"]
209
174
  solr_doc["my_datastream__publisher_sort"].should == ["publisher1"]
@@ -212,47 +177,20 @@ describe ActiveFedora::NtriplesRDFDatastream do
212
177
  solr_doc["my_datastream__based_near_t"].sort.should == ["coverage1", "coverage2"]
213
178
  solr_doc["my_datastream__based_near_display"].sort.should == ["coverage1", "coverage2"]
214
179
  solr_doc["my_datastream__based_near_facet"].sort.should == ["coverage1", "coverage2"]
215
- solr_doc["my_datastream__created_sort"].should == ["fake-date"]
216
- solr_doc["my_datastream__created_display"].should == ["fake-date"]
180
+ solr_doc["my_datastream__created_sort"].should == ["2009-10-10"]
181
+ solr_doc["my_datastream__created_display"].should == ["2009-10-10"]
217
182
  solr_doc["my_datastream__title_t"].should == ["fake-title"]
218
183
  solr_doc["my_datastream__title_sort"].should == ["fake-title"]
219
184
  solr_doc["my_datastream__title_display"].should == ["fake-title"]
220
185
  solr_doc["my_datastream__related_url_t"].should == ["http://example.org/"]
221
186
  solr_doc["my_datastream__empty_field_t"].should be_nil
222
- end
223
- it 'should append create keys in format field_name + _ + field_type' do
224
- @subject.stub(:fields).and_return(@sample_fields)
225
-
226
- #should have these
227
- @subject.to_solr["my_datastream__publisher_t"].should_not be_nil
228
- @subject.to_solr["my_datastream__based_near_t"].should_not be_nil
229
- @subject.to_solr["my_datastream__title_t"].should_not be_nil
230
- @subject.to_solr["my_datastream__related_url_t"].should_not be_nil
231
187
 
232
188
  #should NOT have these
233
- @subject.to_solr["my_datastream__narrator"].should be_nil
234
- @subject.to_solr["my_datastream__empty_field"].should be_nil
235
- @subject.to_solr["my_datastream__creator"].should be_nil
189
+ solr_doc["my_datastream__narrator"].should be_nil
190
+ solr_doc["my_datastream__empty_field"].should be_nil
191
+ solr_doc["my_datastream__creator"].should be_nil
236
192
  end
237
- it "should use Solr mappings to generate field names" do
238
- ActiveFedora::SolrService.load_mappings(File.join(File.dirname(__FILE__), "..", "..", "config", "solr_mappings_af_0.1.yml"))
239
- @subject.stub(:fields).and_return(@sample_fields)
240
- solr_doc = @subject.to_solr
241
193
 
242
- #should have these
243
- solr_doc["my_datastream__publisher_field"].should == ["publisher1"]
244
- solr_doc["my_datastream__based_near_field"].sort.should == ["coverage1", "coverage2"]
245
- solr_doc["my_datastream__created_display"].should == ["fake-date"]
246
- solr_doc["my_datastream__title_field"].should == ["fake-title"]
247
-
248
- solr_doc["my_datastream__title_t"].should be_nil
249
- solr_doc["my_datastream__publisher_t"].should be_nil
250
- solr_doc["my_datastream__based_near_t"].should be_nil
251
- solr_doc["my_datastream__created_dt"].should be_nil
252
-
253
- # Reload default mappings
254
- ActiveFedora::SolrService.load_mappings
255
- end
256
194
  describe "with an actual object" do
257
195
  before(:each) do
258
196
  class Foo < ActiveFedora::Base
@@ -278,75 +216,33 @@ describe ActiveFedora::NtriplesRDFDatastream do
278
216
  @obj.save
279
217
  end
280
218
 
281
- it "should save content properly upon save" do
282
- foo = Foo.new(:pid => 'test:1')
283
- foo.title = 'Hamlet'
284
- foo.save
285
- foo.title.should == ['Hamlet']
286
- foo.descMetadata.content = File.new('spec/fixtures/mixed_rdf_descMetadata.nt').read
287
- foo.save
288
- foo.title.should == ['Title of work']
289
- end
290
219
  describe ".fields()" do
291
- it "should return the right # of fields" do
292
- @obj.fields.keys.count.should == 5
293
- end
294
220
  it "should return the right fields" do
295
- @obj.fields.keys.should include(:my_datastream__related_url)
296
- @obj.fields.keys.should include(:my_datastream__publisher)
297
- @obj.fields.keys.should include(:my_datastream__created)
298
- @obj.fields.keys.should include(:my_datastream__title)
299
- @obj.fields.keys.should include(:my_datastream__based_near)
221
+ @obj.send(:fields).keys.should == [:created, :title, :publisher, :based_near, :related_url]
300
222
  end
301
223
  it "should return the right values" do
302
- @obj.fields[:my_datastream__related_url][:values].should == ["http://example.org/blogtastic/"]
224
+ fields = @obj.send(:fields)
225
+ fields[:related_url][:values].should == ["http://example.org/blogtastic/"]
226
+ fields[:based_near][:values].should == ["Tacoma, WA", "Renton, WA"]
303
227
  end
304
228
  it "should return the right type information" do
305
- @obj.fields[:my_datastream__created][:type].should == :date
306
- end
307
- it "should return multi-value fields as expected" do
308
- @obj.fields[:my_datastream__based_near][:values].count.should == 2
309
- @obj.fields[:my_datastream__based_near][:values].should include("Tacoma, WA")
310
- @obj.fields[:my_datastream__based_near][:values].should include("Renton, WA")
311
- end
312
- it "should solrize even when the object is not new" do
313
- foo = Foo.new
314
- foo.should_receive(:update_index).once
315
- foo.title = "title1"
316
- foo.save
317
- foo = Foo.find(foo.pid)
318
- foo.should_receive(:update_index).once
319
- foo.publisher = "Allah2"
320
- foo.title = "The Work2"
321
- foo.save
229
+ fields = @obj.send(:fields)
230
+ fields[:created][:type].should == :date
322
231
  end
323
232
  end
324
233
  describe ".to_solr()" do
325
- it "should return the right # of fields" do
326
- @obj.to_solr.keys.count.should == 13
327
- end
328
234
  it "should return the right fields" do
329
- @obj.to_solr.keys.should include("my_datastream__related_url_t")
330
- @obj.to_solr.keys.should include("my_datastream__publisher_t")
331
- @obj.to_solr.keys.should include("my_datastream__publisher_sort")
332
- @obj.to_solr.keys.should include("my_datastream__publisher_display")
333
- @obj.to_solr.keys.should include("my_datastream__publisher_facet")
334
- @obj.to_solr.keys.should include("my_datastream__created_sort")
335
- @obj.to_solr.keys.should include("my_datastream__created_display")
336
- @obj.to_solr.keys.should include("my_datastream__title_t")
337
- @obj.to_solr.keys.should include("my_datastream__title_sort")
338
- @obj.to_solr.keys.should include("my_datastream__title_display")
339
- @obj.to_solr.keys.should include("my_datastream__based_near_t")
340
- @obj.to_solr.keys.should include("my_datastream__based_near_facet")
341
- @obj.to_solr.keys.should include("my_datastream__based_near_display")
235
+ @obj.to_solr.keys.count.should == 13
236
+ @obj.to_solr.keys.should include("my_datastream__related_url_t", "my_datastream__publisher_t", "my_datastream__publisher_sort",
237
+ "my_datastream__publisher_display", "my_datastream__publisher_facet", "my_datastream__created_sort",
238
+ "my_datastream__created_display", "my_datastream__title_t", "my_datastream__title_sort", "my_datastream__title_display",
239
+ "my_datastream__based_near_t", "my_datastream__based_near_facet", "my_datastream__based_near_display")
240
+
342
241
  end
242
+
343
243
  it "should return the right values" do
344
244
  @obj.to_solr["my_datastream__related_url_t"].should == ["http://example.org/blogtastic/"]
345
- end
346
- it "should return multi-value fields as expected" do
347
- @obj.to_solr["my_datastream__based_near_t"].count.should == 2
348
- @obj.to_solr["my_datastream__based_near_t"].should include("Tacoma, WA")
349
- @obj.to_solr["my_datastream__based_near_t"].should include("Renton, WA")
245
+ @obj.to_solr["my_datastream__based_near_t"].should == ["Tacoma, WA","Renton, WA"]
350
246
  end
351
247
  end
352
248
  end