active-fedora 4.0.0.rc1 → 4.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/Gemfile.lock +2 -11
  2. data/History.txt +4 -1
  3. data/active-fedora.gemspec +2 -2
  4. data/lib/active_fedora/associations/association_collection.rb +1 -1
  5. data/lib/active_fedora/associations/belongs_to_association.rb +1 -1
  6. data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +1 -1
  7. data/lib/active_fedora/base.rb +10 -6
  8. data/lib/active_fedora/file_management.rb +1 -1
  9. data/lib/active_fedora/fixture_loader.rb +1 -1
  10. data/lib/active_fedora/model.rb +39 -38
  11. data/lib/active_fedora/nokogiri_datastream.rb +1 -1
  12. data/lib/active_fedora/persistence.rb +9 -11
  13. data/lib/active_fedora/predicates.rb +2 -2
  14. data/lib/active_fedora/rdf_datastream.rb +49 -7
  15. data/lib/active_fedora/relationships.rb +6 -9
  16. data/lib/active_fedora/service_definitions.rb +1 -1
  17. data/lib/active_fedora/solr_service.rb +15 -8
  18. data/lib/active_fedora/version.rb +1 -1
  19. data/lib/tasks/active_fedora.rake +3 -5
  20. data/lib/tasks/active_fedora_dev.rake +2 -1
  21. data/spec/fixtures/solr_rdf_descMetadata.nt +7 -0
  22. data/spec/integration/base_file_management_spec.rb +1 -1
  23. data/spec/integration/base_find_by_fields_spec.rb +16 -14
  24. data/spec/integration/base_spec.rb +10 -9
  25. data/spec/integration/datastream_collections_spec.rb +5 -5
  26. data/spec/integration/datastream_spec.rb +1 -1
  27. data/spec/integration/full_featured_model_spec.rb +1 -1
  28. data/spec/integration/model_spec.rb +14 -11
  29. data/spec/integration/mods_article_integration_spec.rb +2 -2
  30. data/spec/integration/nokogiri_datastream_spec.rb +1 -1
  31. data/spec/integration/ntriples_datastream_spec.rb +1 -0
  32. data/spec/integration/rels_ext_datastream_spec.rb +5 -6
  33. data/spec/integration/semantic_node_spec.rb +0 -1
  34. data/spec/integration/solr_service_spec.rb +8 -8
  35. data/spec/unit/base_extra_spec.rb +47 -7
  36. data/spec/unit/base_file_management_spec.rb +1 -1
  37. data/spec/unit/base_spec.rb +44 -15
  38. data/spec/unit/model_spec.rb +16 -29
  39. data/spec/unit/ntriples_datastream_spec.rb +152 -1
  40. data/spec/unit/relationships_spec.rb +16 -18
  41. data/spec/unit/solr_config_options_spec.rb +1 -3
  42. data/spec/unit/solr_service_spec.rb +12 -24
  43. metadata +68 -86
  44. data/spec/integration/base_loader_spec.rb +0 -40
@@ -31,24 +31,27 @@ describe ActiveFedora::Model do
31
31
  end
32
32
 
33
33
  describe '#find' do
34
- it "should return an array of instances of the calling Class" do
35
- result = ModelIntegrationSpec::Basic.find(:all)
36
- result.should be_instance_of(Array)
37
- # this test is meaningless if the array length is zero
38
- result.length.should > 0
39
- result.each do |obj|
40
- obj.class.should == ModelIntegrationSpec::Basic
34
+ describe "with :all" do
35
+ it "should return an array of instances of the calling Class" do
36
+ result = ModelIntegrationSpec::Basic.find(:all)
37
+ result.should be_instance_of(Array)
38
+ # this test is meaningless if the array length is zero
39
+ result.length.should > 0
40
+ result.each do |obj|
41
+ obj.class.should == ModelIntegrationSpec::Basic
42
+ end
41
43
  end
42
44
  end
