active-fedora 3.3.2 → 4.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/Gemfile.lock +21 -22
  2. data/History.txt +9 -0
  3. data/README.textile +1 -1
  4. data/TODO +1 -0
  5. data/active-fedora.gemspec +3 -3
  6. data/config/fedora.yml +9 -3
  7. data/lib/active_fedora.rb +43 -33
  8. data/lib/active_fedora/base.rb +80 -31
  9. data/lib/active_fedora/config.rb +38 -0
  10. data/lib/active_fedora/content_model.rb +0 -6
  11. data/lib/active_fedora/datastream.rb +22 -0
  12. data/lib/active_fedora/delegating.rb +24 -25
  13. data/lib/active_fedora/digital_object.rb +2 -1
  14. data/lib/active_fedora/file_management.rb +1 -0
  15. data/lib/active_fedora/fixture_exporter.rb +1 -1
  16. data/lib/active_fedora/fixture_loader.rb +3 -3
  17. data/lib/active_fedora/metadata_datastream.rb +6 -0
  18. data/lib/active_fedora/model.rb +24 -5
  19. data/lib/active_fedora/nokogiri_datastream.rb +1 -0
  20. data/lib/active_fedora/ntriples_rdf_datastream.rb +0 -1
  21. data/lib/active_fedora/persistence.rb +2 -1
  22. data/lib/active_fedora/predicates.rb +27 -27
  23. data/lib/active_fedora/rdf_datastream.rb +104 -30
  24. data/lib/active_fedora/rels_ext_datastream.rb +14 -10
  25. data/lib/active_fedora/rubydora_connection.rb +4 -27
  26. data/lib/active_fedora/service_definitions.rb +2 -3
  27. data/lib/active_fedora/solr_digital_object.rb +22 -8
  28. data/lib/active_fedora/solr_service.rb +1 -1
  29. data/lib/active_fedora/unsaved_digital_object.rb +1 -4
  30. data/lib/active_fedora/version.rb +1 -1
  31. data/lib/tasks/active_fedora.rake +6 -6
  32. data/lib/tasks/active_fedora_dev.rake +0 -1
  33. data/spec/fixtures/mixed_rdf_descMetadata.nt +6 -0
  34. data/spec/fixtures/rails_root/config/fedora.yml +3 -1
  35. data/spec/fixtures/sharded_fedora.yml +11 -0
  36. data/spec/integration/base_file_management_spec.rb +6 -3
  37. data/spec/integration/base_find_by_fields_spec.rb +15 -16
  38. data/spec/integration/base_spec.rb +11 -178
  39. data/spec/integration/datastream_collections_spec.rb +1 -1
  40. data/spec/integration/full_featured_model_spec.rb +1 -2
  41. data/spec/integration/model_spec.rb +8 -9
  42. data/spec/integration/mods_article_integration_spec.rb +1 -1
  43. data/spec/integration/nokogiri_datastream_spec.rb +1 -1
  44. data/spec/integration/ntriples_datastream_spec.rb +80 -0
  45. data/spec/integration/rels_ext_datastream_spec.rb +0 -1
  46. data/spec/integration/semantic_node_spec.rb +18 -26
  47. data/spec/integration/solr_service_spec.rb +51 -1
  48. data/{lib/active_fedora → spec}/samples/hydra-mods_article_datastream.rb +0 -0
  49. data/{lib/active_fedora → spec}/samples/hydra-rights_metadata_datastream.rb +0 -0
  50. data/{lib/active_fedora → spec}/samples/marpa-dc_datastream.rb +0 -0
  51. data/spec/samples/models/hydrangea_article.rb +2 -2
  52. data/spec/samples/samples.rb +2 -0
  53. data/{lib/active_fedora → spec}/samples/special_thing.rb +3 -3
  54. data/spec/spec_helper.rb +1 -0
  55. data/spec/unit/active_fedora_spec.rb +17 -50
  56. data/spec/unit/base_extra_spec.rb +4 -0
  57. data/spec/unit/base_file_management_spec.rb +5 -2
  58. data/spec/unit/base_spec.rb +692 -628
  59. data/spec/unit/config_spec.rb +19 -0
  60. data/spec/unit/content_model_spec.rb +1 -24
  61. data/spec/unit/datastream_collections_spec.rb +11 -14
  62. data/spec/unit/datastreams_spec.rb +49 -54
  63. data/spec/unit/model_spec.rb +24 -53
  64. data/spec/unit/nokogiri_datastream_spec.rb +6 -1
  65. data/spec/unit/ntriples_datastream_spec.rb +73 -0
  66. data/spec/unit/qualified_dublin_core_datastream_spec.rb +1 -1
  67. data/spec/unit/relationships_spec.rb +6 -3
  68. data/spec/unit/rels_ext_datastream_spec.rb +19 -0
  69. data/spec/unit/rubydora_connection_spec.rb +2 -56
  70. data/spec/unit/solr_service_spec.rb +3 -1
  71. data/spec/unit/unsaved_digital_object_spec.rb +2 -2
  72. metadata +46 -33
  73. data/lib/active_fedora/dcrdf_datastream.rb +0 -11
  74. data/lib/active_fedora/relationship.rb +0 -47
  75. data/lib/active_fedora/samples.rb +0 -3
  76. data/spec/integration/dc_rdf_datastream_spec.rb +0 -24
  77. data/spec/unit/dc_rdf_datastream_spec.rb +0 -50
  78. data/spec/unit/relationship_spec.rb +0 -92
