active-fedora 4.5.1 → 4.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -160,6 +160,10 @@ module ActiveFedora
160
160
  @target = Array.new
161
161
  end
162
162
 
163
+ def construct_query
164
+ @counter_query = @finder_query = ActiveFedora::SolrService.construct_query_for_rel(@reflection.options[:property], @owner.internal_uri)
165
+ end
166
+
163
167
 
164
168
  private
165
169
 
@@ -43,12 +43,6 @@ module ActiveFedora
43
43
  r.remove_relationship(@reflection.options[:property], @owner)
44
44
  end
45
45
  end
46
-
47
- def construct_query
48
- internal_uri = @owner.internal_uri
49
- escaped_uri = internal_uri.gsub(/(:)/, '\\:')
50
- @counter_query = @finder_query = "#{@reflection.options[:property]}_s:#{escaped_uri}"
51
- end
52
46
  end
53
47
  end
54
48
  end
@@ -44,13 +44,6 @@ module ActiveFedora
44
44
  r.remove_relationship(@reflection.options[:property], @owner)
45
45
  end
46
46
  end
47
-
48
-
49
- def construct_query
50
- internal_uri = @owner.internal_uri
51
- escaped_uri = internal_uri.gsub(/(:)/, '\\:')
52
- @counter_query = @finder_query = "#{@reflection.options[:property]}_s:#{escaped_uri}"
53
- end
54
47
  end
55
48
  end
56
49
  end
@@ -306,7 +306,7 @@ module ActiveFedora
306
306
  end
307
307
  datastreams.each_value do |ds|
308
308
  ds.ensure_xml_loaded if ds.respond_to? :ensure_xml_loaded ### Can't put this in the model because it's often implemented in Solrizer::XML::TerminologyBasedSolrizer
309
- solr_doc = ds.to_solr(solr_doc) if ds.kind_of?(ActiveFedora::RDFDatastream) || ds.kind_of?(ActiveFedora::NokogiriDatastream) || ds.kind_of?(ActiveFedora::MetadataDatastream)
309
+ solr_doc = ds.to_solr(solr_doc)
310
310
  end
311
311
  solr_doc = solrize_relationships(solr_doc) unless opts[:model_only]
312
312
  solr_doc
@@ -397,8 +397,7 @@ module ActiveFedora
397
397
  raise "Solr document record id and pid do not match" unless pid == solr_doc[SOLR_DOCUMENT_ID]
398
398
  end
399
399
  klass = if class_str = solr_doc['has_model_s']
400
- # Parse RDF string "info:fedora/afmodel:ActiveFedora_Base"
401
- class_str.first.split(/:/).last.gsub(/_/,"::").constantize
400
+ ActiveFedora::SolrService.class_from_solr_document(solr_doc)
402
401
  else
403
402
  ActiveFedora::Base
404
403
  end
@@ -416,9 +415,7 @@ module ActiveFedora
416
415
  if ds.respond_to?(:profile_from_hash) and (ds_prof = profile_hash['datastreams'][ds.dsid])
417
416
  ds.profile_from_hash(ds_prof)
418
417
  end
419
- if ds.respond_to?(:from_solr)
420
- ds.from_solr(solr_doc) if ds.kind_of?(ActiveFedora::MetadataDatastream) || ds.kind_of?(ActiveFedora::NokogiriDatastream) || ( ds.kind_of?(ActiveFedora::RelsExtDatastream))
421
- end
418
+ ds.from_solr(solr_doc) if ds.respond_to?(:from_solr)
422
419
  end
423
420
  obj.inner_object.freeze
424
421
  obj
@@ -119,6 +119,10 @@ module ActiveFedora
119
119
  profile[key] = value.to_s
120
120
  end
121
121
  end
122
+
123
+ def to_solr(solr_doc = Hash.new)
124
+ solr_doc
125
+ end
122
126
  end
123
127
 
124
128
  class DatastreamConcurrencyException < Exception # :nodoc:
@@ -99,14 +99,18 @@ module ActiveFedora
99
99
  # @param [Hash] opts the options to create a message with.
100
100
  # @option opts [Integer] :rows when :all is passed, the maximum number of rows to load from solr
101
101
  # @option opts [Boolean] :cast when true, examine the model and cast it to the first known cModel
102
- def find(args, opts={})
102
+ def find(args, opts={}, &block)
103
103
  return find_one(args, opts[:cast]) if args.class == String
104
+ return to_enum(:find, args, opts).to_a unless block_given?
105
+
104
106
  args = {} if args == :all
105
- results = []
106
107
  find_each(args, opts) do |obj|
107
- results << obj
108
+ yield obj
108
109
  end
109
- results
110
+ end
111
+
112
+ def all(opts = {}, &block)
113
+ find(:all, opts, &block)
110
114
  end
111
115
 
112
116
 
@@ -314,7 +318,7 @@ module ActiveFedora
314
318
  end
315
319
 
316
320
  def quote_for_solr(value)