45
+ describe "#find with a valid pid" do
46
+ subject { ActiveFedora::Base.find('hydrangea:fixture_mods_article1') }
47
+ it { should be_instance_of HydrangeaArticle}
48
+ end
43
49
  end
44
50
 
45
- describe "#find_document with a valid pid" do
46
- subject { ActiveFedora::Base.find_document('hydrangea:fixture_mods_article1') }
47
- it { should be_instance_of HydrangeaArticle}
48
- end
49
51
 
50
52
  describe '#load_instance' do
51
53
  it "should return an object of the given Model whose inner object is nil" do
54
+ ActiveSupport::Deprecation.expects(:warn).with("load_instance is deprecated. Use find instead")
52
55
  result = ModelIntegrationSpec::Basic.load_instance(@test_instance.pid)
53
56
  result.class.should == ModelIntegrationSpec::Basic
54
57
  result.inner_object.new?.should be_false
@@ -21,7 +21,7 @@ describe ActiveFedora::Base do
21
21
  end
22
22
 
23
23
  before(:each) do
24
- @test_article = HydrangeaArticle.load_instance("hydrangea:fixture_mods_article1")
24
+ @test_article = HydrangeaArticle.find("hydrangea:fixture_mods_article1")
25
25
  end
26
26
 
27
27
  describe ".update_indexed_attributes" do
@@ -37,7 +37,7 @@ describe ActiveFedora::Base do
37
37
  @test_article.update_indexed_attributes(test_args[:params], test_args[:opts])
38
38
  @test_article.get_values_from_datastream("descMetadata", [{:person=>0}, :first_name]).should == ["Replacement FirstName"]
39
39
  @test_article.save
40
- retrieved_article = HydrangeaArticle.load_instance("hydrangea:fixture_mods_article1")
40
+ retrieved_article = HydrangeaArticle.find("hydrangea:fixture_mods_article1")
41
41
  retrieved_article.get_values_from_datastream("descMetadata", [{:person=>0}, :first_name]).should == ["Replacement FirstName"]
42
42
  end
43
43
  end
@@ -26,7 +26,7 @@ describe ActiveFedora::NokogiriDatastream do
26
26
  before do
27
27
  @pid = "hydrangea:fixture_mods_article1"
28
28
  @test_solr_object = HydrangeaArticle2.load_instance_from_solr(@pid)
29
- @test_object = HydrangeaArticle2.load_instance(@pid)
29
+ @test_object = HydrangeaArticle2.find(@pid)
30
30
  end
31
31
 
32
32
  it "should return the same values whether getting from solr or Fedora" do
@@ -3,6 +3,7 @@ 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
6
7
  map_predicates do |map|
7
8
  map.title(:in => RDF::DC)
8
9
  map.part(:to => "hasPart", :in => RDF::DC)
@@ -73,8 +73,7 @@ describe ActiveFedora::RelsExtDatastream do
73
73
  @test_object.save
74
74
  # make sure that _something_ was actually added to the object's relationships hash
75
75
  @test_object.ids_for_outbound(:is_member_of).size.should == 1
76
- o = ActiveFedora::Base.load_instance(@test_object.pid)
77
- new_rels = ActiveFedora::Base.load_instance(@test_object.pid).relationships
76
+ new_rels = ActiveFedora::Base.find(@test_object.pid).relationships
78
77
  new_rels.should == @test_object.relationships
79
78
  end
80
79
 
@@ -115,16 +114,16 @@ describe ActiveFedora::RelsExtDatastream do
115
114
  model_rel = MockAFRelsSolr.to_class_uri
116
115
  #check inbound correct, testing goes to :has_part and testing2 goes to :has_member
117
116
  #get solr doc for @test_object2
118
- solr_doc = MockAFRelsSolr.find_by_solr(@test_object2.pid).hits.first
117
+ solr_doc = MockAFRelsSolr.find_by_solr(@test_object2.pid).first
119
118
  test_from_solr_object2 = MockAFRelsSolr.new
