active-fedora 3.2.2 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. data/Gemfile +2 -2
  2. data/Gemfile.lock +33 -57
  3. data/History.txt +9 -0
  4. data/active-fedora.gemspec +5 -5
  5. data/lib/active_fedora.rb +37 -10
  6. data/lib/active_fedora/base.rb +0 -18
  7. data/lib/active_fedora/datastream.rb +10 -5
  8. data/lib/active_fedora/datastreams.rb +33 -7
  9. data/lib/active_fedora/dcrdf_datastream.rb +11 -0
  10. data/lib/active_fedora/delegating.rb +2 -2
  11. data/lib/active_fedora/metadata_datastream.rb +3 -2
  12. data/lib/active_fedora/nested_attributes.rb +0 -1
  13. data/lib/active_fedora/ntriples_rdf_datastream.rb +19 -0
  14. data/lib/active_fedora/predicates.rb +4 -0
  15. data/lib/active_fedora/rdf_datastream.rb +108 -0
  16. data/lib/active_fedora/rdf_xml_writer.rb +53 -41
  17. data/lib/active_fedora/relationship_graph.rb +15 -71
  18. data/lib/active_fedora/rels_ext_datastream.rb +1 -4
  19. data/lib/active_fedora/rubydora_connection.rb +2 -9
  20. data/lib/active_fedora/unsaved_digital_object.rb +1 -0
  21. data/lib/active_fedora/version.rb +1 -1
  22. data/lib/tasks/active_fedora_dev.rake +1 -1
  23. data/spec/fixtures/dublin_core_rdf_descMetadata.nt +13 -0
  24. data/spec/fixtures/rails_root/config/fedora.yml +1 -15
  25. data/spec/integration/base_loader_spec.rb +0 -1
  26. data/spec/integration/dc_rdf_datastream_spec.rb +24 -0
  27. data/spec/integration/full_featured_model_spec.rb +1 -1
  28. data/spec/integration/model_spec.rb +0 -1
  29. data/spec/unit/active_fedora_spec.rb +22 -14
  30. data/spec/unit/base_spec.rb +9 -184
  31. data/spec/unit/datastream_collections_spec.rb +2 -2
  32. data/spec/unit/datastream_spec.rb +36 -6
  33. data/spec/unit/datastreams_spec.rb +251 -0
  34. data/spec/unit/dc_rdf_datastream_spec.rb +50 -0
  35. data/spec/unit/metadata_datastream_spec.rb +1 -1
  36. data/spec/unit/nokogiri_datastream_spec.rb +2 -2
  37. data/spec/unit/{rdf_xml_writer.rb → rdf_xml_writer_spec.rb} +8 -8
  38. data/spec/unit/relationship_graph_spec.rb +14 -0
  39. data/spec/unit/rels_ext_datastream_spec.rb +29 -2
  40. data/spec/unit/rubydora_connection_spec.rb +2 -4
  41. data/spec/unit/unsaved_digital_object_spec.rb +22 -9
  42. metadata +106 -258
  43. data/.hg/00changelog.i +0 -0
  44. data/.hg/branch +0 -1
  45. data/.hg/branch.cache +0 -2
  46. data/.hg/dirstate +0 -0
  47. data/.hg/hgrc +0 -2
  48. data/.hg/requires +0 -2
  49. data/.hg/store/00changelog.i +0 -0
  50. data/.hg/store/00manifest.i +0 -0
  51. data/.hg/store/data/.hgignore.i +0 -0
  52. data/.hg/store/data/.hgtags.i +0 -0
  53. data/.hg/store/data/_c_o_p_y_i_n_g.txt.i +0 -0
  54. data/.hg/store/data/_c_o_y_i_n_g._l_e_s_s_e_r.txt.i +0 -0
  55. data/.hg/store/data/_history.txt.i +0 -0
  56. data/.hg/store/data/_license.txt.i +0 -0
  57. data/.hg/store/data/_manifest.txt.i +0 -0
  58. data/.hg/store/data/_post_install.txt.i +0 -0
  59. data/.hg/store/data/_r_e_a_d_m_e.rdoc.i +0 -0
  60. data/.hg/store/data/_r_e_a_d_m_e.txt.i +0 -0
  61. data/.hg/store/data/_rakefile.i +0 -0
  62. data/.hg/store/data/_v_e_r_s_i_o_n.i +0 -0
  63. data/.hg/store/data/active-fedora.gemspec.i +0 -0
  64. data/.hg/store/data/active__fedora/_history.txt.i +0 -0
  65. data/.hg/store/data/active__fedora/_manifest.txt.i +0 -0
  66. data/.hg/store/data/active__fedora/_post_install.txt.i +0 -0
  67. data/.hg/store/data/active__fedora/_r_e_a_d_m_e.rdoc.i +0 -0
  68. data/.hg/store/data/active__fedora/_rakefile.i +0 -0
  69. data/.hg/store/data/active__fedora/lib/active__fedora.rb.i +0 -0
  70. data/.hg/store/data/active__fedora/script/console.i +0 -0
  71. data/.hg/store/data/active__fedora/script/destroy.i +0 -0
  72. data/.hg/store/data/active__fedora/script/generate.i +0 -0
  73. data/.hg/store/data/active__fedora/spec/active__fedora__spec.rb.i +0 -0
  74. data/.hg/store/data/active__fedora/spec/spec__helper.rb.i +0 -0
  75. data/.hg/store/data/config/fedora.yml.i +0 -0
  76. data/.hg/store/data/config/solr__mappings.yml.i +0 -0
  77. data/.hg/store/data/config/solr__mappings__af__0.1.yml.i +0 -0
  78. data/.hg/store/data/config/solr__mappings__bl__2.4.yml.i +0 -0
  79. data/.hg/store/data/lib/active-fedora.rb.i +0 -0
  80. data/.hg/store/data/lib/active__fedora.rb.i +0 -0
  81. data/.hg/store/data/lib/active__fedora/base.rb.i +0 -0
  82. data/.hg/store/data/lib/active__fedora/content__model.rb.i +0 -0
  83. data/.hg/store/data/lib/active__fedora/datastream.rb.i +0 -0
  84. data/.hg/store/data/lib/active__fedora/fedora__object.rb.i +0 -0
  85. data/.hg/store/data/lib/active__fedora/metadata__datastream.rb.i +0 -0
  86. data/.hg/store/data/lib/active__fedora/model.rb.i +0 -0
  87. data/.hg/store/data/lib/active__fedora/property.rb.i +0 -0
  88. data/.hg/store/data/lib/active__fedora/qualified__dublin__core__datastream.rb.i +0 -0
  89. data/.hg/store/data/lib/active__fedora/relationship.rb.i +0 -0
  90. data/.hg/store/data/lib/active__fedora/rels__ext__datastream.rb.i +0 -0
  91. data/.hg/store/data/lib/active__fedora/semantic__node.rb.i +0 -0
  92. data/.hg/store/data/lib/active__fedora/solr__mapper.rb.i +0 -0
  93. data/.hg/store/data/lib/active__fedora/solr__service.rb.i +0 -0
  94. data/.hg/store/data/lib/fedora/base.rb.i +0 -0
  95. data/.hg/store/data/lib/fedora/connection.rb.i +0 -0
  96. data/.hg/store/data/lib/fedora/datastream.rb.i +0 -0
  97. data/.hg/store/data/lib/fedora/fedora__object.rb.i +0 -0
  98. data/.hg/store/data/lib/fedora/formats.rb.i +0 -0
  99. data/.hg/store/data/lib/fedora/generic__search.rb.i +0 -0
  100. data/.hg/store/data/lib/fedora/repository.rb.i +0 -0
  101. data/.hg/store/data/lib/ruby-fedora.rb.i +0 -0
  102. data/.hg/store/data/lib/util/class__level__inheritable__attributes.rb.i +0 -0
  103. data/.hg/store/data/script/console.i +0 -0
  104. data/.hg/store/data/script/destroy.i +0 -0
  105. data/.hg/store/data/script/generate.i +0 -0
  106. data/.hg/store/data/solr/config/schema-1.5.xml.i +0 -0
  107. data/.hg/store/data/solr/config/schema.xml.i +0 -0
  108. data/.hg/store/data/solr/config/solrconfig-1.5.xml.i +0 -0
  109. data/.hg/store/data/spec/fixtures/changeme155.xml.i +0 -0
  110. data/.hg/store/data/spec/fixtures/dino.jpg.i +0 -0
  111. data/.hg/store/data/spec/fixtures/minivan.jpg.d +0 -0
  112. data/.hg/store/data/spec/fixtures/minivan.jpg.i +0 -0
  113. data/.hg/store/data/spec/fixtures/test__12.foxml.xml.i +0 -0
  114. data/.hg/store/data/spec/integration/active__fedora/base__spec.rb.i +0 -0
  115. data/.hg/store/data/spec/integration/active__fedora/datastream__spec.rb.i +0 -0
  116. data/.hg/store/data/spec/integration/active__fedora/fedora__object__spec.rb.i +0 -0
  117. data/.hg/store/data/spec/integration/active__fedora/full__featured__model__spec.rb.i +0 -0
  118. data/.hg/store/data/spec/integration/active__fedora/model__spec.rb.i +0 -0
  119. data/.hg/store/data/spec/integration/active__fedora/rels__ext__datastream__spec.rb.i +0 -0
  120. data/.hg/store/data/spec/integration/active__fedora/semantic__node__spec.rb.i +0 -0
  121. data/.hg/store/data/spec/integration/base__file__management__spec.rb.i +0 -0
  122. data/.hg/store/data/spec/integration/base__spec.rb.i +0 -0
  123. data/.hg/store/data/spec/integration/bug__spec.rb.i +0 -0
  124. data/.hg/store/data/spec/integration/datastream__spec.rb.i +0 -0
  125. data/.hg/store/data/spec/integration/datastreams__crud__spec.rb.i +0 -0
  126. data/.hg/store/data/spec/integration/fedora__object__spec.rb.i +0 -0
  127. data/.hg/store/data/spec/integration/full__featured__model__spec.rb.i +0 -0
  128. data/.hg/store/data/spec/integration/model__spec.rb.i +0 -0
  129. data/.hg/store/data/spec/integration/rels__ext__datastream__spec.rb.i +0 -0
  130. data/.hg/store/data/spec/integration/repository__spec.rb.i +0 -0
  131. data/.hg/store/data/spec/integration/rf__fedora__object__spec.rb.i +0 -0
  132. data/.hg/store/data/spec/integration/semantic__node__spec.rb.i +0 -0
  133. data/.hg/store/data/spec/integration/solr__service__spec.rb.i +0 -0
  134. data/.hg/store/data/spec/samples/models/audio__record.rb.i +0 -0
  135. data/.hg/store/data/spec/samples/models/image.rb.i +0 -0
  136. data/.hg/store/data/spec/samples/models/oral__history.rb.i +0 -0
  137. data/.hg/store/data/spec/samples/models/seminar.rb.i +0 -0
  138. data/.hg/store/data/spec/samples/models/seminar__audio__file.rb.i +0 -0
  139. data/.hg/store/data/spec/samples/oh__qdc.xml.i +0 -0
  140. data/.hg/store/data/spec/samples/oral__history.rb.i +0 -0
  141. data/.hg/store/data/spec/samples/oral__history__sample.xml.i +0 -0
  142. data/.hg/store/data/spec/samples/oral__history__sample__model.rb.i +0 -0
  143. data/.hg/store/data/spec/samples/oral__history__xml.xml.i +0 -0
  144. data/.hg/store/data/spec/spec.opts.i +0 -0
  145. data/.hg/store/data/spec/spec__helper.rb.i +0 -0
  146. data/.hg/store/data/spec/unit/active__fedora/base__cma__spec.rb.i +0 -0
  147. data/.hg/store/data/spec/unit/active__fedora/base__extra__spec.rb.i +0 -0
  148. data/.hg/store/data/spec/unit/active__fedora/base__spec.rb.i +0 -0
  149. data/.hg/store/data/spec/unit/active__fedora/content__model__spec.rb.i +0 -0
  150. data/.hg/store/data/spec/unit/active__fedora/datastream__spec.rb.i +0 -0
  151. data/.hg/store/data/spec/unit/active__fedora/inheritance__spec.rb.i +0 -0
  152. data/.hg/store/data/spec/unit/active__fedora/metadata__datastream__spec.rb.i +0 -0
  153. data/.hg/store/data/spec/unit/active__fedora/model__spec.rb.i +0 -0
  154. data/.hg/store/data/spec/unit/active__fedora/property__spec.rb.i +0 -0
  155. data/.hg/store/data/spec/unit/active__fedora/qualified__dublin__core__datastream__spec.rb.i +0 -0
  156. data/.hg/store/data/spec/unit/active__fedora/relationship__spec.rb.i +0 -0
  157. data/.hg/store/data/spec/unit/active__fedora/rels__ext__datastream__spec.rb.i +0 -0
  158. data/.hg/store/data/spec/unit/active__fedora/semantic__node__spec.rb.i +0 -0
  159. data/.hg/store/data/spec/unit/active__fedora/solr__service__spec.rb.i +0 -0
  160. data/.hg/store/data/spec/unit/active__fedora__spec.rb.i +0 -0
  161. data/.hg/store/data/spec/unit/base__cma__spec.rb.i +0 -0
  162. data/.hg/store/data/spec/unit/base__datastream__management__spec.rb.i +0 -0
  163. data/.hg/store/data/spec/unit/base__extra__spec.rb.i +0 -0
  164. data/.hg/store/data/spec/unit/base__file__management__spec.rb.i +0 -0
  165. data/.hg/store/data/spec/unit/base__loader__spec.rb.i +0 -0
  166. data/.hg/store/data/spec/unit/base__spec.rb.i +0 -0
  167. data/.hg/store/data/spec/unit/connection__spec.rb.i +0 -0
  168. data/.hg/store/data/spec/unit/content__model__spec.rb.i +0 -0
  169. data/.hg/store/data/spec/unit/datastream__concurrency__spec.rb.i +0 -0
  170. data/.hg/store/data/spec/unit/datastream__spec.rb.i +0 -0
  171. data/.hg/store/data/spec/unit/fedora__object__spec.rb.i +0 -0
  172. data/.hg/store/data/spec/unit/inheritance__spec.rb.i +0 -0
  173. data/.hg/store/data/spec/unit/metadata__datastream__spec.rb.i +0 -0
  174. data/.hg/store/data/spec/unit/model__spec.rb.i +0 -0
  175. data/.hg/store/data/spec/unit/property__spec.rb.i +0 -0
  176. data/.hg/store/data/spec/unit/qualified__dublin__core__datastream__spec.rb.i +0 -0
  177. data/.hg/store/data/spec/unit/relationship__spec.rb.i +0 -0
  178. data/.hg/store/data/spec/unit/rels__ext__datastream__spec.rb.i +0 -0
  179. data/.hg/store/data/spec/unit/repository__spec.rb.i +0 -0
  180. data/.hg/store/data/spec/unit/rf__datastream__spec.rb.i +0 -0
  181. data/.hg/store/data/spec/unit/semantic__node__spec.rb.i +0 -0
  182. data/.hg/store/data/spec/unit/solr__config__options__spec.rb.i +0 -0
  183. data/.hg/store/data/spec/unit/solr__mapper__spec.rb.i +0 -0
  184. data/.hg/store/data/spec/unit/solr__service__spec.rb.i +0 -0
  185. data/.hg/store/data/tasks/rspec.rake.i +0 -0
  186. data/.hg/store/undo +0 -0
  187. data/.hg/undo.branch +0 -1
  188. data/.hg/undo.dirstate +0 -0
  189. data/.hgignore +0 -7
  190. data/.hgtags +0 -14
