active-fedora 3.0.7 → 3.1.0.pre1

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.
Files changed (67) hide show
  1. data/.rvmrc +1 -1
  2. data/Gemfile.lock +39 -10
  3. data/History.txt +0 -4
  4. data/active-fedora.gemspec +4 -3
  5. data/lib/active_fedora.rb +9 -9
  6. data/lib/active_fedora/base.rb +92 -163
  7. data/lib/active_fedora/datastream.rb +59 -60
  8. data/lib/active_fedora/datastream_hash.rb +18 -0
  9. data/lib/active_fedora/metadata_datastream.rb +3 -2
  10. data/lib/active_fedora/metadata_datastream_helper.rb +3 -15
  11. data/lib/active_fedora/model.rb +3 -3
  12. data/lib/active_fedora/nokogiri_datastream.rb +305 -302
  13. data/lib/active_fedora/qualified_dublin_core_datastream.rb +24 -19
  14. data/lib/active_fedora/rels_ext_datastream.rb +39 -37
  15. data/lib/active_fedora/rubydora_connection.rb +40 -0
  16. data/lib/active_fedora/semantic_node.rb +1 -1
  17. data/lib/active_fedora/solr_service.rb +1 -1
  18. data/lib/active_fedora/version.rb +1 -1
  19. data/lib/ruby-fedora.rb +0 -8
  20. data/lib/tasks/active_fedora.rake +14 -9
  21. data/lib/tasks/active_fedora_dev.rake +23 -40
  22. data/spec/integration/base_loader_spec.rb +4 -21
  23. data/spec/integration/base_spec.rb +300 -310
  24. data/spec/integration/bug_spec.rb +9 -10
  25. data/spec/integration/datastream_spec.rb +12 -12
  26. data/spec/integration/metadata_datastream_helper_spec.rb +7 -10
  27. data/spec/integration/model_spec.rb +3 -2
  28. data/spec/integration/rels_ext_datastream_spec.rb +9 -15
  29. data/spec/spec_helper.rb +2 -29
  30. data/spec/unit/active_fedora_spec.rb +5 -5
  31. data/spec/unit/base_cma_spec.rb +0 -7
  32. data/spec/unit/base_datastream_management_spec.rb +8 -67
  33. data/spec/unit/base_delegate_spec.rb +26 -9
  34. data/spec/unit/base_extra_spec.rb +5 -3
  35. data/spec/unit/base_file_management_spec.rb +10 -17
  36. data/spec/unit/base_named_datastream_spec.rb +76 -199
  37. data/spec/unit/base_spec.rb +152 -69
  38. data/spec/unit/content_model_spec.rb +1 -1
  39. data/spec/unit/datastream_concurrency_spec.rb +5 -4
  40. data/spec/unit/datastream_spec.rb +28 -48
  41. data/spec/unit/has_many_collection_spec.rb +2 -0
  42. data/spec/unit/inheritance_spec.rb +6 -6
  43. data/spec/unit/metadata_datastream_spec.rb +12 -28
  44. data/spec/unit/model_spec.rb +10 -10
  45. data/spec/unit/nokogiri_datastream_spec.rb +31 -33
  46. data/spec/unit/qualified_dublin_core_datastream_spec.rb +15 -15
  47. data/spec/unit/rels_ext_datastream_spec.rb +35 -29
  48. data/spec/unit/rubydora_connection_spec.rb +26 -0
  49. data/spec/unit/semantic_node_spec.rb +12 -17
  50. data/spec/unit/solr_config_options_spec.rb +13 -14
  51. data/spec/unit/solr_service_spec.rb +14 -17
  52. metadata +59 -55
  53. data/lib/fedora/base.rb +0 -38
  54. data/lib/fedora/connection.rb +0 -218
  55. data/lib/fedora/datastream.rb +0 -67
  56. data/lib/fedora/fedora_object.rb +0 -161
  57. data/lib/fedora/formats.rb +0 -30
  58. data/lib/fedora/generic_search.rb +0 -71
  59. data/lib/fedora/repository.rb +0 -298
  60. data/spec/integration/datastreams_crud_spec.rb +0 -208
  61. data/spec/integration/fedora_object_spec.rb +0 -77
  62. data/spec/integration/repository_spec.rb +0 -301
  63. data/spec/integration/rf_fedora_object_spec.rb +0 -95
  64. data/spec/unit/connection_spec.rb +0 -25
  65. data/spec/unit/fedora_object_spec.rb +0 -74
  66. data/spec/unit/repository_spec.rb +0 -143
  67. data/spec/unit/rf_datastream_spec.rb +0 -63
@@ -15,37 +15,42 @@ module ActiveFedora
15
15
 
16
16
  #Constructor. this class will call self.field for each DCTERM. In short, all DCTERMS fields will already exist
17
17
  #when this method returns. Each term is marked as a multivalue string.
18
- def initialize(attrs=nil)
19
- super
18
+ def initialize(digital_object, dsid, exists_in_fedora=false )
19
+ super(digital_object, dsid)
20
20
  DCTERMS.each do |el|
21
21
  field el, :string, :multiple=>true
22
22
  end
23
+ ###TODO this is loading eagerly, but we could make it lazy
24
+ self.class.from_xml(exists_in_fedora ? content : nil, self)
23
25
  self
24
26
  end
25
27
 
26
- def set_blob_for_save # :nodoc:
27
- self.blob = self.to_dc_xml
28
- end
29
-
30
28
  # Populate a QualifiedDublinCoreDatastream object based on the "datastream" node from a FOXML file
29
+ # @param [String] node the xml from the content. Assumes that the content of this datastream is that of an ActiveFedora QualifiedDublinCoreDatastream
31
30
  # @param [ActiveFedora::Datastream] tmpl the Datastream object that you are building
32
- # @param [Nokogiri::XML::Node] node the "foxml:datastream" node from a FOXML file. Assumes that the content of this datastream is that of an ActiveFedora QualifiedDublinCoreDatastream
33
- def self.from_xml(tmpl, node) # :nodoc:
34
- tmpl.fields.each do |z|
35
- fname = z.first
36
- fspec = z.last
37
- node_name = "dcterms:#{fspec[:xml_node] ? fspec[:xml_node] : fname}"
38
- attr_modifier= "[@xsi:type='#{fspec[:encoding]}']" if fspec[:encoding]
39
- query = "./foxml:datastreamVersion[last()]/foxml:xmlContent/dc/#{node_name}#{attr_modifier}"
40
- node.xpath(query, {"foxml"=>"info:fedora/fedora-system:def/foxml#", "dcterms"=>'http://purl.org/dc/terms/', "xsi"=>'http://www.w3.org/2001/XMLSchema-instance'}).each do |f|
41
- tmpl.send("#{fname}_append", f.text)
31
+ def self.from_xml(xml, tmpl) # :nodoc:
32
+ return if xml.nil?
33
+ node = Nokogiri::XML::Document.parse(xml)
34
+ tmpl.fields.each do |z|
35
+ fname = z.first
36
+ fspec = z.last
37
+ node_name = "dcterms:#{fspec[:xml_node] ? fspec[:xml_node] : fname}"
38
+ attr_modifier= "[@xsi:type='#{fspec[:encoding]}']" if fspec[:encoding]
39
+ query = "/dc/#{node_name}#{attr_modifier}"
40
+
41
+ node.xpath(query).each do |f|
42
+ tmpl.send("#{fname}_append", f.text)
42
43
  end
43
44
 
44
- end
45
- tmpl.instance_variable_set(:@dirty, false)
46
- tmpl
45
+ end
46
+ tmpl.instance_variable_set(:@dirty, false)
47
+ tmpl
47
48
  end
48
49
 
50
+ def to_xml()
51
+ to_dc_xml()
52
+ end
53
+
49
54
  #Render self as a Fedora DC xml document.
50
55
  def to_dc_xml
51
56
  #TODO: pull the modifiers up into MDDS
@@ -1,3 +1,4 @@
1
+ require 'active_support/core_ext/class/inheritable_attributes'
1
2
  require 'solrizer/field_name_mapper'
2
3
  require 'uri'
3
4
 
@@ -8,50 +9,51 @@ module ActiveFedora
8
9
  include Solrizer::FieldNameMapper
9
10
 
10
11
 
11
- def initialize(attrs=nil)
12
- super
13
- self.dsid = "RELS-EXT"
12
+ # def initialize(digital_object, dsid, exists_in_fedora=nil)
13
+ # super(digital_object, 'RELS-EXT')
14
+ # end
15
+
16
+ def changed?
17
+ relationships_are_dirty || super
18
+ end
19
+
20
+ def serialize!
21
+ self.content = to_rels_ext(self.pid) if relationships_are_dirty
22
+ relationships_are_dirty = false
14
23
  end
15
24
 
16
- def save
17
- if @dirty == true
18
- self.content = to_rels_ext(self.pid)
19
- end
20
- super
25
+
26
+ def to_xml(fields_xml)
27
+ to_rels_ext(self.pid)
21
28
  end
22
29
 
23
- def pid=(pid)
24
- super
25
- self.blob = <<-EOL
26
- <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
27
- <rdf:Description rdf:about="info:fedora/#{pid}">
28
- </rdf:Description>
29
- </rdf:RDF>
30
- EOL
31
- end
32
-
33
- # Populate a RelsExtDatastream object based on the "datastream" node from a FOXML file
30
+ # Populate a RelsExtDatastream object based on the "datastream" content
34
31
  # Assumes that the datastream contains RDF XML from a Fedora RELS-EXT datastream
35
32
  # @param [ActiveFedora::MetadataDatastream] tmpl the Datastream object that you are populating