317
- '"' + value.gsub(/(:)/, '\\:').gsub(/"/, '\\"') + '"'
321
+ '"' + value.gsub(/(:)/, '\\:').gsub(/(\/)/, '\\/').gsub(/"/, '\\"') + '"'
318
322
  end
319
323
 
320
324
  # @deprecated
@@ -362,8 +366,7 @@ module ActiveFedora
362
366
  # Return the solr clause that queries for this type of class
363
367
  def search_model_clause
364
368
  unless self == ActiveFedora::Base
365
- escaped_class_uri = SolrService.escape_uri_for_query(self.to_class_uri)
366
- return "#{ActiveFedora::SolrService.solr_name(:has_model, :symbol)}:#{escaped_class_uri}"
369
+ return ActiveFedora::SolrService.construct_query_for_rel(:has_model, self.to_class_uri)
367
370
  end
368
371
  end
369
372
 
@@ -354,9 +354,7 @@ module ActiveFedora
354
354
  subject = :inbound
355
355
  if relationships_desc.has_key?(subject) && relationships_desc[subject].has_key?(relationship_name)
356
356
  predicate = relationships_desc[subject][relationship_name][:predicate]
357
- internal_uri = "info:fedora/#{pid}"
358
- escaped_uri = internal_uri.gsub(/(:)/, '\\:')
359
- query = "#{predicate}_s:#{escaped_uri}"
357
+ query = ActiveFedora::SolrService.construct_query_for_rel(predicate, "info:fedora/#{pid}")
360
358
  if relationships_desc.has_key?(subject) && relationships_desc[subject].has_key?(relationship_name) && relationships_desc[subject][relationship_name].has_key?(:solr_fq)
361
359
  solr_fq = relationships_desc[subject][relationship_name][:solr_fq]
362
360
  query << " AND " unless query.empty?
@@ -51,8 +51,10 @@ module ActiveFedora
51
51
  end
52
52
 
53
53
  def self.class_from_solr_document(hit)
54
- model_value = hit[solr_name("has_model", :symbol)].first
55
- Model.from_class_uri(model_value)
54
+ model_value = nil
55
+ hit[solr_name("has_model", :symbol)].each {|value| model_value ||= Model.from_class_uri(value)}
56
+ logger.warn "Could not find a model for #{hit["id"]}, defaulting to ActiveFedora::Base" unless model_value
57
+ model_value || ActiveFedora::Base
56
58
  end
57
59
 
58
60
  # Construct a solr query for a list of pids
@@ -70,7 +72,11 @@ module ActiveFedora
70
72
  end
71
73
 
72
74
  def self.escape_uri_for_query(uri)
73
- return uri.gsub(/(:)/, '\\:')
75
+ return uri.gsub(/(:)/, '\\:').gsub(/(\/)/, '\\/')
76
+ end
77
+
78
+ def self.construct_query_for_rel(predicate, target_uri)
79
+ "#{solr_name(predicate, :symbol)}:#{escape_uri_for_query(target_uri)}"
74
80
  end
75
81
 
76
82
  def self.query(query, args={})
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "4.5.1"
2
+ VERSION = "4.5.2"
3
3
  end
@@ -18,11 +18,11 @@ describe ActiveFedora::SemanticNode do
18
18
  class SpecNodeSolrFilterQuery < ActiveFedora::Base
19
19
  include ActiveFedora::Relationships
20
20
  has_relationship("parts", :is_part_of, :inbound => true)
21
- has_relationship("special_parts", :is_part_of, :inbound => true, :solr_fq=>"has_model_s:info\\:fedora/afmodel\\:SpecialPart")
21
+ has_relationship("special_parts", :is_part_of, :inbound => true, :solr_fq=>"has_model_s:info\\:fedora\\/afmodel\\:SpecialPart")
22
22
  has_relationship("containers", :is_member_of)
23
- has_relationship("special_containers", :is_member_of, :solr_fq=>"has_model_s:info\\:fedora/afmodel\\:SpecialContainer")
23
+ has_relationship("special_containers", :is_member_of, :solr_fq=>"has_model_s:info\\:fedora\\/afmodel\\:SpecialContainer")
24
24
  has_bidirectional_relationship("bi_containers", :is_member_of, :has_member)
25
- has_bidirectional_relationship("bi_special_containers", :is_member_of, :has_member, :solr_fq=>"has_model_s:info\\:fedora/afmodel\\:SpecialContainer")
25
+ has_bidirectional_relationship("bi_special_containers", :is_member_of, :has_member, :solr_fq=>"has_model_s:info\\:fedora\\/afmodel\\:SpecialContainer")
26
26
  end
27
27
 
28
28
  @test_object = SNSpecModel.new
@@ -89,7 +89,9 @@ describe ActiveFedora::SemanticNode do
89
89
  @special_part.add_relationship(:has_model, SpecialPart.to_class_uri)
90
90
  @special_part.add_relationship(:is_part_of, @test_object_query)
91
91
  @special_part.save
92
-
92
+
93
+ @special_container_query = "has_model_s:#{solr_uri("info:fedora/afmodel:SpecialContainer")}"
94
+ @special_part_query = "has_model_s:#{solr_uri("info:fedora/afmodel:SpecialPart")}"
93
95
  end
94
96
 
95
97
  after(:all) do
@@ -251,17 +253,17 @@ describe ActiveFedora::SemanticNode do
251
253
  end
252
254
 
253
255
  it "should return a solr query for an inbound relationship" do
254
- @test_object_query.special_parts_query.should == "#{@test_object_query.relationship_predicates[:inbound]['special_parts']}_s:#{@test_object_query.internal_uri.gsub(/(:)/, '\\:')} AND has_model_s:info\\:fedora/afmodel\\:SpecialPart"
256
+ @test_object_query.special_parts_query.should == "#{@test_object_query.relationship_predicates[:inbound]['special_parts']}_s:#{solr_uri(@test_object_query.internal_uri)} AND #{@special_part_query}"
255
257
  end
256
258
  end
257
259
 
258
260
  describe "inbound relationship query" do
259
261
  it "should return a properly formatted query for a relationship that has a solr filter query defined" do
260
- SpecNodeSolrFilterQuery.inbound_relationship_query(@test_object_query.pid,"special_parts").should == "#{@test_object_query.relationship_predicates[:inbound]['special_parts']}_s:#{@test_object_query.internal_uri.gsub(/(:)/, '\\:')} AND has_model_s:info\\:fedora/afmodel\\:SpecialPart"
262
+ SpecNodeSolrFilterQuery.inbound_relationship_query(@test_object_query.pid,"special_parts").should == "#{@test_object_query.relationship_predicates[:inbound]['special_parts']}_s:#{solr_uri(@test_object_query.internal_uri)} AND #{@special_part_query}"
261
263
  end
262
264
 
263
265
  it "should return a properly formatted query for a relationship that does not have a solr filter query defined" do
264
- SpecNodeSolrFilterQuery.inbound_relationship_query(@test_object_query.pid,"parts").should == "is_part_of_s:#{@test_object_query.internal_uri.gsub(/(:)/, '\\:')}"
266
+ SpecNodeSolrFilterQuery.inbound_relationship_query(@test_object_query.pid,"parts").should == "is_part_of_s:#{solr_uri(@test_object_query.internal_uri)}"
265
267
  end
266
268
  end
267
269
 
@@ -270,7 +272,7 @@ describe ActiveFedora::SemanticNode do
270
272
  expected_string = ""
271
273
  @test_object_query.containers_ids.each_with_index do |id,index|
272
274
  expected_string << " OR " if index > 0
273
- expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND has_model_s:info\\:fedora/afmodel\\:SpecialContainer)"
275
+ expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND #{@special_container_query})"
274
276
  end
275
277
  SpecNodeSolrFilterQuery.outbound_relationship_query("special_containers",@test_object_query.containers_ids).should == expected_string
276
278
  end
@@ -290,10 +292,10 @@ describe ActiveFedora::SemanticNode do
290
292
  expected_string = ""
291
293
  @test_object_query.bi_containers_outbound_ids.each_with_index do |id,index|
292
294
  expected_string << " OR " if index > 0
293
- expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND has_model_s:info\\:fedora/afmodel\\:SpecialContainer)"
295
+ expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND #{@special_container_query})"
294
296
  end
