active-fedora 5.1.0 → 5.2.0

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.
Files changed (49) hide show
  1. data/active-fedora.gemspec +1 -2
  2. data/lib/active_fedora/datastreams.rb +14 -14
  3. data/lib/active_fedora/file_management.rb +5 -3
  4. data/lib/active_fedora/metadata_datastream_helper.rb +5 -1
  5. data/lib/active_fedora/nokogiri_datastream.rb +17 -4
  6. data/lib/active_fedora/rdf_datastream.rb +59 -36
  7. data/lib/active_fedora/relationships.rb +28 -11
  8. data/lib/active_fedora/version.rb +1 -1
  9. data/spec/config_helper.rb +3 -3
  10. data/spec/integration/base_spec.rb +15 -3
  11. data/spec/integration/bug_spec.rb +0 -3
  12. data/spec/integration/datastream_collections_spec.rb +9 -9
  13. data/spec/integration/datastream_spec.rb +1 -1
  14. data/spec/integration/full_featured_model_spec.rb +3 -4
  15. data/spec/integration/ntriples_datastream_spec.rb +0 -1
  16. data/spec/integration/rels_ext_datastream_spec.rb +12 -1
  17. data/spec/integration/semantic_node_spec.rb +10 -0
  18. data/spec/integration/solr_service_spec.rb +2 -2
  19. data/spec/spec_helper.rb +4 -7
  20. data/spec/support/mock_fedora.rb +10 -10
  21. data/spec/unit/active_fedora_spec.rb +8 -8
  22. data/spec/unit/association_proxy_spec.rb +2 -1
  23. data/spec/unit/base_cma_spec.rb +2 -2
  24. data/spec/unit/base_datastream_management_spec.rb +9 -9
  25. data/spec/unit/base_extra_spec.rb +25 -25
  26. data/spec/unit/base_file_management_spec.rb +32 -23
  27. data/spec/unit/base_spec.rb +94 -151
  28. data/spec/unit/callback_spec.rb +16 -11
  29. data/spec/unit/code_configurator_spec.rb +4 -4
  30. data/spec/unit/content_model_spec.rb +8 -8
  31. data/spec/unit/datastream_collections_spec.rb +23 -23
  32. data/spec/unit/datastream_spec.rb +7 -7
  33. data/spec/unit/datastreams_spec.rb +189 -304
  34. data/spec/unit/file_configurator_spec.rb +56 -56
  35. data/spec/unit/has_many_collection_spec.rb +1 -1
  36. data/spec/unit/model_spec.rb +51 -56
  37. data/spec/unit/nokogiri_datastream_spec.rb +24 -25
  38. data/spec/unit/ntriples_datastream_spec.rb +18 -27
  39. data/spec/unit/property_spec.rb +0 -2
  40. data/spec/unit/qualified_dublin_core_datastream_spec.rb +1 -2
  41. data/spec/unit/rdfxml_rdf_datastream_spec.rb +1 -1
  42. data/spec/unit/relationship_graph_spec.rb +1 -1
  43. data/spec/unit/relationships_spec.rb +64 -52
  44. data/spec/unit/rels_ext_datastream_spec.rb +7 -7
  45. data/spec/unit/semantic_node_spec.rb +5 -5
  46. data/spec/unit/service_definitions_spec.rb +18 -16
  47. data/spec/unit/solr_config_options_spec.rb +6 -6
  48. data/spec/unit/solr_service_spec.rb +16 -16
  49. metadata +5 -21
@@ -15,12 +15,12 @@ describe ActiveFedora::NokogiriDatastream do
15
15
  before(:each) do
16
16
  @mock_inner = mock('inner object')
17
17
  @mock_repo = mock('repository')
18
- @mock_repo.stubs(:datastream_dissemination=>'My Content', :config=>{})
19
- @mock_inner.stubs(:repository).returns(@mock_repo)
20
- @mock_inner.stubs(:pid)
21
- @mock_inner.stubs(:new? => false)
18
+ @mock_repo.stub(:datastream_dissemination=>'My Content', :config=>{})
19
+ @mock_inner.stub(:repository).and_return(@mock_repo)
20
+ @mock_inner.stub(:pid)
21
+ @mock_inner.stub(:new? => false)
22
22
  @test_ds = ActiveFedora::NokogiriDatastream.new(@mock_inner, "descMetadata")
23
- @test_ds.stubs(:new? => false, :profile => {}, :datastream_content => '<test_xml/>')
23
+ @test_ds.stub(:new? => false, :profile => {}, :datastream_content => '<test_xml/>')
24
24
  @test_ds.content="<test_xml/>"
25
25
  end
26
26
 
@@ -44,7 +44,7 @@ describe ActiveFedora::NokogiriDatastream do
44
44
  test_ds1.ng_xml.to_xml.should == "<?xml version=\"1.0\"?>\n<xml>\n <foo/>\n</xml>\n"
45
45
  end
46
46
  it "should initialize from #xml_template if no xml is provided" do
47
- ActiveFedora::NokogiriDatastream.expects(:xml_template).returns("<fake template/>")
47
+ ActiveFedora::NokogiriDatastream.should_receive(:xml_template).and_return("<fake template/>")
48
48
  n = ActiveFedora::NokogiriDatastream.new
49
49
  n.ng_xml.should be_equivalent_to("<fake template/>")
50
50
  end
@@ -86,7 +86,7 @@ describe ActiveFedora::NokogiriDatastream do
86
86
  end
87
87
  it "should do nothing if field key is a string (must be an array or symbol). Will not accept xpath queries!" do
88
88
  xml_before = @mods_ds.to_xml