36
- # @param [Nokogiri::XML::Node] node the "foxml:datastream" node from a FOXML file
37
- def self.from_xml(tmpl, node)
38
- # node.xpath("./foxml:datastreamVersion[last()]/foxml:xmlContent/rdf:RDF/rdf:Description/*").each do |f|
39
- node.xpath("./foxml:datastreamVersion[last()]/foxml:xmlContent/rdf:RDF/rdf:Description/*", {"rdf"=>"http://www.w3.org/1999/02/22-rdf-syntax-ns#", "foxml"=>"info:fedora/fedora-system:def/foxml#"}).each do |f|
40
- if f.namespace
41
- ns_mapping = self.predicate_mappings[f.namespace.href]
42
- predicate = ns_mapping ? ns_mapping.invert[f.name] : nil
43
- predicate = "#{f.namespace.prefix}_#{f.name}" if predicate.nil?
44
- else
45
- logger.warn "You have a predicate without a namespace #{f.name}. Verify your rels-ext is correct."
46
- predicate = "#{f.name}"
47
- end
48
- is_obj = f["resource"]
49
- object = is_obj ? f["resource"] : f.inner_text
50
- r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>predicate, :object=>object, :is_literal=>!is_obj)
51
- tmpl.add_relationship(r)
33
+ # @param [String] the "rdf" node
34
+ def self.from_xml(xml, tmpl)
35
+ if (xml.nil?)
36
+ ### maybe put the template here?
37
+ else
38
+ node = Nokogiri::XML::Document.parse(xml)
39
+ node.xpath("rdf:RDF/rdf:Description/*", {"rdf"=>"http://www.w3.org/1999/02/22-rdf-syntax-ns#"}).each do |f|
40
+ if f.namespace
41
+ ns_mapping = self.predicate_mappings[f.namespace.href]
42
+ predicate = ns_mapping ? ns_mapping.invert[f.name] : nil
43
+ predicate = "#{f.namespace.prefix}_#{f.name}" if predicate.nil?
44
+ else
45
+ logger.warn "You have a predicate without a namespace #{f.name}. Verify your rels-ext is correct."
46
+ predicate = "#{f.name}"
47
+ end
48
+ is_obj = f["resource"]
49
+ object = is_obj ? f["resource"] : f.inner_text
50
+ r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>predicate, :object=>object, :is_literal=>!is_obj)
51
+ tmpl.add_relationship(r)
52
+ end
53
+ tmpl.relationships_are_dirty = false
54
+ #tmpl.send(:dirty=, false)
55
+ tmpl
52
56
  end
53
- tmpl.send(:dirty=, false)
54
- tmpl
55
57
  end
56
58
 
57
59
  # Serialize the datastream's RDF relationships to solr
@@ -0,0 +1,40 @@
1
+ require 'singleton'
2
+ require 'rubydora'
3
+
4
+ module ActiveFedora
5
+ class RubydoraConnection
6
+ include Singleton
7
+
8
+ attr_reader :connection
9
+ attr_accessor :options
10
+
11
+ def self.connect(params={})
12
+ if params.kind_of? String
13
+ u = URI.parse params
14
+ params = {}
15
+ params[:user] = u.user
16
+ params[:password] = u.password
17
+ params[:url] = "#{u.scheme}://#{u.host}:#{u.port}#{u.path}"
18
+ end
19
+ instance = self.instance
20
+ instance.options = params
21
+ instance.connect
22
+ instance
23
+ end
24
+
25
+ def connect()
26
+ return unless @connection.nil?
27
+ @connection = Rubydora.connect :url => options[:url], :user => options[:user], :password => options[:password]
28
+ end
29
+
30
+ def nextid(attrs={})
31
+ d = REXML::Document.new(connection.next_pid(:namespace=>attrs[:namespace]))
32
+ d.elements['//pid'].text
33
+ end
34
+
35
+ def find_model(pid, klass)
36
+ klass.new(:pid=>pid)
37
+ end
38
+
39
+ end
40
+ end
@@ -16,11 +16,11 @@ module ActiveFedora
16
16
  def add_relationship(relationship)
17
17
  # Only accept ActiveFedora::Relationships as input arguments
18
18
  assert_kind_of 'relationship', relationship, ActiveFedora::Relationship
19
- self.relationships_are_dirty = true
20
19
  register_triple(relationship.subject, relationship.predicate, relationship.object)
21
20
  end
22
21
 
23
22
  def register_triple(subject, predicate, object)
23
+ self.relationships_are_dirty = true
24
24
  register_subject(subject)
25
25
  register_predicate(subject, predicate)
26
26
  relationships[subject][predicate] << object
@@ -36,7 +36,7 @@ module ActiveFedora
36
36
  if opts[:load_from_solr]
37
37
  results << classname.load_instance_from_solr(hit[SOLR_DOCUMENT_ID])
38
38
  else
39
- results << Fedora::Repository.instance.find_model(hit[SOLR_DOCUMENT_ID], classname)
39
+ results << ActiveFedora::RubydoraConnection.instance.find_model(hit[SOLR_DOCUMENT_ID], classname)
40
40
  end
41
41
  end
42
42
  return results
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "3.0.7"
2
+ VERSION = "3.1.0.pre1"
3
3
  end
@@ -10,11 +10,3 @@ class Hash
10
10
  self.each {|k,v| self[k.to_sym]=v; self.delete(k) unless self[k.to_sym]}
11
11
  end
12
12
  end
13
- require 'fedora/base'
14
- require 'fedora/connection'
15
- require 'fedora/datastream'
16
- require 'fedora/fedora_object'
17
- require 'fedora/formats'
18
- require 'fedora/generic_search'
19
- require 'fedora/repository'
20
- #require 'util/class_level_inheritable_attributes'
@@ -19,17 +19,15 @@ namespace :af do
19
19
  puts "You must specify a valid pid. Example: rake fedora:delete pid=demo:12"
20
20
  else
21
21
  pid = ENV["pid"]
22
- puts "Deleting '#{pid}' from #{Fedora::Repository.instance.fedora_url}"
22
+ puts "Deleting '#{pid}' from #{ActiveFedora::RubydoraConnection.instance.options[:url]}"
23
23
  begin
24
24
  ActiveFedora::Base.load_instance(pid).delete
25
25
  rescue ActiveFedora::ObjectNotFoundError
26
26
  puts "The object #{pid} has already been deleted (or was never created)."
27
27
  rescue Errno::ECONNREFUSED => e
28
28
  puts "Can't connect to Fedora! Are you sure jetty is running?"
29
- rescue Fedora::ServerError => e
30
- logger.error("Received a Fedora error while deleting #{pid}")
31
29
  end
32
- logger.info "Deleted '#{pid}' from #{Fedora::Repository.instance.fedora_url}"
30
+ logger.info "Deleted '#{pid}' from #{ActiveFedora::RubydoraConnection.instance.options[:url]}"
33
31
  end
34
32
  end
35
33
 
@@ -53,7 +51,7 @@ namespace :af do
53
51
  rescue ActiveFedora::ObjectNotFoundError
54
52
  # The object has already been deleted (or was never created). Do nothing.
55
53
  end
56
- puts "Deleted '#{pid}' from #{Fedora::Repository.instance.fedora_url}"
54
+ puts "Deleted '#{pid}' from #{ActiveFedora::RubydoraConnection.instance.options[:url]}"
57
55
  i += 1
58
56
  end
59
57
  end
@@ -63,14 +61,18 @@ namespace :af do
63
61
 
64
62
  # If a source url has been provided, attampt to export from the fedora repository there.
65
63
  if ENV["source"]
66
- Fedora::Repository.register(ENV["source"])
64
+ #FIXME
65
+ raise "Not Implemented"
66
+ #Fedora::Repository.register(ENV["source"])
67
67
  end
68
68
 
69
69
  if ENV["pid"].nil?
70
70
  puts "You must specify a valid pid. Example: rake fedora:harvest_fixture pid=demo:12"
71
71
  else
72
72
  pid = ENV["pid"]
73
- puts "Exporting '#{pid}' from #{Fedora::Repository.instance.fedora_url}"
73
+ puts "Exporting '#{pid}' from #{ActiveFedora::RubydoraConnection.instance.options[:url]}"
74
+ #FIXME
75
+ raise "Not Implemented"
74
76
  foxml = Fedora::Repository.instance.export(pid)
75
77
  filename = File.join("spec","fixtures","#{pid.gsub(":","_")}.foxml.xml")
76
78
  file = File.new(filename,"w")
@@ -84,6 +86,8 @@ namespace :af do
84
86
 
85
87
  # If a destination url has been provided, attampt to export from the fedora repository there.
86
88
  if ENV["destination"]
89
+ #FIXME
90
+ raise "Not Implemented"
87
91
  Fedora::Repository.register(ENV["destination"])
88
92
  end
89
93
 
@@ -97,9 +101,10 @@ namespace :af do
97
101
  end
98
102
 
99
103
  if !filename.nil?
100
- puts "Importing '#{filename}' to #{Fedora::Repository.instance.fedora_url}"
104
+ puts "Importing '#{filename}' to #{ActiveFedora::RubydoraConnection.instance.options[:url]}"
101
105
  file = File.new(filename, "r")
102
- result = foxml = Fedora::Repository.instance.ingest(file.read)
106
+ result = foxml = ActiveFedora::RubydoraConnection.instance.connection.ingest(:file=>file.read)
107
+ # result = foxml = Fedora::Repository.instance.ingest(file.read)
103
108
  if result
104
109
  puts "The fixture has been ingested as #{result.body}"
105
110
  if !pid.nil?
@@ -14,18 +14,21 @@ EOS
14
14
  exit(0)
15
15
  end
16
16
 
17
+ APP_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../")
18
+ require 'jettywrapper'
19
+
17
20
  $: << 'lib'
18
- def jetty_params
19
- project_root = File.expand_path("#{File.dirname(__FILE__)}/../../")
20
- {
21
- :quiet => false,
22
- :jetty_home => File.join(project_root,'jetty'),
23
- :jetty_port => 8983,
24
- :solr_home => File.expand_path(File.join(project_root,'jetty','solr')),
25
- :fedora_home => File.expand_path(File.join(project_root,'jetty','fedora','default')),
26
- :startup_wait=>30
27
- }
28
- end
21
+ # def jetty_params
22
+ # project_root = File.expand_path("#{File.dirname(__FILE__)}/../../")
23
+ # {
24
+ # :quiet => false,
25
+ # :jetty_home => File.join(project_root,'jetty'),
26
+ # :jetty_port => 8983,
27
+ # :solr_home => File.expand_path(File.join(project_root,'jetty','solr')),
28
+ # :fedora_home => File.expand_path(File.join(project_root,'jetty','fedora','default')),
29
+ # :startup_wait=>30
30
+ # }
31
+ # end
29
32
 