@@ -17,12 +17,16 @@ describe ActiveFedora::Datastream do
17
17
  @test_datastream.to_param.should == 'foo%2ebar'
18
18
  end
19
19
 
20
+ it "should be inspectable" do
21
+ @test_datastream.inspect.should match /#<ActiveFedora::Datastream:-?\d+ @pid=\"__DO_NOT_USE__\" @dsid=\"abcd\" @controlGroup=\"M\" @dirty=\"false\" @mimeType=\"\" >/
22
+ end
23
+
20
24
  describe '#save' do
21
25
  it "should set dirty? to false" do
22
- @mock_repo = mock('repository')
23
- @mock_repo.stubs(:add_datastream).with(:mimeType=>'text/xml', :versionable => true, :pid => @test_object.pid, :dsid => 'abcd', :controlGroup => 'M', :dsState => 'A', :content => 'hi there', :checksumType => 'DISABLED')
24
- @mock_repo.expects(:datastream).with(:dsid => 'abcd', :pid => @test_object.pid)
25
- @test_object.inner_object.stubs(:repository).returns(@mock_repo)
26
+ mock_repo = mock('repository', :config=>{})
27
+ mock_repo.stubs(:add_datastream).with(:mimeType=>'text/xml', :versionable => true, :pid => @test_object.pid, :dsid => 'abcd', :controlGroup => 'M', :dsState => 'A', :content => 'hi there')
28
+ mock_repo.expects(:datastream).with(:dsid => 'abcd', :pid => @test_object.pid)
29
+ @test_object.inner_object.stubs(:repository).returns(mock_repo)
26
30
  @test_datastream.dirty?.should be_true
