active-fedora 2.3.4 → 2.3.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,6 +5,21 @@ require 'equivalent-xml'
5
5
 
6
6
  describe ActiveFedora do
7
7
 
8
+ after :all do
9
+ unstub_rails
10
+ unstub_blacklight
11
+ # Restore to default fedora configs
12
+ fedora_config_path = File.join(File.dirname(__FILE__), "..", "..", "config", "fedora.yml")
13
+ ActiveFedora.init(:environment=>"test", :fedora_config=>fedora_config_path)
14
+ end
15
+
16
+ before(:each) do
17
+ # Stubbing register_fedora_and_solr in order to speed up tests.
18
+ # If you have tests that need fedora & solr registered,
19
+ # put them in the separate ActiveFedora describe block towards the end of this file.
20
+ ActiveFedora.stubs(:register_fedora_and_solr)
21
+ end
22
+
8
23
  describe "initialization methods" do
9
24
 
10
25
  describe "environment" do
@@ -24,6 +39,7 @@ describe ActiveFedora do
24
39
  ENV['environment'] = "wichita"
25
40
  ActiveFedora.expects(:config_options).at_least_once.returns({})
26
41
  ActiveFedora.environment.should eql("wichita")
42
+ ENV['environment']='test'
27
43
  end
28
44
 
29
45
  it "should use ENV['RAILS_ENV'] and log a warning if none of the above are set" do
@@ -173,16 +189,6 @@ describe ActiveFedora do
173
189
  end
174
190
  end
175
191
 
176
- describe "register_solr_and_fedora" do
177
- it "should regiser instances with the appropriate urls" do
178
- ActiveFedora.expects(:solr_config).at_least_once.returns({:url=>"http://megasolr:8983"})
179
- ActiveFedora.expects(:fedora_config).at_least_once.returns({:url=>"http://megafedora:8983"})
180
- ActiveFedora.register_fedora_and_solr
181
- ActiveFedora.solr.conn.url.to_s.should eql("http://megasolr:8983")
182
- ActiveFedora.fedora.fedora_url.to_s.should eql("http://megafedora:8983")
183
- end
184
- end
185
-
186
192
  describe "check_fedora_path_for_solr" do
187
193
  it "should find the solr.yml file and return it if it exists" do
188
194
  ActiveFedora.expects(:fedora_config_path).returns("/path/to/fedora/fedora.yml")
@@ -208,7 +214,9 @@ describe ActiveFedora do
208
214
  end
209
215
 
210
216
  after(:all) do
211
- ActiveFedora.init(File.join(File.dirname(__FILE__), "..", "..", "config", "fedora.yml"))
217
+ config_file = File.join(File.dirname(__FILE__), "..", "..", "config", "fedora.yml")
218
+ environment = "test"
219
+ ActiveFedora.init(:environment=>environment, :fedora_config_path=>config_file)
212
220
  end
213
221
 
214
222
  it "can tell its config paths" do
@@ -343,9 +351,13 @@ describe ActiveFedora do
343
351
  ActiveFedora.init()
344
352
  ActiveFedora.fedora.fedora_url.to_s.should == "http://fedoraAdmin:fedoraAdmin@127.0.0.1:8983/fedora"
345
353
  end
346
- it "should load the passed config if explicit config passed in" do
354
+ it "should load the passed config if explicit config passed in as a string" do
347
355
  ActiveFedora.init('./spec/fixtures/rails_root/config/fedora.yml')
348
- ActiveFedora.fedora.fedora_url.to_s.should == "http://fedoraAdmin:fedoraAdmin@testhost.com:8983/fedora"
356
+ ActiveFedora.fedora_config[:url].should == "http://fedoraAdmin:fedoraAdmin@testhost.com:8983/fedora"
357
+ end
358
+ it "should load the passed config if explicit config passed in as a string" do
359
+ ActiveFedora.init(:fedora_config_path=>'./spec/fixtures/rails_root/config/fedora.yml')
360
+ ActiveFedora.fedora_config[:url].should == "http://fedoraAdmin:fedoraAdmin@testhost.com:8983/fedora"
349
361
  end
350
362
  end
351
363
 
@@ -380,16 +392,12 @@ describe ActiveFedora do
380
392
  it "should look for the file in the path defined at Rails.root" do
381
393
  stub_rails(:root=>File.join(File.dirname(__FILE__),"../fixtures/rails_root"))
382
394
  ActiveFedora.init()
383
- ActiveFedora.solr.class.should == ActiveFedora::SolrService
384
- ActiveFedora.fedora.class.should == Fedora::Repository
385
- ActiveFedora.fedora.fedora_url.to_s.should == "http://fedoraAdmin:fedoraAdmin@testhost.com:8983/fedora"
395
+ ActiveFedora.fedora_config[:url].should == "http://fedoraAdmin:fedoraAdmin@testhost.com:8983/fedora"
386
396
  end
387
397
  it "should load the default file if no config is found at Rails.root" do
388
398
  stub_rails(:root=>File.join(File.dirname(__FILE__),"../fixtures/bad/path/to/rails_root"))
389
399
  ActiveFedora.init()
390
- ActiveFedora.solr.class.should == ActiveFedora::SolrService
391
- ActiveFedora.fedora.class.should == Fedora::Repository
392
- ActiveFedora.fedora.fedora_url.to_s.should == "http://fedoraAdmin:fedoraAdmin@127.0.0.1:8983/fedora"
400
+ ActiveFedora.fedora_config[:url].should == "http://fedoraAdmin:fedoraAdmin@127.0.0.1:8983/fedora"
393
401
  end
394
402
  end
395
403
  end
@@ -397,6 +405,21 @@ describe ActiveFedora do
397
405
  end
398
406
  end
399
407
 
408
+
409
+ describe ActiveFedora do
410
+ # Put methods whose tests require registering Fedora & Solr here.
411
+ # to allow tests to run fast, keep these to a minimum.
412
+ describe "register_solr_and_fedora" do
413
+ it "should regiser instances with the appropriate urls" do
414
+ ActiveFedora.expects(:solr_config).at_least_once.returns({:url=>"http://megasolr:8983"})
415
+ ActiveFedora.expects(:fedora_config).at_least_once.returns({:url=>"http://megafedora:8983"})
416
+ ActiveFedora.register_fedora_and_solr
417
+ ActiveFedora.solr.conn.url.to_s.should eql("http://megasolr:8983")
418
+ ActiveFedora.fedora.fedora_url.to_s.should eql("http://megafedora:8983")
419
+ end
420
+ end
421
+ end
422
+
400
423
  def mock_yaml(hash, path)
401
424
  mock_file = mock(path.split("/")[-1])
402
425
  File.stubs(:exist?).with(path).returns(true)
@@ -101,6 +101,7 @@ describe ActiveFedora::Base do
101
101
  @test_object.stubs(:pid).returns("foo")
102
102
  ActiveFedora::SolrService.instance.conn.expects(:delete).with("foo")
103
103
  Fedora::Repository.instance.stubs(:delete).with(@test_object.inner_object)
104
+ @test_object.expects(:inbound_relationships).returns({})
104
105
  @test_object.delete
105
106
  end
106
107
 
@@ -31,6 +31,7 @@ describe ActiveFedora::Base do
31
31
  Fedora::Repository.instance.stubs(:nextid).returns(increment_pid.to_s)
32
32
  @test_object = ActiveFedora::Base.new