30
33
  desc "Run active-fedora rspec tests"
31
34
  task :spec do
@@ -34,21 +37,17 @@ end
34
37
 
35
38
  desc "Hudson build"
36
39
  task :hudson do
37
- require 'jettywrapper'
38
40
 
39
- if (ENV['environment'] == "test")
40
- Rake::Task["active_fedora:doc"].invoke
41
- Rake::Task["active_fedora:configure_jetty"].invoke
42
- error = Jettywrapper.wrap(jetty_params) do
43
- ENV["FEDORA_HOME"]=File.expand_path(File.join(File.dirname(__FILE__),'..','..','jetty','fedora','default'))
44
- Rake::Task["active_fedora:load_fixtures"].invoke
45
- Rake::Task["active_fedora:rspec"].invoke
46
- end
47
- raise "test failures: #{error}" if error
48
- else
49
- system("rake hudson environment=test")
50
- fail unless $?.success?
41
+ ENV['environment'] = "test"
42
+ Rake::Task["active_fedora:doc"].invoke
43
+ Rake::Task["active_fedora:configure_jetty"].invoke
44
+ jetty_params = Jettywrapper.load_config
45
+ error = Jettywrapper.wrap(jetty_params) do
46
+ ENV["FEDORA_HOME"]=File.expand_path(File.join(File.dirname(__FILE__),'..','..','jetty','fedora','default'))
47
+ Rake::Task["active_fedora:load_fixtures"].invoke
48
+ Rake::Task["active_fedora:rspec"].invoke
51
49
  end
50
+ raise "test failures: #{error}" if error
52
51
  end
53
52
 
54
53
  namespace :active_fedora do
@@ -115,20 +114,6 @@ namespace :active_fedora do
115
114
  cp("#{f}", 'jetty/solr/test-core/conf/', :verbose => true)
116
115
  end
117
116
  end
118
-
119
- namespace :jetty do
120
- desc "start jetty"
121
- task :start do
122
- require 'jettywrapper'
123
- Jettywrapper.start(jetty_params)
124
- end
125
- desc "stop jetty"
126
- task :stop do
127
- require 'jettywrapper'
128
- Jettywrapper.stop(jetty_params)
129
- end
130
- end
131
-
132
117
  end
133
118
 
134
119
  # Provides an :environment task for use while working within a working copy of active-fedora
@@ -138,6 +123,4 @@ task :environment do
138
123
  puts "Initializing ActiveFedora Rake environment. This should only be called when working within a workign copy of the active-fedora code."
139
124
  require 'spec/samples/models/hydrangea_article'
140
125
  require 'active_fedora/samples'
141
- # $:.unshift(File.dirname(__FILE__) + '/../lib')
142
- # Dir[File.join(File.dirname(__FILE__)+'/../lib/')+'**/*.rb'].each{|x| require x}
143
126
  end
@@ -24,22 +24,6 @@ describe ActiveFedora::Base do
24
24
  @test_object.delete
25
25
  end
26
26
 
27
- describe "deserialize" do
28
- it "should return an object whose inner_object is not marked as new. The datastreams should only be marked new if the model expects a datastream that doesn't exist yet in fedora" do
29
- #mocko = mock("object")
30
- #ActiveFedora::Base.expects(:new).returns(mocko)
31
- @test_object.datastreams["sensitive_passages"].delete
32
- doc = Nokogiri::XML::Document.parse(@test_object.inner_object.object_xml)
33
- result = OralHistorySampleModel.deserialize(doc)
34
- result.new_object?.should be_false
35
- result.datastreams_in_memory.should have_key("dublin_core")
36
- result.datastreams_in_memory.should have_key("properties")
37
- result.datastreams_in_memory.each do |name,ds|
38
- ds.new_object?.should be_false unless name == "sensitive_passages"
39
- end
40
- result.datastreams_in_memory["sensitive_passages"].new_object?.should be_true
41
- end
42
- end
43
27
  describe "load_instance" do
44
28
  it "should retain all datastream attributes pulled from fedora" do
45
29
  # raw_object = Fedora::Repository.instance.find_objects("pid=#{@test_object.pid}").first
@@ -48,12 +32,11 @@ describe ActiveFedora::Base do
48
32
  raw_datastreams = raw_object.datastreams
49
33
  loaded_datastreams = loaded.datastreams
50
34
  raw_datastreams.each_pair do |k,v|
51
- v.attributes.each_pair do |attr_name, attr_value|
52
- loaded_datastreams[k].attributes.should have_key(attr_name)
53
- loaded_datastreams[k].attributes[attr_name].should == attr_value
54
- end
35
+ v.dsid.should == loaded_datastreams[k].dsid
36
+ v.dsLabel.should == loaded_datastreams[k].dsLabel
37
+ v.mimeType.should == loaded_datastreams[k].mimeType
55
38
  end
56
39
  end
57
40
  end
58
41
 
59
- end
42
+ end
@@ -95,20 +95,19 @@ describe ActiveFedora::Base do
95
95
 
96
96
  it "should set the CMA hasModel relationship in the Rels-EXT" do
97
97
  @test_object2.save
98
- rexml = REXML::Document.new(@test_object.datastreams_in_fedora["RELS-EXT"].content)
98
+ rexml = REXML::Document.new(@test_object2.datastreams["RELS-EXT"].content)
99
99
  # Purpose: confirm that the isMemberOf entries exist and have real RDF in them
100
100
  rexml.root.elements["rdf:Description/hasModel"].attributes["rdf:resource"].should == 'info:fedora/afmodel:ActiveFedora_Base'
101
101
  end
102
102
  it "should merge attributes from fedora into attributes hash" do
103
103
  inner_object = @test_object2.inner_object
104
- inner_object.attributes.should == {:pid=>@test_object2.pid}
104
+ inner_object.pid.should == @test_object2.pid
105
105
  @test_object2.save
106
- inner_object.attributes.should have_key(:state)
107
- inner_object.attributes.should have_key(:create_date)
108
- inner_object.attributes.should have_key(:modified_date)
109
- inner_object.attributes.should have_key(:owner_id)
106
+ inner_object.should respond_to(:state)
107
+ inner_object.should respond_to(:lastModifiedDate)
108
+ inner_object.should respond_to(:ownerId)
110
109
  inner_object.state.should == "A"
111
- inner_object.owner_id.should == "fedoraAdmin"
110
+ inner_object.ownerId.should == "fedoraAdmin"
112
111
  end
113
112
  end
114
113
 
@@ -119,19 +118,19 @@ describe ActiveFedora::Base do
119
118
  end
120
119
  end
121
120
 
122
- describe ".datastreams_in_fedora" do
121
+ describe ".datastreams" do
123
122
  it "should return a Hash of datastreams from fedora" do
124
- datastreams = @test_object.datastreams_in_fedora
125
- datastreams.should be_an_instance_of(Hash)
123
+ datastreams = @test_object.datastreams
124
+ datastreams.should be_a_kind_of(Hash)
126
125
  datastreams.each_value do |ds|
127
126
  ds.should be_a_kind_of(ActiveFedora::Datastream)
128
127
  end
129
- @test_object.datastreams_in_fedora["DC"].should be_an_instance_of(ActiveFedora::Datastream)
128
+ @test_object.datastreams["DC"].should be_an_instance_of(ActiveFedora::Datastream)
130
129
  datastreams["DC"].should_not be_nil
131
130
  datastreams["DC"].should be_an_instance_of(ActiveFedora::Datastream)
132
131
  end
133
132
  it "should initialize the datastream pointers with @new_object=false" do
134
- datastreams = @test_object.datastreams_in_fedora
133
+ datastreams = @test_object.datastreams
135
134
  datastreams.each_value do |ds|
136
135
  ds.new_object?.should be_false
137
136
  end
@@ -140,9 +139,9 @@ describe ActiveFedora::Base do
140
139
 
141
140
  describe ".metadata_streams" do
142
141
  it "should return all of the datastreams from the object that are kinds of MetadataDatastreams " do
143
- mds1 = ActiveFedora::MetadataDatastream.new(:dsid => "md1")
144
- mds2 = ActiveFedora::QualifiedDublinCoreDatastream.new(:dsid => "qdc")
145
- fds = ActiveFedora::Datastream.new(:dsid => "fds")
142
+ mds1 = ActiveFedora::MetadataDatastream.new(@test_object.inner_object, "md1")
143
+ mds2 = ActiveFedora::QualifiedDublinCoreDatastream.new(@test_object.inner_object, "qdc")
144
+ fds = ActiveFedora::Datastream.new(@test_object.inner_object, "fds")
146
145
  @test_object.add_datastream(mds1)
147
146
  @test_object.add_datastream(mds2)
148
147
  @test_object.add_datastream(fds)
@@ -156,9 +155,9 @@ describe ActiveFedora::Base do
156
155
 
157
156
  describe ".file_streams" do
158
157
  it "should return all of the datastreams from the object that are kinds of MetadataDatastreams" do
159
- fds1 = ActiveFedora::Datastream.new(:dsid => "fds1")
160
- fds2 = ActiveFedora::Datastream.new(:dsid => "fds2")
161
- mds = ActiveFedora::MetadataDatastream.new(:dsid => "mds")
158
+ fds1 = ActiveFedora::Datastream.new(@test_object.inner_object, "fds1")
159
+ fds2 = ActiveFedora::Datastream.new(@test_object.inner_object, "fds2")
160
+ mds = ActiveFedora::MetadataDatastream.new(@test_object.inner_object, "mds")
162
161
  @test_object.add_datastream(fds1)