27
31
  @test_datastream.save
28
32
  @test_datastream.dirty?.should be_false
@@ -85,8 +89,10 @@ describe ActiveFedora::Datastream do
85
89
  <dsChecksum>none</dsChecksum>
86
90
  </datastreamProfile>"
87
91
  EOS
88
- @test_datastream.expects(:repository).returns(@mock_repo)
89
- @mock_repo.expects(:datastream).with(:dsid => 'abcd', :pid => @test_object.pid).returns(ds_profile)
92
+
93
+ mock_repo = mock('repository', :config=>{})
94
+ @test_datastream.stubs(:repository).returns(mock_repo)
95
+ mock_repo.expects(:datastream).with(:dsid => 'abcd', :pid => @test_object.pid).returns(ds_profile)
90
96
  @test_datastream.size.should == 9999
91
97
  end
92
98
 
@@ -94,5 +100,29 @@ describe ActiveFedora::Datastream do
94
100
  @test_datastream.size.should be_nil
95
101
  end
96
102
  end
103
+
104
+ describe ".from_xml" do
105
+ it "should load a FOXML datastream node" do
106
+ ds_xml = <<-EOS
107
+ <foxml:datastream ID="DC" STATE="A" CONTROL_GROUP="X" VERSIONABLE="true" xmlns:foxml="info:fedora/fedora-system:def/foxml#">
108
+ <foxml:xmlContent>
109
+ <datastream ID="DC" STATE="A" CONTROL_GROUP="X" VERSIONABLE="true">
110
+ <datastreamVersion ID="DC.1" LABEL="Dublin Core Record for this object" CREATED="2011-09-28T22:50:18.626Z" MIMETYPE="text/xml" FORMAT_URI="http://www.openarchives.org/OAI/2.0/oai_dc/" SIZE="526">
111
+ <xmlContent>
112
+ <oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
113
+ <dc:title>Title</dc:title>
114
+ <dc:identifier>0123456789</dc:identifier>
115
+ </oai_dc:dc>
116
+ </xmlContent>
117
+ </datastreamVersion>
118
+ </datastream>
119
+ </foxml:xmlContent>
120
+ </foxml:datastream>
121
+ EOS
122
+ ds_node = Nokogiri::XML(ds_xml).root
123
+ ds = ActiveFedora::Datastream.from_xml(@test_datastream, ds_node)
124
+ ds.should be_a(ActiveFedora::Datastream)
125
+ end
126
+ end
97
127
 