89
- logger.expects(:warn).with "WARNING: descMetadata ignoring {\"fubar\" => \"the role\"} because \"fubar\" is a String (only valid OM Term Pointers will be used). Make sure your html has the correct field_selector tags in it."
89
+ logger.should_receive(:warn).with "WARNING: descMetadata ignoring {\"fubar\" => \"the role\"} because \"fubar\" is a String (only valid OM Term Pointers will be used). Make sure your html has the correct field_selector tags in it."
90
90
  @mods_ds.update_indexed_attributes( { "fubar"=>"the role" } ).should == {}
91
91
  @mods_ds.to_xml.should == xml_before
92
92
  end
@@ -149,12 +149,12 @@ describe ActiveFedora::NokogiriDatastream do
149
149
  end
150
150
 
151
151
  it "should call lookup with field_name and return the text values from each resulting node" do
152
- @mods_ds.expects(:term_values).with("--my xpath--").returns(["value1", "value2"])
152
+ @mods_ds.should_receive(:term_values).with("--my xpath--").and_return(["value1", "value2"])
153
153
  @mods_ds.get_values("--my xpath--").should == ["value1", "value2"]
154
154
  end
155
155
  it "should assume that field_names that are strings are xpath queries" do
156
- ActiveFedora::NokogiriDatastream.expects(:accessor_xpath).never
157
- @mods_ds.expects(:term_values).with("--my xpath--").returns(["abstract1", "abstract2"])
156
+ ActiveFedora::NokogiriDatastream.should_receive(:accessor_xpath).never
157
+ @mods_ds.should_receive(:term_values).with("--my xpath--").and_return(["abstract1", "abstract2"])
158
158
  @mods_ds.get_values("--my xpath--").should == ["abstract1", "abstract2"]
159
159
  end
160
160
  end
@@ -164,7 +164,6 @@ describe ActiveFedora::NokogiriDatastream do
164
164
  mods_xml = Nokogiri::XML::Document.parse( fixture(File.join("mods_articles", "hydrangea_article1.xml")) )
165
165
  tmpl = Hydra::ModsArticleDatastream.new
166
166
  Hydra::ModsArticleDatastream.from_xml(mods_xml,tmpl).ng_xml.root.to_xml.should == mods_xml.root.to_xml
167
- tmpl.should_not be_changed
168
167
  end
169
168
  end
170
169
 
@@ -178,9 +177,9 @@ describe ActiveFedora::NokogiriDatastream do
178
177
  @test_ds.should respond_to(:save)
179
178
  end
180
179
  it "should persist the product of .to_xml in fedora" do
181
- @test_ds.expects(:new?).returns(true).at_least_once
182
- @test_ds.stubs(:to_xml => "fake xml")
183
- @mock_repo.expects(:add_datastream).with(:pid => nil, :dsid => 'descMetadata', :versionable => true, :content => 'fake xml', :controlGroup => 'X', :dsState => 'A', :mimeType=>'text/xml')
180
+ @test_ds.stub(:new? => true)
181
+ @test_ds.stub(:to_xml => "fake xml")
182
+ @mock_repo.should_receive(:add_datastream).with(:pid => nil, :dsid => 'descMetadata', :versionable => true, :content => 'fake xml', :controlGroup => 'X', :dsState => 'A', :mimeType=>'text/xml')
184
183
 
185
184
  @test_ds.serialize!
186
185
  @test_ds.save
@@ -191,19 +190,19 @@ describe ActiveFedora::NokogiriDatastream do
191
190
  describe '.content=' do
192
191
  subject { ActiveFedora::NokogiriDatastream.new(@mock_inner, "descMetadata") }
193
192
  it "should update the content" do
194
- subject.stubs(:new? => false )
193
+ subject.stub(:new? => false )
195
194
  subject.content = "<a />"
196
195
  subject.datastream_content.should == '<a />'
197
196
  end
198
197
 
199
198
  it "should mark the object as changed" do
200
- subject.stubs(:new? => false )
199
+ subject.stub(:new? => false )
201
200
  subject.content = "<a />"
202
201
  subject.should be_changed
203
202
  end
204
203
 
205
204
  it "update ngxml and mark the xml as loaded" do
206
- subject.stubs(:new? => false )
205
+ subject.stub(:new? => false )
207
206
  subject.content = "<a />"
208
207
  subject.ng_xml.to_xml.should =~ /<a\/>/
209
208
  subject.xml_loaded.should be_true
@@ -240,13 +239,13 @@ describe ActiveFedora::NokogiriDatastream do
240
239
  end
241
240
 
242
241
  it "should ng_xml.to_xml" do
243
- @test_ds.expects(:ng_xml).returns(Nokogiri::XML::Document.parse("<text_document/>")).twice
242
+ @test_ds.stub(:ng_xml => Nokogiri::XML::Document.parse("<text_document/>"))
244
243
  @test_ds.to_xml.should == "<text_document/>\n"
245
244
  end
246
245
 
247
246
  it 'should accept an optional Nokogiri::XML Document as an argument and insert its fields into that (mocked test)' do
248
247
  doc = Nokogiri::XML::Document.parse("<test_document/>")
249
- doc.root.expects(:add_child)#.with(@test_ds.ng_xml.root)
248
+ doc.root.should_receive(:add_child)#.with(@test_ds.ng_xml.root)
250
249
  @test_ds.to_xml(doc)
251
250
  end
252
251
 
@@ -286,10 +285,10 @@ describe ActiveFedora::NokogiriDatastream do
286
285
 
287
286
  it "should return correct values from solr_doc given different term pointers" do
288
287
  mock_term = mock("OM::XML::Term")
289
- mock_term.stubs(:type).returns(:text)
288
+ mock_term.stub(:type).and_return(:text)
290
289
  mock_terminology = mock("OM::XML::Terminology")