163
162
  @test_object.add_datastream(fds2)
164
163
  @test_object.add_datastream(mds)
@@ -169,9 +168,9 @@ describe ActiveFedora::Base do
169
168
  result.should include(fds2)
170
169
  end
171
170
  it "should skip DC and RELS-EXT datastreams" do
172
- fds1 = ActiveFedora::Datastream.new(:dsid => "fds1")
173
- dc = ActiveFedora::Datastream.new(:dsid => "DC")
174
- rels_ext = ActiveFedora::RelsExtDatastream.new
171
+ fds1 = ActiveFedora::Datastream.new(@test_object.inner_object,"fds1")
172
+ dc = ActiveFedora::Datastream.new(@test_object.inner_object, "DC")
173
+ rels_ext = ActiveFedora::RelsExtDatastream.new(@test_object.inner_object, 'RELS-EXT')
175
174
  @test_object.add_datastream(fds1)
176
175
  @test_object.add_datastream(dc)
177
176
  @test_object.add_datastream(rels_ext)
@@ -198,10 +197,10 @@ describe ActiveFedora::Base do
198
197
 
199
198
  it 'should create the RELS-EXT datastream if it doesnt exist' do
200
199
  test_object = ActiveFedora::Base.new
201
- test_object.datastreams["RELS-EXT"].should == nil
200
+ #test_object.datastreams["RELS-EXT"].should == nil
202
201
  test_object.rels_ext
203
- test_object.datastreams_in_memory["RELS-EXT"].should_not == nil
204
- test_object.datastreams_in_memory["RELS-EXT"].class.should == ActiveFedora::RelsExtDatastream
202
+ test_object.datastreams["RELS-EXT"].should_not == nil
203
+ test_object.datastreams["RELS-EXT"].class.should == ActiveFedora::RelsExtDatastream
205
204
  end
206
205
  end
207
206
 
@@ -214,7 +213,7 @@ describe ActiveFedora::Base do
214
213
  @test_object.add_relationship(rel.predicate, rel.object)
215
214
  end
216
215
  @test_object.save
217
- rexml = REXML::Document.new(@test_object.datastreams_in_fedora["RELS-EXT"].content)
216
+ rexml = REXML::Document.new(@test_object.datastreams["RELS-EXT"].content)
218
217
  # Purpose: confirm that the isMemberOf entries exist and have real RDF in them
219
218
  rexml.root.elements["rdf:Description/isMemberOf[@rdf:resource='info:fedora/demo:5']"].attributes["xmlns"].should == 'info:fedora/fedora-system:def/relations-external#'
220
219
  rexml.root.elements["rdf:Description/isMemberOf[@rdf:resource='info:fedora/demo:10']"].attributes["xmlns"].should == 'info:fedora/fedora-system:def/relations-external#'
@@ -229,50 +228,56 @@ describe ActiveFedora::Base do
229
228
  @test_object.save
230
229
  test_obj = ActiveFedora::Base.load_instance(@test_object.pid)
231
230
  #check case where nothing passed in does not have correct mime type
232
- test_obj.datastreams["DS1"].attributes["mimeType"].should == "application/octet-stream"
231
+ test_obj.datastreams["DS1"].mimeType.should == "application/octet-stream"
233
232
  @test_object2 = ActiveFedora::Base.new
233
+ f = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino_jpg_no_file_ext" ))
234
234
  @test_object2.add_file_datastream(f,{:mimeType=>"image/jpeg"})
235
235
  @test_object2.save
236
236
  test_obj = ActiveFedora::Base.load_instance(@test_object2.pid)
237
- test_obj.datastreams["DS1"].attributes["mimeType"].should == "image/jpeg"
237
+ test_obj.datastreams["DS1"].mimeType.should == "image/jpeg"
238
238
  @test_object3 = ActiveFedora::Base.new
239
+ f = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino_jpg_no_file_ext" ))
239
240
  @test_object3.add_file_datastream(f,{:mime_type=>"image/jpeg"})
240
241
  @test_object3.save
241
242
  test_obj = ActiveFedora::Base.load_instance(@test_object3.pid)
242
- test_obj.datastreams["DS1"].attributes["mimeType"].should == "image/jpeg"
243
+ test_obj.datastreams["DS1"].mimeType.should == "image/jpeg"
243
244
  @test_object4 = ActiveFedora::Base.new
245
+ f = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino_jpg_no_file_ext" ))
244
246
  @test_object4.add_file_datastream(f,{:content_type=>"image/jpeg"})
245
247
  @test_object4.save
246
248
  test_obj = ActiveFedora::Base.load_instance(@test_object4.pid)
247
- test_obj.datastreams["DS1"].attributes["mimeType"].should == "image/jpeg"
249
+ test_obj.datastreams["DS1"].mimeType.should == "image/jpeg"
248
250
  end
249
251
  end
250
252
 
251
253
  describe '.add_datastream' do
252
254
 
253
255
  it "should be able to add datastreams" do
254
- ds = ActiveFedora::Datastream.new(:dsID => 'DS1', :dsLabel => 'hello', :altIDs => '3333',
255
- :controlGroup => 'M', :blob => fixture('dino.jpg'))
256
+ ds = ActiveFedora::Datastream.new(@test_object.inner_object, 'DS1')
257
+ # ds = ActiveFedora::Datastream.new(:dsID => 'DS1', :dsLabel => 'hello', :altIDs => '3333',
258
+ # :controlGroup => 'M', :blob => fixture('dino.jpg'))
256
259
  @test_object.add_datastream(ds).should be_true
257
260
  end
258
261
 
259
- it "adding and saving should add the datastream to the datastreams_in_fedora array" do
260
- ds = ActiveFedora::Datastream.new(:dsid => 'DS1', :dsLabel => 'hello', :altIDs => '3333',
261
- :controlGroup => 'M', :blob => fixture('dino.jpg'))
262
+ it "adding and saving should add the datastream to the datastreams array" do
263
+ ds = ActiveFedora::Datastream.new(@test_object.inner_object, 'DS1')
264
+ ds.content = fixture('dino.jpg').read
265
+ # ds = ActiveFedora::Datastream.new(:dsid => 'DS1', :dsLabel => 'hello', :altIDs => '3333',
266
+ # :controlGroup => 'M', :blob => fixture('dino.jpg'))
262
267
  @test_object.datastreams.should_not have_key("DS1")
263
268
  @test_object.add_datastream(ds)
264
269
  ds.save
265
- @test_object.datastreams_in_fedora.should have_key("DS1")
270
+ @test_object.datastreams.should have_key("DS1")
266
271
  end
267
272
 
268
273
  end
269
274
 
270
275
  it "should retrieve blobs that match the saved blobs" do
271
- ds = ActiveFedora::Datastream.new(:dsid => 'DS1', :dsLabel => 'hello', :altIDs => '3333',
272
- :controlGroup => 'M', :blob => fixture('dino.jpg'))
273
- @test_object.add_datastream(ds)
274
- ds.save
275
- @test_object.datastreams_in_fedora["DS1"].content.should == ds.content
276
+ ds = ActiveFedora::Datastream.new(@test_object.inner_object, 'DS1')
277
+ ds.content = "foo"
278
+ new_ds = ds.save
279
+ @test_object.add_datastream(new_ds)
280
+ @test_object.class.find(@test_object.pid).datastreams["DS1"].content.should == new_ds.content
276
281
  end
277
282
 
278
283
  describe ".create_date" do
@@ -298,16 +303,16 @@ describe ActiveFedora::Base do
298
303
  describe '#delete' do
299
304
  it 'if inbound relationships exist should remove relationships from those inbound targets as well when deleting this object' do
300
305
  @test_object2 = MockAFBaseRelationship.new
301
- @test_object2.new_object = true
306
+ # @test_object2.new_object = true
302
307
  @test_object2.save
303
308
  @test_object3 = MockAFBaseRelationship.new
304
- @test_object3.new_object = true
309
+ # @test_object3.new_object = true
305
310
  @test_object3.save
306
311
  @test_object4 = MockAFBaseRelationship.new
307
- @test_object4.new_object = true
312
+ # @test_object4.new_object = true
308
313
  @test_object4.save
309
314
  @test_object5 = MockAFBaseRelationship.new
310
- @test_object5.new_object = true
315
+ # @test_object5.new_object = true
311
316
  @test_object5.save
312
317
  #append to relationship by 'testing'
313
318
  @test_object2.add_relationship_by_name("testing",@test_object3)
@@ -366,16 +371,16 @@ describe ActiveFedora::Base do
366
371
  describe '#relationships' do
367
372
  it 'should return internal relationships with no parameters and include inbound if false passed in' do
368
373
  @test_object2 = MockAFBaseRelationship.new
369
- @test_object2.new_object = true
374
+ # @test_object2.new_object = true
370
375
  @test_object2.save
371
376
  @test_object3 = MockAFBaseRelationship.new
372
- @test_object3.new_object = true
377
+ # @test_object3.new_object = true
373
378
  @test_object3.save
374
379
  @test_object4 = MockAFBaseRelationship.new
375
- @test_object4.new_object = true
380
+ # @test_object4.new_object = true
376
381
  @test_object4.save
377
382
  @test_object5 = MockAFBaseRelationship.new
378
- @test_object5.new_object = true
383
+ # @test_object5.new_object = true
379
384
  @test_object5.save
380
385
  #append to named relationship 'testing'
381
386
  @test_object2.testing_append(@test_object3)
@@ -424,16 +429,16 @@ describe ActiveFedora::Base do
424
429
  describe '#inbound_relationships' do
425
430
  it 'should return a hash of inbound relationships' do
426
431
  @test_object2 = MockAFBaseRelationship.new
427
- @test_object2.new_object = true
432
+ #@test_object2.new_object = true
428
433
  @test_object2.save
429
434
  @test_object3 = MockAFBaseRelationship.new
430
- @test_object3.new_object = true
435
+ #@test_object3.new_object = true
431
436
  @test_object3.save
432
437
  @test_object4 = MockAFBaseRelationship.new