33
33
  @test_object.new_object = true
34
+ @test_history = FooHistory.new
34
35
  end
35
36
 
36
37
  after(:each) do
@@ -342,11 +343,6 @@ describe ActiveFedora::Base do
342
343
  solr_doc[:id].should eql("#{@test_object.pid}")
343
344
  end
344
345
 
345
- it "should add self.class as the :active_fedora_model" do
346
- solr_doc = @test_object.to_solr
347
- solr_doc["active_fedora_model_s"].should eql(@test_object.class.inspect)
348
- end
349
-
350
346
  it "should call .to_xml on all MetadataDatastreams and return the resulting document" do
351
347
  ds1 = ActiveFedora::MetadataDatastream.new
352
348
  ds2 = ActiveFedora::MetadataDatastream.new
@@ -393,8 +389,8 @@ describe ActiveFedora::Base do
393
389
  end
394
390
 
395
391
  it "should add self.class as the :active_fedora_model" do
396
- solr_doc = @test_object.to_solr
397
- solr_doc["active_fedora_model_s"].should eql(@test_object.class.inspect)
392
+ solr_doc = @test_history.to_solr
393
+ solr_doc["active_fedora_model_s"].should eql("FooHistory")
398
394
  end
399
395
 
400
396
  it "should use mappings.yml to decide names of solr fields" do
@@ -617,11 +613,11 @@ describe ActiveFedora::Base do
617
613
  FooHistory.solr_search("pid: foobar", {:ding=>:dang}).should == {:baz=>:bif}
618
614
  end
619
615
 
620
- it 'should provide #named_relationships' do
621
- @test_object.should respond_to(:named_relationships)
616
+ it 'should provide #relationships_by_name' do
617
+ @test_object.should respond_to(:relationships_by_name)
622
618
  end
623
619
 
624
- describe '#named_relationships' do
620
+ describe '#relationships_by_name' do
625
621
 
626
622
  class MockNamedRelationships < ActiveFedora::Base
627
623
  has_relationship "testing", :has_part, :type=>ActiveFedora::Base
@@ -629,25 +625,25 @@ describe ActiveFedora::Base do
629
625
  has_relationship "testing_inbound", :has_part, :type=>ActiveFedora::Base, :inbound=>true
630
626
  end
631
627
 
632
- it 'should return current named relationships' do
628
+ it 'should return current relationships by name' do
633
629
  Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
634
630
  @test_object2 = MockNamedRelationships.new
635
631
  @test_object2.add_relationship(:has_model, ActiveFedora::ContentModel.pid_from_ruby_class(MockNamedRelationships))
636
632
  @test_object.add_relationship(:has_model, ActiveFedora::ContentModel.pid_from_ruby_class(ActiveFedora::Base))
637
633
  #should return expected named relationships
638
- @test_object2.named_relationships
639
- @test_object2.named_relationships.should == {:self=>{"testing"=>[],"testing2"=>[]}}
634
+ @test_object2.relationships_by_name
635
+ @test_object2.relationships_by_name.should == {:self=>{"testing2"=>[], "collection_members"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[]}}
640
636
  r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:dummy,:object=>@test_object})
641
- @test_object2.add_named_relationship("testing",@test_object)
642
- @test_object2.named_relationships.should == {:self=>{"testing"=>[r.object],"testing2"=>[]}}
637
+ @test_object2.add_relationship_by_name("testing",@test_object)
638
+ @test_object2.relationships_by_name.should == {:self=>{"testing"=>[r.object],"testing2"=>[],"part_of"=>[], "parts_outbound"=>[r.object], "collection_members"=>[]}}
643
639
  end
644
640
  end
645
641
 
646
642
 
647
- describe '#create_named_relationship_methods' do
643
+ describe '#create_relationship_name_methods' do
648
644
  class MockCreateNamedRelationshipMethodsBase < ActiveFedora::Base
649
- register_named_relationship :self, "testing", :is_part_of, :type=>ActiveFedora::Base
650
- create_named_relationship_methods "testing"
645
+ register_relationship_desc :self, "testing", :is_part_of, :type=>ActiveFedora::Base
646
+ create_relationship_name_methods "testing"
651
647
  end
652
648
 
653
649
  it 'should append and remove using helper methods for each outbound relationship' do
@@ -662,9 +658,9 @@ describe ActiveFedora::Base do
662
658
  @test_object2.testing_append(@test_object)
663
659
  #create relationship to access generate_uri method for an object
664
660
  r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object)
665
- @test_object2.named_relationships.should == {:self=>{"testing"=>[r.object]}}
661
+ @test_object2.relationships_by_name.should == {:self=>{"testing"=>[r.object],"collection_members"=>[], "part_of"=>[r.object], "parts_outbound"=>[]}}
666
662
  @test_object2.testing_remove(@test_object)
667
- @test_object2.named_relationships.should == {:self=>{"testing"=>[]}}
663
+ @test_object2.relationships_by_name.should == {:self=>{"testing"=>[],"collection_members"=>[], "part_of"=>[], "parts_outbound"=>[]}}
668
664
  end
669
665
  end
670
666
  end