98
128
  end
@@ -0,0 +1,251 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveFedora::Datastreams do
4
+ before do
5
+ @test_object = ActiveFedora::Base.new
6
+ end
7
+
8
+ it "should respond_to has_metadata" do
9
+ ActiveFedora::Base.respond_to?(:has_metadata).should be_true
10
+ end
11
+
12
+ describe "has_metadata" do
13
+ @@last_pid = 0
14
+ def increment_pid
15
+ @@last_pid += 1
16
+ end
17
+
18
+ before(:each) do
19
+ @this_pid = increment_pid.to_s
20
+ stub_get(@this_pid)
21
+ Rubydora::Repository.any_instance.stubs(:client).returns(@mock_client)
22
+ ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(@this_pid)
23
+ end
24
+
25
+ describe "creates datastreams" do
26
+ before do
27
+ class FooHistory < ActiveFedora::Base
28
+ has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"someData" do |m|
29
+ m.field "fubar", :string
30
+ m.field "swank", :text
31
+ end
32
+ has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"withText" do |m|
33
+ m.field "fubar", :text
34
+ end
35
+ has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"withText2", :label=>"withLabel" do |m|
36
+ m.field "fubar", :text
37
+ end
38
+ delegate :fubar, :to=>'withText'
39
+ delegate :swank, :to=>'someData'
40
+ end
41
+ stub_ingest(@this_pid)
42
+ stub_add_ds(@this_pid, ['RELS-EXT', 'someData', 'withText', 'withText2'])
43
+
44
+ @n = FooHistory.new()
45
+ @n.datastreams['RELS-EXT'].expects(:changed?).returns(true).at_least_once
46
+ @n.expects(:update_index)
47
+ @n.save
48
+ end
49
+
50
+ after do
51
+ Object.send(:remove_const, :FooHistory)
52
+ end
53
+
54
+ it "should create specified datastreams with specified fields" do
55
+ @n.datastreams["someData"].should_not be_nil
56
+ @n.datastreams["someData"].fubar_values='bar'
57
+ @n.datastreams["someData"].fubar_values.should == ['bar']
58
+ @n.datastreams["withText2"].dsLabel.should == "withLabel"
59
+ end
60
+ end
61
+
62
+
63
+ it "should create specified datastreams with appropriate control group" do
64
+ ActiveFedora.fedora_config.stubs(:[]).returns({:url=>'sub_url'})
65
+ stub_ingest(@this_pid)
66
+ stub_add_ds(@this_pid, ['RELS-EXT', 'DC', 'rightsMetadata', 'properties', 'descMetadata', 'UKETD_DC'])
67
+ stub_get(@this_pid, ['RELS-EXT', 'DC', 'rightsMetadata', 'properties', 'descMetadata', 'UKETD_DC'])
68
+ class UketdObject < ActiveFedora::Base
69
+ has_metadata :name => "rightsMetadata", :label=>"Rights metadata", :type => ActiveFedora::NokogiriDatastream
70
+
71
+ # Uses the Hydra MODS Article profile for tracking most of the descriptive metadata
72
+ # TODO: define terminology for ETD
73
+ has_metadata :name => "descMetadata", :label=>"MODS metadata", :control_group=>"M", :type => ActiveFedora::NokogiriDatastream
74
+
75
+ has_metadata :name => "UKETD_DC", :label=>"UKETD_DC metadata", :control_group => "E", :disseminator=>"hull-sDef:uketdObject/getUKETDMetadata", :type => ActiveFedora::NokogiriDatastream
76
+
77
+ has_metadata :name => "DC", :type => ActiveFedora::NokogiriDatastream, :label=>"DC admin metadata"
78
+
79
+ # A place to put extra metadata values
80
+ has_metadata :name => "properties", :label=>"Workflow properties", :type => ActiveFedora::MetadataDatastream do |m|
81
+ m.field 'collection', :string
82
+ m.field 'depositor', :string
83
+ end
84
+
85
+ end
86
+ @n = UketdObject.new()
87
+ @n.save
88
+ @n.datastreams["DC"].controlGroup.should eql("X")
89
+ @n.datastreams["rightsMetadata"].controlGroup.should eql("X")
90
+ @n.datastreams["properties"].controlGroup.should eql("X")
91
+ @n.datastreams["descMetadata"].controlGroup.should eql("M")
92
+ @n.datastreams["UKETD_DC"].controlGroup.should eql("E")
93
+ @n.datastreams["UKETD_DC"].dsLocation.should == "sub_url/objects/#{@this_pid}/methods/hull-sDef:uketdObject/getUKETDMetadata"
94
+ end
95
+
96
+ context ":control_group => 'E'" do
97
+ before do
98
+ stub_get(@this_pid)
99
+ stub_add_ds(@this_pid, ['RELS-EXT', 'externalDisseminator', 'externalUrl'])
100
+ end
101
+ before :all do
102
+ class MoreFooHistory < ActiveFedora::Base
103
+ has_metadata :type=>ActiveFedora::NokogiriDatastream, :name=>"externalDisseminator", :control_group => "E"
104
+ end
105
+ end
106
+
107
+ after(:all) do
108
+ # clean up test class
109
+ Object.send(:remove_const, :MoreFooHistory)
110
+ end
111
+ it "should raise an error without :disseminator or :url option" do
112
+ lambda { @n = MoreFooHistory.new }.should raise_exception
113
+ end
114
+
115
+ it "should allow :control_group => 'E' with a :url option" do
116
+ class MoreFooHistory < ActiveFedora::Base
117
+ has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "E", :url => "http://exampl.com/mypic.jpg"
118
+ end
119
+ stub_ingest(@this_pid)
120
+ @n = MoreFooHistory.new
121
+ @n.save
122
+ end
123
+ it "should raise an error if :url is malformed" do
124
+ class MoreFooHistory < ActiveFedora::Base
125
+ has_metadata :type => ActiveFedora::NokogiriDatastream, :name=>"externalUrl", :url=>"my_rul", :control_group => "E"
126
+ end
127
+ client = mock_client.stubs(:[]).with do |params|
128
+ /objects\/#{@this_pid}\/datastreams\/externalUrl/.match(params)
129
+ end
130
+ client.raises(RuntimeError, "Error adding datastream externalUrl for object changeme:4020. See logger for details")
131
+ @n = MoreFooHistory.new
132
+ lambda {@n.save }.should raise_exception
133
+ end
134
+ end
135
+
136
+ context ":control_group => 'R'" do
137
+ before do
138
+ stub_get(@this_pid)
139
+ stub_add_ds(@this_pid, ['RELS-EXT', 'externalDisseminator' ])
140
+ end
141
+ it "should raise an error without :url option" do
142
+ class MoreFooHistory < ActiveFedora::Base
143
+ has_metadata :type=>ActiveFedora::NokogiriDatastream, :name=>"externalDisseminator", :control_group => "R"
144
+ end
145
+ lambda { @n = MoreFooHistory.new }.should raise_exception
146
+ end
147
+
148
+ it "should work with a valid :url option" do
149
+ stub_ingest(@this_pid)
150
+ class MoreFooHistory < ActiveFedora::Base
151
+ has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "R", :url => "http://exampl.com/mypic.jpg"
152
+ end
153
+ @n = MoreFooHistory.new
154
+ @n.save
155
+ end
156
+ it "should not take a :disseminator option without a :url option" do
157
+ class MoreFooHistory < ActiveFedora::Base
158
+ has_metadata :type=>ActiveFedora::NokogiriDatastream, :name=>"externalDisseminator", :control_group => "R", :disseminator => "foo:s-def/hull-cModel:Foo"
159
+ end
160
+ lambda { @n = MoreFooHistory.new }.should raise_exception
161
+ end
162
+ it "should raise an error if :url is malformed" do
163
+ class MoreFooHistory < ActiveFedora::Base
164
+ has_metadata :type => ActiveFedora::NokogiriDatastream, :name=>"externalUrl", :url=>"my_rul", :control_group => "R"
165
+ end
166
+ client = mock_client.stubs(:[]).with do |params|
167
+ /objects\/#{@this_pid}\/datastreams\/externalUrl/.match(params)
168
+ end
169
+ client.raises(RuntimeError, "Error adding datastream externalUrl for object changeme:4020. See logger for details")
170
+ lambda {MoreFooHistory.new }.should raise_exception
171
+ end
172
+ end
173
+ end
174
+
175
+ describe "#create_datastream" do
176
+ it 'should create a datastream object using the type of object supplied in the string (does reflection)' do
177
+ f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
178
+ f.stubs(:content_type).returns("image/jpeg")
179
+ f.stubs(:original_filename).returns("minivan.jpg")
180
+ ds = @test_object.create_datastream("ActiveFedora::Datastream", 'NAME', {:blob=>f})
181
+ ds.class.should == ActiveFedora::Datastream
182
+ ds.dsLabel.should == "minivan.jpg"
183
+ ds.mimeType.should == "image/jpeg"
184
+ end
185
+ it 'should create a datastream object from a string' do
186
+ ds = @test_object.create_datastream("ActiveFedora::Datastream", 'NAME', {:blob=>"My file data"})
187
+ ds.class.should == ActiveFedora::Datastream
188
+ ds.dsLabel.should == nil
189
+ ds.mimeType.should == "application/octet-stream"
190
+ end
191
+
192
+ it 'should not set dsLocation if dsLocation is nil' do
193
+ ActiveFedora::Datastream.any_instance.expects(:dsLocation=).never
194
+ ds = @test_object.create_datastream("ActiveFedora::Datastream", 'NAME', {:dsLocation=>nil})
195
+ end
196
+
197
+ it 'should set attributes passed in onto the datastream' do
198
+ ds = @test_object.create_datastream("ActiveFedora::Datastream", 'NAME', {:dsLocation=>"a1", :mimeType=>'image/png', :controlGroup=>'X', :dsLabel=>'My Label', :checksumType=>'SHA-1'})
199
+ ds.location.should == 'a1'
200
+ ds.mimeType.should == 'image/png'
201
+ ds.controlGroup.should == 'X'
202
+ ds.label.should == 'My Label'
203
+ ds.checksumType.should == 'SHA-1'
204
+ end
205
+ end
206
+
207
+ describe ".has_file_datastream" do
208
+ before do
209
+ class FileDS < ActiveFedora::Datastream; end
210
+ class FooHistory < ActiveFedora::Base
211
+ has_file_datastream :type=>FileDS
212
+ end
213
+ end
214
+ after do
215
+ Object.send(:remove_const, :FooHistory)
216
+ Object.send(:remove_const, :FileDS)
217
+ end
218
+ it "Should add a line in ds_spec" do
219
+ FooHistory.ds_specs['content'][:type].should == FileDS
220
+ FooHistory.ds_specs['content'][:label].should == "File Datastream"
221
+ FooHistory.ds_specs['content'][:control_group].should == "M"
222
+ end
223
+ end
224
+
225
+ describe "#add_file_datastream" do
226
+ before do
227
+ @mock_file = mock('file')
228
+ end
229
+ it "should pass prefix" do
230
+ stub_add_ds(@test_object.pid, ['content1'])
231
+ @test_object.add_file_datastream(@mock_file, :prefix=>'content' )
232
+ @test_object.datastreams.keys.should include 'content1'
233
+ end
234
+ it "should pass dsid" do
235
+ stub_add_ds(@test_object.pid, ['MY_DSID'])
236
+ @test_object.add_file_datastream(@mock_file, :dsid=>'MY_DSID')
237
+ @test_object.datastreams.keys.should include 'MY_DSID'
238
+ end
239
+ it "without dsid or prefix" do
240
+ stub_add_ds(@test_object.pid, ['DS1'])
241
+ @test_object.add_file_datastream(@mock_file, {} )
242
+ @test_object.datastreams.keys.should include 'DS1'
243
+ end
244
+ it "Should pass checksum Type" do
245
+ stub_add_ds(@test_object.pid, ['DS1'])
246
+ @test_object.add_file_datastream(@mock_file, {:checksumType=>'MD5'} )
247
+ @test_object.datastreams['DS1'].checksumType.should == 'MD5'
248
+ end
249
+ end
250
+
251
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveFedora::DCRDFDatastream do
4
+
5
+ describe "an instance with content" do
6
+ before do
7
+ @subject = ActiveFedora::DCRDFDatastream.new(@inner_object, 'dc_rdf')
8
+ @subject.content = File.new('spec/fixtures/dublin_core_rdf_descMetadata.nt').read
9
+ @subject.stubs(:pid => 'test:1')
10
+ @subject.stubs(:new? => false)
11
+ end
12
+ it "should have controlGroup" do
13
+ @subject.controlGroup.should == 'M'
14
+ end
15
+ it "should have mimeType" do
16
+ @subject.mimeType.should == 'text/plain'
17
+ end
18
+ it "should have dsid" do
19
+ @subject.dsid.should == 'dc_rdf'
20
+ end
21
+ it "should have fields" do
22
+ @subject.publisher.should == ["Penn State"]
23
+ end
24
+ it "should have method missing" do
25
+ lambda{@subject.frank}.should raise_exception NoMethodError
26
+ end
27
+
28
+ it "should set fields" do
29
+ @subject.publisher= "St. Martin's Press"
30
+ @subject.publisher.should == ["St. Martin's Press"]
31
+ end
32
+ it "should append fields" do
33
+ @subject.append(RDF::DC.publisher, "St. Martin's Press")
34
+ @subject.publisher.should == ["Penn State", "St. Martin's Press"]
35
+ end
36
+
37
+ end
38
+
39
+ describe "a new instance" do
40
+ before do
41
+ @subject = ActiveFedora::DCRDFDatastream.new(@inner_object, 'dc_rdf')
42
+ @subject.stubs(:pid => 'test:1')
43
+ end
44
+ it "should save and reload" do
45
+ @subject.publisher= ["St. Martin's Press"]
46
+ @subject.save
47
+ end
48
+ end
49
+
50
+ end
@@ -22,7 +22,7 @@ describe ActiveFedora::MetadataDatastream do
22
22
  @test_object = ActiveFedora::Base.new