120
119
  test_from_solr_object2.rels_ext.from_solr(solr_doc)
121
- solr_doc = MockAFRelsSolr.find_by_solr(@test_object3.pid).hits.first
120
+ solr_doc = MockAFRelsSolr.find_by_solr(@test_object3.pid).first
122
121
  test_from_solr_object3 = MockAFRelsSolr.new
123
122
  test_from_solr_object3.rels_ext.from_solr(solr_doc)
124
- solr_doc = MockAFRelsSolr.find_by_solr(@test_object4.pid).hits.first
123
+ solr_doc = MockAFRelsSolr.find_by_solr(@test_object4.pid).first
125
124
  test_from_solr_object4 = MockAFRelsSolr.new
126
125
  test_from_solr_object4.rels_ext.from_solr(solr_doc)
127
- solr_doc = MockAFRelsSolr.find_by_solr(@test_object5.pid).hits.first
126
+ solr_doc = MockAFRelsSolr.find_by_solr(@test_object5.pid).first
128
127
  test_from_solr_object5 = MockAFRelsSolr.new
129
128
  test_from_solr_object5.rels_ext.from_solr(solr_doc)
130
129
 
@@ -152,7 +152,6 @@ describe ActiveFedora::SemanticNode do
152
152
  collection_members.first.pid.should == @test_object.pid
153
153
  collection_members.first.class.should == @test_object.class
154
154
  end
155
- it "should create useable inbound finders if :inbound is set to true"
156
155
  end
157
156
 
158
157
  describe "inbound relationship finders" do
@@ -43,12 +43,12 @@ describe ActiveFedora::SolrService do
43
43
  @foo_content = @foo_object.datastreams['descMetadata'].content
44
44
  end
45
45
  after(:all) do
46
- @test_object.delete
47
- @foo_object.delete
46
+ # @test_object.delete
47
+ # @foo_object.delete
48
48
  end
49
49
  it "should return an array of objects that are of the class stored in active_fedora_model_s" do
50
50
  query = "id\:#{ActiveFedora::SolrService.escape_uri_for_query(@test_object.pid)} OR id\:#{ActiveFedora::SolrService.escape_uri_for_query(@foo_object.pid)}"
51
- solr_result = ActiveFedora::SolrService.instance.conn.query(query)
51
+ solr_result = ActiveFedora::SolrService.query(query)
52
52
  result = ActiveFedora::SolrService.reify_solr_results(solr_result)
53
53
  result.length.should == 2
54
54
  result.each do |r|
@@ -58,7 +58,7 @@ describe ActiveFedora::SolrService do
58
58
 
59
59
  it 'should load objects from solr data if a :load_from_solr option is passed in' do
60
60
  query = "id\:#{ActiveFedora::SolrService.escape_uri_for_query(@test_object.pid)} OR id\:#{ActiveFedora::SolrService.escape_uri_for_query(@foo_object.pid)}"
61
- solr_result = ActiveFedora::SolrService.instance.conn.query(query)
61
+ solr_result = ActiveFedora::SolrService.query(query)
62
62
  result = ActiveFedora::SolrService.reify_solr_results(solr_result,{:load_from_solr=>true})
63
63
  result.length.should == 2
64
64
  result.each do |r|
@@ -75,7 +75,7 @@ describe ActiveFedora::SolrService do
75
75
 
76
76
  it 'should #reify a lightweight object as a new instance' do
77
77
  query = "id\:#{ActiveFedora::SolrService.escape_uri_for_query(@foo_object.pid)}"
78
- solr_result = ActiveFedora::SolrService.instance.conn.query(query)
78
+ solr_result = ActiveFedora::SolrService.query(query)
79
79
  result = ActiveFedora::SolrService.reify_solr_results(solr_result,{:load_from_solr=>true})
80
80
  solr_foo = result.first
81
81
  real_foo = solr_foo.reify