295
297
  expected_string << " OR "
296
- expected_string << "(#{@test_object_query.relationship_predicates[:inbound]['bi_special_containers_inbound']}_s:#{@test_object_query.internal_uri.gsub(/(:)/, '\\:')} AND has_model_s:info\\:fedora/afmodel\\:SpecialContainer)"
298
+ expected_string << "(#{@test_object_query.relationship_predicates[:inbound]['bi_special_containers_inbound']}_s:#{solr_uri(@test_object_query.internal_uri)} AND #{@special_container_query})"
297
299
  SpecNodeSolrFilterQuery.bidirectional_relationship_query(@test_object_query.pid,"bi_special_containers",@test_object_query.bi_containers_outbound_ids).should == expected_string
298
300
  end
299
301
 
@@ -304,7 +306,7 @@ describe ActiveFedora::SemanticNode do
304
306
  expected_string << "id:" + id.gsub(/(:)/, '\\:')
305
307
  end
306
308
  expected_string << " OR "
307
- expected_string << "(#{@test_object_query.relationship_predicates[:inbound]['bi_special_containers_inbound']}_s:#{@test_object_query.internal_uri.gsub(/(:)/, '\\:')})"
309
+ expected_string << "(#{@test_object_query.relationship_predicates[:inbound]['bi_special_containers_inbound']}_s:#{solr_uri(@test_object_query.internal_uri)})"
308
310
  SpecNodeSolrFilterQuery.bidirectional_relationship_query(@test_object_query.pid,"bi_containers",@test_object_query.bi_containers_outbound_ids).should == expected_string
309
311
  end
310
312
  end
@@ -367,7 +369,7 @@ describe ActiveFedora::SemanticNode do
367
369
  expected_string = ""
368
370
  @test_object_query.containers_ids.each_with_index do |id,index|
369
371
  expected_string << " OR " if index > 0
370
- expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND has_model_s:info\\:fedora/afmodel\\:SpecialContainer)"
372
+ expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND #{@special_container_query})"
371
373
  end
372
374
  @test_object_query.special_containers_query.should == expected_string
373
375
  end
@@ -412,10 +414,10 @@ describe ActiveFedora::SemanticNode do
412
414
  expected_string = ""
413
415
  @test_object_query.bi_containers_outbound_ids.each_with_index do |id,index|
414
416
  expected_string << " OR " if index > 0
415
- expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND has_model_s:info\\:fedora/afmodel\\:SpecialContainer)"
417
+ expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND #{@special_container_query})"
416
418
  end
417
419
  expected_string << " OR "
418
- expected_string << "(#{@test_object_query.relationship_predicates[:inbound]['bi_special_containers_inbound']}_s:#{@test_object_query.internal_uri.gsub(/(:)/, '\\:')} AND has_model_s:info\\:fedora/afmodel\\:SpecialContainer)"
420
+ expected_string << "(#{@test_object_query.relationship_predicates[:inbound]['bi_special_containers_inbound']}_s:#{solr_uri(@test_object_query.internal_uri)} AND #{@special_container_query})"
419
421
  @test_object_query.bi_special_containers_query.should == expected_string
420
422
  end
421
423
  end
@@ -35,3 +35,7 @@ end
35
35
  def fixture(file)
36
36
  File.open(File.join(File.dirname(__FILE__), 'fixtures', file), 'rb')
37
37
  end
38
+
39
+ def solr_uri(uri)
40
+ uri.gsub(/(:)/, "\\:").gsub(/(\/)/,"\\/")
41
+ end
@@ -87,19 +87,12 @@ describe ActiveFedora::Base do
87
87
  # Actually uses self.to_solr internally to gather solr info from all metadata datastreams
88
88
  mock1 = mock("ds1", :to_solr)
89
89
  mock2 = mock("ds2", :to_solr)
90
- mock3 = mock("RELS-EXT")
90
+ mock3 = mock("RELS-EXT", :to_solr)
91
91
 
92
92
  mock_datastreams = {:ds1 => mock1, :ds2 => mock2, :rels_ext => mock3}