@@ -57,7 +57,8 @@ module ActiveFedora
57
57
  end
58
58
 
59
59
  def self.short_predicate(predicate)
60
- if match = /^(#{Predicates.predicate_mappings.keys.join('|')})(.+)$/.match(predicate.to_str)
60
+ # for this regex to short-circuit correctly, namespaces must be sorted into descending order by length
61
+ if match = /^(#{Predicates.predicate_mappings.keys.sort.reverse.join('|')})(.+)$/.match(predicate.to_str)
61
62
  namespace = match[1]
62
63
  predicate = match[2]
63
64
  pred = Predicates.predicate_mappings[namespace].invert[predicate]
@@ -78,18 +79,21 @@ module ActiveFedora
78
79
  # ====Warning
79
80
  # Solr must be synchronized with RELS-EXT data in Fedora.
80
81
  def from_solr(solr_doc)
82
+ profile_from_solr(solr_doc)
81
83
  #cycle through all possible predicates
82
84
  model.relationships_loaded = true
83
- Predicates.predicate_mappings[Predicates.default_predicate_namespace].keys.each do |predicate|
84
- predicate_symbol = ActiveFedora::SolrService.solr_name(predicate, :symbol)
85
- value = (solr_doc[predicate_symbol].nil? ? solr_doc[predicate_symbol.to_s]: solr_doc[predicate_symbol])
86
- unless value.nil?
87
- if value.is_a? Array
88
- value.each do |obj|
89
- model.add_relationship(predicate, obj)
85
+ Predicates.predicate_mappings.each_pair do |namespace,predicates|
86
+ predicates.keys.each do |predicate|
87
+ predicate_symbol = ActiveFedora::SolrService.solr_name(predicate, :symbol)
88
+ value = (solr_doc[predicate_symbol].nil? ? solr_doc[predicate_symbol.to_s]: solr_doc[predicate_symbol])
89
+ unless value.nil?
90
+ if value.is_a? Array
91
+ value.each do |obj|
92
+ model.add_relationship(predicate, obj)
93
+ end
94
+ else
95
+ model.add_relationship(predicate, value)
90
96
  end
91
- else
92
- model.add_relationship(predicate, value)
93
97
  end
94
98
  end
95
99
  end
@@ -1,29 +1,16 @@
1
- require 'singleton'
2
1
  require 'rubydora'
3
2
 
4
3
  module ActiveFedora
5
4
  class RubydoraConnection
6
- include Singleton
7
5
 
8
- attr_accessor :options
6
+ attr_accessor :options, :connection
9
7
 
10
- def self.connect(params={})
8
+ def initialize(params={})
11
9
  params = params.dup
12
- instance = self.instance
13
- force = params.delete(:force)
14
- instance.options = params
15
- instance.connect force
16
- instance
10
+ self.options = params
11
+ connect
17
12
  end
18
13
 
19
- def connection
20
- return @connection if @connection
21
- ActiveFedora.load_configs
22
- ActiveFedora::RubydoraConnection.connect(ActiveFedora.config_for_environment)
23
- @connection
24
- end
25
-
26
-
27
14
  def connect(force=false)
28
15
  return unless @connection.nil? or force
29
16
  allowable_options = [:url, :user, :password, :timeout, :open_timeout, :ssl_client_cert, :ssl_client_key, :validateChecksum]
@@ -31,15 +18,5 @@ module ActiveFedora
31
18
  #puts "CLIENT OPTS #{client_options.inspect}"
32
19
  @connection = Rubydora.connect client_options
33
20
  end
34
-
35
- def nextid(attrs={})
36
- d = REXML::Document.new(connection.next_pid(:namespace=>attrs[:namespace]))
37
- d.elements['//pid'].text
38
- end
39
-
40
- def find_model(pid, klass)
41
- klass.allocate.init_with(DigitalObject.find(klass, pid))
42
- end
43
-
44
21
  end
45
22
  end
@@ -59,7 +59,7 @@ module ServiceDefinitions
59
59
  # inject methods by symbol key
60
60
  def add_sdef_methods! sdef_pid
61
61
  unless sdef_pid == "fedora-system:3"
62
- content = ActiveFedora::RubydoraConnection.instance.connection.datastream_dissemination(:pid=>sdef_pid, :dsid=>"METHODMAP")
62
+ content = ActiveFedora::Base.connection_for_pid(sdef_pid).datastream_dissemination(:pid=>sdef_pid, :dsid=>"METHODMAP")
63
63
  method_map = Nokogiri::XML.parse(content)
64
64
  methods = method_map.xpath('//fmm:Method').collect { |method|
65
65
  method["operationName"]
@@ -78,9 +78,8 @@ module ServiceDefinitions
78
78
  define_method(method_key) { |*args, &block|
79
79
  opts = args[0] || {}
80
80
  opts = opts.merge({:pid => pid, :sdef => sdef_pid, :method => method_name })
81
- repo = ActiveFedora::RubydoraConnection.instance.connection
82
81
  # dispatch to the dissemination method on restAPI client
83
- repo.dissemination opts, &block
82
+ ActiveFedora::Base.connection_for_pid(pid).dissemination opts, &block
84
83
  }
85
84
  end
86
85
  end
@@ -1,19 +1,33 @@
1
1
  module ActiveFedora
2
2
  class SolrDigitalObject
3
- attr_accessor :pid, :attributes, :datastreams
3
+ attr_reader :pid, :label, :state, :ownerId, :profile, :datastreams
4
4
 
5
- def initialize(attr)
6
- self.datastreams = {}
7
- self.attributes = attr
8
- self.pid = attr[:pid]
5
+ def initialize(solr_doc)
6
+ @pid = solr_doc[SOLR_DOCUMENT_ID]
7
+ profile_attrs = solr_doc.keys.select { |k| k =~ /^objProfile_/ }
8
+ @profile = {}
9
+ profile_attrs.each do |key|
10
+ attr_name = key.split(/_/)[1..-2].join('_')
11
+ @profile[attr_name] = solr_doc[key].to_s
12
+ end
13
+ @profile['objCreateDate'] ||= Time.now.xmlschema
14
+ @profile['objLastModDate'] ||= @profile['objCreateDate']
15
+
16
+ @datastreams = {}
17
+ @label = @profile['objLabel']
18
+ @state = @profile['objState']
19
+ @ownerId = @profile['objOwnerId']
9
20
  end
10
21
 
22
+ def freeze
23
+ @profile.freeze
24
+ @datastreams.freeze
25
+ self
26
+ end
27
+
11
28
  def new?
12
29
  false
13
30
  end
14
31
 
15
- def profile
16
- attributes
17
- end
18
32
  end
19
33
  end
@@ -42,7 +42,7 @@ module ActiveFedora
42
42
  if opts[:load_from_solr]
43
43
  results << classname.load_instance_from_solr(hit[SOLR_DOCUMENT_ID])
44
44
  else
45
- results << ActiveFedora::RubydoraConnection.instance.find_model(hit[SOLR_DOCUMENT_ID], classname)
45
+ results << classname.find(hit[SOLR_DOCUMENT_ID])
46
46
  end
47
47
  end
48
48
  return results
@@ -32,10 +32,7 @@ module ActiveFedora
32
32
 
33
33
  def assign_pid
34
34
  return @pid if @pid
35
- args = {}
36
- args[:namespace] = self.namespace if self.namespace
37
- @pid = RubydoraConnection.instance.nextid args
38
- @pid
35
+ self.original_class.assign_pid(self)
39
36
  end
40
37
 
41
38
 
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "3.3.2"
2
+ VERSION = "4.0.0.rc1"
3
3
  end
@@ -19,7 +19,7 @@ namespace :repo do
19
19
  rescue Errno::ECONNREFUSED => e
20
20
  puts "Can't connect to Fedora! Are you sure jetty is running?"
21
21
  end
22
- puts "Deleted '#{pid}' from #{ActiveFedora.fedora_config[:url]}"
22
+ puts "Deleted '#{pid}' from #{ActiveFedora::Base.connection_for_pid(pid).client.url}"
23
23
  end
24
24
  end
25
25
 
@@ -40,7 +40,7 @@ namespace :repo do
40
40
  rescue ActiveFedora::ObjectNotFoundError
41
41
  # The object has already been deleted (or was never created). Do nothing.
42
42
  end
43
- puts "Deleted '#{pid}' from #{ActiveFedora.fedora_config[:url]}"
43
+ puts "Deleted '#{pid}' from #{ActiveFedora::Base.connection_for_pid(pid).client.url}"
44
44
  i += 1
45
45
  end
46
46
  end
@@ -51,7 +51,7 @@ namespace :repo do
51
51
  puts "You must specify a valid pid. Example: rake repo:export pid=demo:12"
52
52
  else
53
53
  pid = ENV["pid"]
54
- puts "Exporting '#{pid}' from #{ActiveFedora.fedora_config[:url]}"
54
+ puts "Exporting '#{pid}' from #{ActiveFedora::Base.connection_for_pid(pid).client.url}"
55
55
  if !ENV["path"].nil?
56
56
  path = ENV["path"]
57
57
  else
@@ -78,12 +78,12 @@ namespace :repo do
78
78
  end
79
79
 
80
80
  if !filename.nil?
81
- puts "Loading '#{filename}' in #{ActiveFedora.fedora_config[:url]}"
81
+ puts "Loading '#{filename}' in #{ActiveFedora::Base.connection_for_pid(pid).client.url}"
82
82
  file = File.new(filename, "r")
83
- result = ActiveFedora::RubydoraConnection.instance.connection.ingest(:file=>file.read)
83
+ result = ActiveFedora::Base.connection_for_pid(pid).ingest(:file=>file.read)
84
84
  if result
85
85
  puts "The object has been loaded as #{result.body}"
86
- if pid.nil?
86
+ if pid.nil?
87
87
  pid = result.body
88
88
  end
89
89
  solrizer = Solrizer::Fedora::Solrizer.new
@@ -82,7 +82,6 @@ desc 'Set up ActiveFedora environment. !! Only for use while working within a w
82
82
  task :environment do
83
83
  puts "Initializing ActiveFedora Rake environment. This should only be called when working within a workign copy of the active-fedora code."
84
84
  require "#{APP_ROOT}/spec/samples/models/hydrangea_article"
85
- require 'active_fedora/samples'
86
85
  end
87
86
 
88
87
  end
@@ -0,0 +1,6 @@
1
+ <info:fedora/test:1> <http://purl.org/dc/terms/created> "2010-12-31"^^<http://www.w3.org/2001/XMLSchema#date> .
2
+ <info:fedora/test:1> <http://purl.org/dc/terms/title> "Title of work" .
3
+ <info:fedora/test:1> <http://purl.org/dc/terms/publisher> "Penn State" .
4
+ <info:fedora/test:1> <http://xmlns.com/foaf/0.1/based_near> "New York, NY, US" .
5
+ <info:fedora/test:1> <http://www.w3.org/2000/01/rdf-schema#seeAlso> <http://google.com/> .
6
+
@@ -1,2 +1,4 @@
1
1
  test:
2
- url: http://fedoraAdmin:fedoraAdmin@testhost.com:8983/fedora
2
+ user: fedoraAdmin
3
+ password: fedoraAdmin
4
+ url: http://testhost.com:8983/fedora
@@ -0,0 +1,11 @@
1
+ test:
2
+ - user: fedoraAdmin
3
+ password: fedoraAdmin
4
+ url: http://127.0.0.1:8983/fedora1
5
+ - user: fedoraAdmin
6
+ password: fedoraAdmin
7
+ url: http://127.0.0.1:8983/fedora2
8
+ - user: fedoraAdmin
9
+ password: fedoraAdmin
10
+ url: http://127.0.0.1:8983/fedora3
11
+
@@ -3,18 +3,21 @@ require 'spec_helper'
3
3
  describe ActiveFedora::Base do
4
4
 
5
5
  before(:each) do
6
- @test_container = ActiveFedora::Base.new
6
+ class FileMgmt < ActiveFedora::Base
7
+ include ActiveFedora::FileManagement
8
+ end
9
+ @test_container = FileMgmt.new
7
10
  @test_container.add_relationship(:has_collection_member, "info:fedora/foo:2")
8
11
  @test_container.save
9
12
  end
10
13
 
11
14
  after(:each) do
12
15
  @test_container.delete
16
+ Object.send(:remove_const, :FileMgmt)
13
17
  end
14
18
 
15
19
  it "should persist and re-load collection members" do
16
- ActiveSupport::Deprecation.stubs(:warn)
17
- container_copy = ActiveFedora::Base.load_instance(@test_container.pid)
20
+ container_copy = FileMgmt.load_instance(@test_container.pid)
18
21
  container_copy.collection_members(:response_format=>:id_array).should == ["foo:2"]
19
22
  end
20
23
 
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require "active_fedora/samples"
3
2
 
4
3
  class MockAFBaseQuerySolr < ActiveFedora::Base
5
4
  has_metadata :name => "properties", :type => ActiveFedora::MetadataDatastream do |m|
@@ -24,29 +23,29 @@ describe ActiveFedora::Base do
24
23
  @test_object = ActiveFedora::Base.new
25
24
  #get objects into fedora and solr
26
25
  @test_object2 = MockAFBaseQuerySolr.new
27
- attributes = {"holding_id"=>{0=>"Holding 1"},
28
- "language"=>{0=>"Italian"},
29
- "creator"=>{0=>"Linguist, A."},
30
- "geography"=>{0=>"Italy"},
31
- "title"=>{0=>"Italian and Spanish: A Comparison of Common Phrases"}}
26
+ attributes = {[:holding_id]=>{0=>"Holding 1"},
27
+ [:language]=>{0=>"Italian"},
28
+ [:creator]=>{0=>"Linguist, A."},
29
+ [:geography]=>{0=>"Italy"},
30
+ [:title]=>{0=>"Italian and Spanish: A Comparison of Common Phrases"}}
32
31
  @test_object2.update_indexed_attributes(attributes)
33
32
  @test_object2.save
34
33
 
35
34
  @test_object3 = MockAFBaseQuerySolr.new
36
- attributes = {"holding_id"=>{0=>"Holding 2"},
37
- "language"=>{0=>"Spanish;Latin"},
38
- "creator"=>{0=>"Linguist, A."},
39
- "geography"=>{0=>"Spain"},
40
- "title"=>{0=>"A study of the evolution of Spanish from Latin"}}
35
+ attributes = {[:holding_id]=>{0=>"Holding 2"},
36
+ [:language]=>{0=>"Spanish;Latin"},
37
+ [:creator]=>{0=>"Linguist, A."},
38
+ [:geography]=>{0=>"Spain"},
39
+ [:title]=>{0=>"A study of the evolution of Spanish from Latin"}}
41
40
  @test_object3.update_indexed_attributes(attributes)
42
41
  @test_object3.save
43
42
 
44
43
  @test_object4 = MockAFBaseQuerySolr.new
45
- attributes = {"holding_id"=>{0=>"Holding 3"},
46
- "language"=>{0=>"Spanish;Latin"},
47
- "creator"=>{0=>"Linguist, A."},
48
- "geography"=>{0=>"Spain"},
49
- "title"=>{0=>"An obscure look into early nomadic tribes of Spain"}}
44
+ attributes = {[:holding_id]=>{0=>"Holding 3"},
45
+ [:language]=>{0=>"Spanish;Latin"},
46
+ [:creator]=>{0=>"Linguist, A."},
47
+ [:geography]=>{0=>"Spain"},
48
+ [:title]=>{0=>"An obscure look into early nomadic tribes of Spain"}}
50
49
  @test_object4.update_indexed_attributes(attributes)
51
50
  @test_object4.save
52
51
 
@@ -28,7 +28,6 @@ end
28
28
 
29
29
  describe ActiveFedora::Base do
30
30
  before :all do
31
- ActiveSupport::Deprecation.stubs(:warn).with("Deprecation: Relationships will not be included by default in the next version. To use has_relationship add 'include ActiveFedora::Relationships' to your model")
32
31
  class MockAFBaseRelationship < ActiveFedora::Base
33
32
  include ActiveFedora::FileManagement
34
33
  has_relationship "testing", :has_part, :type=>MockAFBaseRelationship
@@ -42,6 +41,7 @@ describe ActiveFedora::Base do
42
41
  end
43
42
 
44
43
  class MockAFBaseFromSolr < ActiveFedora::Base
44
+ include ActiveFedora::Relationships
45
45
  has_relationship "testing", :has_part, :type=>MockAFBaseFromSolr
46
46
  has_relationship "testing2", :has_member, :type=>MockAFBaseFromSolr
47
47
  has_relationship "testing_inbound", :has_part, :type=>MockAFBaseFromSolr, :inbound=>true
@@ -99,10 +99,19 @@ describe ActiveFedora::Base do
99
99
  @test_object.should have(0).errors
100
100
  @test_object.pid.should_not be_nil
101
101
  end
102
+ end
102
103
 
104
+ describe '.assign_pid' do
105
+ it "should get nextid" do
106
+ one = ActiveFedora::Base.assign_pid(ActiveFedora::UnsavedDigitalObject.new(ActiveFedora::Base, 'changeme'))
107
+ two = ActiveFedora::Base.assign_pid(ActiveFedora::UnsavedDigitalObject.new(ActiveFedora::Base, 'changeme'))
108
+ one = one.gsub('changeme:', '').to_i
109
+ two = two.gsub('changeme:', '').to_i
110
+ two.should == one + 1
111
+ end
103
112
  end
104
113
 
105
- describe ".save" do
114
+ describe "#save" do
106
115
  before(:each) do
107
116
  @test_object2 = ActiveFedora::Base.new
108
117
  end
@@ -661,180 +670,4 @@ describe ActiveFedora::Base do
661
670
 
662
671
  end
663
672
  end
664
-
665
- # describe '#load_instance_from_solr' do
666
- # it 'should populate an instance of an ActiveFedora::Base object using solr instead of Fedora' do
667
- #
668
- # @test_object2 = MockAFBaseFromSolr.new
669
- # # @test_object2.new_object = true
670
- # attributes = {"holding_id"=>{0=>"Holding 1"},
671
- # "language"=>{0=>"Italian"},
672
- # "creator"=>{0=>"Linguist, A."},
673
- # "geography"=>{0=>"Italy"},
674
- # "title"=>{0=>"Italian and Spanish: A Comparison of Common Phrases"}}
675
- # @test_object2.update_indexed_attributes(attributes)
676
- # @test_object2.save
677
- # @test_object3 = MockAFBaseFromSolr.new
678
- # # @test_object3.new_object = true
679
- # attributes = {"holding_id"=>{0=>"Holding 2"},
680
- # "language"=>{0=>"Spanish;Latin"},
681
- # "creator"=>{0=>"Linguist, A."},
682
- # "geography"=>{0=>"Spain"},
683
- # "title"=>{0=>"A study of the evolution of Spanish from Latin"}}
684
- # @test_object3.update_indexed_attributes(attributes)
685
- # @test_object3.save
686
- # @test_object4 = MockAFBaseFromSolr.new
687
- # attributes = {"holding_id"=>{0=>"Holding 3"},
688
- # "language"=>{0=>"Spanish;Latin"},
689
- # "creator"=>{0=>"Linguist, A."},
690
- # "geography"=>{0=>"Spain"},
691
- # "title"=>{0=>"An obscure look into early nomadic tribes of Spain"}}
692
- # @test_object4.update_indexed_attributes(attributes)
693
- # # @test_object4.new_object = true
694
- # @test_object4.save
695
- # @test_object5 = MockAFBaseFromSolr.new
696
- # # @test_object5.new_object = true
697
- # @test_object5.save
698
- #
699
- # #append to named relationship 'testing'
700
- # @test_object2.testing_append(@test_object3)
701
- # @test_object2.testing2_append(@test_object4)
702
- # @test_object5.testing_append(@test_object2)
703
- # @test_object5.testing2_append(@test_object3)
704
- # @test_object2.save
705
- # @test_object5.save
706
- # model_rel = MockAFBaseFromSolr.to_class_uri
707
- # #check inbound correct, testing goes to :has_part and testing2 goes to :has_member
708
- # test_from_solr_object2 = MockAFBaseFromSolr.load_instance_from_solr(@test_object2.pid)
709
- # test_from_solr_object3 = MockAFBaseFromSolr.load_instance_from_solr(@test_object3.pid)
710
- # test_from_solr_object4 = MockAFBaseFromSolr.load_instance_from_solr(@test_object4.pid)
711
- # test_from_solr_object5 = MockAFBaseFromSolr.load_instance_from_solr(@test_object5.pid)
712
- #
713
- # # need to check pid, system create and system modify
714
- # test_from_solr_object2.pid.should == @test_object2.pid
715
- # test_from_solr_object3.pid.should == @test_object3.pid
716
- # test_from_solr_object4.pid.should == @test_object4.pid
717
- # test_from_solr_object5.pid.should == @test_object5.pid
718
- #
719
- # Time.parse(test_from_solr_object2.create_date).should == Time.parse(@test_object2.create_date)
720
- # Time.parse(test_from_solr_object3.create_date).should == Time.parse(@test_object3.create_date)
721
- # Time.parse(test_from_solr_object4.create_date).should == Time.parse(@test_object4.create_date)
722
- # Time.parse(test_from_solr_object5.create_date).should == Time.parse(@test_object5.create_date)
723
- #
724
- # Time.parse(test_from_solr_object2.modified_date).should == Time.parse(@test_object2.modified_date)
725
- # Time.parse(test_from_solr_object3.modified_date).should == Time.parse(@test_object3.modified_date)
726
- # Time.parse(test_from_solr_object4.modified_date).should == Time.parse(@test_object4.modified_date)
727
- # Time.parse(test_from_solr_object5.modified_date).should == Time.parse(@test_object5.modified_date)
728
- #
729
- # # need to test outbound and inbound relationships
730
- # test_from_solr_object2.relationships(false).should == {:self=>{:has_model=>[model_rel],
731
- # :has_part=>[@test_object3],
732
- # :has_member=>[@test_object4]},
733
- # :inbound=>{:has_part=>[@test_object5]}}
734
- # test_from_solr_object2.relationships_by_name(false).should == {:self=>{"testing"=>[@test_object3],"testing2"=>[@test_object4],
735
- # "collection_members"=>[],"part_of"=>[],"parts_outbound"=>[@test_object3]},
736
- # :inbound=>{"testing_inbound"=>[@test_object5],"testing_inbound2"=>[],"parts_inbound"=>[]}}
737
- # test_from_solr_object3.relationships(false).should == {:self=>{:has_model=>[model_rel]},
738
- # :inbound=>{:has_part=>[@test_object2],
739
- # :has_member=>[@test_object5]}}
740
- # test_from_solr_object3.relationships_by_name(false).should == {:self=>{"testing"=>[],"testing2"=>[], "collection_members"=>[],"part_of"=>[],"parts_outbound"=>[]},
741
- # :inbound=>{"testing_inbound"=>[@test_object2],"testing_inbound2"=>[@test_object5], "parts_inbound"=>[]}}
742
- # test_from_solr_object4.relationships(false).should == {:self=>{:has_model=>[model_rel]},
743
- # :inbound=>{:has_member=>[@test_object2]}}
744
- # test_from_solr_object4.relationships_by_name(false).should == {:inbound=>{"parts_inbound"=>[], "testing_inbound"=>[], "testing_inbound2"=>[@test_object2]}, :self=>{"testing2"=>[], "collection_members"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[]}}
745
- # test_from_solr_object5.relationships(false).should == {:self=>{:has_model=>[model_rel],
746
- # :has_part=>[@test_object2],
747
- # :has_member=>[@test_object3]},
748
- # :inbound=>{}}
749
- # test_from_solr_object5.relationships_by_name(false).should == {:inbound=>{"parts_inbound"=>[], "testing_inbound"=>[], "testing_inbound2"=>[]}, :self=>{"testing2"=>[@test_object3], "collection_members"=>[], "part_of"=>[], "testing"=>[@test_object2], "parts_outbound"=>[@test_object2]}}
750
- # #all inbound should now be empty if no parameter supplied to relationships
751
- # test_from_solr_object2.relationships.should == {:self=>{:has_part=>[@test_object3],:has_member=>[@test_object4],:has_model=>[model_rel]}}
752
- # test_from_solr_object2.relationships_by_name.should == {:self=>{"testing2"=>[@test_object4], "collection_members"=>[], "part_of"=>[], "testing"=>[@test_object3], "parts_outbound"=>[@test_object3]}}
753
- # test_from_solr_object3.relationships.should == {:self=>{:has_model=>[model_rel]}}
754
- # test_from_solr_object3.relationships_by_name.should == {:self=>{"testing2"=>[], "collection_members"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[]}}
755
- # test_from_solr_object4.relationships.should == {:self=>{:has_model=>[model_rel]}}
756
- # test_from_solr_object4.relationships_by_name.should == {:self=>{"testing2"=>[], "collection_members"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[]}}
757
- # test_from_solr_object5.relationships.should == {:self=>{:has_model=>[model_rel],
758
- # :has_part=>[@test_object2],
759
- # :has_member=>[@test_object3]}}
760
- # test_from_solr_object5.relationships_by_name.should == {:self=>{"testing2"=>[@test_object3], "collection_members"=>[], "part_of"=>[], "testing"=>[@test_object2], "parts_outbound"=>[@test_object2]}}
761
- # # need to check metadata
762
- # test_from_solr_object2.fields[:language][:values].should == ["Italian"]
763
- # test_from_solr_object2.fields[:creator][:values].should == ["Linguist, A."]
764
- # test_from_solr_object2.fields[:geography][:values].should == ["Italy"]
765
- # test_from_solr_object2.fields[:title][:values].should == ["Italian and Spanish: A Comparison of Common Phrases"]
766
- # test_from_solr_object2.fields[:holding_id][:values].should == ["Holding 1"]
767
- #
768
- # test_from_solr_object3.fields[:language][:values].should == ["Spanish;Latin"]
769
- # test_from_solr_object3.fields[:creator][:values].should == ["Linguist, A."]
770
- # test_from_solr_object3.fields[:geography][:values].should == ["Spain"]
771
- # test_from_solr_object3.fields[:title][:values].should == ["A study of the evolution of Spanish from Latin"]
772
- # test_from_solr_object3.fields[:holding_id][:values].should == ["Holding 2"]
773
- #
774
- # test_from_solr_object4.fields[:language][:values].should == ["Spanish;Latin"]
775
- # test_from_solr_object4.fields[:creator][:values].should == ["Linguist, A."]
776
- # test_from_solr_object4.fields[:geography][:values].should == ["Spain"]
777
- # test_from_solr_object4.fields[:title][:values].should == ["An obscure look into early nomadic tribes of Spain"]
778
- # test_from_solr_object4.fields[:holding_id][:values].should == ["Holding 3"]
779
- #
780
- # #need to check system modified and system created values correct
781
- # # need to implement for nokogiri datastream as well
782
- # #false.should == true
783
- # end
784
- # end
785
- #
786
- # describe 'load_from_solr using relationship finders'
787
- # it 'resulting finder should accept :load_from_solr as :response_format and return object instantiated using load_instance_from_solr' do
788
- # # solr_result = mock("solr result")
789
- # # SpecNode.create_inbound_relationship_finders("constituents", :is_constituent_of, :inbound => true)
790
- # # local_node = SpecNode.new
791
- # # mock_repo = mock("repo")
792
- # # mock_repo.expects(:find_model).never
793
- # # SpecNode.expects(:load_instance_from_solr).times(1)
794
- # # local_node.expects(:internal_uri).returns("info:fedora/test:sample_pid")
795
- # # ActiveFedora::SolrService.instance.conn.expects(:query).with("is_constituent_of_s:info\\:fedora/test\\:sample_pid").returns(solr_result)
796
- # # local_node.constituents(:response_format => :solr).should equal(solr_result)
797
- # end
798
- #
799
- # it 'when an object is loaded via solr instead of fedora it should automatically load objects from finders from solr as well' do
800
- # @test_object2 = MockAFBaseFromSolr.new
801
- # @test_object2.save
802
- # @test_object3 = MockAFBaseFromSolr.new
803
- # @test_object3.save
804
- # @test_object2.testing_append(@test_object3)
805
- # @test_object2.save
806
- #
807
- # test_object2_from_solr = MockAFBaseFromSolr.load_instance_from_solr(@test_object2.pid)
808
- # test_object3_from_solr = MockAFBaseFromSolr.load_instance_from_solr(@test_object3.pid)
809
- # MockAFBaseFromSolr.expects(:load_instance_from_solr).times(4)
810
- # test_object2_from_solr.testing({:response_format=>:load_from_solr})
811
- # test_object3_from_solr.testing_inbound({:response_format=>:load_from_solr})
812
- # test_object2_from_solr.testing
813
- # test_object3_from_solr.testing_inbound
814
- # end
815
- #
816
- # it 'when a load_from_solr is not set it should not call load_instance_from_solr for finders unless passing option in' do
817
- # @test_object2 = MockAFBaseFromSolr.new
818
- # @test_object2.save
819
- # @test_object3 = MockAFBaseFromSolr.new
820
- # @test_object3.save
821
- # @test_object2.testing_append(@test_object3)
822
- # @test_object2.save
823
- #
824
- # MockAFBaseFromSolr.expects(:load_instance_from_solr).never()
825
- # @test_object2.testing
826
- # @test_object3.testing_inbound
827
- #
828
- # #now try calling with option
829
- # MockAFBaseFromSolr.expects(:load_instance_from_solr).twice()
830
- # @test_object2.testing({:response_format=>:load_from_solr})
831
- # @test_object3.testing_inbound({:response_format=>:load_from_solr})
832
- #
833
- # #now call other finder method
834
- # MockAFBaseFromSolr.expects(:load_instance_from_solr).twice()
835
- # @test_object2.testing_from_solr
836
- # @test_object3.testing_inbound_from_solr
837
- #
838
- # end
839
-
840
673
  end