291
- mock_terminology.stubs(:retrieve_term).returns(mock_term)
292
- ActiveFedora::NokogiriDatastream.stubs(:terminology).returns(mock_terminology)
290
+ mock_terminology.stub(:retrieve_term).and_return(mock_term)
291
+ ActiveFedora::NokogiriDatastream.stub(:terminology).and_return(mock_terminology)
293
292
  @mods_ds.from_solr(@solr_doc)
294
293
  term_pointer = [:name,:role,:roleTerm]
295
294
  @mods_ds.get_values_from_solr(:name,:role,:roleTerm).should == ["creator","submitter","teacher"]
@@ -348,7 +347,7 @@ describe ActiveFedora::NokogiriDatastream do
348
347
  end
349
348
 
350
349
  it "should update a value internally call OM::XML::TermValueOperators::update_values if internal_solr_doc is not set" do
351
- @mods_ds.stubs(:om_update_values).once()
350
+ @mods_ds.stub(:om_update_values).once()
352
351
  term_pointer = [:name,:role,:roleTerm]
353
352
  @mods_ds.update_values([{":person"=>"0"}, "role", "text"]=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"})
354
353
  end
@@ -369,7 +368,7 @@ describe ActiveFedora::NokogiriDatastream do
369
368
  end
370
369
 
371
370
  it "should call OM::XML::term_values if internal_solr_doc is not set and return values from xml" do
372
- @mods_ds.stubs(:om_term_values).once()
371
+ @mods_ds.stub(:om_term_values).once()
373
372
  term_pointer = [:name,:role,:roleTerm]
374
373
  @mods_ds.term_values(*term_pointer)
375
374
  end
@@ -378,7 +377,7 @@ describe ActiveFedora::NokogiriDatastream do
378
377
  it "should call get_values_from_solr if internal_solr_doc is set" do
379
378
  @mods_ds.from_solr(@solr_doc)
380
379
  term_pointer = [:name,:role,:roleTerm]
381
- @mods_ds.stubs(:get_values_from_solr).once()
380
+ @mods_ds.stub(:get_values_from_solr).once()
382
381
  @mods_ds.term_values(*term_pointer)
383
382
  end
384
383
  end
@@ -103,8 +103,8 @@ describe ActiveFedora::NtriplesRDFDatastream do
103
103
  end
104
104
  end
105
105
  @subject = MyDatastream.new(@inner_object, 'mixed_rdf')
106
- @subject.stubs(:pid => 'test:1')
107
- @subject.stubs(:new? => false)
106
+ @subject.stub(:pid => 'test:1')
107
+ @subject.stub(:new? => false)
108
108
  @subject.content = File.new('spec/fixtures/mixed_rdf_descMetadata.nt').read
109
109
  end
110
110
 
@@ -126,7 +126,7 @@ describe ActiveFedora::NtriplesRDFDatastream do
126
126
  end
127
127
  end
128
128
  @subject = MyDatastream.new(@inner_object, 'mixed_rdf')
129
- @subject.stubs(:pid => 'test:1', :repository => ActiveFedora::Base.connection_for_pid(0))
129
+ @subject.stub(:pid => 'test:1', :repository => ActiveFedora::Base.connection_for_pid(0))
130
130
  end
131
131
  after(:each) do
132
132
  Object.send(:remove_const, :MyDatastream)
@@ -166,10 +166,12 @@ describe ActiveFedora::NtriplesRDFDatastream do
166
166
  map.rights(:in => RDF::DC)
167
167
  end
168
168
  end
169
+ end
170
+ before(:each) do
169
171
  @subject = MyDatastream.new(@inner_object, 'solr_rdf')
170
172
  @subject.content = File.new('spec/fixtures/solr_rdf_descMetadata.nt').read
171
- @subject.stubs(:pid => 'test:1')
172
- @subject.stubs(:new? => false)
173
+ @subject.stub(:pid => 'test:1')
174
+ @subject.stub(:new? => false)
173
175
  @sample_fields = {:my_datastream__publisher => {:values => ["publisher1"], :type => :string, :behaviors => [:facetable, :sortable, :searchable, :displayable]},
174
176
  :my_datastream__based_near => {:values => ["coverage1", "coverage2"], :type => :text, :behaviors => [:displayable, :facetable, :searchable]},
175
177
  :my_datastream__created => {:values => "fake-date", :type => :date, :behaviors => [:sortable, :displayable]},
@@ -195,7 +197,7 @@ describe ActiveFedora::NtriplesRDFDatastream do
195
197
  @subject.to_solr(doc).should == doc
196
198
  end
197
199
  it "should iterate through @fields hash" do
198
- @subject.expects(:fields).returns(@sample_fields)
200
+ @subject.should_receive(:fields).and_return(@sample_fields)
199
201
  solr_doc = @subject.to_solr
200
202
  solr_doc["my_datastream__publisher_t"].should == ["publisher1"]
201
203
  solr_doc["my_datastream__publisher_sort"].should == ["publisher1"]
@@ -213,7 +215,7 @@ describe ActiveFedora::NtriplesRDFDatastream do
213
215
  solr_doc["my_datastream__empty_field_t"].should be_nil
214
216
  end
215
217
  it 'should append create keys in format field_name + _ + field_type' do
216
- @subject.stubs(:fields).returns(@sample_fields)
218
+ @subject.stub(:fields).and_return(@sample_fields)
217
219
 
218
220
  #should have these
219
221
  @subject.to_solr["my_datastream__publisher_t"].should_not be_nil
@@ -228,7 +230,7 @@ describe ActiveFedora::NtriplesRDFDatastream do
228
230
  end
229
231
  it "should use Solr mappings to generate field names" do
230
232
  ActiveFedora::SolrService.load_mappings(File.join(File.dirname(__FILE__), "..", "..", "config", "solr_mappings_af_0.1.yml"))
231
- @subject.stubs(:fields).returns(@sample_fields)
233
+ @subject.stub(:fields).and_return(@sample_fields)
232
234
  solr_doc = @subject.to_solr
233
235
 
234
236
  #should have these
@@ -257,9 +259,10 @@ describe ActiveFedora::NtriplesRDFDatastream do
257
259
  delegate :rights, :to => :descMetadata
258
260
  end
259
261
  @obj = MyDatastream.new(@inner_object, 'solr_rdf')
260
- @obj.stubs(:repository => mock(), :pid => 'test:1')
261
- @obj.repository.stubs(:modify_datastream)
262
- @obj.repository.stubs(:add_datastream)
262
+ repository = mock()
263
+ @obj.stub(:repository => repository, :pid => 'test:1')
264
+ repository.stub(:modify_datastream)
265
+ repository.stub(:add_datastream)
263
266
  @obj.created = "2012-03-04"
264
267
  @obj.title = "Of Mice and Men, The Sequel"
265
268
  @obj.publisher = "Bob's Blogtastic Publishing"
@@ -268,26 +271,14 @@ describe ActiveFedora::NtriplesRDFDatastream do
268
271
  @obj.rights = "Totally open, y'all"
269
272
  @obj.save
270
273
  end
271
- describe '#save' do
272
- it "should set dirty? to false" do
273
- @obj.should_not be_changed
274
- @obj.title = "something"
275
- @obj.should be_changed
276
- @obj.save
277
- @obj.should_not be_changed
278
- end
279
- end
274
+
280
275
  describe '.content=' do
281
276
  it "should update the content and graph, marking the datastream as changed" do
282
- mock_repo = mock('repository')
283
277
  sample_rdf = File.new('spec/fixtures/mixed_rdf_descMetadata.nt').read
284
- @obj.stubs(:pid).returns('test:123')
285
- @obj.stubs(:repository).returns(mock_repo)
278
+ @obj.stub(:new? => false)
286
279
  @obj.should_not be_changed
287
- @obj.content.should_not be_equivalent_to(sample_rdf)
288
280
  @obj.content = sample_rdf
289
281
  @obj.should be_changed
290
- @obj.content.should be_equivalent_to(sample_rdf)
291
282
  end
292
283
  end
293
284
  it "should save content properly upon save" do
@@ -323,11 +314,11 @@ describe ActiveFedora::NtriplesRDFDatastream do
323
314
  end
324
315
  it "should solrize even when the object is not new" do
325
316
  foo = Foo.new
326
- foo.expects(:update_index).once
317
+ foo.should_receive(:update_index).once
327
318
  foo.title = "title1"
328
319
  foo.save
329
320
  foo = Foo.find(foo.pid)
330
- foo.expects(:update_index).once
321
+ foo.should_receive(:update_index).once
331
322
  foo.publisher = "Allah2"
332
323
  foo.title = "The Work2"
333
324
  foo.save
@@ -2,8 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  require 'active_fedora'
4
4
  require 'active_fedora/model'
5
- require 'mocha'
6
- include Mocha::API
7
5
 
8
6
  describe ActiveFedora::Property do
9
7
 
@@ -60,7 +60,6 @@ describe ActiveFedora::QualifiedDublinCoreDatastream do
60
60
  n = ActiveFedora::QualifiedDublinCoreDatastream.from_xml(stream.to_xml, ds)
61
61
  n.spatial.should == ["Boston [7013445]", "Dorchester [7013575]", "Roxbury [7015002]"]
62
62
  n.title.should == ["Oral history with Frances Addelson, 1997 November 14"]
63
- n.should_not be_changed
64
63
  end
65
64
 
66
65
 
@@ -94,7 +93,7 @@ describe ActiveFedora::QualifiedDublinCoreDatastream do
94
93
 
95
94
  describe '.to_xml' do
96
95
  it 'should output the fields hash as Qualified Dublin Core XML' do
97
- #@test_ds.expects(:new?).returns(true).twice
96
+ #@test_ds.should_receive(:new?).and_return(true).twice
98
97
  sample_xml = "<dc xmlns:dcterms='http://purl.org/dc/terms/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><dcterms:title>title1</dcterms:title><dcterms:publisher>publisher1</dcterms:publisher><dcterms:creator>creator1</dcterms:creator><dcterms:creator>creator2</dcterms:creator></dc>"
99
98
  @test_ds = ActiveFedora::QualifiedDublinCoreDatastream.new(nil, 'qdc' )
100
99
 
@@ -10,7 +10,7 @@ describe ActiveFedora::RdfxmlRDFDatastream do
10
10
  end
11
11
  end
12
12
  @subject = MyRdfxmlDatastream.new(@inner_object, 'mixed_rdf')
13
- @subject.stubs(:pid => 'test:1')
13
+ @subject.stub(:pid => 'test:1')
14
14
  end
15
15
  after(:each) do
16
16
  Object.send(:remove_const, :MyRdfxmlDatastream)
@@ -4,7 +4,7 @@ describe ActiveFedora::RelationshipGraph do
4
4
  before do
5
5
  @graph = ActiveFedora::RelationshipGraph.new
6
6
  @n1 = ActiveFedora::Base.new()
7
- @n1.stubs(:pid => 'foo:777')
7
+ @n1.stub(:pid => 'foo:777')
8
8
  end
9
9
 
10
10
  describe "#relationships" do
@@ -3,6 +3,18 @@ require 'spec_helper'
3
3
  @@last_pid = 0
4
4
 
5
5
  describe ActiveFedora::Relationships do
6
+ before(:all) do
7
+ @behavior = ActiveFedora::Relationships.deprecation_behavior
8
+ @c_behavior = ActiveFedora::Relationships::ClassMethods.deprecation_behavior
9
+ ActiveFedora::Relationships.deprecation_behavior = :silence
10
+ ActiveFedora::Relationships::ClassMethods.deprecation_behavior = :silence
11
+ end
12
+
13
+ after :all do
14
+ ActiveFedora::Relationships.deprecation_behavior = @behavior
15
+ ActiveFedora::Relationships::ClassMethods.deprecation_behavior = @c_behavior
16
+ end
17
+
6
18
  def increment_pid
7
19
  @@last_pid += 1
8
20
  end
@@ -74,12 +86,12 @@ describe ActiveFedora::Relationships do
74
86
  end
75
87
 
76
88
  it 'should create inbound relationship finders' do
77
- SpecNode.expects(:create_inbound_relationship_finders)
89
+ SpecNode.should_receive(:create_inbound_relationship_finders)
78
90
  SpecNode.has_relationship("parts", :is_part_of, :inbound => true)
79
91
  end
80
92
 
81
93
  it 'should create outbound relationship finders' do
82
- SpecNode.expects(:create_outbound_relationship_finders).times(2)
94
+ SpecNode.should_receive(:create_outbound_relationship_finders).exactly(2).times
83
95
  SpecNode.has_relationship("parts", :is_part_of, :inbound => false)
84
96
  SpecNode.has_relationship("container", :is_member_of)
85
97
  end
@@ -90,7 +102,7 @@ describe ActiveFedora::Relationships do
90
102
  #local_node.internal_uri = "info:fedora/#{@pid}"
91
103
  local_node.pid = @pid
92
104
 
93
- local_node.expects(:rels_ext).returns(stub("rels_ext", :content_will_change! => true, :content=>'')).at_least_once
105
+ local_node.stub(:rels_ext).and_return(stub("rels_ext", :content_will_change! => true, :content=>''))
94
106
  local_node.add_relationship(:is_member_of, "info:fedora/container:A")
95
107
  local_node.add_relationship(:is_member_of, "info:fedora/container:B")
96
108
 
@@ -121,8 +133,8 @@ describe ActiveFedora::Relationships do
121
133
  it 'should create relationship descriptions both inbound and outbound' do
122
134
  @test_object2 = MockHasRelationship.new
123
135
  @test_object2.pid = increment_pid
124
- @test_object2.stubs(:testing_inbound).returns({})
125
- @test_object2.expects(:rels_ext).returns(stub("rels_ext", :content_will_change! => true, :content =>'')).at_least_once
136
+ @test_object2.stub(:testing_inbound).and_return({})
137
+ @test_object2.stub(:rels_ext).and_return(stub("rels_ext", :content_will_change! => true, :content =>''))
126
138
  @test_object2.add_relationship(:has_model, SpecNode.to_class_uri)
127
139
  @test_object2.should respond_to(:testing_append)
128
140
  @test_object2.should respond_to(:testing_remove)
@@ -173,9 +185,9 @@ describe ActiveFedora::Relationships do
173
185
  {"id"=>"_PID3_", "has_model_s"=>["info:fedora/afmodel:AudioRecord"]}]
174
186
  SpecNode.create_inbound_relationship_finders("parts", :is_part_of, :inbound => true)
175
187
  local_node = SpecNode.new()
176
- local_node.expects(:pid).returns("test:sample_pid")
177
- SpecNode.expects(:relationships_desc).returns({:inbound=>{"parts"=>{:predicate=>:is_part_of}}}).at_least_once()
178
- ActiveFedora::SolrService.expects(:query).with(@part_of_sample, :rows=>25).returns(@sample_solr_hits)
188
+ local_node.should_receive(:pid).and_return("test:sample_pid")
189
+ SpecNode.stub(:relationships_desc).and_return({:inbound=>{"parts"=>{:predicate=>:is_part_of}}})
190
+ ActiveFedora::SolrService.should_receive(:query).with(@part_of_sample, :rows=>25).and_return(@sample_solr_hits)
179
191
  local_node.parts_ids.should == ["_PID1_", "_PID2_", "_PID3_"]
180
192
  end
181
193
 
@@ -184,11 +196,11 @@ describe ActiveFedora::Relationships do
184
196
  SpecNode.create_inbound_relationship_finders("constituents", :is_constituent_of, :inbound => true)
185
197
  local_node = SpecNode.new
186
198
  mock_repo = mock("repo")
187
- mock_repo.expects(:find).never
188
- local_node.expects(:pid).returns("test:sample_pid")
189
- SpecNode.expects(:relationships_desc).returns({:inbound=>{"constituents"=>{:predicate=>:is_constituent_of}}}).at_least_once()
199
+ mock_repo.should_receive(:find).never
200
+ local_node.should_receive(:pid).and_return("test:sample_pid")
201
+ SpecNode.stub(:relationships_desc).and_return({:inbound=>{"constituents"=>{:predicate=>:is_constituent_of}}})
190
202
  instance = stub(:conn=>stub(:conn))
191
- ActiveFedora::SolrService.expects(:query).with(@constituent_of_sample, :raw=>true, :rows=>101).returns(solr_result)
203
+ ActiveFedora::SolrService.should_receive(:query).with(@constituent_of_sample, :raw=>true, :rows=>101).and_return(solr_result)
192
204
  local_node.constituents(:response_format => :solr, :rows=>101).should == solr_result
193
205
  end
194
206
 
@@ -196,23 +208,23 @@ describe ActiveFedora::Relationships do
196
208
  it "resulting _ids finder should search against solr and return an array of fedora PIDs" do
197
209
  SpecNode.create_inbound_relationship_finders("parts", :is_part_of, :inbound => true)
198
210
  local_node = SpecNode.new
199
- local_node.expects(:pid).returns("test:sample_pid")
200
- SpecNode.expects(:relationships_desc).returns({:inbound=>{"parts"=>{:predicate=>:is_part_of}}}).at_least_once()
201
- ActiveFedora::SolrService.expects(:query).with(@part_of_sample, :rows=>25).returns([Hash["id"=>"pid1"], Hash["id"=>"pid2"]])
211
+ local_node.should_receive(:pid).and_return("test:sample_pid")
212
+ SpecNode.stub(:relationships_desc).and_return({:inbound=>{"parts"=>{:predicate=>:is_part_of}}})
213
+ ActiveFedora::SolrService.should_receive(:query).with(@part_of_sample, :rows=>25).and_return([Hash["id"=>"pid1"], Hash["id"=>"pid2"]])
202
214
  local_node.parts(:response_format => :id_array).should == ["pid1", "pid2"]
203
215
  end
204
216
 
205
217
  it "resulting _ids finder should call the basic finder with :result_format => :id_array" do
206
218
  SpecNode.create_inbound_relationship_finders("parts", :is_part_of, :inbound => true)
207
219
  local_node = SpecNode.new
208
- local_node.expects(:parts).with(:response_format => :id_array)
220
+ local_node.should_receive(:parts).with(:response_format => :id_array)
209
221
  local_node.parts_ids
210
222
  end
211
223
 
212
224
  it "resulting _query finder should call relationship_query" do
213
225
  SpecNode.create_inbound_relationship_finders("parts", :is_part_of, :inbound => true)
214
226
  local_node = SpecNode.new
215
- local_node.expects(:relationship_query).with("parts")
227
+ local_node.should_receive(:relationship_query).with("parts")
216
228
  local_node.parts_query
217
229
  end
218
230
  end
@@ -240,15 +252,15 @@ describe ActiveFedora::Relationships do
240
252
  it "should read from relationships array and use Repository.find to build an array of objects" do
241
253
  SpecNode.create_outbound_relationship_finders("containers", :is_member_of)
242
254
  local_node = SpecNode.new
243
- local_node.expects(:ids_for_outbound).with(:is_member_of).returns(["my:_PID1_", "my:_PID2_", "my:_PID3_"])
255
+ local_node.should_receive(:ids_for_outbound).with(:is_member_of).and_return(["my:_PID1_", "my:_PID2_", "my:_PID3_"])
244
256
 
245
- #ActiveFedora::ContentModel.expects(:known_models_for).returns([SpecNode]).times(3)
246
- ActiveFedora::SolrService.expects(:query).with("id:my\\:_PID1_ OR id:my\\:_PID2_ OR id:my\\:_PID3_").returns([{"id"=> "my:_PID1_", "has_model_s"=>["info:fedora/afmodel:SpecNode"]},
257
+ #ActiveFedora::ContentModel.should_receive(:known_models_for).and_return([SpecNode]).times(3)
258
+ ActiveFedora::SolrService.should_receive(:query).with("id:my\\:_PID1_ OR id:my\\:_PID2_ OR id:my\\:_PID3_").and_return([{"id"=> "my:_PID1_", "has_model_s"=>["info:fedora/afmodel:SpecNode"]},
247
259
  {"id"=> "my:_PID2_", "has_model_s"=>["info:fedora/afmodel:SpecNode"]},
248
260
  {"id"=> "my:_PID3_", "has_model_s"=>["info:fedora/afmodel:SpecNode"]}])
249
- ActiveFedora::DigitalObject.expects(:find).with(SpecNode, 'my:_PID1_').returns(stub("inner obj", :'new?'=>false, :pid=>'my:_PID1_'))
250
- ActiveFedora::DigitalObject.expects(:find).with(SpecNode, 'my:_PID2_').returns(stub("inner obj", :'new?'=>false, :pid=>'my:_PID2_'))
251
- ActiveFedora::DigitalObject.expects(:find).with(SpecNode, 'my:_PID3_').returns(stub("inner obj", :'new?'=>false, :pid=>'my:_PID3_'))
261
+ ActiveFedora::DigitalObject.should_receive(:find).with(SpecNode, 'my:_PID1_').and_return(stub("inner obj", :'new?'=>false, :pid=>'my:_PID1_'))
262
+ ActiveFedora::DigitalObject.should_receive(:find).with(SpecNode, 'my:_PID2_').and_return(stub("inner obj", :'new?'=>false, :pid=>'my:_PID2_'))
263
+ ActiveFedora::DigitalObject.should_receive(:find).with(SpecNode, 'my:_PID3_').and_return(stub("inner obj", :'new?'=>false, :pid=>'my:_PID3_'))
252
264
  local_node.containers.map(&:pid).should == ["my:_PID1_", "my:_PID2_", "my:_PID3_"]
253
265
  end
254
266
 
@@ -257,23 +269,23 @@ describe ActiveFedora::Relationships do
257
269
  SpecNode.create_outbound_relationship_finders("constituents", :is_constituent_of)
258
270
  local_node = SpecNode.new
259
271
  mock_repo = mock("repo")
260
- mock_repo.expects(:find).never
261
- local_node.expects(:rels_ext).returns(stub('rels-ext', :content=>''))
262
- ActiveFedora::SolrService.expects(:query).returns(solr_result)
272
+ mock_repo.should_receive(:find).never
273
+ local_node.should_receive(:rels_ext).and_return(stub('rels-ext', :content=>''))
274
+ ActiveFedora::SolrService.should_receive(:query).and_return(solr_result)
263
275
  local_node.constituents(:response_format => :solr).should == solr_result
264
276
  end
265
277
 
266
278
  it "(:response_format => :id_array) should read from relationships array" do
267
279
  SpecNode.create_outbound_relationship_finders("containers", :is_member_of)
268
280
  local_node = SpecNode.new
269
- local_node.expects(:ids_for_outbound).with(:is_member_of).returns([])
281
+ local_node.should_receive(:ids_for_outbound).with(:is_member_of).and_return([])
270
282
  local_node.containers_ids
271
283
  end
272
284
 
273
285
  it "(:response_format => :id_array) should return an array of fedora PIDs" do
274
286
  SpecNode.create_outbound_relationship_finders("containers", :is_member_of)
275
287
  local_node = SpecNode.new
276
- local_node.expects(:rels_ext).returns(stub("rels_ext", :content_will_change! => true, :content=>'')).at_least_once
288
+ local_node.stub(:rels_ext => mock("rels_ext", :content_will_change! => true, :content=>''))
277
289
  local_node.add_relationship(:is_member_of, "demo:10")
278
290
  result = local_node.containers_ids
279
291
  result.should be_instance_of(Array)
@@ -286,7 +298,7 @@ describe ActiveFedora::Relationships do
286
298
  it "should call the basic finder with :result_format => :id_array" do
287
299
  SpecNode.create_outbound_relationship_finders("parts", :is_part_of)
288
300
  local_node = SpecNode.new
289
- local_node.expects(:parts).with(:response_format => :id_array)
301
+ local_node.should_receive(:parts).with(:response_format => :id_array)
290
302
  local_node.parts_ids
291
303
  end
292
304
  end
@@ -294,7 +306,7 @@ describe ActiveFedora::Relationships do
294
306
  it "resulting _query finder should call relationship_query" do
295
307
  SpecNode.create_outbound_relationship_finders("containers", :is_member_of)
296
308
  local_node = SpecNode.new
297
- local_node.expects(:relationship_query).with("containers")
309
+ local_node.should_receive(:relationship_query).with("containers")
298
310
  local_node.containers_query
299
311
  end
300
312
  end
@@ -312,21 +324,21 @@ describe ActiveFedora::Relationships do
312
324
  @local_node.should respond_to(:all_parts_outbound)
313
325
  end
314
326
  it "should rely on inbound & outbound finders" do
315
- @local_node.expects(:all_parts_inbound).with(:rows => 25).returns(["foo1"])
316
- @local_node.expects(:all_parts_outbound).with(:rows => 25).returns(["foo2"])
327
+ @local_node.should_receive(:all_parts_inbound).with(:rows => 25).and_return(["foo1"])
328
+ @local_node.should_receive(:all_parts_outbound).with(:rows => 25).and_return(["foo2"])
317
329
  @local_node.all_parts.should == ["foo1", "foo2"]
318
330
  end
319
331
  it "(:response_format => :id_array) should rely on inbound & outbound finders" do
320
- @local_node.expects(:all_parts_inbound).with(:response_format=>:id_array, :rows => 34).returns(["fooA"])
321
- @local_node.expects(:all_parts_outbound).with(:response_format=>:id_array, :rows => 34).returns(["fooB"])
332
+ @local_node.should_receive(:all_parts_inbound).with(:response_format=>:id_array, :rows => 34).and_return(["fooA"])
333
+ @local_node.should_receive(:all_parts_outbound).with(:response_format=>:id_array, :rows => 34).and_return(["fooB"])
322
334
  @local_node.all_parts(:response_format=>:id_array, :rows => 34).should == ["fooA", "fooB"]
323
335
  end
324
336
  it "(:response_format => :solr) should construct a solr query that combines inbound and outbound searches" do
325
337
  # get the id array for outbound relationships then construct solr query by combining id array with inbound relationship search
326
- @local_node.expects(:ids_for_outbound).with(:has_part).returns(["mypid:1"])
338
+ @local_node.should_receive(:ids_for_outbound).with(:has_part).and_return(["mypid:1"])
327
339
  id_array_query = ActiveFedora::SolrService.construct_query_for_pids(["mypid:1"])
328
340
  solr_result = mock("solr result")
329
- ActiveFedora::SolrService.expects(:query).with("#{id_array_query} OR (#{@part_of_sample})", :rows=>25).returns(solr_result)
341
+ ActiveFedora::SolrService.should_receive(:query).with("#{id_array_query} OR (#{@part_of_sample})", :rows=>25).and_return(solr_result)
330
342
  @local_node.all_parts(:response_format=>:solr)
331
343
  end
332
344
 
@@ -345,14 +357,14 @@ describe ActiveFedora::Relationships do
345
357
  it "resulting _query finder should call relationship_query" do
346
358
  SpecNode.create_bidirectional_relationship_finders("containers", :is_member_of, :has_member)
347
359
  local_node = SpecNode.new
348
- local_node.expects(:relationship_query).with("containers")
360
+ local_node.should_receive(:relationship_query).with("containers")
349
361
  local_node.containers_query
350
362
  end
351
363
  end
352
364
 
353
365
  describe "#has_bidirectional_relationship" do
354
366
  it "should ..." do
355
- SpecNode.expects(:create_bidirectional_relationship_finders).with("all_parts", :has_part, :is_part_of, {})
367
+ SpecNode.should_receive(:create_bidirectional_relationship_finders).with("all_parts", :has_part, :is_part_of, {})
356
368
  SpecNode.has_bidirectional_relationship("all_parts", :has_part, :is_part_of)
357
369
  end
358
370
 
@@ -363,9 +375,9 @@ describe ActiveFedora::Relationships do
363
375
  @local_node2 = SpecNode.new
364
376
  @local_node2.pid = "mypid2"
365
377
  model_def = SpecNode.to_class_uri
366
- @local_node.expects(:rels_ext).returns(stub("rels_ext", :content_will_change! => true, :content=>'')).at_least_once
378
+ @local_node.stub(:rels_ext => mock("rels_ext", :content_will_change! => true, :content=>''))
367
379
  @local_node.add_relationship(:has_model, model_def)
368
- @local_node2.expects(:rels_ext).returns(stub("rels_ext", :content_will_change! => true, :content=>'')).at_least_once
380
+ @local_node2.stub(:rels_ext => mock("rels_ext", :content_will_change! => true, :content=>''))
369
381
  @local_node2.add_relationship(:has_model, model_def)
370
382
  @local_node.add_relationship(:has_part, @local_node2)
371
383
  @local_node2.add_relationship(:has_part, @local_node)
@@ -441,7 +453,7 @@ describe ActiveFedora::Relationships do
441
453
  graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_model), RDF::URI.new(MockRelationshipNames.to_class_uri))
442
454
  graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_member), RDF::URI.new(@test_object4.internal_uri))
