active-fedora 5.7.1 → 6.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/.gitmodules +1 -1
  2. data/Gemfile +2 -1
  3. data/History.txt +0 -14
  4. data/Rakefile +1 -2
  5. data/active-fedora.gemspec +2 -2
  6. data/lib/active_fedora.rb +1 -16
  7. data/lib/active_fedora/associations.rb +8 -11
  8. data/lib/active_fedora/associations/association_collection.rb +2 -4
  9. data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +3 -12
  10. data/lib/active_fedora/associations/has_many_association.rb +0 -4
  11. data/lib/active_fedora/base.rb +6 -6
  12. data/lib/active_fedora/config.rb +0 -7
  13. data/lib/active_fedora/datastream.rb +0 -37
  14. data/lib/active_fedora/datastream_collections.rb +0 -10
  15. data/lib/active_fedora/datastreams.rb +0 -17
  16. data/lib/active_fedora/digital_object.rb +1 -1
  17. data/lib/active_fedora/file_configurator.rb +0 -22
  18. data/lib/active_fedora/fixture_loader.rb +1 -1
  19. data/lib/active_fedora/nokogiri_datastream.rb +9 -51
  20. data/lib/active_fedora/qualified_dublin_core_datastream.rb +1 -1
  21. data/lib/active_fedora/querying.rb +8 -4
  22. data/lib/active_fedora/rdf_datastream.rb +10 -9
  23. data/lib/active_fedora/rdf_node.rb +1 -1
  24. data/lib/active_fedora/rdf_node/term_proxy.rb +9 -5
  25. data/lib/active_fedora/relation.rb +1 -1
  26. data/lib/active_fedora/rels_ext_datastream.rb +1 -8
  27. data/lib/active_fedora/semantic_node.rb +0 -35
  28. data/lib/active_fedora/simple_datastream.rb +1 -1
  29. data/lib/active_fedora/solr_service.rb +6 -8
  30. data/lib/active_fedora/version.rb +1 -1
  31. data/lib/tasks/active_fedora_dev.rake +11 -3
  32. data/solr/conf/schema.xml +10 -1
  33. data/spec/integration/base_spec.rb +2 -347
  34. data/spec/integration/complex_rdf_datastream_spec.rb +1 -1
  35. data/spec/integration/full_featured_model_spec.rb +1 -9
  36. data/spec/integration/ntriples_datastream_spec.rb +4 -4
  37. data/spec/integration/om_datastream_spec.rb +2 -1
  38. data/spec/integration/rels_ext_datastream_spec.rb +1 -89
  39. data/spec/integration/scoped_query_spec.rb +4 -4
  40. data/spec/samples/hydra-mods_article_datastream.rb +2 -2
  41. data/spec/spec_helper.rb +3 -0
  42. data/spec/unit/base_spec.rb +7 -81
  43. data/spec/unit/datastream_spec.rb +0 -25
  44. data/spec/unit/has_many_collection_spec.rb +2 -27
  45. data/spec/unit/ntriples_datastream_spec.rb +28 -39
  46. data/spec/unit/om_datastream_spec.rb +13 -13
  47. data/spec/unit/qualified_dublin_core_datastream_spec.rb +1 -1
  48. data/spec/unit/query_spec.rb +1 -24
  49. data/spec/unit/semantic_node_spec.rb +0 -2
  50. data/spec/unit/simple_datastream_spec.rb +2 -2
  51. data/spec/unit/solr_config_options_spec.rb +1 -1
  52. metadata +76 -57
  53. checksums.yaml +0 -7
  54. data/.travis.yml +0 -8
  55. data/lib/active_fedora/file_management.rb +0 -81
  56. data/lib/active_fedora/metadata_datastream_helper.rb +0 -43
  57. data/lib/active_fedora/named_relationships.rb +0 -99
  58. data/lib/active_fedora/relationships.rb +0 -663
  59. data/spec/integration/base_file_management_spec.rb +0 -24
  60. data/spec/integration/has_many_associations_spec.rb +0 -64
  61. data/spec/integration/metadata_datastream_helper_spec.rb +0 -100
  62. data/spec/integration/semantic_node_spec.rb +0 -457
  63. data/spec/unit/base_file_management_spec.rb +0 -95
  64. data/spec/unit/has_and_belongs_to_many_collection_spec.rb +0 -59
  65. data/spec/unit/relationships_spec.rb +0 -871