93
- mock_datastreams.values.each do |ds|
94
- ds.stubs(:kind_of?).with(ActiveFedora::RDFDatastream).returns(false)
95
- ds.stubs(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(false)
96
- end
97
93
  mock1.expects(:solrize_profile).returns({})
98
94
  mock2.expects(:solrize_profile).returns({})
99
95
  mock3.expects(:solrize_profile).returns({})
100
- mock1.expects(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(true)
101
- mock2.expects(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(true)
102
- mock3.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(false)
103
96
  @test_object.expects(:datastreams).twice.returns(mock_datastreams)
104
97
  @test_object.expects(:solrize_relationships)
105
98
  @test_object.update_index
@@ -109,19 +102,12 @@ describe ActiveFedora::Base do
109
102
  # Actually uses self.to_solr internally to gather solr info from all metadata datastreams
110
103
  mock1 = mock("ds1", :to_solr)
111
104
  mock2 = mock("ds2", :to_solr)
112
- mock3 = mock("RELS-EXT")
105
+ mock3 = mock("RELS-EXT", :to_solr)
113
106
 
114
107
  mock_datastreams = {:ds1 => mock1, :ds2 => mock2, :rels_ext => mock3}
115
- mock_datastreams.values.each do |ds|
116
- ds.stubs(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(false)
117
- ds.stubs(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(false)
118
- end
119
108
  mock1.expects(:solrize_profile).returns({})
120
109
  mock2.expects(:solrize_profile).returns({})
121
110
  mock3.expects(:solrize_profile).returns({})
122
- mock1.expects(:kind_of?).with(ActiveFedora::RDFDatastream).returns(true)
123
- mock2.expects(:kind_of?).with(ActiveFedora::RDFDatastream).returns(true)
124
- mock3.expects(:kind_of?).with(ActiveFedora::RDFDatastream).returns(false)
125
111
  @test_object.expects(:datastreams).twice.returns(mock_datastreams)
126
112
  @test_object.expects(:solrize_relationships)
127
113
  @test_object.update_index
@@ -623,12 +623,6 @@ describe ActiveFedora::Base do
623
623
  ngds.expects(:solrize_profile)
624
624
  mock1.expects(:solrize_profile)
625
625
  mock2.expects(:solrize_profile)
626
- mock1.expects(:kind_of?).with(ActiveFedora::RDFDatastream).returns(false)
627
- mock1.expects(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(true)
628
- mock2.expects(:kind_of?).with(ActiveFedora::RDFDatastream).returns(false)
629
- mock2.expects(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(true)
630
- ngds.expects(:kind_of?).with(ActiveFedora::RDFDatastream).returns(false)
631
- ngds.expects(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(true)
632
626
 
633
627
  @test_object.expects(:datastreams).twice.returns({:ds1 => mock1, :ds2 => mock2, :ngds => ngds})
634
628
  @test_object.expects(:solrize_relationships)
@@ -637,7 +631,6 @@ describe ActiveFedora::Base do
637
631
  it "should call .to_solr on all RDFDatastreams, passing the resulting document to solr" do
638
632
  mock = mock("ds1", :to_solr)
639
633
  mock.expects(:solrize_profile)
640
- mock.expects(:kind_of?).with(ActiveFedora::RDFDatastream).returns(true)
641
634
 
642
635
  @test_object.expects(:datastreams).twice.returns({:ds1 => mock})
643
636
  @test_object.expects(:solrize_relationships)
@@ -10,6 +10,7 @@ describe ActiveFedora::Model do
10
10
  end
11
11
  end
12
12
  end
13
+ @model_query = "has_model_s:#{solr_uri("info:fedora/afmodel:SpecModel_Basic")}"
13
14
  end
14
15
 
15
16
  after(:all) do
@@ -27,7 +28,7 @@ describe ActiveFedora::Model do
27
28
  mock_docs = mock('docs')
28
29
  mock_docs.expects(:each).multiple_yields([{"id" => "changeme:30"}],[{"id" => "changeme:22"}])
29
30
  mock_docs.expects(:has_next?).returns(false)
30
- ActiveFedora::SolrService.instance.conn.expects(:paginate).with(1, 1000, 'select', :params=>{:q=>'has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic', :qt => 'standard', :sort => ['system_create_dt asc'], :fl=> 'id', }).returns('response'=>{'docs'=>mock_docs})
31
+ ActiveFedora::SolrService.instance.conn.expects(:paginate).with(1, 1000, 'select', :params=>{:q=>@model_query, :qt => 'standard', :sort => ['system_create_dt asc'], :fl=> 'id', }).returns('response'=>{'docs'=>mock_docs})
31
32
  SpecModel::Basic.find(:all).should == ["Fake Object1", "Fake Object2"]
32
33
  end
33
34
  end
@@ -79,7 +80,7 @@ describe ActiveFedora::Model do
79
80
  hash[:params] &&
80
81
  hash[:params][:sort] == ['system_create_dt asc'] &&
81
82
  hash[:params][:fl] == 'id' &&
82
- hash[:params][:q].split(" AND ").include?("has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic") &&
83
+ hash[:params][:q].split(" AND ").include?(@model_query) &&
83
84
  hash[:params][:q].split(" AND ").include?("foo:\"bar\"") &&
84
85
  hash[:params][:q].split(" AND ").include?("baz:\"quix\"") &&
85
86
  hash[:params][:q].split(" AND ").include?("baz:\"quack\"")
@@ -89,12 +90,19 @@ describe ActiveFedora::Model do
89
90
  end
90
91
  end
91
92
 
93
+ describe '#all' do
94
+ it "should pass everything through to .find" do
95
+ SpecModel::Basic.expects(:find).with(:all, {})
96
+ SpecModel::Basic.all
97
+ end
98
+ end
99
+
92
100
  describe '#find_each' do
93
101
  it "should query solr for all objects with :active_fedora_model_s of self.class" do
94
102
  mock_docs = mock('docs')
95
103
  mock_docs.expects(:each).multiple_yields([{"id" => "changeme:30"}],[{"id" => "changeme:22"}])
96
104
  mock_docs.expects(:has_next?).returns(false)
97
- ActiveFedora::SolrService.instance.conn.expects(:paginate).with(1, 1000, 'select', :params=>{:q=>'has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic', :qt => 'standard', :sort => ['system_create_dt asc'], :fl=> 'id', }).returns('response'=>{'docs'=>mock_docs})
105
+ ActiveFedora::SolrService.instance.conn.expects(:paginate).with(1, 1000, 'select', :params=>{:q=>@model_query, :qt => 'standard', :sort => ['system_create_dt asc'], :fl=> 'id', }).returns('response'=>{'docs'=>mock_docs})
98
106
 
99
107
  SpecModel::Basic.expects(:find_one).with("changeme:30", nil).returns(SpecModel::Basic.new(:pid=>'changeme:30'))
100
108
  SpecModel::Basic.expects(:find_one).with("changeme:22", nil).returns(SpecModel::Basic.new(:pid=>'changeme:22'))
@@ -117,7 +125,7 @@ describe ActiveFedora::Model do
117
125
  hash[:params] &&
118
126
  hash[:params][:sort] == ['system_create_dt asc'] &&
119
127
  hash[:params][:fl] == 'id' &&
120
- hash[:params][:q].split(" AND ").include?("has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic") &&
128
+ hash[:params][:q].split(" AND ").include?(@model_query) &&
121
129
  hash[:params][:q].split(" AND ").include?("foo:\"bar\"") &&
122
130
  hash[:params][:q].split(" AND ").include?("baz:\"quix\"") &&
123
131
  hash[:params][:q].split(" AND ").include?("baz:\"quack\"")
@@ -141,7 +149,7 @@ describe ActiveFedora::Model do
141
149
  hash[:params] &&
142
150
  hash[:params][:sort] == ['system_create_dt asc'] &&
143
151
  hash[:params][:fl] == 'id' &&
144
- hash[:params][:q].split(" AND ").include?("has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic") &&
152
+ hash[:params][:q].split(" AND ").include?(@model_query) &&
145
153
  hash[:params][:q].split(" AND ").include?("foo:\"bar\"") &&
146
154
  hash[:params][:q].split(" AND ").include?("baz:\"quix\"") &&
147
155
  hash[:params][:q].split(" AND ").include?("baz:\"quack\"")
@@ -157,12 +165,12 @@ describe ActiveFedora::Model do
157
165
 
158
166
  it "should return a count" do
159
167
  mock_result = {'response'=>{'numFound'=>7}}
160
- ActiveFedora::SolrService.expects(:query).with('has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic', :rows=>0, :raw=>true).returns(mock_result)
168
+ ActiveFedora::SolrService.expects(:query).with(@model_query, :rows=>0, :raw=>true).returns(mock_result)
161
169
  SpecModel::Basic.count.should == 7
162
170
  end
163
171
  it "should allow conditions" do
164
172
  mock_result = {'response'=>{'numFound'=>7}}
165
- ActiveFedora::SolrService.expects(:query).with('has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic AND foo:bar', :rows=>0, :raw=>true).returns(mock_result)
173
+ ActiveFedora::SolrService.expects(:query).with("#{@model_query} AND foo:bar", :rows=>0, :raw=>true).returns(mock_result)
166
174
  SpecModel::Basic.count(:conditions=>'foo:bar').should == 7
167
175
  end
168
176
  end
@@ -188,7 +196,7 @@ describe ActiveFedora::Model do
188
196
  ActiveFedora::SolrService.expects(:query).with() { |args|
189
197
  q = args.first if args.is_a? Array
190
198
  q ||= args
191
- q.split(" AND ").include?("has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic") &&
199
+ q.split(" AND ").include?(@model_query) &&
192
200
  q.split(" AND ").include?("foo:\"bar\"") &&
193
201
  q.split(" AND ").include?("baz:\"quix\"") &&
194
202
  q.split(" AND ").include?("baz:\"quack\"")
@@ -201,8 +209,8 @@ describe ActiveFedora::Model do
201
209
  ActiveFedora::SolrService.expects(:query).with() { |args|
202
210
  q = args.first if args.is_a? Array
203
211
  q ||= args
204
- q.split(" AND ").include?("has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic") &&
205
- q.split(" AND ").include?("has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic") &&
212
+ q.split(" AND ").include?(@model_query) &&
213
+ q.split(" AND ").include?(@model_query) &&
206
214
  q.split(" AND ").include?('foo:"9\\" Nails"') &&
207
215
  q.split(" AND ").include?('baz:"7\\" version"') &&
208
216
  q.split(" AND ").include?('baz:"quack"')
@@ -6,6 +6,12 @@ describe ActiveFedora::Relationships do
6
6
  def increment_pid
7
7
  @@last_pid += 1
8
8
  end
9
+
10
+ before(:all) do
11
+ @part_of_sample = "is_part_of_s:#{solr_uri("info:fedora/test:sample_pid")}"
12
+ @constituent_of_sample = "is_constituent_of_s:#{solr_uri("info:fedora/test:sample_pid")}"
13
+ @is_part_query = "has_model_s:#{solr_uri("info:fedora/SpecialPart")}"
14
+ end
9
15
 
10
16
  before(:each) do
11
17
  class SpecNode
@@ -169,7 +175,7 @@ describe ActiveFedora::Relationships do
169
175
  local_node = SpecNode.new()
170
176
  local_node.expects(:pid).returns("test:sample_pid")
171
177
  SpecNode.expects(:relationships_desc).returns({:inbound=>{"parts"=>{:predicate=>:is_part_of}}}).at_least_once()
172
- ActiveFedora::SolrService.expects(:query).with("is_part_of_s:info\\:fedora/test\\:sample_pid", :rows=>25).returns(@sample_solr_hits)
178
+ ActiveFedora::SolrService.expects(:query).with(@part_of_sample, :rows=>25).returns(@sample_solr_hits)
173
179
  local_node.parts_ids.should == ["_PID1_", "_PID2_", "_PID3_"]
174
180
  end
175
181
 
@@ -182,7 +188,7 @@ describe ActiveFedora::Relationships do
182
188
  local_node.expects(:pid).returns("test:sample_pid")
183
189
  SpecNode.expects(:relationships_desc).returns({:inbound=>{"constituents"=>{:predicate=>:is_constituent_of}}}).at_least_once()
184
190
  instance = stub(:conn=>stub(:conn))
185
- ActiveFedora::SolrService.expects(:query).with("is_constituent_of_s:info\\:fedora/test\\:sample_pid", :raw=>true, :rows=>101).returns(solr_result)
191
+ ActiveFedora::SolrService.expects(:query).with(@constituent_of_sample, :raw=>true, :rows=>101).returns(solr_result)
186
192
  local_node.constituents(:response_format => :solr, :rows=>101).should == solr_result
187
193
  end
188
194
 
@@ -192,7 +198,7 @@ describe ActiveFedora::Relationships do
192
198
  local_node = SpecNode.new
193
199
  local_node.expects(:pid).returns("test:sample_pid")
194
200
  SpecNode.expects(:relationships_desc).returns({:inbound=>{"parts"=>{:predicate=>:is_part_of}}}).at_least_once()
195
- ActiveFedora::SolrService.expects(:query).with("is_part_of_s:info\\:fedora/test\\:sample_pid", :rows=>25).returns([Hash["id"=>"pid1"], Hash["id"=>"pid2"]])
201
+ ActiveFedora::SolrService.expects(:query).with(@part_of_sample, :rows=>25).returns([Hash["id"=>"pid1"], Hash["id"=>"pid2"]])
196
202
  local_node.parts(:response_format => :id_array).should == ["pid1", "pid2"]
197
203
  end
198
204
 
@@ -320,7 +326,7 @@ describe ActiveFedora::Relationships do
320
326
  @local_node.expects(:ids_for_outbound).with(:has_part).returns(["mypid:1"])
321
327
  id_array_query = ActiveFedora::SolrService.construct_query_for_pids(["mypid:1"])
322
328
  solr_result = mock("solr result")
323
- ActiveFedora::SolrService.expects(:query).with("#{id_array_query} OR (is_part_of_s:info\\:fedora/test\\:sample_pid)", :rows=>25).returns(solr_result)
329
+ ActiveFedora::SolrService.expects(:query).with("#{id_array_query} OR (#{@part_of_sample})", :rows=>25).returns(solr_result)
324
330
  @local_node.all_parts(:response_format=>:solr)
325
331
  end
326
332
 
@@ -747,8 +753,8 @@ describe ActiveFedora::Relationships do
747
753
  describe "bidirectional_relationship_query" do
748
754
  before do
749
755
  class MockBiNamedRelationshipQuery < SpecNode
750
- register_relationship_desc(:self, "testing_query_outbound", :has_part, :type=>SpecNode, :solr_fq=>"has_model_s:info\\:fedora/SpecialPart")
751
- register_relationship_desc(:inbound, "testing_query_inbound", :is_part_of, :type=>SpecNode, :solr_fq=>"has_model_s:info\\:fedora/SpecialPart")
756
+ register_relationship_desc(:self, "testing_query_outbound", :has_part, :type=>SpecNode, :solr_fq=>"has_model_s:info\\:fedora\\/SpecialPart")
757
+ register_relationship_desc(:inbound, "testing_query_inbound", :is_part_of, :type=>SpecNode, :solr_fq=>"has_model_s:info\\:fedora\\/SpecialPart")
752
758
  create_bidirectional_relationship_name_methods("testing","testing_outbound")
753
759
  register_relationship_desc(:self, "testing_no_solr_fq_outbound", :has_part, :type=>SpecNode)
754
760
  register_relationship_desc(:inbound, "testing_no_solr_fq_inbound", :is_part_of, :type=>SpecNode)
@@ -774,10 +780,10 @@ describe ActiveFedora::Relationships do
774
780
  ids = ["changeme:1","changeme:2","changeme:3","changeme:4","changeme:5"]
775
781
  ids.each_with_index do |id,index|
776
782
  expected_string << " OR " if index > 0
777
- expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND has_model_s:info\\:fedora/SpecialPart)"
783
+ expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND #{@is_part_query})"
778
784
  end
779
785
  expected_string << " OR "
780
- expected_string << "(is_part_of_s:info\\:fedora/changeme\\:6 AND has_model_s:info\\:fedora/SpecialPart)"
786
+ expected_string << "(is_part_of_s:info\\:fedora\\/changeme\\:6 AND #{@is_part_query})"
781
787
  MockBiNamedRelationshipQuery.bidirectional_relationship_query("changeme:6","testing_query",ids).should == expected_string
782
788
  end
783
789
 
@@ -789,7 +795,7 @@ describe ActiveFedora::Relationships do
789
795
  expected_string << "id:" + id.gsub(/(:)/, '\\:')
790
796
  end
791
797
  expected_string << " OR "
792
- expected_string << "(is_part_of_s:info\\:fedora/changeme\\:6)"
798
+ expected_string << "(is_part_of_s:info\\:fedora\\/changeme\\:6)"
793
799
  MockBiNamedRelationshipQuery.bidirectional_relationship_query("changeme:6","testing_no_solr_fq",ids).should == expected_string
794
800
  end
795
801
  end
@@ -797,7 +803,7 @@ describe ActiveFedora::Relationships do
797
803
  describe "inbound_relationship_query" do
798
804
  before do
799
805
  class MockInboundNamedRelationshipQuery < SpecNode
800
- register_relationship_desc(:inbound, "testing_inbound_query", :is_part_of, :type=>SpecNode, :solr_fq=>"has_model_s:info\\:fedora/SpecialPart")
806
+ register_relationship_desc(:inbound, "testing_inbound_query", :is_part_of, :type=>SpecNode, :solr_fq=>"has_model_s:#{solr_uri("info:fedora/SpecialPart")}")
801
807
  register_relationship_desc(:inbound, "testing_inbound_no_solr_fq", :is_part_of, :type=>SpecNode)
802
808
  end
803
809
  end
@@ -806,11 +812,11 @@ describe ActiveFedora::Relationships do
806
812
  end
807
813
 
808
814
  it "should return a properly formatted query for a relationship that has a solr filter query defined" do
809
- 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"
815
+ MockInboundNamedRelationshipQuery.inbound_relationship_query("changeme:1","testing_inbound_query").should == "is_part_of_s:info\\:fedora\\/changeme\\:1 AND #{@is_part_query}"
810
816
  end
811
817
 
812
818
  it "should return a properly formatted query for a relationship that does not have a solr filter query defined" do
813
- MockInboundNamedRelationshipQuery.inbound_relationship_query("changeme:1","testing_inbound_no_solr_fq").should == "is_part_of_s:info\\:fedora/changeme\\:1"
819
+ MockInboundNamedRelationshipQuery.inbound_relationship_query("changeme:1","testing_inbound_no_solr_fq").should == "is_part_of_s:info\\:fedora\\/changeme\\:1"
814
820
  end
815
821
  end
816
822
 
@@ -820,7 +826,7 @@ describe ActiveFedora::Relationships do
820
826
  describe "outbound_relationship_query" do
821
827
  before do
822
828
  class MockOutboundNamedRelationshipQuery < SpecNode
823
- register_relationship_desc(:self, "testing_query", :is_part_of, :type=>SpecNode, :solr_fq=>"has_model_s:info\\:fedora/SpecialPart")
829
+ register_relationship_desc(:self, "testing_query", :is_part_of, :type=>SpecNode, :solr_fq=>"has_model_s:#{solr_uri("info:fedora/SpecialPart")}")
824
830
  register_relationship_desc(:self,"testing_no_solr_fq", :is_part_of, :type=>SpecNode)
825
831
  end
826
832
  end
@@ -833,7 +839,7 @@ describe ActiveFedora::Relationships do
833
839
  expected_string = ""
834
840
  ids.each_with_index do |id,index|
835
841
  expected_string << " OR " if index > 0
836
- expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND has_model_s:info\\:fedora/SpecialPart)"
842
+ expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND has_model_s:#{solr_uri("info:fedora/SpecialPart")})"
837
843
  end
838
844
  MockOutboundNamedRelationshipQuery.outbound_relationship_query("testing_query",ids).should == expected_string
839
845
  end
@@ -51,7 +51,7 @@ describe ActiveFedora do
51
51
 
52
52
  it "should be used by ActiveFedora::Base#find_with_conditions" do
53
53
  mock_response = mock("SolrResponse")
54
- ActiveFedora::SolrService.expects(:query).with("has_model_s:info\\:fedora/afmodel\\:SolrSpecModel_Basic AND " + SOLR_DOCUMENT_ID + ':"changeme\\:30"', {:sort => ['system_create_dt asc']}).returns(mock_response)
54
+ ActiveFedora::SolrService.expects(:query).with("has_model_s:info\\:fedora\\/afmodel\\:SolrSpecModel_Basic AND " + SOLR_DOCUMENT_ID + ':"changeme\\:30"', {:sort => ['system_create_dt asc']}).returns(mock_response)
55
55
 
56
56
  SolrSpecModel::Basic.find_with_conditions(:id=>"changeme:30").should equal(mock_response)
57
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-fedora
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.5.1
4
+ version: 4.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-08-16 00:00:00.000000000 Z
14
+ date: 2012-08-30 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rsolr
@@ -522,7 +522,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
522
522
  version: '0'
523
523
  segments:
524
524
  - 0
525
- hash: 580091629
525
+ hash: -146245566086376860
526
526
  required_rubygems_version: !ruby/object:Gem::Requirement
527
527
  none: false
528
528
  requirements:
@@ -531,12 +531,139 @@ required_rubygems_version: !ruby/object:Gem::Requirement
531
531
  version: '0'
532
532
  segments:
533
533
  - 0
534
- hash: 580091629
534
+ hash: -146245566086376860
535
535
  requirements: []
536
536
  rubyforge_project: rubyfedora
537
- rubygems_version: 1.8.24
537
+ rubygems_version: 1.8.23
538
538
  signing_key:
539
539
  specification_version: 3
540
540
  summary: A convenience libary for manipulating documents in the Fedora Repository.
541
- test_files: []
541
+ test_files:
542
+ - spec/config_helper.rb
543
+ - spec/fixtures/changeme155.xml
544
+ - spec/fixtures/dino.jpg
545
+ - spec/fixtures/dino_jpg_no_file_ext
546
+ - spec/fixtures/dublin_core_rdf_descMetadata.nt
547
+ - spec/fixtures/hydrangea_fixture_mods_article1.foxml.xml
548
+ - spec/fixtures/minivan.jpg
549
+ - spec/fixtures/mixed_rdf_descMetadata.nt
550
+ - spec/fixtures/mods_articles/hydrangea_article1.xml
551
+ - spec/fixtures/rails_root/config/fake_fedora.yml
552
+ - spec/fixtures/rails_root/config/fedora.yml
553
+ - spec/fixtures/rails_root/config/predicate_mappings.yml
554
+ - spec/fixtures/rails_root/config/solr.yml
555
+ - spec/fixtures/rails_root/config/solr_mappings.yml
556
+ - spec/fixtures/rails_root/config/solr_mappings_af_0.1.yml
557
+ - spec/fixtures/rails_root/config/solr_mappings_bl_2.4.yml
558
+ - spec/fixtures/sharded_fedora.yml
559
+ - spec/fixtures/solr_rdf_descMetadata.nt
560
+ - spec/fixtures/test_12.foxml.xml
561
+ - spec/hydrangea_fixture_mods_article1.foxml.xml
562
+ - spec/integration/associations_spec.rb
563
+ - spec/integration/base_file_management_spec.rb
564
+ - spec/integration/base_find_by_fields_spec.rb
565
+ - spec/integration/base_spec.rb
566
+ - spec/integration/bug_spec.rb
567
+ - spec/integration/datastream_collections_spec.rb
568
+ - spec/integration/datastream_spec.rb
569
+ - spec/integration/datastreams_spec.rb
570
+ - spec/integration/full_featured_model_spec.rb
571
+ - spec/integration/metadata_datastream_helper_spec.rb
572
+ - spec/integration/metadata_datastream_spec.rb
573
+ - spec/integration/model_spec.rb
574
+ - spec/integration/mods_article_integration_spec.rb
575
+ - spec/integration/nested_attribute_spec.rb
576
+ - spec/integration/nokogiri_datastream_spec.rb
577
+ - spec/integration/ntriples_datastream_spec.rb
578
+ - spec/integration/rels_ext_datastream_spec.rb
579
+ - spec/integration/semantic_node_spec.rb
580
+ - spec/integration/solr_service_spec.rb
581
+ - spec/rails3_test_app/.gitignore
582
+ - spec/rails3_test_app/.rspec
583
+ - spec/rails3_test_app/.rvmrc
584
+ - spec/rails3_test_app/Gemfile
585
+ - spec/rails3_test_app/Gemfile.lock
586
+ - spec/rails3_test_app/Rakefile
587
+ - spec/rails3_test_app/app/controllers/application_controller.rb
588
+ - spec/rails3_test_app/app/helpers/application_helper.rb
589
+ - spec/rails3_test_app/app/views/layouts/application.html.erb
590
+ - spec/rails3_test_app/config.ru
591
+ - spec/rails3_test_app/config/application.rb
592
+ - spec/rails3_test_app/config/boot.rb
593
+ - spec/rails3_test_app/config/database.yml
594
+ - spec/rails3_test_app/config/environment.rb
595
+ - spec/rails3_test_app/config/environments/development.rb
596
+ - spec/rails3_test_app/config/environments/production.rb
597
+ - spec/rails3_test_app/config/environments/test.rb
598
+ - spec/rails3_test_app/config/initializers/backtrace_silencers.rb
599
+ - spec/rails3_test_app/config/initializers/inflections.rb
600
+ - spec/rails3_test_app/config/initializers/mime_types.rb
601
+ - spec/rails3_test_app/config/initializers/secret_token.rb
602
+ - spec/rails3_test_app/config/initializers/session_store.rb
603
+ - spec/rails3_test_app/config/locales/en.yml
604
+ - spec/rails3_test_app/config/routes.rb
605
+ - spec/rails3_test_app/db/seeds.rb
606
+ - spec/rails3_test_app/run_tests
607
+ - spec/rails3_test_app/script/rails
608
+ - spec/rails3_test_app/spec/spec_helper.rb
609
+ - spec/rails3_test_app/spec/unit/rails_3_init.rb
610
+ - spec/rcov.opts
611
+ - spec/samples/hydra-mods_article_datastream.rb
612
+ - spec/samples/hydra-rights_metadata_datastream.rb
613
+ - spec/samples/marpa-dc_datastream.rb
614
+ - spec/samples/models/audio_record.rb
615
+ - spec/samples/models/hydrangea_article.rb
616
+ - spec/samples/models/image.rb
617
+ - spec/samples/models/oral_history.rb
618
+ - spec/samples/models/seminar.rb
619
+ - spec/samples/models/seminar_audio_file.rb
620
+ - spec/samples/oral_history_sample.xml
621
+ - spec/samples/oral_history_sample_model.rb
622
+ - spec/samples/oral_history_xml.xml
623
+ - spec/samples/samples.rb
624
+ - spec/samples/special_thing.rb
625
+ - spec/spec.opts
626
+ - spec/spec_helper.rb
627
+ - spec/support/mock_fedora.rb
628
+ - spec/unit/active_fedora_spec.rb
629
+ - spec/unit/association_proxy_spec.rb
630
+ - spec/unit/base_active_model_spec.rb
631
+ - spec/unit/base_cma_spec.rb
632
+ - spec/unit/base_datastream_management_spec.rb
633
+ - spec/unit/base_delegate_spec.rb
634
+ - spec/unit/base_delegate_to_spec.rb
635
+ - spec/unit/base_extra_spec.rb
636
+ - spec/unit/base_file_management_spec.rb
637
+ - spec/unit/base_spec.rb
638
+ - spec/unit/callback_spec.rb
639
+ - spec/unit/code_configurator_spec.rb
640
+ - spec/unit/config_spec.rb
641
+ - spec/unit/content_model_spec.rb
642
+ - spec/unit/datastream_collections_spec.rb
643
+ - spec/unit/datastream_spec.rb
644
+ - spec/unit/datastreams_spec.rb
645
+ - spec/unit/file_configurator_spec.rb
646
+ - spec/unit/has_many_collection_spec.rb
647
+ - spec/unit/inheritance_spec.rb
648
+ - spec/unit/metadata_datastream_spec.rb
649
+ - spec/unit/model_spec.rb
650
+ - spec/unit/nokogiri_datastream_spec.rb
651
+ - spec/unit/ntriples_datastream_spec.rb
652
+ - spec/unit/predicates_spec.rb
653
+ - spec/unit/property_spec.rb
654
+ - spec/unit/qualified_dublin_core_datastream_spec.rb
655
+ - spec/unit/rdf_xml_writer_spec.rb
656
+ - spec/unit/rdfxml_rdf_datastream_spec.rb
657
+ - spec/unit/relationship_graph_spec.rb
658
+ - spec/unit/relationships_spec.rb
659
+ - spec/unit/rels_ext_datastream_spec.rb
660
+ - spec/unit/rubydora_connection_spec.rb
661
+ - spec/unit/semantic_node_spec.rb
662
+ - spec/unit/service_definitions_spec.rb
663
+ - spec/unit/simple_datastream_spec.rb
664
+ - spec/unit/solr_config_options_spec.rb
665
+ - spec/unit/solr_digital_object_spec.rb
666
+ - spec/unit/solr_service_spec.rb
667
+ - spec/unit/unsaved_digital_object_spec.rb
668
+ - spec/unit/validations_spec.rb
542
669
  has_rdoc: