active-fedora 2.3.1 → 2.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -47,6 +47,10 @@ module ActiveFedora
47
47
  return results
48
48
  end
49
49
 
50
+ # Construct a solr query for a list of pids
51
+ # This is used to get a solr response based on the list of pids in an object's RELS-EXT relationhsips
52
+ # If the pid_array is empty, defaults to a query of "id:NEVER_USE_THIS_ID", which will return an empty solr response
53
+ # @param [Array] pid_array the pids that you want included in the query
50
54
  def self.construct_query_for_pids(pid_array)
51
55
  query = ""
52
56
  pid_array.each_index do |i|
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "2.3.1"
2
+ VERSION = "2.3.3"
3
3
  end
@@ -3,15 +3,18 @@ require 'fedora/repository'
3
3
 
4
4
  class Fedora::Datastream < Fedora::BaseObject
5
5
 
6
- attr_accessor :mime_type
7
6
 
8
7
  def initialize(attrs = {})
9
8
  super
10
9
  if attrs
11
- if attrs[:mime_type]
10
+ if attrs[:mime_type]
12
11
  self.mime_type = attrs[:mime_type]
13
- elsif attrs[:mimeType]
12
+ elsif attrs[:mimeType]
14
13
  self.mime_type = attrs[:mimeType]
14
+ elsif attrs["mimeType"]
15
+ self.mime_type = attrs["mimeType"]
16
+ elsif attrs["mime_type"]
17
+ self.mime_type = attrs["mime_type"]
15
18
  end
16
19
  end
17
20
  self.control_group='M' if @attributes[:mimeType]
@@ -44,6 +47,14 @@ class Fedora::Datastream < Fedora::BaseObject
44
47
  @attributes[:dsLabel] = new_label
45
48
  end
46
49
 
50
+ def mime_type
51
+ @mime_type
52
+ end
53
+
54
+ def mime_type=(new_mime_type)
55
+ @mime_type = new_mime_type
56
+ end
57
+
47
58
  # See http://www.fedora.info/definitions/identifiers/
48
59
  def uri
49
60
  "fedora:info/#{pid}/datastreams/#{dsid}"
@@ -26,7 +26,7 @@ task :hudson do
26
26
  require 'jettywrapper'
27
27
  project_root = File.expand_path("#{File.dirname(__FILE__)}/../../")
28
28
 
29
- if (ENV['RAILS_ENV'] == "test")
29
+ if (ENV['environment'] == "test")
30
30
  Rake::Task["active_fedora:doc"].invoke
31
31
  Rake::Task["active_fedora:configure_jetty"].invoke
32
32
  jetty_params = {
@@ -44,7 +44,7 @@ task :hudson do
44
44
  end
45
45
  raise "test failures: #{error}" if error
46
46
  else
47
- system("rake hudson RAILS_ENV=test")
47
+ system("rake hudson environment=test")
48
48
  fail unless $?.success?
49
49
  end
50
50
  end
@@ -1,13 +1,13 @@
1
1
  development:
2
2
  fedora:
3
- url: http://fedoraAdmin:fedoraAdmin@localhost:8983/fedora
3
+ url: http://fedoraAdmin:fedoraAdmin@testhost.com:8983/fedora
4
4
  solr:
5
- url: http://localhost:8983/solr/development
5
+ url: http://testhost.com:8983/solr/development
6
6
  test:
7
7
  fedora:
8
- url: http://fedoraAdmin:fedoraAdmin@localhost:8983/fedora
8
+ url: http://fedoraAdmin:fedoraAdmin@testhost.com:8983/fedora
9
9
  solr:
10
- url: http://localhost:8983/solr/development
10
+ url: http://testhost.com:8983/solr/development
11
11
  production:
12
12
  fedora:
13
13
  url: http://fedoraAdmin:fedoraAdmin@testhost.com:8080/fedora
@@ -7,7 +7,7 @@ require 'ftools'
7
7
  require 'mocha'
8
8
 
9
9
  include ActiveFedora::Model
10
- include Mocha::Standalone
10
+ include Mocha::API
11
11
 
12
12
  describe 'bugs' do
13
13
  class FooHistory < ActiveFedora::Base
@@ -7,7 +7,7 @@ require 'ftools'
7
7
  require 'mocha'
8
8
 
9
9
  include ActiveFedora::Model
10
- include Mocha::Standalone
10
+ include Mocha::API
11
11
 
12
12
  describe ActiveFedora::Model do
13
13
 
@@ -20,8 +20,7 @@ describe ActiveFedora::NokogiriDatastream do
20
20
  m.field 'collection', :string
21
21
  end
22
22
  end
23
-
24
- RAILS_ENV='development'
23
+
25
24
  @pid = "hydrangea:fixture_mods_article1"
26
25
  @test_solr_object = HydrangeaArticle2.load_instance_from_solr(@pid)
27
26
  @test_object = HydrangeaArticle2.load_instance(@pid)
@@ -13,15 +13,6 @@ describe ActiveFedora::SemanticNode do
13
13
  class SNSpecModel < ActiveFedora::Base
14
14
  has_relationship("parts", :is_part_of, :inbound => true)
15
15
  has_relationship("containers", :is_member_of)
16
- has_bidirectional_relationship("bi_containers", :is_member_of, :has_member)
17
- end
18
- class SpecNodeQueryParam < ActiveFedora::Base
19
- has_relationship("parts", :is_part_of, :inbound => true)
20
- has_relationship("special_parts", :is_part_of, :inbound => true, :query_params=>{:q=>{"has_model_s"=>"info:fedora/SpecialPart"}})
21
- has_relationship("containers", :is_member_of)
22
- has_relationship("special_containers", :is_member_of, :query_params=>{:q=>{"has_model_s"=>"info:fedora/SpecialContainer"}})
23
- has_bidirectional_relationship("bi_containers", :is_member_of, :has_member)
24
- has_bidirectional_relationship("bi_special_containers", :is_member_of, :has_member, :query_params=>{:q=>{"has_model_s"=>"info:fedora/SpecialContainer"}})
25
16
  end
26
17
 
27
18
  @test_object = SNSpecModel.new
@@ -34,89 +25,24 @@ describe ActiveFedora::SemanticNode do
34
25
  @part2.add_relationship(:is_part_of, @test_object)
35
26
  @part2.save
36
27
 
28
+
37
29
  @container1 = ActiveFedora::Base.new()
38
30
  @container1.save
39
31
  @container2 = ActiveFedora::Base.new()
40
32
  @container2.save
41
- @container3 = ActiveFedora::Base.new()
42
- @container3.save
43
33
 
44
34
  @test_object.add_relationship(:is_member_of, @container1)
45
35
  @test_object.add_relationship(:is_member_of, @container2)
46
36
  @test_object.save
47
-
48
- @special_container = ActiveFedora::Base.new()
49
- @special_container.add_relationship(:has_model,"SpecialContainer")
50
- @special_container.save
51
-
52
- #even though adding container3 and special container, it should only include special_container when returning via named finder methods
53
- #also should only return special part similarly
54
- @test_object_query = SpecNodeQueryParam.new
55
- @test_object_query.add_relationship(:is_member_of, @container3)
56
- @test_object_query.add_relationship(:is_member_of, @special_container)
57
- @test_object_query.save
58
-
59
- @special_container2 = ActiveFedora::Base.new()
60
- @special_container2.add_relationship(:has_model,"SpecialContainer")
61
- @special_container2.add_relationship(:has_member,@test_object_query.pid)
62
- @special_container2.save
63
-
64
- @part3 = ActiveFedora::Base.new()
65
- @part3.add_relationship(:is_part_of, @test_object_query)
66
- @part3.save
67
-
68
- @special_part = ActiveFedora::Base.new()
69
- @special_part.add_relationship(:has_model,"SpecialPart")
70
- @special_part.add_relationship(:is_part_of, @test_object_query)
71
- @special_part.save
72
-
73
37
  end
74
38
 
75
39
  after(:all) do
76
- begin
77
40
  @part1.delete
78
- rescue
79
- end
80
- begin
81
41
  @part2.delete
82
- rescue
83
- end
84
- begin
85
- @part3.delete
86
- rescue
87
- end
88
- begin
89
42
  @container1.delete
90
- rescue
91
- end
92
- begin
93
43
  @container2.delete
94
- rescue
95
- end
96
- begin
97
- @container3.delete
98
- rescue
99
- end
100
- begin
101
44
  @test_object.delete
102
- rescue
103
- end
104
- begin
105
- @test_object_query.delete
106
- rescue
107
- end
108
- begin
109
- @special_part.delete
110
- rescue
111
- end
112
- begin
113
- @special_container.delete
114
- rescue
115
- end
116
- begin
117
- @special_container2.delete
118
- rescue
119
- end
45
+
120
46
  Object.send(:remove_const, :SNSpecModel)
121
47
 
122
48
  end
@@ -148,73 +74,6 @@ describe ActiveFedora::SemanticNode do
148
74
  id.should satisfy {|id| id == @part1.pid || @part2.pid}
149
75
  end
150
76
  end
151
- it "should return an array of Base objects with some filtered out if using query params" do
152
- @test_object_query.special_parts_ids.should == [@special_part.pid]
153
- end
154
-
155
- it "should return an array of all Base objects with relationship if not using query params" do
156
- @test_object_query.parts_ids.size.should == 2
157
- @test_object_query.parts_ids.include?(@special_part.pid).should == true
158
- @test_object_query.parts_ids.include?(@part3.pid).should == true
159
- end
160
-
161
- it "should return a solr query for an inbound relationship" do
162
- @test_object_query.special_parts_query.should == "#{@test_object_query.named_relationship_predicates[:inbound]['special_parts']}_s:#{@test_object_query.internal_uri.gsub(/(:)/, '\\:')} AND has_model_s:info\\:fedora/SpecialPart"
163
- end
164
- end
165
-
166
- describe "inbound named relationship query" do
167
- it "should return a properly formatted query for a relationship that has a query param defined" do
168
- SpecNodeQueryParam.inbound_named_relationship_query(@test_object_query.pid,"special_parts").should == "#{@test_object_query.named_relationship_predicates[:inbound]['special_parts']}_s:#{@test_object_query.internal_uri.gsub(/(:)/, '\\:')} AND has_model_s:info\\:fedora/SpecialPart"
169
- end
170
-
171
- it "should return a properly formatted query for a relationship that does not have a query param defined" do
172
- SpecNodeQueryParam.inbound_named_relationship_query(@test_object_query.pid,"parts").should == "is_part_of_s:#{@test_object_query.internal_uri.gsub(/(:)/, '\\:')}"
173
- end
174
- end
175
-
176
- describe "outbound named relationship query" do
177
- it "should return a properly formatted query for a relationship that has a query param defined" do
178
- expected_string = ""
179
- @test_object_query.containers_ids.each_with_index do |id,index|
180
- expected_string << " OR " if index > 0
181
- expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND has_model_s:info\\:fedora/SpecialContainer)"
182
- end
183
- SpecNodeQueryParam.outbound_named_relationship_query("special_containers",@test_object_query.containers_ids).should == expected_string
184
- end
185
-
186
- it "should return a properly formatted query for a relationship that does not have a query param defined" do
187
- expected_string = ""
188
- @test_object_query.containers_ids.each_with_index do |id,index|
189
- expected_string << " OR " if index > 0
190
- expected_string << "id:" + id.gsub(/(:)/, '\\:')
191
- end
192
- SpecNodeQueryParam.outbound_named_relationship_query("containers",@test_object_query.containers_ids).should == expected_string
193
- end
194
- end
195
-
196
- describe "bidirectional named relationship query" do
197
- it "should return a properly formatted query for a relationship that has a query param defined" do
198
- expected_string = ""
199
- @test_object_query.bi_containers_outbound_ids.each_with_index do |id,index|
200
- expected_string << " OR " if index > 0
201
- expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND has_model_s:info\\:fedora/SpecialContainer)"
202
- end
203
- expected_string << " OR "
204
- expected_string << "(#{@test_object_query.named_relationship_predicates[:inbound]['bi_special_containers_inbound']}_s:#{@test_object_query.internal_uri.gsub(/(:)/, '\\:')} AND has_model_s:info\\:fedora/SpecialContainer)"
205
- SpecNodeQueryParam.bidirectional_named_relationship_query(@test_object_query.pid,"bi_special_containers",@test_object_query.bi_containers_outbound_ids).should == expected_string
206
- end
207
-
208
- it "should return a properly formatted query for a relationship that does not have a query param defined" do
209
- expected_string = ""
210
- @test_object_query.bi_containers_outbound_ids.each_with_index do |id,index|
211
- expected_string << " OR " if index > 0
212
- expected_string << "id:" + id.gsub(/(:)/, '\\:')
213
- end
214
- expected_string << " OR "
215
- expected_string << "(#{@test_object_query.named_relationship_predicates[:inbound]['bi_special_containers_inbound']}_s:#{@test_object_query.internal_uri.gsub(/(:)/, '\\:')})"
216
- SpecNodeQueryParam.bidirectional_named_relationship_query(@test_object_query.pid,"bi_containers",@test_object_query.bi_containers_outbound_ids).should == expected_string
217
- end
218
77
  end
219
78
 
220
79
  describe "outbound relationship finders" do
@@ -231,121 +90,5 @@ describe ActiveFedora::SemanticNode do
231
90
  id.should satisfy {|id| id == @container1.pid || @container2.pid}
232
91
  end
233
92
  end
234
-
235
- it "should return an array of Base objects with some filtered out if using query params" do
236
- @test_object_query.special_containers_ids.size.should == 1
237
- @test_object_query.special_containers_ids.include?(@container3.pid).should == false
238
- @test_object_query.special_containers_ids.include?(@special_container.pid).should == true
239
- end
240
-
241
- it "should return an array of all Base objects with relationship if not using query params" do
242
- @test_object_query.containers_ids.size.should == 2
243
- @test_object_query.containers_ids.include?(@special_container2.pid).should == false
244
- @test_object_query.containers_ids.include?(@special_container.pid).should == true
245
- @test_object_query.containers_ids.include?(@container3.pid).should == true
246
- end
247
-
248
- it "should return a solr query for an outbound relationship" do
249
- expected_string = ""
250
- @test_object_query.containers_ids.each_with_index do |id,index|
251
- expected_string << " OR " if index > 0
252
- expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND has_model_s:info\\:fedora/SpecialContainer)"
253
- end
254
- @test_object_query.special_containers_query.should == expected_string
255
- end
256
93
  end
257
-
258
- describe "bidirectional relationship finders" do
259
- it "should return an array of Base objects" do
260
- containers = @test_object.bi_containers
261
- containers.length.should > 0
262
- containers.each do |container|
263
- container.should be_kind_of(ActiveFedora::Base)
264
- end
265
- end
266
- it "_ids should return an array of pids" do
267
- ids = @test_object.bi_containers_ids
268
- ids.size.should == 2
269
- ids.each do |id|
270
- id.should satisfy {|id| id == @container1.pid || @container2.pid}
271
- end
272
- end
273
-
274
- it "should return an array of Base objects with some filtered out if using query params" do
275
- ids = @test_object_query.bi_special_containers_ids
276
- ids.size.should == 2
277
- ids.each do |id|
278
- id.should satisfy {|id| id == @special_container.pid || @special_container2.pid}
279
- end
280
- end
281
-
282
- it "should return an array of all Base objects with relationship if not using query params" do
283
- ids = @test_object_query.bi_containers_ids
284
- ids.size.should == 3
285
- ids.each do |id|
286
- id.should satisfy {|id| id == @special_container.pid || @special_container2.pid || @container3.pid}
287
- end
288
- end
289
-
290
- it "should return a solr query for a bidirectional relationship" do
291
- expected_string = ""
292
- @test_object_query.bi_containers_outbound_ids.each_with_index do |id,index|
293
- expected_string << " OR " if index > 0
294
- expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND has_model_s:info\\:fedora/SpecialContainer)"
295
- end
296
- expected_string << " OR "
297
- expected_string << "(#{@test_object_query.named_relationship_predicates[:inbound]['bi_special_containers_inbound']}_s:#{@test_object_query.internal_uri.gsub(/(:)/, '\\:')} AND has_model_s:info\\:fedora/SpecialContainer)"
298
- @test_object_query.bi_special_containers_query.should == expected_string
299
- end
300
- end
301
-
302
- describe "named_relationship_query" do
303
- it "should return correct query for a bidirectional relationship with query params" do
304
- expected_string = ""
305
- @test_object_query.bi_containers_outbound_ids.each_with_index do |id,index|
306
- expected_string << " OR " if index > 0
307
- expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND has_model_s:info\\:fedora/SpecialContainer)"
308
- end
309
- expected_string << " OR "
310
- expected_string << "(#{@test_object_query.named_relationship_predicates[:inbound]['bi_special_containers_inbound']}_s:#{@test_object_query.internal_uri.gsub(/(:)/, '\\:')} AND has_model_s:info\\:fedora/SpecialContainer)"
311
- @test_object_query.named_relationship_query("bi_special_containers").should == expected_string
312
- end
313
-
314
- it "should return correct query for a bidirectional relationship without query params" do
315
- expected_string = ""
316
- @test_object_query.bi_containers_outbound_ids.each_with_index do |id,index|
317
- expected_string << " OR " if index > 0
318
- expected_string << "id:" + id.gsub(/(:)/, '\\:')
319
- end
320
- expected_string << " OR "
321
- expected_string << "(#{@test_object_query.named_relationship_predicates[:inbound]['bi_special_containers_inbound']}_s:#{@test_object_query.internal_uri.gsub(/(:)/, '\\:')})"
322
- @test_object_query.named_relationship_query("bi_containers").should == expected_string
323
- end
324
-
325
- it "should return a properly formatted query for an outbound relationship that has a query param defined" do
326
- expected_string = ""
327
- @test_object_query.containers_ids.each_with_index do |id,index|
328
- expected_string << " OR " if index > 0
329
- expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND has_model_s:info\\:fedora/SpecialContainer)"
330
- end
331
- @test_object_query.named_relationship_query("special_containers").should == expected_string
332
- end
333
-
334
- it "should return a properly formatted query for an outbound relationship that does not have a query param defined" do
335
- expected_string = ""
336
- @test_object_query.containers_ids.each_with_index do |id,index|
337
- expected_string << " OR " if index > 0
338
- expected_string << "id:" + id.gsub(/(:)/, '\\:')
339
- end
340
- @test_object_query.named_relationship_query("containers").should == expected_string
341
- end
342
-
343
- it "should return a properly formatted query for an inbound relationship that has a query param defined" do
344
- @test_object_query.named_relationship_query("special_parts").should == "#{@test_object_query.named_relationship_predicates[:inbound]['special_parts']}_s:#{@test_object_query.internal_uri.gsub(/(:)/, '\\:')} AND has_model_s:info\\:fedora/SpecialPart"
345
- end
346
-
347
- it "should return a properly formatted query for an inbound relationship that does not have a query param defined" do
348
- @test_object_query.named_relationship_query("parts").should == "is_part_of_s:#{@test_object_query.internal_uri.gsub(/(:)/, '\\:')}"
349
- end
350
- end
351
94
  end