433
- @test_object4.new_object = true
438
+ #@test_object4.new_object = true
434
439
  @test_object4.save
435
440
  @test_object5 = MockAFBaseRelationship.new
436
- @test_object5.new_object = true
441
+ #@test_object5.new_object = true
437
442
  @test_object5.save
438
443
  #append to named relationship 'testing'
439
444
  @test_object2.testing_append(@test_object3)
@@ -459,16 +464,16 @@ describe ActiveFedora::Base do
459
464
  describe '#inbound_relationships_by_name' do
460
465
  it 'should return a hash of inbound relationship names to array of objects' do
461
466
  @test_object2 = MockAFBaseRelationship.new
462
- @test_object2.new_object = true
467
+ #@test_object2.new_object = true
463
468
  @test_object2.save
464
469
  @test_object3 = MockAFBaseRelationship.new
465
- @test_object3.new_object = true
470
+ #@test_object3.new_object = true
466
471
  @test_object3.save
467
472
  @test_object4 = MockAFBaseRelationship.new
468
- @test_object4.new_object = true
473
+ #@test_object4.new_object = true
469
474
  @test_object4.save
470
475
  @test_object5 = MockAFBaseRelationship.new
471
- @test_object5.new_object = true
476
+ #@test_object5.new_object = true
472
477
  @test_object5.save
473
478
  #append to named relationship 'testing'
474
479
  @test_object2.testing_append(@test_object3)
@@ -497,16 +502,16 @@ describe ActiveFedora::Base do
497
502
  describe '#relationships_by_name' do
498
503
  it '' do
499
504
  @test_object2 = MockAFBaseRelationship.new
500
- @test_object2.new_object = true
505
+ #@test_object2.new_object = true
501
506
  @test_object2.save
502
507
  @test_object3 = MockAFBaseRelationship.new
503
- @test_object3.new_object = true
508
+ #@test_object3.new_object = true
504
509
  @test_object3.save
505
510
  @test_object4 = MockAFBaseRelationship.new
506
- @test_object4.new_object = true
511
+ #@test_object4.new_object = true
507
512
  @test_object4.save
508
513
  @test_object5 = MockAFBaseRelationship.new
509
- @test_object5.new_object = true
514
+ #@test_object5.new_object = true
510
515
  @test_object5.save
511
516
  #append to named relationship 'testing'
512
517
  @test_object2.testing_append(@test_object3)
@@ -536,16 +541,16 @@ describe ActiveFedora::Base do
536
541
  describe '#add_relationship_by_name' do
537
542
  it 'should add a named relationship to an object' do
538
543
  @test_object2 = MockAFBaseRelationship.new
539
- @test_object2.new_object = true
544
+ #@test_object2.new_object = true
540
545
  @test_object2.save
541
546
  @test_object3 = MockAFBaseRelationship.new
542
- @test_object3.new_object = true
547
+ #@test_object3.new_object = true
543
548
  @test_object3.save
544
549
  @test_object4 = MockAFBaseRelationship.new
545
- @test_object4.new_object = true
550
+ #@test_object4.new_object = true
546
551
  @test_object4.save
547
552
  @test_object5 = MockAFBaseRelationship.new
548
- @test_object5.new_object = true
553
+ #@test_object5.new_object = true
549
554
  @test_object5.save
550
555
  #append to named relationship 'testing'
551
556
  @test_object2.add_relationship_by_name("testing",@test_object3)
@@ -570,16 +575,16 @@ describe ActiveFedora::Base do
570
575
  describe '#remove_named_relationship' do
571
576
  it 'should remove an existing relationship from an object' do
572
577
  @test_object2 = MockAFBaseRelationship.new
573
- @test_object2.new_object = true
578
+ #@test_object2.new_object = true
574
579
  @test_object2.save
575
580
  @test_object3 = MockAFBaseRelationship.new
576
- @test_object3.new_object = true
581
+ #@test_object3.new_object = true
577
582
  @test_object3.save
578
583
  @test_object4 = MockAFBaseRelationship.new
579
- @test_object4.new_object = true
584
+ #@test_object4.new_object = true
580
585
  @test_object4.save
581
586
  @test_object5 = MockAFBaseRelationship.new
582
- @test_object5.new_object = true
587
+ #@test_object5.new_object = true
583
588
  @test_object5.save
584
589
  #append to named relationship 'testing'
585
590
  @test_object2.add_relationship_by_name("testing",@test_object3)
@@ -616,16 +621,16 @@ describe ActiveFedora::Base do
616
621
  describe '#find_relationship_by_name' do
617
622
  it 'should find relationships based on name passed in for inbound or outbound' do
618
623
  @test_object2 = MockAFBaseRelationship.new
619
- @test_object2.new_object = true
624
+ # @test_object2.new_object = true
620
625
  @test_object2.save
621
626
  @test_object3 = MockAFBaseRelationship.new
622
- @test_object3.new_object = true
627
+ # @test_object3.new_object = true
623
628
  @test_object3.save
624
629
  @test_object4 = MockAFBaseRelationship.new
625
- @test_object4.new_object = true
630
+ # @test_object4.new_object = true
626
631
  @test_object4.save
627
632
  @test_object5 = MockAFBaseRelationship.new
628
- @test_object5.new_object = true
633
+ # @test_object5.new_object = true
629
634
  @test_object5.save
630
635
  #append to named relationship 'testing'
631
636
  @test_object2.add_relationship_by_name("testing",@test_object3)
@@ -665,7 +670,7 @@ describe ActiveFedora::Base do
665
670
  describe '#add_named_datastream' do
666
671
  it 'should add a datastream with the given name to the object in fedora' do
667
672
  @test_object2 = MockAFBaseDatastream.new
668
- @test_object2.new_object = true
673
+ # @test_object2.new_object = true
669
674
  f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
670
675
  f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
671
676
  f2.stubs(:original_filename).returns("dino.jpg")
@@ -681,21 +686,25 @@ describe ActiveFedora::Base do
681
686
  @test_object2.named_datastreams.keys.include?("high").should == true
682
687
  @test_object2.named_datastreams["thumbnail"].size.should == 1
683
688
  @test_object2.named_datastreams["high"].size.should == 1
684
- @test_object2.named_datastreams["thumbnail"].first.attributes.should == {"label"=>ds.label,"dsid"=>ds.dsid,
685
- "mimeType"=>ds.attributes[:mimeType],
686
- :controlGroup=>ds.attributes[:controlGroup],
687
- :pid=>ds.pid, :dsID=>ds.dsid, :dsLabel=>ds.attributes[:dsLabel]}
688
- @test_object2.named_datastreams["high"].first.attributes.should == {"label"=>ds2.label,"dsid"=>ds2.dsid,
689
- "mimeType"=>ds2.attributes[:mimeType],
690
- :controlGroup=>ds2.attributes[:controlGroup],
691
- :pid=>ds2.pid, :dsID=>ds2.dsid, :dsLabel=>ds2.attributes[:dsLabel]}
689
+ t2_thumb1 = @test_object2.named_datastreams["thumbnail"].first
690
+ t2_thumb1.dsid.should == ds.dsid
691
+ t2_thumb1.mimeType.should == ds.mimeType
692
+ t2_thumb1.pid.should == ds.pid
693
+ t2_thumb1.dsLabel.should == ds.dsLabel
694
+ t2_thumb1.controlGroup.should == ds.controlGroup
695
+ t2_high1 = @test_object2.named_datastreams["high"].first
696
+ t2_high1.dsid.should == ds2.dsid
697
+ t2_high1.mimeType.should == ds2.mimeType
698
+ t2_high1.pid.should == ds2.pid
699
+ t2_high1.dsLabel.should == ds2.dsLabel
700
+ t2_high1.controlGroup.should == ds2.controlGroup
692
701
  end
693
702
  end
694
703
 
695
704
  describe '#add_named_file_datastream' do
696
705
  it 'should add a file datastream with the given name to the object in fedora' do
697
706
  @test_object2 = MockAFBaseDatastream.new
698
- @test_object2.new_object = true
707
+ # @test_object2.new_object = true
699
708
  f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
700
709
  f.stubs(:content_type).returns("image/jpeg")
701
710
  @test_object2.add_named_file_datastream("thumbnail",f)
@@ -703,19 +712,30 @@ describe ActiveFedora::Base do
703
712
  @test_object2.save
704
713
  @test_object2 = MockAFBaseDatastream.load_instance(@test_object2.pid)
705
714
  @test_object2.named_datastreams["thumbnail"].size.should == 1
706
- @test_object2.named_datastreams["thumbnail"].first.attributes.should == {"label"=>ds.label,"dsid"=>ds.dsid,
707
- "mimeType"=>ds.attributes[:mimeType],
708
- :controlGroup=>ds.attributes[:controlGroup],
709
- :pid=>ds.pid, :dsID=>ds.dsid, :dsLabel=>ds.attributes[:dsLabel]}
715
+ t2_thumb1 = @test_object2.named_datastreams["thumbnail"].first
716
+ t2_thumb1.dsid.should == "THUMB1"
717
+ t2_thumb1.mimeType.should == "image/jpeg"
718
+ t2_thumb1.pid.should == @test_object2.pid
719
+ t2_thumb1.dsLabel.should == "minivan.jpg"
720
+ t2_thumb1.controlGroup.should == "M"
721
+
722
+ # .attributes.should == {"label"=>ds.label,"dsid"=>ds.dsid,
723
+ # "mimeType"=>ds.attributes[:mimeType],
724
+ # :controlGroup=>ds.attributes[:controlGroup],
725
+ # :pid=>ds.pid, :dsID=>ds.dsid, :dsLabel=>ds.attributes[:dsLabel]}
710
726
  end
711
727
  end
712
728
 
713
729
  describe '#update_named_datastream' do
714
730
  it 'should update a named datastream to have a new file' do
715
731
  @test_object2 = MockAFBaseDatastream.new
716
- @test_object2.new_object = true
732
+ # @test_object2.new_object = true
717
733
  f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