@@ -87,7 +87,7 @@ describe ActiveFedora::SolrService do
87
87
 
88
88
  it 'should #reify! a lightweight object within the same instance' do
89
89
  query = "id\:#{ActiveFedora::SolrService.escape_uri_for_query(@foo_object.pid)}"
90
- solr_result = ActiveFedora::SolrService.instance.conn.query(query)
90
+ solr_result = ActiveFedora::SolrService.query(query)
91
91
  result = ActiveFedora::SolrService.reify_solr_results(solr_result,{:load_from_solr=>true})
92
92
  solr_foo = result.first
93
93
  solr_foo.inner_object.should be_a(ActiveFedora::SolrDigitalObject)
@@ -98,7 +98,7 @@ describe ActiveFedora::SolrService do
98
98
 
99
99
  it 'should raise an exception when attempting to reify a first-class object' do
100
100
  query = "id\:#{ActiveFedora::SolrService.escape_uri_for_query(@foo_object.pid)}"
101
- solr_result = ActiveFedora::SolrService.instance.conn.query(query)
101
+ solr_result = ActiveFedora::SolrService.query(query)
102
102
  result = ActiveFedora::SolrService.reify_solr_results(solr_result,{:load_from_solr=>true})
103
103
  solr_foo = result.first
104
104
  lambda {solr_foo.reify}.should_not raise_exception
@@ -109,7 +109,7 @@ describe ActiveFedora::SolrService do
109
109
 
110
110
  it 'should call load_instance_from_solr if :load_from_solr option passed in' do
111
111
  query = "id\:#{ActiveFedora::SolrService.escape_uri_for_query(@test_object.pid)} OR id\:#{ActiveFedora::SolrService.escape_uri_for_query(@foo_object.pid)}"
112
- solr_result = ActiveFedora::SolrService.instance.conn.query(query)
112
+ solr_result = ActiveFedora::SolrService.query(query)
113
113
  ActiveFedora::Base.expects(:load_instance_from_solr).times(1)
114
114
  FooObject.expects(:load_instance_from_solr).times(1)
115
115
  result = ActiveFedora::SolrService.reify_solr_results(solr_result,{:load_from_solr=>true})
@@ -68,15 +68,26 @@ describe ActiveFedora::Base do
68
68
  end
69
69
 
70
70
  describe ".update_index" do
71
+ before do
72
+ mock_conn = mock("SolrConnection")
73
+ mock_conn.expects(:add)
74
+ mock_conn.expects(:commit)
75
+ mock_ss = mock("SolrService")
76
+ mock_ss.stubs(:conn).returns(mock_conn)
77
+ ActiveFedora::SolrService.stubs(:instance).returns(mock_ss)
78
+ end
79
+
71
80
  it "should call .to_solr on all MetadataDatastreams AND RelsExtDatastreams and pass the resulting document to solr" do
72
- ActiveFedora::SolrService.expects(:instance).returns(mock("SolrService", :conn => mock("SolrConnection", :update)))
73
81
  # Actually uses self.to_solr internally to gather solr info from all metadata datastreams
74
82
  mock1 = mock("ds1", :to_solr)
75
83
  mock2 = mock("ds2", :to_solr)
76
84
  mock3 = mock("RELS-EXT")
77
85
 
78
86
  mock_datastreams = {:ds1 => mock1, :ds2 => mock2, :rels_ext => mock3}