443
455
  graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_part), RDF::URI.new(@test_object3.internal_uri))
444
- @test_object2.expects(:relationships).returns(graph).at_least_once
456
+ @test_object2.stub(:relationships =>graph)
445
457
  @test_object2.find_relationship_by_name("testing").should == [@test_object3.internal_uri]
446
458
  end
447
459
  end
@@ -470,22 +482,22 @@ describe ActiveFedora::Relationships do
470
482
 
471
483
  it "should call bidirectional_relationship_query if a bidirectional relationship" do
472
484
  ids = ["changeme:1","changeme:2","changeme:3","changeme:4"]
473
- @mockrelsquery.expects(:ids_for_outbound).with(:has_part).returns(ids).at_least_once
474
- @mockrelsquery.expects(:pid).returns("changeme:5")
475
- MockNamedRelationshipQuery.expects(:bidirectional_relationship_query).with("changeme:5","testing_bi_query",ids)
485
+ @mockrelsquery.stub(:ids_for_outbound).with(:has_part).and_return(ids)
486
+ @mockrelsquery.should_receive(:pid).and_return("changeme:5")
487
+ MockNamedRelationshipQuery.should_receive(:bidirectional_relationship_query).with("changeme:5","testing_bi_query",ids)
476
488
  @mockrelsquery.relationship_query("testing_bi_query")