734
+ minivan = f.read
735
+ f.rewind
718
736
  f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
737
+ dino = f.read
738
+ f.rewind
719
739
  f.stubs(:content_type).returns("image/jpeg")
720
740
  f.stubs(:original_filename).returns("minivan.jpg")
721
741
  f2.stubs(:content_type).returns("image/jpeg")
@@ -728,62 +748,32 @@ describe ActiveFedora::Base do
728
748
  @test_object2.thumbnail.size.should == 1
729
749
  @test_object2.thumbnail_ids == ["THUMB1"]
730
750
  ds = @test_object2.thumbnail.first
731
- ds.attributes.should == {"mimeType"=>"image/jpeg",
732
- :controlGroup=>"M", "dsid"=>"THUMB1",
733
- :pid=>@test_object2.pid, :dsID=>"THUMB1",
734
- "label"=>"minivan.jpg",:dsLabel=>"minivan.jpg"}
735
- expected_content = ""
736
- f.each {|line|
737
- expected_content << line
738
- }
739
- raise "Datastream content mismatch on save of datastream" unless ds.content == expected_content
751
+ ds.dsid.should == "THUMB1"
752
+ ds.mimeType.should == "image/jpeg"
753
+ ds.pid.should == @test_object2.pid
754
+ ds.dsLabel.should == "minivan.jpg"
755
+ ds.controlGroup.should == "M"
756
+
757
+ ds.content.should == minivan
740
758
  @test_object2.update_named_datastream("thumbnail",{:file=>f2,:dsid=>"THUMB1"})
741
759
  @test_object2.save
742
760
  @test_object2 = MockAFBaseDatastream.load_instance(@test_object2.pid)
743
761
  @test_object2.thumbnail.size.should == 1
744
762
  @test_object2.thumbnail_ids == ["THUMB1"]
745
- ds = @test_object2.thumbnail.first
746
- ds.attributes.should == {"mimeType"=>"image/jpeg",
747
- :controlGroup=>"M", "dsid"=>"THUMB1",
748
- :pid=>@test_object2.pid, :dsID=>"THUMB1",
749
- "label"=>"dino.jpg", :dsLabel=>"dino.jpg"}
750
- expected_content = ""
751
- f2.each {|line|
752
- expected_content << line
753
- }
754
- raise "Datastream content mismatch after update of datastream" unless ds.content == expected_content
755
- end
756
- end
757
-
758
- describe '#named_datastreams_attributes' do
759
- it 'should return a hash of name to hash of dsid to attribute hashes for each named datastream' do
760
- @test_object2 = MockAFBaseDatastream.new
761
- @test_object2.new_object = true
762
- f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
763
- f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
764
- f2.stubs(:original_filename).returns("dino.jpg")
765
- f.stubs(:content_type).returns("image/jpeg")
766
- @test_object2.add_named_datastream("thumbnail",{:content_type=>"image/jpeg",:blob=>f, :label=>"testDS"})
767
- @test_object2.add_named_datastream("high",{:content_type=>"image/jpeg",:blob=>f2})
768
- ds = @test_object2.thumbnail.first
769
- ds2 = @test_object2.high.first
770
- @test_object2.save
771
- @test_object2 = MockAFBaseDatastream.load_instance(@test_object2.pid)
772
- @test_object2.named_datastreams_attributes.should == {"thumbnail"=>{"THUMB1"=>{"label"=>ds.label,"dsid"=>ds.dsid,
773
- "mimeType"=>ds.attributes[:mimeType],
774
- :controlGroup=>ds.attributes[:controlGroup],
775
- :pid=>ds.pid, :dsID=>ds.dsid, :dsLabel=>ds.attributes[:dsLabel]}},
776
- "high"=>{"HIGH1"=>{"label"=>ds2.label,"dsid"=>ds2.dsid,
777
- "mimeType"=>ds2.attributes[:mimeType],
778
- :controlGroup=>ds2.attributes[:controlGroup],
779
- :pid=>ds2.pid, :dsID=>ds2.dsid, :dsLabel=>ds2.attributes[:dsLabel]}}}
763
+ ds2 = @test_object2.thumbnail.first
764
+ ds2.dsid.should == "THUMB1"
765
+ ds2.mimeType.should == "image/jpeg"
766
+ ds2.pid.should == @test_object2.pid
767
+ ds2.dsLabel.should == "dino.jpg"
768
+ ds2.controlGroup.should == "M"
769
+ (ds2.content == dino).should be_true
780
770
  end
781
771
  end
782
772
 
783
773
  describe '#named_datastreams_ids' do
784
774
  it 'should return a hash of datastream name to an array of dsids' do
785
775
  @test_object2 = MockAFBaseDatastream.new
786
- @test_object2.new_object = true
776
+ # @test_object2.new_object = true
787
777
  f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
788
778
  f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
789
779
  f2.stubs(:original_filename).returns("dino.jpg")
@@ -796,183 +786,183 @@ describe ActiveFedora::Base do
796
786
  end
797
787
  end
798
788
 