23
23
  @mock_repo = mock('repository')
24
24
  @mock_repo.stubs(:datastream)
25
- @mock_repo.stubs(:datastream_dissemination=>'My Content')
25
+ @mock_repo.stubs(:datastream_dissemination=>'My Content', :config=>{})
26
26
  mock_inner.stubs(:repository).returns(@mock_repo)
27
27
  mock_inner.stubs(:pid)
28
28
  @test_ds = ActiveFedora::MetadataDatastream.new(mock_inner, 'mdDs')
@@ -16,7 +16,7 @@ describe ActiveFedora::NokogiriDatastream do
16
16
  before(:each) do
17
17
  @mock_inner = mock('inner object')
18
18
  @mock_repo = mock('repository')
19
- @mock_repo.stubs(:datastream_dissemination=>'My Content')
19
+ @mock_repo.stubs(:datastream_dissemination=>'My Content', :config=>{})
20
20
  @mock_inner.stubs(:repository).returns(@mock_repo)
21
21
  @mock_inner.stubs(:pid)
22
22
  @test_ds = ActiveFedora::NokogiriDatastream.new(@mock_inner, "descMetadata")
@@ -172,7 +172,7 @@ describe ActiveFedora::NokogiriDatastream do
172
172
  it "should persist the product of .to_xml in fedora" do