@@ -71,6 +71,11 @@ describe ActiveFedora do
71
71
  end
72
72
 
73
73
  describe ".init" do
74
+
75
+ after(:all) do
76
+ # Restore to default fedora configs
77
+ ActiveFedora.init()
78
+ end
74
79
 
75
80
  describe "outside of rails" do
76
81
  it "should load the default packaged config/fedora.yml file if no explicit config path is passed" do
@@ -79,7 +84,7 @@ describe ActiveFedora do
79
84
  end
80
85
  it "should load the passed config if explicit config passed in" do
81
86
  ActiveFedora.init('./spec/fixtures/rails_root/config/fedora.yml')
82
- ActiveFedora.fedora.fedora_url.to_s.should == "http://fedoraAdmin:fedoraAdmin@localhost:8983/fedora"
87
+ ActiveFedora.fedora.fedora_url.to_s.should == "http://fedoraAdmin:fedoraAdmin@testhost.com:8983/fedora"
83
88
  end
84
89
  end
85
90
 
@@ -115,7 +120,7 @@ describe ActiveFedora do
115
120
  ActiveFedora.init()
116
121
  ActiveFedora.solr.class.should == ActiveFedora::SolrService
117
122
  ActiveFedora.fedora.class.should == Fedora::Repository
118
- ActiveFedora.fedora.fedora_url.to_s.should == "http://fedoraAdmin:fedoraAdmin@localhost:8983/fedora"
123
+ ActiveFedora.fedora.fedora_url.to_s.should == "http://fedoraAdmin:fedoraAdmin@testhost.com:8983/fedora"
119
124
  end
120
125
  it "should load the default file if no config is found at Rails.root" do
121
126
  Rails.expects(:root).returns(File.join(File.dirname(__FILE__),"../fixtures/bad/path/to/rails_root"))