477
489
  end
478
490
 
479
491
  it "should call outbound_relationship_query if an outbound relationship" do
480
492
  ids = ["changeme:1","changeme:2","changeme:3","changeme:4"]
481
- @mockrelsquery.expects(:ids_for_outbound).with(:is_part_of).returns(ids).at_least_once
482
- MockNamedRelationshipQuery.expects(:outbound_relationship_query).with("testing_outbound_no_solr_fq",ids)
493
+ @mockrelsquery.stub(:ids_for_outbound).with(:is_part_of).and_return(ids)
494
+ MockNamedRelationshipQuery.should_receive(:outbound_relationship_query).with("testing_outbound_no_solr_fq",ids)
483
495
  @mockrelsquery.relationship_query("testing_outbound_no_solr_fq")
484
496
  end
485
497
 
486
498
  it "should call inbound_relationship_query if an inbound relationship" do
487
- @mockrelsquery.expects(:pid).returns("changeme:5")
488
- MockNamedRelationshipQuery.expects(:inbound_relationship_query).with("changeme:5","testing_inbound_query")
499
+ @mockrelsquery.should_receive(:pid).and_return("changeme:5")
500
+ MockNamedRelationshipQuery.should_receive(:inbound_relationship_query).with("changeme:5","testing_inbound_query")
489
501
  @mockrelsquery.relationship_query("testing_inbound_query")