173
173
  @test_ds.expects(:new?).returns(true).twice
174
174
  @mock_repo.expects(:datastream).with(:pid => nil, :dsid => 'descMetadata')
175
- @mock_repo.expects(:add_datastream).with(:pid => nil, :dsid => 'descMetadata', :checksumType => 'DISABLED', :versionable => true, :content => 'fake xml', :controlGroup => 'M', :dsState => 'A', :mimeType=>'text/xml')
175
+ @mock_repo.expects(:add_datastream).with(:pid => nil, :dsid => 'descMetadata', :versionable => true, :content => 'fake xml', :controlGroup => 'M', :dsState => 'A', :mimeType=>'text/xml')
176
176
  @test_ds.expects(:to_xml).returns("fake xml")
177
177
  @test_ds.serialize!
178
178
  @test_ds.save
@@ -28,24 +28,24 @@ describe ActiveFedora::RDFXMLWriter do
28
28
  it "should serialize graphs using the rdf:Description element despite the presence of rdf:type statements" do
29
29
  graph = RDF::Graph.new
30
30
  subject = RDF::URI.new "info:fedora/test:sample_pid"
31
- graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:is_member_of), RDF::URI.new('demo:10'))
31
+ graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:is_member_of), RDF::URI.new('demo:10'))
32
32
  graph.insert RDF::Statement.new(subject, RDF::URI('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), RDF::URI.new('http://purl.org/dc/dcmitype/Collection'))
33
- content = RDF::RDFXML::Writer.buffer do |writer|
33
+ content = ActiveFedora::RDFXMLWriter.buffer do |writer|
34
34
  graph.each_statement do |statement|
35
35
  writer << statement
36
36
  end
37
37
  end
38
- EquivalentXml.equivalent?(content, @rdf_xml_with_type).should be_true
38
+ content.should be_equivalent_to @rdf_xml_with_type
39
39
  end
40
40
 
41
41
  it 'should serialize graphs without rdf:type equivalently to RDF::RDFXML::Writer' do
42
42
  graph = RDF::Graph.new
43
43
  subject = RDF::URI.new "info:fedora/test:sample_pid"
44
- graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:is_member_of), RDF::URI.new('info:fedora/demo:10'))
45
- graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:is_part_of), RDF::URI.new('info:fedora/demo:11'))
46
- graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:has_part), RDF::URI.new('info:fedora/demo:12'))
47
- graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:has_model), RDF::URI.new("info:fedora/afmodel:OtherModel"))
48
- graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:has_model), RDF::URI.new("info:fedora/afmodel:SampleModel"))
44
+ graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:is_member_of), RDF::URI.new('info:fedora/demo:10'))
45
+ graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:is_part_of), RDF::URI.new('info:fedora/demo:11'))
46
+ graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_part), RDF::URI.new('info:fedora/demo:12'))
47
+ graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_model), RDF::URI.new("info:fedora/afmodel:OtherModel"))
48
+ graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_model), RDF::URI.new("info:fedora/afmodel:SampleModel"))
49
49
 