79
- mock_datastreams.values.each {|ds| ds.stubs(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(false)}
87
+ mock_datastreams.values.each do |ds|
88
+ ds.stubs(:kind_of?).with(ActiveFedora::RDFDatastream).returns(false)
89
+ ds.stubs(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(false)
90
+ end
80
91
  mock1.expects(:solrize_profile)
81
92
  mock2.expects(:solrize_profile)
82
93
  mock3.expects(:solrize_profile)
@@ -88,12 +99,36 @@ describe ActiveFedora::Base do
88
99
  @test_object.expects(:datastreams).returns(mock_datastreams)
89
100
  @test_object.expects(:solrize_profile)
90
101
  @test_object.expects(:solrize_relationships)
91
- @test_object.send :update_index
102
+ @test_object.update_index
103
+ end
104
+
105
+ it "should call .to_solr on all RDFDatastreams and pass the resulting document to solr" do
106
+ # Actually uses self.to_solr internally to gather solr info from all metadata datastreams
107
+ mock1 = mock("ds1", :to_solr)
108
+ mock2 = mock("ds2", :to_solr)
109
+ mock3 = mock("RELS-EXT")
110
+
111
+ mock_datastreams = {:ds1 => mock1, :ds2 => mock2, :rels_ext => mock3}
112
+ mock_datastreams.values.each do |ds|
113
+ ds.stubs(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(false)
114
+ ds.stubs(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(false)
115
+ end
116
+ mock1.expects(:solrize_profile)
117
+ mock2.expects(:solrize_profile)
118
+ mock3.expects(:solrize_profile)
119
+ mock1.expects(:kind_of?).with(ActiveFedora::RDFDatastream).returns(true)
120
+ mock2.expects(:kind_of?).with(ActiveFedora::RDFDatastream).returns(true)
121
+ mock3.expects(:kind_of?).with(ActiveFedora::RDFDatastream).returns(false)
122
+ #mock3.expects(:kind_of?).with(ActiveFedora::RelsExtDatastream).returns(true)
123
+
124
+ @test_object.expects(:datastreams).returns(mock_datastreams)
125
+ @test_object.expects(:solrize_profile)
126
+ @test_object.expects(:solrize_relationships)
127
+ @test_object.update_index
92
128
  end
93
129
 
94
- it "should retrieve a solr Connection and call Connection.update" do
95
- ActiveFedora::SolrService.expects(:instance).returns(mock("SolrService", :conn => mock("SolrConnection", :update)))
96
- @test_object.send :update_index
130
+ it "should retrieve a solr Connection and call Connection.add" do
131
+ @test_object.update_index
97
132
  end
98
133
 
99
134
  end
@@ -104,8 +139,13 @@ describe ActiveFedora::Base do
104
139
  end
105
140
 
106
141
  it "should delete object from repository and index" do
107
- ActiveFedora::SolrService.instance.conn.expects(:delete).with("__DO_NOT_USE__")
108
142
  @test_object.inner_object.stubs(:delete)
143
+ mock_conn = mock("SolrConnection")
144
+ mock_conn.expects(:delete_by_id).with("__DO_NOT_USE__")
145
+ mock_conn.expects(:commit)
146
+ mock_ss = mock("SolrService")
147
+ mock_ss.stubs(:conn).returns(mock_conn)
148
+ ActiveFedora::SolrService.stubs(:instance).returns(mock_ss)
109
149
  @test_object.expects(:inbound_relationships).returns({})
110
150
  @test_object.delete
111
151
  end
@@ -30,7 +30,7 @@ describe ActiveFedora::Base do
30
30
  mock_child = mock("object")
31
31
  mock_child.expects(:add_relationship).with(:is_part_of, @base)
32
32
  mock_child.expects(:save)
33
- ActiveFedora::Base.expects(:load_instance).with("_PID_").returns(mock_child)
33
+ ActiveFedora::Base.expects(:find).with("_PID_").returns(mock_child)
34
34
  @base.file_objects_append("_PID_")
35
35
  end
36
36
  end
@@ -328,8 +328,6 @@ describe ActiveFedora::Base do
328
328
  end
329
329
 
330
330
  describe '.save' do
331
-
332
-
333
331
  it "should return true and set persisted if object and datastreams all save successfully" do
334
332
  stub_get(@this_pid)
335
333
  stub_add_ds(@this_pid, ['RELS-EXT'])
@@ -403,6 +401,19 @@ describe ActiveFedora::Base do
403
401
 
404
402
  @test_object.save
405
403
  end
404
+ it "should update solr index with all metadata if any RDFDatastreams have changed" do
405
+ stub_ingest(@this_pid)
406
+ stub_add_ds(@this_pid, ['ds1', 'RELS-EXT'])
407
+
408
+ dirty_ds = ActiveFedora::NtriplesRDFDatastream.new(@test_object.inner_object, 'ds1')
409
+ rels_ds = ActiveFedora::RelsExtDatastream.new(@test_object.inner_object, 'RELS-EXT')
410
+ rels_ds.model = @test_object
411
+ @test_object.add_datastream(rels_ds)
412
+ @test_object.add_datastream(dirty_ds)
413
+ @test_object.expects(:update_index)
414
+
415
+ @test_object.save
416
+ end
406
417
  it "should NOT update solr index if no MetadataDatastreams have changed" do
407
418
  pending "Rels-ext is getting automatically added so we can't test this."
408
419
  ActiveFedora::DigitalObject.any_instance.stubs(:save)
@@ -497,11 +508,11 @@ describe ActiveFedora::Base do
497
508
  end
498
509
 
499
510
  it "should add pid, system_create_date and system_modified_date from object attributes" do
500
- @test_object.expects(:create_date).returns("cDate")
501
- @test_object.expects(:modified_date).returns("mDate")
511
+ @test_object.expects(:create_date).returns("2012-03-06T03:12:02Z")
512
+ @test_object.expects(:modified_date).returns("2012-03-07T03:12:02Z")
502
513
  solr_doc = @test_object.to_solr
503
- solr_doc["system_create_dt"].should eql("cDate")
504
- solr_doc["system_modified_dt"].should eql("mDate")
514
+ solr_doc["system_create_dt"].should eql("2012-03-06T03:12:02Z")
515
+ solr_doc["system_modified_dt"].should eql("2012-03-07T03:12:02Z")
505
516
  solr_doc[:id].should eql("#{@test_object.pid}")
506
517
  end
507
518
 
@@ -526,11 +537,11 @@ describe ActiveFedora::Base do
526
537
  end
527
538
 
528
539
  it "should add pid, system_create_date and system_modified_date from object attributes" do
529
- @test_object.expects(:create_date).returns("cDate")
530
- @test_object.expects(:modified_date).returns("mDate")
540
+ @test_object.expects(:create_date).returns("2012-03-04T03:12:02Z")
541
+ @test_object.expects(:modified_date).returns("2012-03-07T03:12:02Z")
531
542
  solr_doc = @test_object.to_solr
532
- solr_doc["system_create_dt"].should eql("cDate")
533
- solr_doc["system_modified_dt"].should eql("mDate")
543
+ solr_doc["system_create_dt"].should eql("2012-03-04T03:12:02Z")
544
+ solr_doc["system_modified_dt"].should eql("2012-03-07T03:12:02Z")
534
545
  solr_doc[:id].should eql("#{@test_object.pid}")
535
546
  end
536
547
 
@@ -552,8 +563,8 @@ describe ActiveFedora::Base do
552
563
  end
553
564
 
554
565
  it "should use mappings.yml to decide names of solr fields" do
555
- cdate = "2008-07-02T05:09:42.015Z"
556
- mdate = "2009-07-07T23:37:18.991Z"
566
+ cdate = "2008-07-02T05:09:42Z"
567
+ mdate = "2009-07-07T23:37:18Z"
557
568
  @test_object.stubs(:create_date).returns(cdate)
558
569
  @test_object.stubs(:modified_date).returns(mdate)
559
570
  solr_doc = @test_object.to_solr
@@ -575,18 +586,36 @@ describe ActiveFedora::Base do
575
586
 
576
587
  it "should call .to_solr on all MetadataDatastreams and NokogiriDatastreams, passing the resulting document to solr" do
577
588
  mock1 = mock("ds1", :to_solr)
578
- mock1.expects(:solrize_profile)
579
589
  mock2 = mock("ds2", :to_solr)
580
- mock2.expects(:solrize_profile)
581
- ngds = mock("ngds")
590
+ ngds = mock("ngds", :to_solr)
582
591
  ngds.expects(:solrize_profile)
592
+ mock1.expects(:solrize_profile)
593
+ mock2.expects(:solrize_profile)
594
+ mock1.expects(:kind_of?).with(ActiveFedora::RDFDatastream).returns(false)
595
+ mock1.expects(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(false)
583
596
  mock1.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(true)
597
+ mock2.expects(:kind_of?).with(ActiveFedora::RDFDatastream).returns(false)
598
+ mock2.expects(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(false)
584
599
  mock2.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(true)
600
+ ngds.expects(:kind_of?).with(ActiveFedora::RDFDatastream).returns(false)
601
+ ngds.expects(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(true)
585
602
 
586
603
  @test_object.expects(:datastreams).returns({:ds1 => mock1, :ds2 => mock2, :ngds => ngds})
604
+ @test_object.expects(:solrize_profile)
605
+ @test_object.expects(:solrize_relationships)
606
+ @test_object.to_solr
607
+ end
608
+ it "should call .to_solr on all RDFDatastreams, passing the resulting document to solr" do
609
+ mock = mock("ds1", :to_solr)
610
+ mock.expects(:solrize_profile)
611
+ mock.expects(:kind_of?).with(ActiveFedora::RDFDatastream).returns(true)
612
+
613
+ @test_object.expects(:datastreams).returns({:ds1 => mock})
614
+ @test_object.expects(:solrize_profile)
587
615
  @test_object.expects(:solrize_relationships)
588
616
  @test_object.to_solr
589
617
  end
618
+
590
619
  it "should call .to_solr on the relationships rels-ext is dirty" do
591
620
  @test_object.add_relationship(:has_collection_member, "info:fedora/foo:member")
592
621
  rels_ext = @test_object.rels_ext
@@ -75,38 +75,29 @@ describe ActiveFedora::Model do
75
75
  describe '#find' do
76
76
 
77
77
  it "(:all) should query solr for all objects with :active_fedora_model_s of self.class" do
78
- mock_solr = mock("SolrConnection")
79
- mock_result = mock("MockResult")
80
- mock_result.expects(:hits).returns([{"id" => "changeme:30"}, {"id" => "changeme:22"}])
81
- mock_solr.expects(:query).with('has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic', :rows=>1001).returns(mock_result)
82
- ActiveFedora::SolrService.expects(:instance).returns(mock("SolrService", :conn => mock_solr))
83
- SpecModel::Basic.expects(:load_instance).with("changeme:30").returns("Fake Object1")
84
- SpecModel::Basic.expects(:load_instance).with("changeme:22").returns("Fake Object2")
78
+ ActiveFedora::SolrService.expects(:query).with('has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic', :rows=>1001).returns([{"id" => "changeme:30"}, {"id" => "changeme:22"}])
79
+ SpecModel::Basic.expects(:find_one).with("changeme:30").returns("Fake Object1")
80
+ SpecModel::Basic.expects(:find_one).with("changeme:22").returns("Fake Object2")
85
81
  SpecModel::Basic.find(:all, :rows=>1001).should == ["Fake Object1", "Fake Object2"]
86
82
  end
87
-
88
- it "(String) should query solr for an object with the given id and return that object" do
89
- SpecModel::Basic.expects(:load_instance).with("changeme:30").returns("Fake Object")
90
- SpecModel::Basic.find("changeme:30").should == "Fake Object"
83
+ it "should use SpecModel::Basic.allocate.init_with to instantiate an object" do
84
+ ActiveFedora::ContentModel.expects(:known_models_for).returns([SpecModel::Basic])
85
+ SpecModel::Basic.any_instance.expects(:init_with).returns(mock("Model", :adapt_to=>SpecModel::Basic ))
86
+ SpecModel::Basic.expects(:connection_for_pid).with("_PID_")
87
+ SpecModel::Basic.find("_PID_")
91
88
  end
92
89
  end
93
90
 
94
91
  describe '#count' do
95
92
 
96
93
  it "should return a count" do
97
- mock_solr = mock("SolrConnection")
98
- mock_result = mock("MockResult")
99
- mock_result.expects(:total_hits).returns(7)
100
- mock_solr.expects(:query).with('has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic', :rows=>0).returns(mock_result)
101
- ActiveFedora::SolrService.expects(:instance).returns(mock("SolrService", :conn => mock_solr))
94
+ mock_result = {'response'=>{'numFound'=>7}}
95
+ ActiveFedora::SolrService.expects(:query).with('has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic', :rows=>0, :raw=>true).returns(mock_result)
102
96
  SpecModel::Basic.count.should == 7
103
97
  end
104
98
  it "should allow conditions" do
105
- mock_solr = mock("SolrConnection")
106
- mock_result = mock("MockResult")
107
- mock_result.expects(:total_hits).returns(7)
108
- mock_solr.expects(:query).with('has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic AND foo:bar', :rows=>0).returns(mock_result)
109
- ActiveFedora::SolrService.expects(:instance).returns(mock("SolrService", :conn => mock_solr))
99
+ mock_result = {'response'=>{'numFound'=>7}}
100
+ ActiveFedora::SolrService.expects(:query).with('has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic AND foo:bar', :rows=>0, :raw=>true).returns(mock_result)
110
101
  SpecModel::Basic.count(:conditions=>'foo:bar').should == 7
111
102
  end
112
103
  end
@@ -118,18 +109,14 @@ describe ActiveFedora::Model do
118
109
 
119
110
  describe '#find_by_solr' do
120
111
  it "(:all) should query solr for all objects with :active_fedora_model_s of self.class and return a Solr result" do
121
- mock_solr = mock("SolrConnection")
122
112
  mock_response = mock("SolrResponse")
123
- mock_solr.expects(:query).with('active_fedora_model_s:SpecModel\:\:Basic', {}).returns(mock_response)
124
- ActiveFedora::SolrService.expects(:instance).returns(mock("SolrService", :conn => mock_solr))
113
+ ActiveFedora::SolrService.expects(:query).with('active_fedora_model_s:SpecModel\:\:Basic', {}).returns(mock_response)
125
114
 
126
115
  SpecModel::Basic.find_by_solr(:all).should equal(mock_response)
127
116
  end
128
117
  it "(String) should query solr for an object with the given id and return the Solr Result" do
129
- mock_solr = mock("SolrConnection")
130
118
  mock_response = mock("SolrResponse")
131
- mock_solr.expects(:query).with('id:changeme\:30', {}).returns(mock_response)
132
- ActiveFedora::SolrService.expects(:instance).returns(mock("SolrService", :conn => mock_solr))
119
+ ActiveFedora::SolrService.expects(:query).with('id:changeme\:30', {}).returns(mock_response)
133
120
 
134
121
  SpecModel::Basic.find_by_solr("changeme:30").should equal(mock_response)
135
122
  end
@@ -137,8 +124,8 @@ describe ActiveFedora::Model do
137
124
 
138
125
  describe "load_instance" do
139
126
  it "should use SpecModel::Basic.allocate.init_with to instantiate an object" do
140
- SpecModel::Basic.any_instance.expects(:init_with)
141
- SpecModel::Basic.expects(:connection_for_pid).with("_PID_")
127
+ ActiveSupport::Deprecation.expects(:warn).with("load_instance is deprecated. Use find instead")
128
+ SpecModel::Basic.expects(:find).with("_PID_")
142
129
  SpecModel::Basic.load_instance("_PID_")
143
130
  end
144
131
  end