@@ -0,0 +1,842 @@
1
+ require File.join( File.dirname(__FILE__), "../spec_helper" )
2
+
3
+ require 'active_fedora'
4
+ require 'xmlsimple'
5
+
6
+ @@last_pid = 0
7
+
8
+ class SpecNamedNode
9
+ include ActiveFedora::RelationshipsHelper
10
+
11
+ attr_accessor :pid
12
+ end
13
+
14
+ describe ActiveFedora::RelationshipsHelper do
15
+
16
+ def increment_pid
17
+ @@last_pid += 1
18
+ end
19
+
20
+ before(:each) do
21
+ @test_object = SpecNamedNode.new
22
+ @test_object.pid = increment_pid
23
+ end
24
+
25
+ describe '#relationship_predicates' do
26
+ class MockNamedRelationshipPredicates < SpecNamedNode
27
+ register_relationship_desc(:self, "testing", :has_part, :type=>SpecNamedNode)
28
+ create_relationship_name_methods("testing")
29
+ register_relationship_desc(:self, "testing2", :has_member, :type=>SpecNamedNode)
30
+ create_relationship_name_methods("testing2")
31
+ register_relationship_desc(:inbound, "testing_inbound", :has_part, :type=>SpecNamedNode)
32
+ end
33
+
34
+ it 'should provide #relationship_predicates' do
35
+ @test_object.should respond_to(:relationship_predicates)
36
+ end
37
+
38
+ it 'should return a map of subject to relationship name to fedora ontology relationship predicate' do
39
+ @test_object2 = MockNamedRelationshipPredicates.new
40
+ @test_object2.relationship_predicates.should == {:self=>{"testing"=>:has_part,"testing2"=>:has_member},
41
+ :inbound=>{"testing_inbound"=>:has_part}}
42
+
43
+ end
44
+ end
45
+
46
+ describe '#conforms_to?' do
47
+ it 'should provide #conforms_to?' do
48
+ @test_object.should respond_to(:conforms_to?)
49
+ end
50
+
51
+ it 'should check if current object is the kind of model class supplied' do
52
+ #has_model relationship does not get created until save called
53
+ r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_model,:object=>ActiveFedora::ContentModel.pid_from_ruby_class(SpecNamedNode)})
54
+ @test_object.expects(:relationships).returns({:self=>{:has_model=>[r.object]}}).at_least_once
55
+ @test_object.conforms_to?(SpecNamedNode).should == true
56
+ end
57
+ end
58
+
59
+ describe '#assert_conforms_to' do
60
+ it 'should provide #assert_conforms_to' do
61
+ @test_object.should respond_to(:assert_conforms_to)
62
+ end
63
+
64
+ it 'should correctly assert if an object is the type of model supplied' do
65
+ @test_object3 = SpecNamedNode.new
66
+ @test_object3.pid = increment_pid
67
+ #has_model relationship does not get created until save called so need to add the has model rel here, is fine since not testing save
68
+ r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_model,:object=>ActiveFedora::ContentModel.pid_from_ruby_class(SpecNamedNode)})
69
+ @test_object.expects(:relationships).returns({:self=>{:has_model=>[r.object]}}).at_least_once
70
+ @test_object3.assert_conforms_to('object',@test_object,SpecNamedNode)
71
+ end
72
+ end
73
+
74
+ it 'should provide #class_from_name' do
75
+ @test_object.should respond_to(:class_from_name)
76
+ end
77
+
78
+ describe '#class_from_name' do
79
+ it 'should return a class constant for a string passed in' do
80
+ @test_object.class_from_name("SpecNamedNode").should == SpecNamedNode
81
+ end
82
+ end
83
+
84
+ describe '#relationships_by_name' do
85
+
86
+ class MockNamedRelationships3 < SpecNamedNode
87
+ register_relationship_desc(:self, "testing", :has_part, :type=>SpecNamedNode)
88
+ create_relationship_name_methods("testing")
89
+ register_relationship_desc(:self, "testing2", :has_member, :type=>SpecNamedNode)
90
+ create_relationship_name_methods("testing2")
91
+ register_relationship_desc(:inbound, "testing_inbound", :has_part, :type=>SpecNamedNode)
92
+ end
93
+
94
+ it 'should provide #relationships_by_name' do
95
+ @test_object.should respond_to(:relationships_by_name)
96
+ end
97
+
98
+ it 'should return current named relationships' do
99
+ @test_object2 = MockNamedRelationships3.new
100
+ @test_object2.pid = increment_pid
101
+ @test_object3 = MockNamedRelationships3.new
102
+ @test_object3.pid = increment_pid
103
+ r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_model,:object=>ActiveFedora::ContentModel.pid_from_ruby_class(MockNamedRelationships3)})
104
+ @test_object2.expects(:relationships).returns({:self=>{:has_model=>[r.object],:has_part=>[],:has_member=>[]},:inbound=>{:has_part=>[]}}).at_least_once
105
+ #should return expected named relationships
106
+ @test_object2.relationships_by_name.should == {:self=>{"testing"=>[],"testing2"=>[]},:inbound=>{"testing_inbound"=>[]}}
107
+ r3 = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_part,:object=>@test_object})
108
+ @test_object3.expects(:relationships).returns({:self=>{:has_model=>[r.object],:has_part=>[r3.object],:has_member=>[]},:inbound=>{:has_part=>[]}}).at_least_once
109
+ @test_object3.relationships_by_name.should == {:self=>{"testing"=>[r3.object],"testing2"=>[]},:inbound=>{"testing_inbound"=>[]}}
110
+ end
111
+ end
112
+
113
+ it 'should provide #relationship_names' do
114
+ @test_object.should respond_to(:relationship_names)
115
+ end
116
+
117
+ describe '#relationship_names' do
118
+ class MockRelationshipNames < SpecNamedNode
119
+ register_relationship_desc(:self, "testing", :has_part, :type=>SpecNamedNode)
120
+ create_relationship_name_methods("testing")
121
+ register_relationship_desc(:self, "testing2", :has_member, :type=>SpecNamedNode)
122
+ create_relationship_name_methods("testing2")
123
+ register_relationship_desc(:inbound, "testing_inbound", :has_part, :type=>SpecNamedNode)
124
+ register_relationship_desc(:inbound, "testing_inbound2", :has_member, :type=>SpecNamedNode)
125
+ end
126
+
127
+ it 'should return an array of relationship names for this model' do
128
+ @test_object2 = MockRelationshipNames.new
129
+ @test_object2.pid = increment_pid
130
+ @test_object2.relationship_names.include?("testing").should == true
131
+ @test_object2.relationship_names.include?("testing2").should == true
132
+ @test_object2.relationship_names.include?("testing_inbound").should == true
133
+ @test_object2.relationship_names.include?("testing_inbound2").should == true
134
+ @test_object2.relationship_names.size.should == 4
135
+ end
136
+ end
137
+
138
+ it 'should provide #inbound_relationship_names' do
139
+ @test_object.should respond_to(:inbound_relationship_names)
140
+ end
141
+
142
+ describe '#inbound_relationship_names' do
143
+ it 'should return an array of inbound relationship names for this model' do
144
+ @test_object2 = MockRelationshipNames.new
145
+ @test_object2.pid = increment_pid
146
+ @test_object2.inbound_relationship_names.include?("testing_inbound").should == true
147
+ @test_object2.inbound_relationship_names.include?("testing_inbound2").should == true
148
+ @test_object2.inbound_relationship_names.size.should == 2
149
+ end
150
+ end
151
+
152
+ it 'should provide #outbound_relationship_names' do
153
+ @test_object.should respond_to(:outbound_relationship_names)
154
+ end
155
+
156
+ describe '#outbound_relationship_names' do
157
+ it 'should return an array of outbound relationship names for this model' do
158
+ @test_object2 = MockRelationshipNames.new
159
+ @test_object2.pid = increment_pid
160
+ @test_object2.outbound_relationship_names.include?("testing").should == true
161
+ @test_object2.outbound_relationship_names.include?("testing2").should == true
162
+ @test_object2.outbound_relationship_names.size.should == 2
163
+ end
164
+ end
165
+
166
+ it 'should provide #outbound_relationships_by_name' do
167
+ @test_object.should respond_to(:outbound_relationships_by_name)
168
+ end
169
+
170
+ describe '#outbound_relationships_by_name' do
171
+ it 'should return hash of outbound relationship names to arrays of object uri' do
172
+ @test_object2 = MockRelationshipNames.new
173
+ @test_object2.pid = increment_pid
174
+ @test_object2.expects(:relationships).returns({:self=>{:has_part=>[],:has_member=>[],:inbound=>{:has_part=>[],:has_member=>[]}}}).at_least_once
175
+ @test_object2.outbound_relationships_by_name.should == {"testing"=>[],
176
+ "testing2"=>[]}
177
+ end
178
+ end
179
+
180
+ it 'should provide #inbound_relationships_by_name' do
181
+ #testing execution of this in integration since touches solr
182
+ @test_object.should respond_to(:inbound_relationships_by_name)
183
+ end
184
+
185
+ it 'should provide #find_relationship_by_name' do
186
+ @test_object.should respond_to(:find_relationship_by_name)
187
+ end
188
+
189
+ describe '#find_relationship_by_name' do
190
+ it 'should return an array of object uri for a given relationship name' do
191
+ @test_object2 = MockRelationshipNames.new
192
+ @test_object2.pid = increment_pid
193
+ r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:has_model, :object=>ActiveFedora::ContentModel.pid_from_ruby_class(MockRelationshipNames))
194
+ @test_object3 = SpecNamedNode.new
195
+ @test_object3.pid = increment_pid
196
+ @test_object4 = SpecNamedNode.new
197
+ @test_object4.pid = increment_pid
198
+ #add relationships that mirror 'testing' and 'testing2'
199
+ r3 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:has_part, :object=>@test_object3)
200
+ r4 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:has_member, :object=>@test_object4)
201
+ @test_object2.expects(:relationships).returns({:self=>{:has_part=>[r3.object]},:has_member=>[r4.object],:has_model=>[r.object]}).at_least_once
202
+ @test_object2.find_relationship_by_name("testing").should == [r3.object]
203
+ end
204
+ end
205
+
206
+ describe "relationship_query" do
207
+ class MockNamedRelationshipQuery < SpecNamedNode
208
+ register_relationship_desc(:inbound, "testing_inbound_query", :is_part_of, :type=>SpecNamedNode, :solr_fq=>"has_model_s:info\\:fedora/SpecialPart")
209
+ register_relationship_desc(:inbound, "testing_inbound_no_solr_fq", :is_part_of, :type=>SpecNamedNode)
210
+ register_relationship_desc(:self, "testing_outbound_query", :is_part_of, :type=>SpecNamedNode, :solr_fq=>"has_model_s:info\\:fedora/SpecialPart")
211
+ register_relationship_desc(:self, "testing_outbound_no_solr_fq", :is_part_of, :type=>SpecNamedNode)
212
+ #for bidirectional relationship testing need to register both outbound and inbound names
213
+ register_relationship_desc(:self, "testing_bi_query_outbound", :has_part, :type=>SpecNamedNode, :solr_fq=>"has_model_s:info\\:fedora/SpecialPart")
214
+ register_relationship_desc(:inbound, "testing_bi_query_inbound", :is_part_of, :type=>SpecNamedNode, :solr_fq=>"has_model_s:info\\:fedora/SpecialPart")
215
+ register_relationship_desc(:self, "testing_bi_no_solr_fq_outbound", :has_part, :type=>SpecNamedNode)
216
+ register_relationship_desc(:inbound, "testing_bi_no_solr_fq_inbound", :is_part_of, :type=>SpecNamedNode)
217
+ end
218
+
219
+ before(:each) do
220
+ @mockrelsquery = MockNamedRelationshipQuery.new
221
+ end
222
+
223
+ it "should call bidirectional_relationship_query if a bidirectional relationship" do
224
+ rels_ids = ["info:fedora/changeme:1","info:fedora/changeme:2","info:fedora/changeme:3","info:fedora/changeme:4"]
225
+ @mockrelsquery.expects(:outbound_relationships).returns({:has_part=>rels_ids}).at_least_once
226
+ ids = ["changeme:1","changeme:2","changeme:3","changeme:4"]
227
+ @mockrelsquery.expects(:pid).returns("changeme:5")
228
+ MockNamedRelationshipQuery.expects(:bidirectional_relationship_query).with("changeme:5","testing_bi_query",ids)
229
+ @mockrelsquery.relationship_query("testing_bi_query")
230
+ end
231
+
232
+ it "should call outbound_relationship_query if an outbound relationship" do
233
+ rels_ids = ["info:fedora/changeme:1","info:fedora/changeme:2","info:fedora/changeme:3","info:fedora/changeme:4"]
234
+ @mockrelsquery.expects(:outbound_relationships).returns({:is_part_of=>rels_ids}).at_least_once
235
+ ids = ["changeme:1","changeme:2","changeme:3","changeme:4"]
236
+ MockNamedRelationshipQuery.expects(:outbound_relationship_query).with("testing_outbound_no_solr_fq",ids)
237
+ @mockrelsquery.relationship_query("testing_outbound_no_solr_fq")
238
+ end
239
+
240
+ it "should call inbound_relationship_query if an inbound relationship" do
241
+ @mockrelsquery.expects(:pid).returns("changeme:5")
242
+ MockNamedRelationshipQuery.expects(:inbound_relationship_query).with("changeme:5","testing_inbound_query")
243
+ @mockrelsquery.relationship_query("testing_inbound_query")
244
+ end
245
+ end
246
+
247
+ describe ActiveFedora::RelationshipsHelper::ClassMethods do
248
+
249
+ after(:each) do
250
+ begin
251
+ @test_object2.delete
252
+ rescue
253
+ end
254
+ end
255
+
256
+ describe '#relationships_desc' do
257
+ it 'should initialize relationships_desc to a new hash containing self' do
258
+ @test_object2 = SpecNamedNode.new
259
+ @test_object2.pid = increment_pid
260
+ @test_object2.relationships_desc.should == {:self=>{}}
261
+ end
262
+ end
263
+
264
+ describe '#register_relationship_desc_subject' do
265
+
266
+ class MockRegisterNamedSubject < SpecNamedNode
267
+ register_relationship_desc_subject :test
268
+ end
269
+
270
+ it 'should add a new named subject to the named relationships only if it does not already exist' do
271
+ @test_object2 = MockRegisterNamedSubject.new
272
+ @test_object2.pid = increment_pid
273
+ @test_object2.relationships_desc.should == {:self=>{}, :test=>{}}
274
+ end
275
+ end
276
+
277
+ describe '#register_relationship_desc' do
278
+
279
+ class MockRegisterNamedRelationship < SpecNamedNode
280
+ register_relationship_desc :self, "testing", :is_part_of, :type=>SpecNamedNode
281
+ register_relationship_desc :inbound, "testing2", :has_part, :type=>SpecNamedNode
282
+ end
283
+
284
+ it 'should add a new named subject to the named relationships only if it does not already exist' do
285
+ @test_object2 = MockRegisterNamedRelationship.new
286
+ @test_object2.pid = increment_pid
287
+ @test_object2.relationships_desc.should == {:inbound=>{"testing2"=>{:type=>SpecNamedNode, :predicate=>:has_part}}, :self=>{"testing"=>{:type=>SpecNamedNode, :predicate=>:is_part_of}}}
288
+ end
289
+ end
290
+
291
+ describe "#is_bidirectional_relationship?" do
292
+
293
+ class MockIsBiRegisterNamedRelationship < SpecNamedNode
294
+ register_relationship_desc(:self, "testing_outbound", :is_part_of, :type=>SpecNamedNode)
295
+ register_relationship_desc(:inbound, "testing_inbound", :has_part, :type=>SpecNamedNode)
296
+ register_relationship_desc(:self, "testing2", :is_member_of,{})
297
+ end
298
+
299
+ it "should return true if both inbound and outbound predicates exist, otherwise false" do
300
+ MockIsBiRegisterNamedRelationship.is_bidirectional_relationship?("testing").should == true
301
+ MockIsBiRegisterNamedRelationship.is_bidirectional_relationship?("testing2").should == false
302
+ #the inbound and outbound internal relationships will not be bidirectional by themselves
303
+ MockIsBiRegisterNamedRelationship.is_bidirectional_relationship?("testing_inbound").should == false
304
+ MockIsBiRegisterNamedRelationship.is_bidirectional_relationship?("testing_outbound").should == false
305
+ end
306
+ end
307
+
308
+ describe '#relationship_has_solr_filter_query' do
309
+ class RelsHasSolrFilter < SpecNamedNode
310
+ register_relationship_desc :self, "testing", :is_part_of, :solr_fq=>"testing:value"
311
+ register_relationship_desc :self, "no_query_testing", :is_part_of
312
+ register_relationship_desc :inbound, "inbound_testing", :has_part, :solr_fq=>"in_testing:value_in"
313
+ register_relationship_desc :inbound, "inbound_testing_no_query", :has_part
314
+ end
315
+
316
+ it 'should return true if an object has an inbound relationship with solr filter query' do
317
+ RelsHasSolrFilter.relationship_has_solr_filter_query?(:inbound,"inbound_testing").should == true
318
+ end
319
+
320
+ it 'should return false if an object does not have inbound relationship with solr filter query' do
321
+ RelsHasSolrFilter.relationship_has_solr_filter_query?(:inbound,"inbound_testing_no_query").should == false
322
+ end
323
+
324
+ it 'should return true if an object has an outbound relationship with solr filter query' do
325
+ RelsHasSolrFilter.relationship_has_solr_filter_query?(:self,"testing").should == true
326
+ end
327
+
328
+ it 'should return false if an object does not have outbound relationship with solr filter query' do
329
+ RelsHasSolrFilter.relationship_has_solr_filter_query?(:self,"testing_no_query").should == false
330
+ end
331
+ end
332
+
333
+ describe '#create_relationship_name_methods' do
334
+ class MockCreateNamedRelationshipMethods < SpecNamedNode
335
+ register_relationship_desc :self, "testing", :is_part_of, :type=>SpecNamedNode
336
+ create_relationship_name_methods "testing"
337
+ end
338
+
339
+ it 'should create an append and remove method for each outbound relationship' do
340
+ @test_object2 = MockCreateNamedRelationshipMethods.new
341
+ @test_object2.pid = increment_pid
342
+ @test_object2.should respond_to(:testing_append)
343
+ @test_object2.should respond_to(:testing_remove)
344
+ #test execution in base_spec since method definitions include methods in ActiveFedora::Base
345
+ end
346
+ end
347
+
348
+ describe '#create_bidirectional_relationship_name_methods' do
349
+ class MockCreateNamedRelationshipMethods < SpecNamedNode
350
+ register_relationship_desc(:self, "testing_outbound", :is_part_of, :type=>SpecNamedNode)
351
+ create_bidirectional_relationship_name_methods "testing", "testing_outbound"
352
+ end
353
+
354
+ it 'should create an append and remove method for each outbound relationship' do
355
+ @test_object2 = MockCreateNamedRelationshipMethods.new
356
+ @test_object2.pid = increment_pid
357
+ @test_object2.should respond_to(:testing_append)
358
+ @test_object2.should respond_to(:testing_remove)
359
+ #test execution in base_spec since method definitions include methods in ActiveFedora::Base
360
+ end
361
+ end
362
+
363
+ describe '#def predicate_exists_with_different_relationship_name?' do
364
+
365
+ it 'should return true if a predicate exists for same subject and different name but not different subject' do
366
+ class MockPredicateExists < SpecNamedNode
367
+ register_relationship_desc :self, "testing", :has_part, :type=>SpecNamedNode
368
+ register_relationship_desc :self, "testing2", :has_member, :type=>SpecNamedNode
369
+ register_relationship_desc :inbound, "testing_inbound", :is_part_of, :type=>SpecNamedNode
370
+
371
+ predicate_exists_with_different_relationship_name?(:self,"testing",:has_part).should == false
372
+ predicate_exists_with_different_relationship_name?(:self,"testing3",:has_part).should == true
373
+ predicate_exists_with_different_relationship_name?(:inbound,"testing",:has_part).should == false
374
+ predicate_exists_with_different_relationship_name?(:self,"testing2",:has_member).should == false
375
+ predicate_exists_with_different_relationship_name?(:self,"testing3",:has_member).should == true
376
+ predicate_exists_with_different_relationship_name?(:inbound,"testing2",:has_member).should == false
377
+ predicate_exists_with_different_relationship_name?(:self,"testing_inbound",:is_part_of).should == false
378
+ predicate_exists_with_different_relationship_name?(:inbound,"testing_inbound",:is_part_of).should == false
379
+ predicate_exists_with_different_relationship_name?(:inbound,"testing_inbound2",:is_part_of).should == true
380
+ end
381
+ end
382
+ end
383
+
384
+ #
385
+ # HYDRA-541
386
+ #
387
+
388
+ describe "bidirectional_relationship_query" do
389
+ class MockBiNamedRelationshipQuery < SpecNamedNode
390
+ register_relationship_desc(:self, "testing_query_outbound", :has_part, :type=>SpecNamedNode, :solr_fq=>"has_model_s:info\\:fedora/SpecialPart")
391
+ register_relationship_desc(:inbound, "testing_query_inbound", :is_part_of, :type=>SpecNamedNode, :solr_fq=>"has_model_s:info\\:fedora/SpecialPart")
392
+ create_bidirectional_relationship_name_methods("testing","testing_outbound")
393
+ register_relationship_desc(:self, "testing_no_solr_fq_outbound", :has_part, :type=>SpecNamedNode)
394
+ register_relationship_desc(:inbound, "testing_no_solr_fq_inbound", :is_part_of, :type=>SpecNamedNode)
395
+ create_bidirectional_relationship_name_methods("testing_no_solr_fq","testing_no_solr_fq_outbound")
396
+ end
397
+
398
+ #
399
+ # HYDRA-541
400
+ #
401
+ it "should rely on outbound query if inbound query is empty" do
402
+ query = MockBiNamedRelationshipQuery.bidirectional_relationship_query("PID",:testing_query,[])
403
+ query.should_not include("OR ()")
404
+ query2 = MockBiNamedRelationshipQuery.bidirectional_relationship_query("PID",:testing_no_solr_fq,[])
405
+ query2.should_not include("OR ()")
406
+ end
407
+
408
+ it "should return a properly formatted query for a relationship that has a solr filter query defined" do
409
+ expected_string = ""
410
+ ids = ["changeme:1","changeme:2","changeme:3","changeme:4","changeme:5"]
411
+ ids.each_with_index do |id,index|
412
+ expected_string << " OR " if index > 0
413
+ expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND has_model_s:info\\:fedora/SpecialPart)"
414
+ end
415
+ expected_string << " OR "
416
+ expected_string << "(is_part_of_s:info\\:fedora/changeme\\:6 AND has_model_s:info\\:fedora/SpecialPart)"
417
+ MockBiNamedRelationshipQuery.bidirectional_relationship_query("changeme:6","testing_query",ids).should == expected_string
418
+ end
419
+
420
+ it "should return a properly formatted query for a relationship that does not have a solr filter query defined" do
421
+ expected_string = ""
422
+ ids = ["changeme:1","changeme:2","changeme:3","changeme:4","changeme:5"]
423
+ ids.each_with_index do |id,index|
424
+ expected_string << " OR " if index > 0
425
+ expected_string << "id:" + id.gsub(/(:)/, '\\:')
426
+ end
427
+ expected_string << " OR "
428
+ expected_string << "(is_part_of_s:info\\:fedora/changeme\\:6)"
429
+ MockBiNamedRelationshipQuery.bidirectional_relationship_query("changeme:6","testing_no_solr_fq",ids).should == expected_string
430
+ end
431
+ end
432
+
433
+ describe "inbound_relationship_query" do
434
+ class MockInboundNamedRelationshipQuery < SpecNamedNode
435
+ register_relationship_desc(:inbound, "testing_inbound_query", :is_part_of, :type=>SpecNamedNode, :solr_fq=>"has_model_s:info\\:fedora/SpecialPart")
436
+ register_relationship_desc(:inbound, "testing_inbound_no_solr_fq", :is_part_of, :type=>SpecNamedNode)
437
+ end
438
+
439
+ it "should return a properly formatted query for a relationship that has a solr filter query defined" do
440
+ MockInboundNamedRelationshipQuery.inbound_relationship_query("changeme:1","testing_inbound_query").should == "is_part_of_s:info\\:fedora/changeme\\:1 AND has_model_s:info\\:fedora/SpecialPart"
441
+ end
442
+
443
+ it "should return a properly formatted query for a relationship that does not have a solr filter query defined" do
444
+ MockInboundNamedRelationshipQuery.inbound_relationship_query("changeme:1","testing_inbound_no_solr_fq").should == "is_part_of_s:info\\:fedora/changeme\\:1"
445
+ end
446
+ end
447
+
448
+ describe "outbound_relationship_query" do
449
+ class MockOutboundNamedRelationshipQuery < SpecNamedNode
450
+ register_relationship_desc(:self, "testing_query", :is_part_of, :type=>SpecNamedNode, :solr_fq=>"has_model_s:info\\:fedora/SpecialPart")
451
+ register_relationship_desc(:self,"testing_no_solr_fq", :is_part_of, :type=>SpecNamedNode)
452
+ end
453
+
454
+ it "should return a properly formatted query for a relationship that has a solr filter query defined" do
455
+ ids = ["changeme:1","changeme:2","changeme:3","changeme:4"]
456
+ expected_string = ""
457
+ ids.each_with_index do |id,index|
458
+ expected_string << " OR " if index > 0
459
+ expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND has_model_s:info\\:fedora/SpecialPart)"
460
+ end
461
+ MockOutboundNamedRelationshipQuery.outbound_relationship_query("testing_query",ids).should == expected_string
462
+ end
463
+
464
+ it "should return a properly formatted query for a relationship that does not have a solr filter query defined" do
465
+ expected_string = ""
466
+ ids = ["changeme:1","changeme:2","changeme:3","changeme:4"]
467
+ ids.each_with_index do |id,index|
468
+ expected_string << " OR " if index > 0
469
+ expected_string << "id:" + id.gsub(/(:)/, '\\:')
470
+ end
471
+ MockOutboundNamedRelationshipQuery.outbound_relationship_query("testing_no_solr_fq",ids).should == expected_string
472
+ end
473
+ end
474
+
475
+ ### Deprecated class method checks for HYDRA-541 methods renamed
476
+ # named_relationships_desc
477
+ # register_named_subject(subject)
478
+ # register_named_relationship(subject, name, predicate, opts={})
479
+ # create_named_relationship_methods(name)
480
+ # create_bidirectional_named_relationship_methods(name,outbound_name)
481
+ # outbound_named_relationship_query(relationship_name,outbound_pids)
482
+ # inbound_named_relationship_query(pid,relationship_name)
483
+ # bidirectional_named_relationship_query(pid,relationship_name,outbound_pids)
484
+ # named_predicate_exists_with_different_name?(subject,name,predicate)
485
+ describe "named_relationships_desc" do
486
+ it 'should throw deprecation warning if old method name called and should call new method name' do
487
+ logger = mock()
488
+ logger.expects(:warn).with("Deprecation: named_relationships_desc has been deprecated. Please call relationships_desc instead.")
489
+ @test_object.class.expects(:logger).returns(logger)
490
+ @test_object.class.respond_to?(:relationships_desc)
491
+ obj = mock()
492
+ @test_object.class.expects(:relationships_desc)
493
+ @test_object.class.named_relationships_desc
494
+ end
495
+ end
496
+
497
+ describe "register_named_subject" do
498
+ it 'should throw deprecation warning if old method name called and should call new method name' do
499
+ logger = mock()
500
+ logger.expects(:warn).with("Deprecation: register_named_subject has been deprecated. Please call register_relationship_desc_subject instead.")
501
+ @test_object.class.expects(:logger).returns(logger)
502
+ @test_object.class.respond_to?(:register_relationship_desc_subject)
503
+ obj = mock()
504
+ @test_object.class.expects(:register_relationship_desc_subject).with(:self)
505
+ @test_object.class.register_named_subject(:self)
506
+ end
507
+ end
508
+
509
+ describe "register_named_relationship" do
510
+ it 'should throw deprecation warning if old method name called and should call new method name' do
511
+ logger = mock()
512
+ logger.expects(:warn).with("Deprecation: register_named_relationship has been deprecated. Please call register_relationship_desc instead.")
513
+ @test_object.class.expects(:logger).returns(logger)
514
+ @test_object.class.respond_to?(:register_relationship_desc)
515
+ obj = mock()
516
+ @test_object.class.expects(:register_relationship_desc).with(:self,"testing",:has_member,{})
517
+ @test_object.class.register_named_relationship(:self,"testing",:has_member,{})
518
+ end
519
+ end
520
+
521
+ describe "create_named_relationship_methods" do
522
+ it 'should throw deprecation warning if old method name called and should call new method name' do
523
+ logger = mock()
524
+ logger.expects(:warn).with("Deprecation: create_named_relationship_methods has been deprecated. Please call create_relationship_name_methods instead.")
525
+ @test_object.class.expects(:logger).returns(logger)
526
+ @test_object.class.respond_to?(:create_relationship_name_methods)
527
+ obj = mock()
528
+ @test_object.class.expects(:create_relationship_name_methods).with("testing")
529
+ @test_object.class.create_named_relationship_methods("testing")
530
+ end
531
+ end
532
+
533
+ describe "create_bidirectional_named_relationship_methods" do
534
+ it 'should throw deprecation warning if old method name called and should call new method name' do
535
+ logger = mock()
536
+ logger.expects(:warn).with("Deprecation: create_bidirectional_named_relationship_methods has been deprecated. Please call create_bidirectional_relationship_name_methods instead.")
537
+ @test_object.class.expects(:logger).returns(logger)
538
+ @test_object.class.respond_to?(:create_bidirectional_relationship_name_methods)
539
+ obj = mock()
540
+ @test_object.class.expects(:create_bidirectional_relationship_name_methods).with("testing","testing_outbound")
541
+ @test_object.class.create_bidirectional_named_relationship_methods("testing","testing_outbound")
542
+ end
543
+ end
544
+
545
+ describe "outbound_named_relationship_query" do
546
+ it 'should throw deprecation warning if old method name called and should call new method name' do
547
+ logger = mock()
548
+ logger.expects(:warn).with("Deprecation: outbound_named_relationship_query has been deprecated. Please call outbound_relationship_query instead.")
549
+ @test_object.class.expects(:logger).returns(logger)
550
+ @test_object.class.respond_to?(:outbound_relationship_query)
551
+ obj = mock()
552
+ @test_object.class.expects(:outbound_relationship_query).with("testing",["testid"])
553
+ @test_object.class.outbound_named_relationship_query("testing",["testid"])
554
+ end
555
+ end
556
+
557
+ describe "inbound_named_relationship_query" do
558
+ it 'should throw deprecation warning if old method name called and should call new method name' do
559
+ logger = mock()
560
+ logger.expects(:warn).with("Deprecation: inbound_named_relationship_query has been deprecated. Please call inbound_relationship_query instead.")
561
+ @test_object.class.expects(:logger).returns(logger)
562
+ @test_object.class.respond_to?(:inbound_relationship_query)
563
+ obj = mock()
564
+ @test_object.class.expects(:inbound_relationship_query).with("testid","testing")
565
+ @test_object.class.inbound_named_relationship_query("testid","testing")
566
+ end
567
+ end
568
+
569
+ describe "bidirectional_named_relationship_query" do
570
+ it 'should throw deprecation warning if old method name called and should call new method name' do
571
+ logger = mock()
572
+ logger.expects(:warn).with("Deprecation: bidirectional_named_relationship_query has been deprecated. Please call bidirectional_relationship_query instead.")
573
+ @test_object.class.expects(:logger).returns(logger)
574
+ @test_object.class.respond_to?(:bidirectional_relationship_query)
575
+ obj = mock()
576
+ @test_object.class.expects(:bidirectional_relationship_query).with("testid","testing",["testid2"])
577
+ @test_object.class.bidirectional_named_relationship_query("testid","testing",["testid2"])
578
+ end
579
+ end
580
+
581
+ describe "named_predicate_exists_with_different_name?" do
582
+ it 'should throw deprecation warning if old method name called and should call new method name' do
583
+ logger = mock()
584
+ logger.expects(:warn).with("Deprecation: named_predicate_exists_with_different_name? has been deprecated. Please call predicate_exists_with_different_relationship_name? instead.")
585
+ @test_object.class.expects(:logger).returns(logger)
586
+ @test_object.class.respond_to?(:predicate_exists_with_different_relationship_name?)
587
+ obj = mock()
588
+ @test_object.class.expects(:predicate_exists_with_different_relationship_name?).with(:subject,"testing",:has_member)
589
+ @test_object.class.named_predicate_exists_with_different_name?(:subject,"testing",:has_member)
590
+ end
591
+ end
592
+ end
593
+
594
+ ## Deprecated method checks for HYDRA-541 methods renamed
595
+ #
596
+ # Old Name New Name
597
+ # named_relationship find_relationship_by_name
598
+ # register_named_subject register_relationship_desc_subject
599
+ # register_named_relationship register_relationship_desc
600
+ # named_relationships relationships_by_name
601
+ # named_relationships_from_class relationships_by_name_from_class
602
+ # named_inbound_relationships inbound_relationship_names
603
+ # outbound_named_relationship_predicates outbound_relationship_predicates
604
+ # inbound_named_relationship_predicates inbound_relationship_predicates
605
+ # named_relationship_predicates relationship_predicates
606
+ # named_relationship_predicates_from_class relationship_predicates_from_class
607
+ # named_outbound_relationships outbound_relationships_by_name
608
+ # is_named_relationship? is_relationship_name?
609
+ # named_relationships_desc relationships_desc
610
+ # named_relationships_desc_from_class relationships_desc_from_class
611
+ # named_relationship_type relationship_model_type
612
+ # add_named_relationship add_relationship_by_name
613
+ # remove_named_relationship remove_relationship_by_name
614
+ # assert_kind_of_model assert_conforms_to
615
+ # kind_of_model? conforms_to?
616
+ # named_relationship_query relationship_query
617
+
618
+ describe "named_relationship" do
619
+ it 'should throw deprecation warning if old method name called and should call new method name' do
620
+ logger = mock()
621
+ logger.expects(:warn).with("Deprecation: named_relationship has been deprecated. Please call find_relationship_by_name instead.")
622
+ @test_object.expects(:logger).returns(logger)
623
+ @test_object.respond_to?(:find_relationship_by_name).should == true
624
+ @test_object.expects(:find_relationship_by_name).with("testing")
625
+ @test_object.named_relationship("testing")
626
+ end
627
+ end
628
+
629
+ describe "register_named_subject" do
630
+ it 'should throw deprecation warning if old method name called and should call new method name' do
631
+ logger = mock()
632
+ logger.expects(:warn).with("Deprecation: register_named_subject has been deprecated. Please call register_relationship_desc_subject instead.")
633
+ @test_object.expects(:logger).returns(logger)
634
+ @test_object.respond_to?(:register_relationship_desc_subject).should == true
635
+ @test_object.expects(:register_relationship_desc_subject).with(:self)
636
+ @test_object.register_named_subject(:self)
637
+ end
638
+ end
639
+
640
+ describe "register_named_relationship" do
641
+ it 'should throw deprecation warning if old method name called and should call new method name' do
642
+ logger = mock()
643
+ logger.expects(:warn).with("Deprecation: register_named_relationship has been deprecated. Please call register_relationship_desc instead.")
644
+ @test_object.expects(:logger).returns(logger)
645
+ @test_object.respond_to?(:register_relationship_desc).should == true
646
+ @test_object.expects(:register_relationship_desc).with(:self,"testing",:has_member,{})
647
+ @test_object.register_named_relationship(:self,"testing",:has_member,{})
648
+ end
649
+ end
650
+
651
+ describe "named_relationships" do
652
+ it 'should throw deprecation warning if old method name called and should call new method name' do
653
+ logger = mock()
654
+ logger.expects(:warn).with("Deprecation: named_relationships has been deprecated. Please call relationships_by_name instead.")
655
+ @test_object.expects(:logger).returns(logger)
656
+ @test_object.respond_to?(:relationships_by_name).should == true
657
+ @test_object.expects(:relationships_by_name)
658
+ @test_object.named_relationships
659
+ end
660
+ end
661
+
662
+ describe "named_relationships_from_class" do
663
+ it 'should throw deprecation warning if old method name called and should call new method name' do
664
+ logger = mock()
665
+ logger.expects(:warn).with("Deprecation: named_relationships_from_class has been deprecated. Please call relationships_by_name_from_class instead.")
666
+ @test_object.expects(:logger).returns(logger)
667
+ @test_object.respond_to?(:relationships_by_name_from_class).should == true
668
+ @test_object.expects(:relationships_by_name_from_class)
669
+ @test_object.named_relationships_from_class
670
+ end
671
+ end
672
+
673
+ describe "named_inbound_relationships" do
674
+ it 'should throw deprecation warning if old method name called and should call new method name' do
675
+ logger = mock()
676
+ logger.expects(:warn).with("Deprecation: named_inbound_relationships has been deprecated. Please call inbound_relationships_by_name instead.")
677
+ @test_object.expects(:logger).returns(logger)
678
+ @test_object.respond_to?(:inbound_relationships_by_name).should == true
679
+ @test_object.expects(:inbound_relationships_by_name)
680
+ @test_object.named_inbound_relationships
681
+ end
682
+ end
683
+
684
+ describe "named_outbound_relationships" do
685
+ it 'should throw deprecation warning if old method name called and should call new method name' do
686
+ logger = mock()
687
+ logger.expects(:warn).with("Deprecation: named_outbound_relationships has been deprecated. Please call outbound_relationships_by_name instead.")
688
+ @test_object.expects(:logger).returns(logger)
689
+ @test_object.respond_to?(:outbound_relationships_by_name).should == true
690
+ @test_object.expects(:outbound_relationships_by_name)
691
+ @test_object.named_outbound_relationships
692
+ end
693
+ end
694
+
695
+ describe "outbound_named_relationship_predicates" do
696
+ it 'should throw deprecation warning if old method name called and should call new method name' do
697
+ logger = mock()
698
+ logger.expects(:warn).with("Deprecation: outbound_named_relationship_predicates has been deprecated. Please call outbound_relationship_predicates instead.")
699
+ @test_object.expects(:logger).returns(logger)
700
+ @test_object.respond_to?(:outbound_relationship_predicates).should == true
701
+ @test_object.expects(:outbound_relationship_predicates)
702
+ @test_object.outbound_named_relationship_predicates
703
+ end
704
+ end
705
+
706
+ describe "inbound_named_relationship_predicates" do
707
+ it 'should throw deprecation warning if old method name called and should call new method name' do
708
+ logger = mock()
709
+ logger.expects(:warn).with("Deprecation: inbound_named_relationship_predicates has been deprecated. Please call inbound_relationship_predicates instead.")
710
+ @test_object.expects(:logger).returns(logger)
711
+ @test_object.respond_to?(:inbound_relationship_predicates).should == true
712
+ @test_object.expects(:inbound_relationship_predicates)
713
+ @test_object.inbound_named_relationship_predicates
714
+ end
715
+ end
716
+
717
+ describe "named_relationship_predicates" do
718
+ it 'should throw deprecation warning if old method name called and should call new method name' do
719
+ logger = mock()
720
+ logger.expects(:warn).with("Deprecation: named_relationship_predicates has been deprecated. Please call relationship_predicates instead.")
721
+ @test_object.expects(:logger).returns(logger)
722
+ @test_object.respond_to?(:relationship_predicates).should == true
723
+ @test_object.expects(:relationship_predicates)
724
+ @test_object.named_relationship_predicates
725
+ end
726
+ end
727
+
728
+ describe "named_relationship_predicates_from_class" do
729
+ it 'should throw deprecation warning if old method name called and should call new method name' do
730
+ logger = mock()
731
+ logger.expects(:warn).with("Deprecation: named_relationship_predicates_from_class has been deprecated. Please call relationship_predicates_from_class instead.")
732
+ @test_object.expects(:logger).returns(logger)
733
+ @test_object.respond_to?(:relationship_predicates_from_class).should == true
734
+ @test_object.expects(:relationship_predicates_from_class)
735
+ @test_object.named_relationship_predicates_from_class
736
+ end
737
+ end
738
+
739
+ describe "is_named_relationship?" do
740
+ it 'should throw deprecation warning if old method name called and should call new method name' do
741
+ logger = mock()
742
+ logger.expects(:warn).with("Deprecation: is_named_relationship? has been deprecated. Please call is_relationship_name? instead.")
743
+ @test_object.expects(:logger).returns(logger)
744
+ @test_object.respond_to?(:is_relationship_name?).should == true
745
+ @test_object.expects(:is_relationship_name?)
746
+ @test_object.is_named_relationship?("testing",true)
747
+ end
748
+ end
749
+
750
+ describe "named_relationships_desc" do
751
+ it 'should throw deprecation warning if old method name called and should call new method name' do
752
+ logger = mock()
753
+ logger.expects(:warn).with("Deprecation: named_relationships_desc has been deprecated. Please call relationships_desc instead.")
754
+ @test_object.expects(:logger).returns(logger)
755
+ @test_object.respond_to?(:relationships_desc)
756
+ @test_object.expects(:relationships_desc)
757
+ @test_object.named_relationships_desc
758
+ end
759
+ end
760
+
761
+ describe "named_relationships_desc_from_class" do
762
+ it 'should throw deprecation warning if old method name called and should call new method name' do
763
+ logger = mock()
764
+ logger.expects(:warn).with("Deprecation: named_relationships_desc_from_class has been deprecated. Please call relationships_desc_from_class instead.")
765
+ @test_object.expects(:logger).returns(logger)
766
+ @test_object.respond_to?(:relationships_desc_from_class)
767
+ @test_object.expects(:relationships_desc_from_class)
768
+ @test_object.named_relationships_desc_from_class
769
+ end
770
+ end
771
+
772
+ describe "named_relationship_type" do
773
+ it 'should throw deprecation warning if old method name called and should call new method name' do
774
+ logger = mock()
775
+ logger.expects(:warn).with("Deprecation: named_relationship_type has been deprecated. Please call relationship_model_type instead.")
776
+ @test_object.expects(:logger).returns(logger)
777
+ @test_object.respond_to?(:relationship_model_type)
778
+ @test_object.expects(:relationship_model_type).with("testing")
779
+ @test_object.named_relationship_type("testing")
780
+ end
781
+ end
782
+
783
+ describe "add_named_relationship" do
784
+ it 'should throw deprecation warning if old method name called and should call new method name' do
785
+ logger = mock()
786
+ logger.expects(:warn).with("Deprecation: add_named_relationship has been deprecated. Please call add_relationship_by_name instead.")
787
+ @test_object.expects(:logger).returns(logger)
788
+ @test_object.respond_to?(:add_relationship_by_name)
789
+ obj = mock()
790
+ @test_object.expects(:add_relationship_by_name).with("testing",obj)
791
+ @test_object.add_named_relationship("testing",obj)
792
+ end
793
+ end
794
+
795
+ describe "remove_named_relationship" do
796
+ it 'should throw deprecation warning if old method name called and should call new method name' do
797
+ logger = mock()
798
+ logger.expects(:warn).with("Deprecation: remove_named_relationship has been deprecated. Please call remove_relationship_by_name instead.")
799
+ @test_object.expects(:logger).returns(logger)
800
+ @test_object.respond_to?(:remove_relationship_by_name)
801
+ obj = mock()
802
+ @test_object.expects(:remove_relationship_by_name).with("testing",obj)
803
+ @test_object.remove_named_relationship("testing",obj)
804
+ end
805
+ end
806
+
807
+ describe "assert_kind_of_model" do
808
+ it 'should throw deprecation warning if old method name called and should call new method name' do
809
+ logger = mock()
810
+ logger.expects(:warn).with("Deprecation: assert_kind_of_model has been deprecated. Please call assert_conforms_to instead.")
811
+ @test_object.expects(:logger).returns(logger)
812
+ @test_object.respond_to?(:assert_conforms_to)
813
+ obj = mock()
814
+ @test_object.expects(:assert_conforms_to).with("testing",obj,ActiveFedora::Base)
815
+ @test_object.assert_kind_of_model("testing",obj,ActiveFedora::Base)
816
+ end
817
+ end
818
+
819
+ describe "kind_of_model?" do
820
+ it 'should throw deprecation warning if old method name called and should call new method name' do
821
+ logger = mock()
822
+ logger.expects(:warn).with("Deprecation: kind_of_model? has been deprecated. Please call conforms_to? instead.")
823
+ @test_object.expects(:logger).returns(logger)
824
+ @test_object.respond_to?(:conforms_to?)
825
+ obj = mock()
826
+ @test_object.expects(:conforms_to?).with(ActiveFedora::Base)
827
+ @test_object.kind_of_model?(ActiveFedora::Base)
828
+ end
829
+ end
830
+
831
+ describe "named_relationship_query" do
832
+ it 'should throw deprecation warning if old method name called and should call new method name' do
833
+ logger = mock()
834
+ logger.expects(:warn).with("Deprecation: named_relationship_query has been deprecated. Please call relationship_query instead.")
835
+ @test_object.expects(:logger).returns(logger)
836
+ @test_object.respond_to?(:relationship_query)
837
+ obj = mock()
838
+ @test_object.expects(:relationship_query).with("testing")
839
+ @test_object.named_relationship_query("testing")
840
+ end
841
+ end
842
+ end