799
- describe '#load_instance_from_solr' do
800
- it 'should populate an instance of an ActiveFedora::Base object using solr instead of Fedora' do
801
-
802
- @test_object2 = MockAFBaseFromSolr.new
803
- @test_object2.new_object = true
804
- attributes = {"holding_id"=>{0=>"Holding 1"},
805
- "language"=>{0=>"Italian"},
806
- "creator"=>{0=>"Linguist, A."},
807
- "geography"=>{0=>"Italy"},
808
- "title"=>{0=>"Italian and Spanish: A Comparison of Common Phrases"}}
809
- @test_object2.update_indexed_attributes(attributes)
810
- @test_object2.save
811
- @test_object3 = MockAFBaseFromSolr.new
812
- @test_object3.new_object = true
813
- attributes = {"holding_id"=>{0=>"Holding 2"},
814
- "language"=>{0=>"Spanish;Latin"},
815
- "creator"=>{0=>"Linguist, A."},
816
- "geography"=>{0=>"Spain"},
817
- "title"=>{0=>"A study of the evolution of Spanish from Latin"}}
818
- @test_object3.update_indexed_attributes(attributes)
819
- @test_object3.save
820
- @test_object4 = MockAFBaseFromSolr.new
821
- attributes = {"holding_id"=>{0=>"Holding 3"},
822
- "language"=>{0=>"Spanish;Latin"},
823
- "creator"=>{0=>"Linguist, A."},
824
- "geography"=>{0=>"Spain"},
825
- "title"=>{0=>"An obscure look into early nomadic tribes of Spain"}}
826
- @test_object4.update_indexed_attributes(attributes)
827
- @test_object4.new_object = true
828
- @test_object4.save
829
- @test_object5 = MockAFBaseFromSolr.new
830
- @test_object5.new_object = true
831
- @test_object5.save
832
-
833
- #append to named relationship 'testing'
834
- @test_object2.testing_append(@test_object3)
835
- @test_object2.testing2_append(@test_object4)
836
- @test_object5.testing_append(@test_object2)
837
- @test_object5.testing2_append(@test_object3)
838
- @test_object2.save
839
- @test_object5.save
840
- r2 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object2)
841
- r3 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object3)
842
- r4 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object4)
843
- r5 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object5)
844
- model_rel = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>ActiveFedora::ContentModel.pid_from_ruby_class(MockAFBaseFromSolr))
845
- #check inbound correct, testing goes to :has_part and testing2 goes to :has_member
846
- test_from_solr_object2 = MockAFBaseFromSolr.load_instance_from_solr(@test_object2.pid)
847
- test_from_solr_object3 = MockAFBaseFromSolr.load_instance_from_solr(@test_object3.pid)
848
- test_from_solr_object4 = MockAFBaseFromSolr.load_instance_from_solr(@test_object4.pid)
849
- test_from_solr_object5 = MockAFBaseFromSolr.load_instance_from_solr(@test_object5.pid)
850
-
851
- # need to check pid, system create and system modify
852
- test_from_solr_object2.pid.should == @test_object2.pid
853
- test_from_solr_object3.pid.should == @test_object3.pid
854
- test_from_solr_object4.pid.should == @test_object4.pid
855
- test_from_solr_object5.pid.should == @test_object5.pid
856
-
857
- Time.parse(test_from_solr_object2.create_date).should == Time.parse(@test_object2.create_date)
858
- Time.parse(test_from_solr_object3.create_date).should == Time.parse(@test_object3.create_date)
859
- Time.parse(test_from_solr_object4.create_date).should == Time.parse(@test_object4.create_date)
860
- Time.parse(test_from_solr_object5.create_date).should == Time.parse(@test_object5.create_date)
861
-
862
- Time.parse(test_from_solr_object2.modified_date).should == Time.parse(@test_object2.modified_date)
863
- Time.parse(test_from_solr_object3.modified_date).should == Time.parse(@test_object3.modified_date)
864
- Time.parse(test_from_solr_object4.modified_date).should == Time.parse(@test_object4.modified_date)
865
- Time.parse(test_from_solr_object5.modified_date).should == Time.parse(@test_object5.modified_date)
866
-
867
- # need to test outbound and inbound relationships
868
- test_from_solr_object2.relationships(false).should == {:self=>{:has_model=>[model_rel.object],
869
- :has_part=>[r3.object],
870
- :has_member=>[r4.object]},
871
- :inbound=>{:has_part=>[r5.object]}}
872
- test_from_solr_object2.relationships_by_name(false).should == {:self=>{"testing"=>[r3.object],"testing2"=>[r4.object],
873
- "collection_members"=>[],"part_of"=>[],"parts_outbound"=>[r3.object]},
874
- :inbound=>{"testing_inbound"=>[r5.object],"testing_inbound2"=>[],"parts_inbound"=>[]}}
875
- test_from_solr_object3.relationships(false).should == {:self=>{:has_model=>[model_rel.object]},
876
- :inbound=>{:has_part=>[r2.object],
877
- :has_member=>[r5.object]}}
878
- test_from_solr_object3.relationships_by_name(false).should == {:self=>{"testing"=>[],"testing2"=>[], "collection_members"=>[],"part_of"=>[],"parts_outbound"=>[]},
879
- :inbound=>{"testing_inbound"=>[r2.object],"testing_inbound2"=>[r5.object], "parts_inbound"=>[]}}
880
- test_from_solr_object4.relationships(false).should == {:self=>{:has_model=>[model_rel.object]},
881
- :inbound=>{:has_member=>[r2.object]}}
882
- test_from_solr_object4.relationships_by_name(false).should == {:inbound=>{"parts_inbound"=>[], "testing_inbound"=>[], "testing_inbound2"=>[r2.object]}, :self=>{"testing2"=>[], "collection_members"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[]}}
883
- test_from_solr_object5.relationships(false).should == {:self=>{:has_model=>[model_rel.object],
884
- :has_part=>[r2.object],
885
- :has_member=>[r3.object]},
886
- :inbound=>{}}
887
- test_from_solr_object5.relationships_by_name(false).should == {:inbound=>{"parts_inbound"=>[], "testing_inbound"=>[], "testing_inbound2"=>[]}, :self=>{"testing2"=>[r3.object], "collection_members"=>[], "part_of"=>[], "testing"=>[r2.object], "parts_outbound"=>[r2.object]}}
888
- #all inbound should now be empty if no parameter supplied to relationships
889
- test_from_solr_object2.relationships.should == {:self=>{:has_part=>[r3.object],:has_member=>[r4.object],:has_model=>[model_rel.object]}}
890
- test_from_solr_object2.relationships_by_name.should == {:self=>{"testing2"=>[r4.object], "collection_members"=>[], "part_of"=>[], "testing"=>[r3.object], "parts_outbound"=>[r3.object]}}
891
- test_from_solr_object3.relationships.should == {:self=>{:has_model=>[model_rel.object]}}
892
- test_from_solr_object3.relationships_by_name.should == {:self=>{"testing2"=>[], "collection_members"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[]}}
893
- test_from_solr_object4.relationships.should == {:self=>{:has_model=>[model_rel.object]}}
894
- test_from_solr_object4.relationships_by_name.should == {:self=>{"testing2"=>[], "collection_members"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[]}}
895
- test_from_solr_object5.relationships.should == {:self=>{:has_model=>[model_rel.object],
896
- :has_part=>[r2.object],
897
- :has_member=>[r3.object]}}
898
- test_from_solr_object5.relationships_by_name.should == {:self=>{"testing2"=>[r3.object], "collection_members"=>[], "part_of"=>[], "testing"=>[r2.object], "parts_outbound"=>[r2.object]}}
899
- # need to check metadata
900
- test_from_solr_object2.fields[:language][:values].should == ["Italian"]
901
- test_from_solr_object2.fields[:creator][:values].should == ["Linguist, A."]
902
- test_from_solr_object2.fields[:geography][:values].should == ["Italy"]
903
- test_from_solr_object2.fields[:title][:values].should == ["Italian and Spanish: A Comparison of Common Phrases"]
904
- test_from_solr_object2.fields[:holding_id][:values].should == ["Holding 1"]
905
-
906
- test_from_solr_object3.fields[:language][:values].should == ["Spanish;Latin"]
907
- test_from_solr_object3.fields[:creator][:values].should == ["Linguist, A."]
908
- test_from_solr_object3.fields[:geography][:values].should == ["Spain"]
909
- test_from_solr_object3.fields[:title][:values].should == ["A study of the evolution of Spanish from Latin"]
910
- test_from_solr_object3.fields[:holding_id][:values].should == ["Holding 2"]
911
-
912
- test_from_solr_object4.fields[:language][:values].should == ["Spanish;Latin"]
913
- test_from_solr_object4.fields[:creator][:values].should == ["Linguist, A."]
914
- test_from_solr_object4.fields[:geography][:values].should == ["Spain"]
915
- test_from_solr_object4.fields[:title][:values].should == ["An obscure look into early nomadic tribes of Spain"]
916
- test_from_solr_object4.fields[:holding_id][:values].should == ["Holding 3"]
917
-
918
- #need to check system modified and system created values correct
919
- # need to implement for nokogiri datastream as well
920
- #false.should == true
921
- end
922
- end
923
-
924
- describe 'load_from_solr using relationship finders'
925
- it 'resulting finder should accept :load_from_solr as :response_format and return object instantiated using load_instance_from_solr' do
926
- # solr_result = mock("solr result")
927
- # SpecNode.create_inbound_relationship_finders("constituents", :is_constituent_of, :inbound => true)
928
- # local_node = SpecNode.new
929
- # mock_repo = mock("repo")
930
- # mock_repo.expects(:find_model).never
931
- # SpecNode.expects(:load_instance_from_solr).times(1)
932
- # local_node.expects(:internal_uri).returns("info:fedora/test:sample_pid")
933
- # ActiveFedora::SolrService.instance.conn.expects(:query).with("is_constituent_of_s:info\\:fedora/test\\:sample_pid").returns(solr_result)
934
- # local_node.constituents(:response_format => :solr).should equal(solr_result)
935
- end
936
-
937
- it 'when an object is loaded via solr instead of fedora it should automatically load objects from finders from solr as well' do
938
- @test_object2 = MockAFBaseFromSolr.new
939
- @test_object2.save
940
- @test_object3 = MockAFBaseFromSolr.new
941
- @test_object3.save
942
- @test_object2.testing_append(@test_object3)
943
- @test_object2.save
944
-
945
- test_object2_from_solr = MockAFBaseFromSolr.load_instance_from_solr(@test_object2.pid)
946
- test_object3_from_solr = MockAFBaseFromSolr.load_instance_from_solr(@test_object3.pid)
947
- MockAFBaseFromSolr.expects(:load_instance_from_solr).times(4)
948
- test_object2_from_solr.testing({:response_format=>:load_from_solr})
949
- test_object3_from_solr.testing_inbound({:response_format=>:load_from_solr})
950
- test_object2_from_solr.testing
951
- test_object3_from_solr.testing_inbound
952
- end
953
-
954
- it 'when a load_from_solr is not set it should not call load_instance_from_solr for finders unless passing option in' do
955
- @test_object2 = MockAFBaseFromSolr.new
956
- @test_object2.save
957
- @test_object3 = MockAFBaseFromSolr.new
958
- @test_object3.save
959
- @test_object2.testing_append(@test_object3)
960
- @test_object2.save
961
-
962
- MockAFBaseFromSolr.expects(:load_instance_from_solr).never()
963
- @test_object2.testing
964
- @test_object3.testing_inbound
965
-
966
- #now try calling with option
967
- MockAFBaseFromSolr.expects(:load_instance_from_solr).twice()
968
- @test_object2.testing({:response_format=>:load_from_solr})
969
- @test_object3.testing_inbound({:response_format=>:load_from_solr})
970
-
971
- #now call other finder method
972
- MockAFBaseFromSolr.expects(:load_instance_from_solr).twice()
973
- @test_object2.testing_from_solr
974
- @test_object3.testing_inbound_from_solr
975
-
976
- end
789
+ # describe '#load_instance_from_solr' do
790
+ # it 'should populate an instance of an ActiveFedora::Base object using solr instead of Fedora' do
791
+ #
792
+ # @test_object2 = MockAFBaseFromSolr.new
793
+ # # @test_object2.new_object = true
794
+ # attributes = {"holding_id"=>{0=>"Holding 1"},
795
+ # "language"=>{0=>"Italian"},
796
+ # "creator"=>{0=>"Linguist, A."},
797
+ # "geography"=>{0=>"Italy"},
798
+ # "title"=>{0=>"Italian and Spanish: A Comparison of Common Phrases"}}
799
+ # @test_object2.update_indexed_attributes(attributes)
800
+ # @test_object2.save
801
+ # @test_object3 = MockAFBaseFromSolr.new
802
+ # # @test_object3.new_object = true
803
+ # attributes = {"holding_id"=>{0=>"Holding 2"},
804
+ # "language"=>{0=>"Spanish;Latin"},
805
+ # "creator"=>{0=>"Linguist, A."},
806
+ # "geography"=>{0=>"Spain"},
807
+ # "title"=>{0=>"A study of the evolution of Spanish from Latin"}}
808
+ # @test_object3.update_indexed_attributes(attributes)
809
+ # @test_object3.save
810
+ # @test_object4 = MockAFBaseFromSolr.new
811
+ # attributes = {"holding_id"=>{0=>"Holding 3"},
812
+ # "language"=>{0=>"Spanish;Latin"},
813
+ # "creator"=>{0=>"Linguist, A."},
814
+ # "geography"=>{0=>"Spain"},
815
+ # "title"=>{0=>"An obscure look into early nomadic tribes of Spain"}}
816
+ # @test_object4.update_indexed_attributes(attributes)
817
+ # # @test_object4.new_object = true
818
+ # @test_object4.save
819
+ # @test_object5 = MockAFBaseFromSolr.new
820
+ # # @test_object5.new_object = true
821
+ # @test_object5.save
822
+ #
823
+ # #append to named relationship 'testing'
824
+ # @test_object2.testing_append(@test_object3)
825
+ # @test_object2.testing2_append(@test_object4)
826
+ # @test_object5.testing_append(@test_object2)
827
+ # @test_object5.testing2_append(@test_object3)
828
+ # @test_object2.save
829
+ # @test_object5.save
830
+ # r2 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object2)
831
+ # r3 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object3)
832
+ # r4 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object4)
833
+ # r5 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object5)
834
+ # model_rel = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>ActiveFedora::ContentModel.pid_from_ruby_class(MockAFBaseFromSolr))
835
+ # #check inbound correct, testing goes to :has_part and testing2 goes to :has_member
836
+ # test_from_solr_object2 = MockAFBaseFromSolr.load_instance_from_solr(@test_object2.pid)
837
+ # test_from_solr_object3 = MockAFBaseFromSolr.load_instance_from_solr(@test_object3.pid)
838
+ # test_from_solr_object4 = MockAFBaseFromSolr.load_instance_from_solr(@test_object4.pid)
839
+ # test_from_solr_object5 = MockAFBaseFromSolr.load_instance_from_solr(@test_object5.pid)
840
+ #
841
+ # # need to check pid, system create and system modify
842
+ # test_from_solr_object2.pid.should == @test_object2.pid
843
+ # test_from_solr_object3.pid.should == @test_object3.pid
844
+ # test_from_solr_object4.pid.should == @test_object4.pid
845
+ # test_from_solr_object5.pid.should == @test_object5.pid
846
+ #
847
+ # Time.parse(test_from_solr_object2.create_date).should == Time.parse(@test_object2.create_date)
848
+ # Time.parse(test_from_solr_object3.create_date).should == Time.parse(@test_object3.create_date)
849
+ # Time.parse(test_from_solr_object4.create_date).should == Time.parse(@test_object4.create_date)
850
+ # Time.parse(test_from_solr_object5.create_date).should == Time.parse(@test_object5.create_date)
851
+ #
852
+ # Time.parse(test_from_solr_object2.modified_date).should == Time.parse(@test_object2.modified_date)
853
+ # Time.parse(test_from_solr_object3.modified_date).should == Time.parse(@test_object3.modified_date)
854
+ # Time.parse(test_from_solr_object4.modified_date).should == Time.parse(@test_object4.modified_date)
855
+ # Time.parse(test_from_solr_object5.modified_date).should == Time.parse(@test_object5.modified_date)
856
+ #
857
+ # # need to test outbound and inbound relationships
858
+ # test_from_solr_object2.relationships(false).should == {:self=>{:has_model=>[model_rel.object],
859
+ # :has_part=>[r3.object],
860
+ # :has_member=>[r4.object]},
861
+ # :inbound=>{:has_part=>[r5.object]}}
862
+ # test_from_solr_object2.relationships_by_name(false).should == {:self=>{"testing"=>[r3.object],"testing2"=>[r4.object],
863
+ # "collection_members"=>[],"part_of"=>[],"parts_outbound"=>[r3.object]},
864
+ # :inbound=>{"testing_inbound"=>[r5.object],"testing_inbound2"=>[],"parts_inbound"=>[]}}
865
+ # test_from_solr_object3.relationships(false).should == {:self=>{:has_model=>[model_rel.object]},
866
+ # :inbound=>{:has_part=>[r2.object],
867
+ # :has_member=>[r5.object]}}
868
+ # test_from_solr_object3.relationships_by_name(false).should == {:self=>{"testing"=>[],"testing2"=>[], "collection_members"=>[],"part_of"=>[],"parts_outbound"=>[]},
869
+ # :inbound=>{"testing_inbound"=>[r2.object],"testing_inbound2"=>[r5.object], "parts_inbound"=>[]}}
870
+ # test_from_solr_object4.relationships(false).should == {:self=>{:has_model=>[model_rel.object]},
871
+ # :inbound=>{:has_member=>[r2.object]}}
872
+ # test_from_solr_object4.relationships_by_name(false).should == {:inbound=>{"parts_inbound"=>[], "testing_inbound"=>[], "testing_inbound2"=>[r2.object]}, :self=>{"testing2"=>[], "collection_members"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[]}}
873
+ # test_from_solr_object5.relationships(false).should == {:self=>{:has_model=>[model_rel.object],
874
+ # :has_part=>[r2.object],
875
+ # :has_member=>[r3.object]},
876
+ # :inbound=>{}}
877
+ # test_from_solr_object5.relationships_by_name(false).should == {:inbound=>{"parts_inbound"=>[], "testing_inbound"=>[], "testing_inbound2"=>[]}, :self=>{"testing2"=>[r3.object], "collection_members"=>[], "part_of"=>[], "testing"=>[r2.object], "parts_outbound"=>[r2.object]}}
878
+ # #all inbound should now be empty if no parameter supplied to relationships
879
+ # test_from_solr_object2.relationships.should == {:self=>{:has_part=>[r3.object],:has_member=>[r4.object],:has_model=>[model_rel.object]}}
880
+ # test_from_solr_object2.relationships_by_name.should == {:self=>{"testing2"=>[r4.object], "collection_members"=>[], "part_of"=>[], "testing"=>[r3.object], "parts_outbound"=>[r3.object]}}
881
+ # test_from_solr_object3.relationships.should == {:self=>{:has_model=>[model_rel.object]}}
882
+ # test_from_solr_object3.relationships_by_name.should == {:self=>{"testing2"=>[], "collection_members"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[]}}
883
+ # test_from_solr_object4.relationships.should == {:self=>{:has_model=>[model_rel.object]}}
884
+ # test_from_solr_object4.relationships_by_name.should == {:self=>{"testing2"=>[], "collection_members"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[]}}
885
+ # test_from_solr_object5.relationships.should == {:self=>{:has_model=>[model_rel.object],
886
+ # :has_part=>[r2.object],
887
+ # :has_member=>[r3.object]}}
888
+ # test_from_solr_object5.relationships_by_name.should == {:self=>{"testing2"=>[r3.object], "collection_members"=>[], "part_of"=>[], "testing"=>[r2.object], "parts_outbound"=>[r2.object]}}
889
+ # # need to check metadata
890
+ # test_from_solr_object2.fields[:language][:values].should == ["Italian"]
891
+ # test_from_solr_object2.fields[:creator][:values].should == ["Linguist, A."]
892
+ # test_from_solr_object2.fields[:geography][:values].should == ["Italy"]
893
+ # test_from_solr_object2.fields[:title][:values].should == ["Italian and Spanish: A Comparison of Common Phrases"]
894
+ # test_from_solr_object2.fields[:holding_id][:values].should == ["Holding 1"]
895
+ #
896
+ # test_from_solr_object3.fields[:language][:values].should == ["Spanish;Latin"]
897
+ # test_from_solr_object3.fields[:creator][:values].should == ["Linguist, A."]
898
+ # test_from_solr_object3.fields[:geography][:values].should == ["Spain"]
899
+ # test_from_solr_object3.fields[:title][:values].should == ["A study of the evolution of Spanish from Latin"]
900
+ # test_from_solr_object3.fields[:holding_id][:values].should == ["Holding 2"]
901
+ #
902
+ # test_from_solr_object4.fields[:language][:values].should == ["Spanish;Latin"]
903
+ # test_from_solr_object4.fields[:creator][:values].should == ["Linguist, A."]
904
+ # test_from_solr_object4.fields[:geography][:values].should == ["Spain"]
905
+ # test_from_solr_object4.fields[:title][:values].should == ["An obscure look into early nomadic tribes of Spain"]
906
+ # test_from_solr_object4.fields[:holding_id][:values].should == ["Holding 3"]
907
+ #
908
+ # #need to check system modified and system created values correct
909
+ # # need to implement for nokogiri datastream as well
910
+ # #false.should == true
911
+ # end
912
+ # end
913
+ #
914
+ # describe 'load_from_solr using relationship finders'
915
+ # it 'resulting finder should accept :load_from_solr as :response_format and return object instantiated using load_instance_from_solr' do
916
+ # # solr_result = mock("solr result")
917
+ # # SpecNode.create_inbound_relationship_finders("constituents", :is_constituent_of, :inbound => true)
918
+ # # local_node = SpecNode.new
919
+ # # mock_repo = mock("repo")
920
+ # # mock_repo.expects(:find_model).never
921
+ # # SpecNode.expects(:load_instance_from_solr).times(1)
922
+ # # local_node.expects(:internal_uri).returns("info:fedora/test:sample_pid")
923
+ # # ActiveFedora::SolrService.instance.conn.expects(:query).with("is_constituent_of_s:info\\:fedora/test\\:sample_pid").returns(solr_result)
924
+ # # local_node.constituents(:response_format => :solr).should equal(solr_result)
925
+ # end
926
+ #
927
+ # it 'when an object is loaded via solr instead of fedora it should automatically load objects from finders from solr as well' do
928
+ # @test_object2 = MockAFBaseFromSolr.new
929
+ # @test_object2.save
930
+ # @test_object3 = MockAFBaseFromSolr.new
931
+ # @test_object3.save
932
+ # @test_object2.testing_append(@test_object3)
933
+ # @test_object2.save
934
+ #
935
+ # test_object2_from_solr = MockAFBaseFromSolr.load_instance_from_solr(@test_object2.pid)
936
+ # test_object3_from_solr = MockAFBaseFromSolr.load_instance_from_solr(@test_object3.pid)
937
+ # MockAFBaseFromSolr.expects(:load_instance_from_solr).times(4)
938
+ # test_object2_from_solr.testing({:response_format=>:load_from_solr})
939
+ # test_object3_from_solr.testing_inbound({:response_format=>:load_from_solr})
940
+ # test_object2_from_solr.testing
941
+ # test_object3_from_solr.testing_inbound
942
+ # end
943
+ #
944
+ # it 'when a load_from_solr is not set it should not call load_instance_from_solr for finders unless passing option in' do
945
+ # @test_object2 = MockAFBaseFromSolr.new
946
+ # @test_object2.save
947
+ # @test_object3 = MockAFBaseFromSolr.new
948
+ # @test_object3.save
949
+ # @test_object2.testing_append(@test_object3)
950
+ # @test_object2.save
951
+ #
952
+ # MockAFBaseFromSolr.expects(:load_instance_from_solr).never()
953
+ # @test_object2.testing
954
+ # @test_object3.testing_inbound
955
+ #
956
+ # #now try calling with option
957
+ # MockAFBaseFromSolr.expects(:load_instance_from_solr).twice()
958
+ # @test_object2.testing({:response_format=>:load_from_solr})
959
+ # @test_object3.testing_inbound({:response_format=>:load_from_solr})
960
+ #
961
+ # #now call other finder method
962
+ # MockAFBaseFromSolr.expects(:load_instance_from_solr).twice()
963
+ # @test_object2.testing_from_solr
964
+ # @test_object3.testing_inbound_from_solr
965
+ #
966
+ # end
977
967
 
978
968
  end