490
502
  end
491
503
  end
@@ -529,7 +541,7 @@ describe ActiveFedora::Relationships do
529
541
  graph = RDF::Graph.new
530
542
  subject = RDF::URI.new "info:fedora/test:sample_pid"
531
543
  graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_model), RDF::URI.new(SpecNode.to_class_uri))
532
- @test_object.expects(:relationships).returns(graph).at_least_once
544
+ @test_object.stub(:relationships).and_return(graph)
533
545
  @test_object.conforms_to?(SpecNode).should == true
534
546
  end
535
547
  end
@@ -549,7 +561,7 @@ describe ActiveFedora::Relationships do
549
561
  graph = RDF::Graph.new
550
562
  subject = RDF::URI.new "info:fedora/test:sample_pid"
551
563
  graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_model), RDF::URI.new(SpecNode.to_class_uri))
552
- @test_object.expects(:relationships).returns(graph).at_least_once
564
+ @test_object.stub(:relationships).and_return(graph)
553
565
  @test_object3.assert_conforms_to('object',@test_object,SpecNode)
554
566
  end
555
567
  end
@@ -595,14 +607,14 @@ describe ActiveFedora::Relationships do
595
607
  graph = RDF::Graph.new
596
608
  subject = RDF::URI.new "info:fedora/test:sample_pid"
597
609
  graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_model), RDF::URI.new(model_pid))
598
- @test_object2.expects(:relationships).returns(graph).at_least_once
610
+ @test_object2.stub(:relationships).and_return(graph)
599
611
  #should return expected named relationships
600
612
  @test_object2.relationships_by_name.should == {:self=>{"testing"=>[],"testing2"=>[]}}
601
613
  graph = RDF::Graph.new
602
614
  subject = RDF::URI.new "info:fedora/test:sample_pid"
603
615
  graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_model), RDF::URI.new(model_pid))
604
616
  graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_part), RDF::URI.new(@test_object.internal_uri))
605
- @test_object3.expects(:relationships).returns(graph).at_least_once
617
+ @test_object3.stub(:relationships).and_return(graph)
606
618
  @test_object3.relationships_by_name.should == {:self=>{"testing"=>[@test_object.internal_uri],"testing2"=>[]}}
607
619
  end
608
620
  end