50
50
  local_content = ActiveFedora::RDFXMLWriter.buffer do |writer|
51
51
  graph.each_statement do |statement|
@@ -40,6 +40,13 @@ describe ActiveFedora::RelationshipGraph do
40
40
  @graph[:has_part].should == [@n1]
41
41
  end
42
42
 
43
+ describe "has_predicate?" do
44
+ it "should return true when it has it" do
45
+ @graph.has_predicate?(:has_part).should be_false
46
+ @graph.add(:has_part, @n1)
47
+ @graph.has_predicate?(:has_part).should be_true
48
+ end
49
+ end
43
50
 
44
51
  describe "delete" do
45
52
  it "should delete an object when an object is passed" do
@@ -69,6 +76,13 @@ describe ActiveFedora::RelationshipGraph do
69
76
  @graph.delete(:has_part, 'info:fedora/foo:777')
70
77
  @graph[:has_part].should == []
71
78
  end
79
+
80
+ it "should delete all the predicates if only one arg is passed" do
81
+ @graph.add(:has_part, @n1)
82
+ @graph[:has_part].should == [@n1]
83
+ @graph.delete(:has_part)
84
+ @graph.has_predicate?(:has_part).should_not be_true
85
+ end
72
86
  end
73
87
  describe "build_statement" do
74
88
  it "should raise an error when the target is a pid, not a uri" do