@@ -1,24 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveFedora::Base do
4
-
5
- before(:each) do
6
- class FileMgmt < ActiveFedora::Base
7
- include ActiveFedora::FileManagement
8
- end
9
- @test_container = FileMgmt.new
10
- @test_container.add_relationship(:has_collection_member, "info:fedora/foo:2")
11
- @test_container.save
12
- end
13
-
14
- after(:each) do
15
- @test_container.delete
16
- Object.send(:remove_const, :FileMgmt)
17
- end
18
-
19
- it "should persist and re-load collection members" do
20
- container_copy = FileMgmt.find(@test_container.pid)
21
- container_copy.collection_members(:response_format=>:id_array).should == ["foo:2"]
22
- end
23
-
24
- end
@@ -1,64 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "When two or more relationships share the same property" do
4
- before do
5
- class Book < ActiveFedora::Base
6
- has_many :collections, :property=>:is_part_of, :class_name=>'Collection'
7
- has_many :people, :property=>:is_part_of
8
- end
9
-
10
- class Person < ActiveFedora::Base
11
- belongs_to :book, :property=>:is_part_of
12
- end
13
-
14
- class Collection < ActiveFedora::Base
15
- belongs_to :book, :property=>:is_part_of
16
- end
17
-
18
- @book = Book.create!
19
- @person1 = Person.create!(:book=>@book)
20
- @person2 = Person.create!(:book=>@book)
21
- end
22
- after do
23
- Object.send(:remove_const, :Collection)
24
- Object.send(:remove_const, :Person)
25
- Object.send(:remove_const, :Book)
26
- end
27
-
28
- it "Should only return relationships of the correct class" do
29
- @book.reload
30
- @book.people.should == [@person1, @person2]
31
- @book.collections.should == []
32
- end
33
- end
34
-
35
- describe "When relationship is restricted to AF::Base" do
36
- before do
37
- class Email < ActiveFedora::Base
38
- has_many :attachments, :property=>:is_part_of, :class_name=>'ActiveFedora::Base'
39
- end
40
-
41
- class Image < ActiveFedora::Base
42
- belongs_to :email, :property=>:is_part_of
43
- end
44
-
45
- class PDF < ActiveFedora::Base
46
- belongs_to :email, :property=>:is_part_of
47
- end
48
-
49
- @book = Email.create!
50
- @image = Image.create!(:email=>@book)
51
- @pdf = PDF.create!(:email=>@book)
52
- end
53
- after do
54
- Object.send(:remove_const, :Image)
55
- Object.send(:remove_const, :PDF)
56
- Object.send(:remove_const, :Email)
57
- end
58
-
59
-
60
- it "Should not restrict relationships " do
61
- @book.reload
62
- @book.attachments.should == [@image, @pdf]
63
- end
64
- end
@@ -1,100 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'active-fedora'
4
- require "rexml/document"
5
-
6
- class MockMetaHelperSolr < ActiveFedora::Base
7
- has_metadata :name => "properties", :type => ActiveFedora::SimpleDatastream do |m|
8
- m.field "holding_id", :string
9
- end
10
-
11
- has_metadata :name => "descMetadata", :type => ActiveFedora::QualifiedDublinCoreDatastream do |m|
12
- m.field "created", :date, :xml_node => "created"
13
- m.field "language", :string, :xml_node => "language"
14
- m.field "creator", :string, :xml_node => "creator"
15
- # Created remaining fields
16
- m.field "geography", :string, :xml_node => "geography"
17
- m.field "title", :string, :xml_node => "title"
18
- end
19
-
20
- end
21
-
22
- describe ActiveFedora::MetadataDatastreamHelper do
23
-
24
- before(:each) do
25
- @test_object = ActiveFedora::Base.new
26
- @test_object.save
27
- end
28
-
29
- after(:each) do
30
- begin
31
- @test_object.delete
32
- rescue
33
- end
34
- begin
35
- @test_object2.delete
36
- rescue
37
- end
38
- begin
39
- @test_object3.delete
40
- rescue
41
- end
42
- end
43
-
44
- describe '#from_solr' do
45
- it 'should return an object with the appropriate metadata fields filled in' do
46
- @test_object = MockMetaHelperSolr.new
47
- attributes = {"holding_id"=>{0=>"Holding 1"},
48
- "language" =>{0=>"Italian"},
49
- "creator"=>{0=>"Linguist, A."},
50
- "geography"=>{0=>"Italy"},
51
- "title"=>{0=>"Italian and Spanish: A Comparison of Common Phrases"}}
52
- @test_object.update_indexed_attributes(attributes)
53
- @test_object.save
54
-
55
- @test_object2 = MockMetaHelperSolr.new
56
- attributes = {"holding_id"=>{0=>"Holding 2"},
57
- "language"=>{0=>"Spanish;Latin"},
58
- "creator"=>{0=>"Linguist, A."},
59
- "geography"=>{0=>"Spain"},
60
- "title"=>{0=>"A study of the evolution of Spanish from Latin"}}
61
- @test_object2.update_indexed_attributes(attributes)
62
- @test_object2.save
63
-
64
- @test_object3 = MockMetaHelperSolr.new
65
- attributes = {"holding_id"=>{0=>"Holding 3"},
66
- "language"=>{0=>"Spanish;Latin"},
67
- "creator"=>{0=>"Linguist, A."},
68
- "geography"=>{0=>"Spain"},
69
- "title"=>{0=>"An obscure look into early nomadic tribes of Spain"}}
70
- @test_object3.update_indexed_attributes(attributes)
71
- @test_object3.save
72
-
73
- #from_solr gets called indirectly
74
- test_from_solr_object = MockMetaHelperSolr.load_instance_from_solr(@test_object.pid)
75
- test_from_solr_object2 = MockMetaHelperSolr.load_instance_from_solr(@test_object2.pid)
76
- test_from_solr_object3 = MockMetaHelperSolr.load_instance_from_solr(@test_object3.pid)
77
-
78
- test_from_solr_object.descMetadata.language.should == ["Italian"]
79
- test_from_solr_object.descMetadata.creator.should == ["Linguist, A."]
80
- test_from_solr_object.descMetadata.geography.should == ["Italy"]
81
- test_from_solr_object.descMetadata.title.should == ["Italian and Spanish: A Comparison of Common Phrases"]
82
- #test_from_solr_object.fields[:holding_id][:values].should == ["Holding 1"]
83
-
84
- test_from_solr_object2.descMetadata.language.should == ["Spanish;Latin"]
85
- test_from_solr_object2.descMetadata.creator.should == ["Linguist, A."]
86
- test_from_solr_object2.descMetadata.geography.should == ["Spain"]
87
- test_from_solr_object2.descMetadata.title.should == ["A study of the evolution of Spanish from Latin"]
88
- #test_from_solr_object2.fields[:holding_id][:values].should == ["Holding 2"]
89
-
90
- test_from_solr_object3.descMetadata.language.should == ["Spanish;Latin"]
91
- test_from_solr_object3.descMetadata.creator.should == ["Linguist, A."]
92
- test_from_solr_object3.descMetadata.geography.should == ["Spain"]
93
- test_from_solr_object3.descMetadata.title.should == ["An obscure look into early nomadic tribes of Spain"]
94
- #test_from_solr_object3.properties.holding_id.should == ["Holding 3"]
95
-
96
-
97
- end
98
- end
99
-
100
- end
@@ -1,457 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'active_fedora'
4
-
5
- describe ActiveFedora::SemanticNode 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
- before(:all) do
18
- class SNSpecNode < ActiveFedora::Base
19
- include ActiveFedora::FileManagement
20
- end
21
- @node = SNSpecNode.new
22
- class SNSpecModel < ActiveFedora::Base
23
- include ActiveFedora::Relationships
24
- has_relationship("parts", :is_part_of, :inbound => true)
25
- has_relationship("containers", :is_member_of)
26
- has_bidirectional_relationship("bi_containers", :is_member_of, :has_member)
27
- end
28
- class SpecNodeSolrFilterQuery < ActiveFedora::Base
29
- include ActiveFedora::Relationships
30
- has_relationship("parts", :is_part_of, :inbound => true)
31
- has_relationship("special_parts", :is_part_of, :inbound => true, :solr_fq=>"#{ActiveFedora::SolrService.solr_name("has_model", :symbol)}:info\\:fedora\\/afmodel\\:SpecialPart")
32
- has_relationship("containers", :is_member_of)
33
- has_relationship("special_containers", :is_member_of, :solr_fq=>"#{ActiveFedora::SolrService.solr_name("has_model", :symbol)}:info\\:fedora\\/afmodel\\:SpecialContainer")
34
- has_bidirectional_relationship("bi_containers", :is_member_of, :has_member)
35
- has_bidirectional_relationship("bi_special_containers", :is_member_of, :has_member, :solr_fq=>"#{ActiveFedora::SolrService.solr_name("has_model", :symbol)}:info\\:fedora\\/afmodel\\:SpecialContainer")
36
- end
37
-
38
- @test_object = SNSpecModel.new
39
- @test_object.save
40
-
41
- @part1 = ActiveFedora::Base.new()
42
- @part1.add_relationship(:is_part_of, @test_object)
43
- @part1.save
44
- @part2 = ActiveFedora::Base.new()
45
- @part2.add_relationship(:is_part_of, @test_object)
46
- @part2.save
47
-
48
-
49
- @container1 = ActiveFedora::Base.new()
50
- @container1.save
51
- @container2 = ActiveFedora::Base.new()
52
- @container2.save
53
- @container3 = ActiveFedora::Base.new()
54
- @container3.save
55
- @container4 = ActiveFedora::Base.new()
56
- @container4.save
57
-
58
- @test_object.add_relationship(:is_member_of, @container1)
59
- @test_object.add_relationship(:is_member_of, @container2)
60
- @test_object.add_relationship(:is_member_of, @container3)
61
- @test_object.save
62
-
63
- @container4.add_relationship(:has_member,@test_object)
64
- @container4.save
65
-
66
- class SpecialContainer < ActiveFedora::Base; end;
67
- class SpecialPart < ActiveFedora::Base; end;
68
- @special_container = ActiveFedora::Base.new()
69
- @special_container.add_relationship(:has_model, SpecialContainer.to_class_uri)
70
- @special_container.save
71
-
72
- @special_container3 = ActiveFedora::Base.new()
73
- @special_container3.add_relationship(:has_model, SpecialContainer.to_class_uri)
74
- @special_container3.save
75
-
76
- @special_container4 = ActiveFedora::Base.new()
77
- @special_container4.add_relationship(:has_model, SpecialContainer.to_class_uri)
78
- @special_container4.save
79
-
80
- #even though adding container3 and 3 special containers, it should only include the special containers when returning via relationship name finder methods
81
- #also should only return special part similarly
82
- @test_object_query = SpecNodeSolrFilterQuery.new
83
- @test_object_query.add_relationship(:is_member_of, @container3)
84
- @test_object_query.add_relationship(:is_member_of, @special_container)
85
- @test_object_query.add_relationship(:is_member_of, @special_container3)
86
- @test_object_query.add_relationship(:is_member_of, @special_container4)
87
- @test_object_query.save
88
-
89
- @special_container2 = ActiveFedora::Base.new()
90
- @special_container2.add_relationship(:has_model, SpecialContainer.to_class_uri)
91
- @special_container2.add_relationship(:has_member, 'info:fedora/'+@test_object_query.pid)
92
- @special_container2.save
93
-
94
- @part3 = ActiveFedora::Base.new()
95
- @part3.add_relationship(:is_part_of, @test_object_query)
96
- @part3.save
97
-
98
- @special_part = ActiveFedora::Base.new()
99
- @special_part.add_relationship(:has_model, SpecialPart.to_class_uri)
100
- @special_part.add_relationship(:is_part_of, @test_object_query)
101
- @special_part.save
102
-
103
- @special_container_query = "#{ActiveFedora::SolrService.solr_name("has_model", :symbol)}:#{solr_uri("info:fedora/afmodel:SpecialContainer")}"
104
- @special_part_query = "#{ActiveFedora::SolrService.solr_name("has_model", :symbol)}:#{solr_uri("info:fedora/afmodel:SpecialPart")}"
105
- end
106
-
107
- after(:all) do
108
- begin
109
- @part1.delete
110
- rescue
111
- end
112
- begin
113
- @part2.delete
114
- rescue
115
- end
116
- begin
117
- @part3.delete
118
- rescue
119
- end
120
- begin
121
- @container1.delete
122
- rescue
123
- end
124
- begin
125
- @container2.delete
126
- rescue
127
- end
128
- begin
129
- @container3.delete
130
- rescue
131
- end
132
- begin
133
- @test_object.delete
134
- rescue
135
- end
136
- begin
137
- @test_object_query.delete
138
- rescue
139
- end
140
- begin
141
- @special_part.delete
142
- rescue
143
- end
144
- begin
145
- @special_container.delete
146
- rescue
147
- end
148
- begin
149
- @special_container2.delete
150
- rescue
151
- end
152
- Object.send(:remove_const, :SNSpecModel)
153
-
154
- end
155
-
156
- describe '#has_relationship' do
157
- it "should create useable finders" do
158
- spec_node = SNSpecNode.new
159
- spec_node.collection_members.should == []
160
-
161
- spec_node.add_relationship(:has_collection_member, @test_object.pid)
162
- collection_members = spec_node.collection_members
163
- collection_members.length.should == 1
164
- collection_members.first.pid.should == @test_object.pid
165
- collection_members.first.class.should == @test_object.class
166
- end
167
- end
168
-
169
- describe "inbound relationship finders" do
170
- describe "when inheriting from parents" do
171
- before do
172
- class Test1 < ActiveFedora::Base
173
- include ActiveFedora::FileManagement
174
- end
175
- @part4 = Test1.new()
176
- @part4.parts
177
-
178
- class Test2 < ActiveFedora::Base
179
- include ActiveFedora::FileManagement
180
- end
181
- class Test3 < Test2
182
- include ActiveFedora::Relationships
183
- has_relationship "testing", :has_member
184
- end
185
-
186
- class Test4 < Test3
187
- include ActiveFedora::Relationships
188
- has_relationship "testing_inbound", :is_member_of, :inbound=>true
189
- end
190
-
191
- class Test5 < Test4
192
- include ActiveFedora::Relationships
193
- has_relationship "testing_inbound", :is_part_of, :inbound=>true
194
- end
195
-
196
- @test_object2 = Test2.new
197
- @test_object2.save
198
- end
199
- it "should have relationships defined" do
200
- Test1.relationships_desc.should have_key(:inbound)
201
- Test2.relationships_desc.should have_key(:inbound)
202
- Test2.relationships_desc[:inbound]["parts_inbound"].should == {:inbound=>true, :predicate=>:is_part_of, :singular=>nil}
203
- end
204
-
205
- it "should have relationships defined from more than one ancestor class" do
206
- Test4.relationships_desc[:self].should have_key("collection_members")
207
- Test4.relationships_desc[:self].should have_key("testing")
208
- Test4.relationships_desc[:inbound].should have_key("testing_inbound")
209
- end
210
-
211
- it "should override a parents relationship description if defined in the child" do
212
- #check parent description
213
- Test4.relationships_desc[:inbound]["testing_inbound"][:predicate].should == :is_member_of
214
- #check child with overwritten relationship description has different predicate
215
- Test5.relationships_desc[:inbound]["testing_inbound"][:predicate].should == :is_part_of
216
- end
217
-
218
- it "should not have relationships bleeding over from other sibling classes" do
219
- SpecNodeSolrFilterQuery.relationships_desc[:inbound].should have_key("bi_special_containers_inbound")
220
- Test1.relationships_desc[:inbound].should_not have_key("bi_special_containers_inbound")
221
- Test2.relationships_desc[:inbound].should_not have_key("bi_special_containers_inbound")
222
- end
223
- it "should return an empty set" do
224
- @test_object2.parts.should == []
225
- @test_object2.parts_outbound.should == []
226
- end
227
- it "should return stuff" do
228
- @part4.add_relationship(:is_part_of, @test_object2)
229
- @test_object2.add_relationship(:has_part, @test_object)
230
- @part4.save
231
- @test_object2.parts_inbound.map(&:pid).should == [@part4.pid]
232
- @test_object2.parts_outbound.map(&:pid).should == [@test_object.pid]
233
- @test_object2.parts.map(&:pid).should == [@part4.pid, @test_object.pid]
234
- end
235
- after do
236
- @test_object2.delete
237
- begin
238
- @part4.delete
239
- rescue
240
- end
241
- end
242
- end
243
- it "should return an array of Base objects" do
244
- parts = @test_object.parts
245
- parts.each do |part|
246
- part.should be_kind_of(ActiveFedora::Base)
247
- end
248
- end
249
- it "_ids should return an array of pids" do
250
- ids = @test_object.parts_ids
251
- ids.size.should == 2
252
- ids.include?(@part1.pid).should == true
253
- ids.include?(@part2.pid).should == true
254
- end
255
- it "should return an array of Base objects with some filtered out if using solr_fq" do
256
- @test_object_query.special_parts_ids.should == [@special_part.pid]
257
- end
258
-
259
- it "should return an array of all Base objects with relationship if not using solr_fq" do
260
- @test_object_query.parts_ids.size.should == 2
261
- @test_object_query.parts_ids.include?(@special_part.pid).should == true
262
- @test_object_query.parts_ids.include?(@part3.pid).should == true
263
- end
264
-
265
- it "should return a solr query for an inbound relationship" do
266
- @test_object_query.special_parts_query.should == "#{ActiveFedora::SolrService.solr_name(@test_object_query.relationship_predicates[:inbound]['special_parts'], :symbol)}:#{solr_uri(@test_object_query.internal_uri)} AND #{@special_part_query}"
267
- end
268
- end
269
-
270
- describe "inbound relationship query" do
271
- it "should return a properly formatted query for a relationship that has a solr filter query defined" do
272
- SpecNodeSolrFilterQuery.inbound_relationship_query(@test_object_query.pid,"special_parts").should == "#{ActiveFedora::SolrService.solr_name(@test_object_query.relationship_predicates[:inbound]['special_parts'], :symbol)}:#{solr_uri(@test_object_query.internal_uri)} AND #{@special_part_query}"
273
- end
274
-
275
- it "should return a properly formatted query for a relationship that does not have a solr filter query defined" do
276
- SpecNodeSolrFilterQuery.inbound_relationship_query(@test_object_query.pid,"parts").should == "#{ActiveFedora::SolrService.solr_name('is_part_of', :symbol)}:#{solr_uri(@test_object_query.internal_uri)}"
277
- end
278
- end
279
-
280
- describe "outbound relationship query" do
281
- it "should return a properly formatted query for a relationship that has a solr filter query defined" do
282
- expected_string = ""
283
- @test_object_query.containers_ids.each_with_index do |id,index|
284
- expected_string << " OR " if index > 0
285
- expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND #{@special_container_query})"
286
- end
287
- SpecNodeSolrFilterQuery.outbound_relationship_query("special_containers",@test_object_query.containers_ids).should == expected_string
288
- end
289
-
290
- it "should return a properly formatted query for a relationship that does not have a solr filter query defined" do
291
- expected_string = ""
292
- @test_object_query.containers_ids.each_with_index do |id,index|
293
- expected_string << " OR " if index > 0
294
- expected_string << "id:" + id.gsub(/(:)/, '\\:')
295
- end
296
- SpecNodeSolrFilterQuery.outbound_relationship_query("containers",@test_object_query.containers_ids).should == expected_string
297
- end
298
- end
299
-
300
- describe "bidirectional relationship query" do
301
- it "should return a properly formatted query for a relationship that has a solr filter query defined" do
302
- expected_string = ""
303
- @test_object_query.bi_containers_outbound_ids.each_with_index do |id,index|
304
- expected_string << " OR " if index > 0
305
- expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND #{@special_container_query})"
306
- end
307
- expected_string << " OR "
308
- expected_string << "(#{ActiveFedora::SolrService.solr_name(@test_object_query.relationship_predicates[:inbound]['bi_special_containers_inbound'], :symbol)}:#{solr_uri(@test_object_query.internal_uri)} AND #{@special_container_query})"
309
- SpecNodeSolrFilterQuery.bidirectional_relationship_query(@test_object_query.pid,"bi_special_containers",@test_object_query.bi_containers_outbound_ids).should == expected_string
310
- end
311
-
312
- it "should return a properly formatted query for a relationship that does not have a solr filter query defined" do
313
- expected_string = ""
314
- @test_object_query.bi_containers_outbound_ids.each_with_index do |id,index|
315
- expected_string << " OR " if index > 0
316
- expected_string << "id:" + id.gsub(/(:)/, '\\:')
317
- end
318
- expected_string << " OR "
319
- expected_string << "(#{ActiveFedora::SolrService.solr_name(@test_object_query.relationship_predicates[:inbound]['bi_special_containers_inbound'], :symbol)}:#{solr_uri(@test_object_query.internal_uri)})"
320
- SpecNodeSolrFilterQuery.bidirectional_relationship_query(@test_object_query.pid,"bi_containers",@test_object_query.bi_containers_outbound_ids).should == expected_string
321
- end
322
- end
323
-
324
- describe "outbound relationship finders" do
325
- it "should return an array of Base objects" do
326
- containers = @test_object.containers
327
- containers.length.should > 0
328
- containers.each do |container|
329
- container.should be_kind_of(ActiveFedora::Base)
330
- end
331
- end
332
- it "_ids should return an array of pids" do
333
- ids = @test_object.containers_ids
334
- ids.size.should == 3
335
- ids.include?(@container1.pid).should == true
336
- ids.include?(@container2.pid).should == true
337
- ids.include?(@container3.pid).should == true
338
- ids.include?(@container4.pid).should == false
339
- end
340
-
341
- it "should return an array of Base objects with some filtered out if using solr_fq" do
342
- @test_object_query.special_containers_ids.size.should == 3
343
- @test_object_query.special_containers_ids.include?(@container3.pid).should == false
344
- @test_object_query.special_containers_ids.include?(@special_container.pid).should == true
345
- @test_object_query.special_containers_ids.include?(@special_container3.pid).should == true
346
- @test_object_query.special_containers_ids.include?(@special_container4.pid).should == true
347
- end
348
-
349
- it "should return an array of all Base objects with relationship if not using solr_fq" do
350
- @test_object_query.containers_ids.size.should == 4
351
- @test_object_query.containers_ids.include?(@special_container2.pid).should == false
352
- @test_object_query.containers_ids.include?(@special_container.pid).should == true
353
- @test_object_query.containers_ids.include?(@container3.pid).should == true
354
- @test_object_query.containers_ids.include?(@special_container3.pid).should == true
355
- @test_object_query.containers_ids.include?(@special_container4.pid).should == true
356
- end
357
-
358
- it "should return a solr query for an outbound relationship" do
359
- end
360
-
361
- it "should return an array of Base objects with some filtered out if using solr_fq" do
362
- @test_object_query.special_containers_ids.size.should == 3
363
- @test_object_query.special_containers_ids.include?(@container3.pid).should == false
364
- @test_object_query.special_containers_ids.include?(@special_container.pid).should == true
365
- @test_object_query.special_containers_ids.include?(@special_container3.pid).should == true
366
- @test_object_query.special_containers_ids.include?(@special_container4.pid).should == true
367
- end
368
-
369
- it "should return an array of all Base objects with relationship if not using solr_fq" do
370
- @test_object_query.containers_ids.size.should == 4
371
- @test_object_query.containers_ids.include?(@special_container2.pid).should == false
372
- @test_object_query.containers_ids.include?(@special_container.pid).should == true
373
- @test_object_query.containers_ids.include?(@container3.pid).should == true
374
- @test_object_query.containers_ids.include?(@special_container3.pid).should == true
375
- @test_object_query.containers_ids.include?(@special_container4.pid).should == true
376
- end
377
-
378
- it "should return a solr query for an outbound relationship" do
379
- expected_string = ""
380
- @test_object_query.containers_ids.each_with_index do |id,index|
381
- expected_string << " OR " if index > 0
382
- expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND #{@special_container_query})"
383
- end
384
- @test_object_query.special_containers_query.should == expected_string
385
- end
386
- end
387
-
388
- describe "bidirectional relationship finders" do
389
- it "should return an array of Base objects" do
390
- containers = @test_object.bi_containers
391
- containers.length.should > 0
392
- containers.each do |container|
393
- container.should be_kind_of(ActiveFedora::Base)
394
- end
395
- end
396
- it "_ids should return an array of pids" do
397
- ids = @test_object.bi_containers_ids
398
- ids.size.should == 4
399
- ids.include?(@container1.pid).should == true
400
- ids.include?(@container2.pid).should == true
401
- ids.include?(@container3.pid).should == true
402
- ids.include?(@container4.pid).should == true
403
- end
404
-
405
- it "should return an array of Base objects with some filtered out if using solr_fq" do
406
- ids = @test_object_query.bi_special_containers_ids
407
- ids.size.should == 4
408
- ids.include?(@container1.pid).should == false
409
- ids.include?(@container2.pid).should == false
410
- ids.include?(@container3.pid).should == false
411
- ids.include?(@special_container.pid).should == true
412
- ids.include?(@special_container2.pid).should == true
413
- ids.include?(@special_container3.pid).should == true
414
- ids.include?(@special_container4.pid).should == true
415
- end
416
-
417
- it "should return an array of all Base objects with relationship if not using solr_fq" do
418
- @test_object_query.bi_containers_ids.should include @container3.pid, @special_container.pid, @special_container2.pid, @special_container3.pid, @special_container4.pid
419
-
420
- @test_object_query.bi_containers_ids.size.should == 5
421
- end
422
-
423
- it "should return a solr query for a bidirectional relationship" do
424
- expected_string = ""
425
- @test_object_query.bi_containers_outbound_ids.each_with_index do |id,index|
426
- expected_string << " OR " if index > 0
427
- expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND #{@special_container_query})"
428
- end
429
- expected_string << " OR "
430
- expected_string << "(#{ActiveFedora::SolrService.solr_name(@test_object_query.relationship_predicates[:inbound]['bi_special_containers_inbound'], :symbol)}:#{solr_uri(@test_object_query.internal_uri)} AND #{@special_container_query})"
431
- @test_object_query.bi_special_containers_query.should == expected_string
432
- end
433
- end
434
-
435
- #putting this test here instead of relationships_helper because testing that relationships_by_name hash gets refreshed if the relationships hash is changed
436
- describe "relationships_by_name" do
437
- before do
438
- class MockSemNamedRelationships < ActiveFedora::Base
439
- include ActiveFedora::FileManagement
440
- has_relationship "testing", :has_part
441
- has_relationship "testing2", :has_member
442
- has_relationship "testing_inbound", :has_part, :inbound=>true
443
- end
444
- end
445
-
446
- it 'should automatically update the relationships_by_name if relationships has changed (no refresh of relationships_by_name hash unless relationships hash has changed' do
447
- @test_object2 = MockSemNamedRelationships.new
448
- @test_object2.add_relationship(:has_model, MockSemNamedRelationships.to_class_uri)
449
- #should return expected named relationships
450
- @test_object2.relationships_by_name.should == {:self=>{"testing"=>[],"testing2"=>[], "collection_members"=>[], "part_of"=>[], "parts_outbound"=>[]}}
451
- @test_object2.add_relationship(:has_part, @test_object.internal_uri)
452
- @test_object2.relationships_by_name.should == {:self=>{"testing"=>[@test_object.internal_uri],"testing2"=>[], "collection_members"=>[], "part_of"=>[], "parts_outbound"=>[@test_object.internal_uri]}}
453
- @test_object2.add_relationship(:has_member, "3", true)
454
- @test_object2.relationships_by_name.should == {:self=>{"testing"=>[@test_object.internal_uri],"testing2"=>["3"], "collection_members"=>[], "part_of"=>[], "parts_outbound"=>[@test_object.internal_uri]}}
455
- end
456
- end
457
- end