active-fedora 8.7.0 → 9.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (242) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +8 -15
  3. data/Gemfile +5 -5
  4. data/History.txt +0 -80
  5. data/README.md +1 -0
  6. data/Rakefile +0 -3
  7. data/active-fedora.gemspec +8 -7
  8. data/config/fedora.yml +5 -4
  9. data/config/predicate_mappings.yml +5 -5
  10. data/gemfiles/rails4.1.gemfile +10 -0
  11. data/gemfiles/rails4.2.beta.gemfile +10 -0
  12. data/lib/active_fedora.rb +151 -117
  13. data/lib/active_fedora/associations.rb +47 -15
  14. data/lib/active_fedora/associations/association.rb +29 -8
  15. data/lib/active_fedora/associations/association_scope.rb +5 -5
  16. data/lib/active_fedora/associations/belongs_to_association.rb +20 -63
  17. data/lib/active_fedora/associations/builder/association.rb +61 -25
  18. data/lib/active_fedora/associations/builder/belongs_to.rb +7 -94
  19. data/lib/active_fedora/associations/builder/collection_association.rb +11 -43
  20. data/lib/active_fedora/associations/builder/contains.rb +28 -0
  21. data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +13 -3
  22. data/lib/active_fedora/associations/builder/has_many.rb +16 -10
  23. data/lib/active_fedora/associations/builder/property.rb +14 -0
  24. data/lib/active_fedora/associations/builder/singular_association.rb +14 -18
  25. data/lib/active_fedora/associations/builder/singular_property.rb +12 -0
  26. data/lib/active_fedora/associations/collection_association.rb +57 -80
  27. data/lib/active_fedora/associations/contains_association.rb +50 -0
  28. data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +44 -24
  29. data/lib/active_fedora/associations/has_many_association.rb +46 -14
  30. data/lib/active_fedora/associations/rdf.rb +86 -0
  31. data/lib/active_fedora/associations/singular_association.rb +4 -8
  32. data/lib/active_fedora/associations/singular_rdf.rb +15 -0
  33. data/lib/active_fedora/attached_files.rb +195 -0
  34. data/lib/active_fedora/attribute_methods.rb +122 -0
  35. data/lib/active_fedora/attribute_methods/dirty.rb +16 -0
  36. data/lib/active_fedora/attribute_methods/read.rb +61 -0
  37. data/lib/active_fedora/attribute_methods/write.rb +47 -0
  38. data/lib/active_fedora/attributes.rb +93 -44
  39. data/lib/active_fedora/attributes/primary_key.rb +12 -0
  40. data/lib/active_fedora/autosave_association.rb +2 -2
  41. data/lib/active_fedora/base.rb +16 -15
  42. data/lib/active_fedora/callbacks.rb +7 -7
  43. data/lib/active_fedora/change_set.rb +34 -0
  44. data/lib/active_fedora/cleaner.rb +62 -0
  45. data/lib/active_fedora/config.rb +4 -22
  46. data/lib/active_fedora/core.rb +173 -99
  47. data/lib/active_fedora/datastream.rb +4 -117
  48. data/lib/active_fedora/datastreams.rb +2 -263
  49. data/lib/active_fedora/datastreams/nokogiri_datastreams.rb +28 -51
  50. data/lib/active_fedora/{datastream_attribute.rb → delegated_attribute.rb} +57 -26
  51. data/lib/active_fedora/errors.rb +61 -0
  52. data/lib/active_fedora/fedora.rb +19 -0
  53. data/lib/active_fedora/fedora_attributes.rb +58 -26
  54. data/lib/active_fedora/file.rb +318 -0
  55. data/lib/active_fedora/file_configurator.rb +32 -32
  56. data/lib/active_fedora/file_path_builder.rb +24 -0
  57. data/lib/active_fedora/files_hash.rb +82 -0
  58. data/lib/active_fedora/fixity_service.rb +40 -0
  59. data/lib/active_fedora/indexing.rb +55 -82
  60. data/lib/active_fedora/indexing_service.rb +70 -0
  61. data/lib/active_fedora/ldp_resource.rb +26 -0
  62. data/lib/active_fedora/loadable_from_json.rb +112 -0
  63. data/lib/active_fedora/model.rb +5 -19
  64. data/lib/active_fedora/nested_attributes.rb +5 -6
  65. data/lib/active_fedora/nom_datastream.rb +15 -25
  66. data/lib/active_fedora/om_datastream.rb +26 -197
  67. data/lib/active_fedora/persistence.rb +95 -71
  68. data/lib/active_fedora/predicates.rb +4 -4
  69. data/lib/active_fedora/qualified_dublin_core_datastream.rb +17 -18
  70. data/lib/active_fedora/querying.rb +3 -4
  71. data/lib/active_fedora/railtie.rb +3 -6
  72. data/lib/active_fedora/rdf.rb +3 -1
  73. data/lib/active_fedora/rdf/datastream_indexing.rb +11 -0
  74. data/lib/active_fedora/rdf/fcrepo.rb +10 -324
  75. data/lib/active_fedora/rdf/indexing.rb +20 -16
  76. data/lib/active_fedora/rdf/ldp.rb +6 -0
  77. data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +1 -1
  78. data/lib/active_fedora/rdf/persistence.rb +5 -6
  79. data/lib/active_fedora/rdf/rdf_datastream.rb +44 -37
  80. data/lib/active_fedora/rdf/rdfxml_datastream.rb +13 -0
  81. data/lib/active_fedora/rdf/rels_ext.rb +26 -0
  82. data/lib/active_fedora/reflection.rb +256 -199
  83. data/lib/active_fedora/relation.rb +18 -6
  84. data/lib/active_fedora/relation/finder_methods.rb +69 -38
  85. data/lib/active_fedora/relation/query_methods.rb +7 -3
  86. data/lib/active_fedora/rspec_matchers/belong_to_associated_active_fedora_object_matcher.rb +7 -7
  87. data/lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb +8 -8
  88. data/lib/active_fedora/rspec_matchers/have_predicate_matcher.rb +9 -11
  89. data/lib/active_fedora/simple_datastream.rb +18 -13
  90. data/lib/active_fedora/solr_instance_loader.rb +18 -38
  91. data/lib/active_fedora/solr_service.rb +37 -20
  92. data/lib/active_fedora/sparql_insert.rb +45 -0
  93. data/lib/active_fedora/test_support.rb +1 -22
  94. data/lib/active_fedora/version.rb +1 -1
  95. data/lib/active_fedora/versionable.rb +90 -0
  96. data/lib/active_fedora/with_metadata.rb +37 -0
  97. data/lib/active_fedora/with_metadata/metadata_node.rb +70 -0
  98. data/lib/generators/active_fedora/config/config_generator.rb +0 -1
  99. data/lib/generators/active_fedora/config/solr/solr_generator.rb +1 -1
  100. data/lib/generators/active_fedora/model/model_generator.rb +5 -5
  101. data/lib/generators/active_fedora/model/templates/datastream_spec.rb.erb +1 -1
  102. data/lib/generators/active_fedora/model/templates/model_spec.rb.erb +2 -2
  103. data/lib/tasks/active_fedora_dev.rake +21 -27
  104. data/spec/config_helper.rb +1 -1
  105. data/spec/fixtures/mixed_rdf_descMetadata.nt +6 -6
  106. data/spec/fixtures/rails_root/config/predicate_mappings.yml +3 -19
  107. data/spec/fixtures/solr_rdf_descMetadata.nt +6 -6
  108. data/spec/integration/associations_spec.rb +133 -153
  109. data/spec/integration/attached_files_spec.rb +164 -0
  110. data/spec/integration/attributes_spec.rb +73 -12
  111. data/spec/integration/autosave_association_spec.rb +3 -3
  112. data/spec/integration/base_spec.rb +57 -351
  113. data/spec/integration/belongs_to_association_spec.rb +86 -76
  114. data/spec/integration/bug_spec.rb +3 -3
  115. data/spec/integration/collection_association_spec.rb +4 -4
  116. data/spec/integration/complex_rdf_datastream_spec.rb +54 -56
  117. data/spec/integration/delete_all_spec.rb +18 -15
  118. data/spec/integration/eradicate_spec.rb +54 -0
  119. data/spec/integration/fedora_solr_sync_spec.rb +7 -5
  120. data/spec/integration/field_to_solr_name_spec.rb +5 -5
  121. data/spec/integration/file_fixity_spec.rb +40 -0
  122. data/spec/integration/file_spec.rb +122 -0
  123. data/spec/integration/full_featured_model_spec.rb +53 -63
  124. data/spec/integration/has_and_belongs_to_many_associations_spec.rb +141 -114
  125. data/spec/integration/has_many_associations_spec.rb +142 -64
  126. data/spec/integration/json_serialization_spec.rb +50 -8
  127. data/spec/integration/model_spec.rb +12 -29
  128. data/spec/integration/nested_attribute_spec.rb +28 -20
  129. data/spec/integration/ntriples_datastream_spec.rb +60 -57
  130. data/spec/integration/om_datastream_spec.rb +51 -140
  131. data/spec/integration/rdf_nested_attributes_spec.rb +16 -14
  132. data/spec/integration/relation_delegation_spec.rb +7 -9
  133. data/spec/integration/relation_spec.rb +9 -7
  134. data/spec/integration/scoped_query_spec.rb +26 -26
  135. data/spec/integration/solr_instance_loader_spec.rb +69 -53
  136. data/spec/integration/solr_service_spec.rb +12 -73
  137. data/spec/integration/versionable_spec.rb +477 -0
  138. data/spec/integration/with_metadata_spec.rb +52 -0
  139. data/spec/samples/hydra-mods_article_datastream.rb +10 -6
  140. data/spec/samples/models/mods_article.rb +6 -2
  141. data/spec/samples/oral_history_sample.xml +1 -1
  142. data/spec/samples/oral_history_xml.xml +1 -1
  143. data/spec/samples/special_thing.rb +3 -3
  144. data/spec/spec_helper.rb +22 -12
  145. data/spec/support/an_active_model.rb +3 -7
  146. data/spec/unit/active_fedora_spec.rb +20 -17
  147. data/spec/unit/attached_files_spec.rb +203 -0
  148. data/spec/unit/attributes_spec.rb +286 -207
  149. data/spec/unit/base_active_model_spec.rb +8 -8
  150. data/spec/unit/base_datastream_management_spec.rb +11 -24
  151. data/spec/unit/base_extra_spec.rb +17 -67
  152. data/spec/unit/base_spec.rb +163 -428
  153. data/spec/unit/builder/has_and_belongs_to_many_spec.rb +2 -2
  154. data/spec/unit/callback_spec.rb +38 -23
  155. data/spec/unit/change_set_spec.rb +46 -0
  156. data/spec/unit/code_configurator_spec.rb +5 -5
  157. data/spec/unit/config_spec.rb +9 -14
  158. data/spec/unit/core_spec.rb +59 -8
  159. data/spec/unit/file_configurator_spec.rb +55 -53
  160. data/spec/unit/file_path_builder_spec.rb +18 -0
  161. data/spec/unit/file_spec.rb +221 -0
  162. data/spec/unit/files_hash_spec.rb +53 -0
  163. data/spec/unit/fixity_service_spec.rb +34 -0
  164. data/spec/unit/has_and_belongs_to_many_association_spec.rb +134 -0
  165. data/spec/unit/has_many_association_spec.rb +51 -0
  166. data/spec/unit/indexing_service_spec.rb +23 -0
  167. data/spec/unit/indexing_spec.rb +26 -0
  168. data/spec/unit/inheritance_spec.rb +9 -10
  169. data/spec/unit/model_spec.rb +15 -33
  170. data/spec/unit/nom_datastream_spec.rb +13 -10
  171. data/spec/unit/ntriples_datastream_spec.rb +81 -96
  172. data/spec/unit/om_datastream_spec.rb +137 -227
  173. data/spec/unit/persistence_spec.rb +28 -34
  174. data/spec/unit/predicates_spec.rb +29 -29
  175. data/spec/unit/property_spec.rb +1 -3
  176. data/spec/unit/qualified_dublin_core_datastream_spec.rb +27 -32
  177. data/spec/unit/query_spec.rb +116 -149
  178. data/spec/unit/rdf_datastream_spec.rb +25 -43
  179. data/spec/unit/rdf_resource_datastream_spec.rb +24 -123
  180. data/spec/unit/{rdfxml_rdf_datastream_spec.rb → rdfxml_datastream_spec.rb} +21 -25
  181. data/spec/unit/readonly_spec.rb +23 -0
  182. data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +6 -6
  183. data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +6 -6
  184. data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +6 -6
  185. data/spec/unit/serializers_spec.rb +1 -1
  186. data/spec/unit/simple_datastream_spec.rb +12 -23
  187. data/spec/unit/solr_config_options_spec.rb +14 -17
  188. data/spec/unit/solr_service_spec.rb +38 -77
  189. data/spec/unit/sparql_insert_spec.rb +32 -0
  190. data/spec/unit/validations_spec.rb +8 -11
  191. metadata +96 -121
  192. data/lib/active_fedora/auditable.rb +0 -9
  193. data/lib/active_fedora/content_model.rb +0 -70
  194. data/lib/active_fedora/datastream_collections.rb +0 -302
  195. data/lib/active_fedora/datastream_hash.rb +0 -35
  196. data/lib/active_fedora/digital_object.rb +0 -55
  197. data/lib/active_fedora/fixture_exporter.rb +0 -33
  198. data/lib/active_fedora/fixture_loader.rb +0 -48
  199. data/lib/active_fedora/rdf/identifiable.rb +0 -66
  200. data/lib/active_fedora/rdf/project_hydra.rb +0 -12
  201. data/lib/active_fedora/rdf/rdfxml_rdf_datastream.rb +0 -13
  202. data/lib/active_fedora/rdf_xml_writer.rb +0 -49
  203. data/lib/active_fedora/relationship_graph.rb +0 -101
  204. data/lib/active_fedora/reload_on_save.rb +0 -16
  205. data/lib/active_fedora/rels_ext_datastream.rb +0 -100
  206. data/lib/active_fedora/rspec_matchers/match_fedora_datastream_matcher.rb +0 -41
  207. data/lib/active_fedora/rubydora_connection.rb +0 -35
  208. data/lib/active_fedora/semantic_node.rb +0 -164
  209. data/lib/active_fedora/service_definitions.rb +0 -88
  210. data/lib/active_fedora/sharding.rb +0 -58
  211. data/lib/active_fedora/solr_digital_object.rb +0 -68
  212. data/lib/active_fedora/unsaved_digital_object.rb +0 -58
  213. data/lib/generators/active_fedora/config/fedora/fedora_generator.rb +0 -12
  214. data/lib/generators/active_fedora/config/fedora/templates/fedora.yml +0 -38
  215. data/lib/generators/active_fedora/config/fedora/templates/fedora_conf/conf/development/fedora.fcfg +0 -953
  216. data/lib/generators/active_fedora/config/fedora/templates/fedora_conf/conf/test/fedora.fcfg +0 -953
  217. data/lib/tasks/active_fedora.rake +0 -83
  218. data/spec/fixtures/sharded_fedora.yml +0 -11
  219. data/spec/integration/auditable_spec.rb +0 -29
  220. data/spec/integration/datastream_collections_spec.rb +0 -127
  221. data/spec/integration/datastream_spec.rb +0 -90
  222. data/spec/integration/datastreams_spec.rb +0 -173
  223. data/spec/integration/load_from_solr_spec.rb +0 -66
  224. data/spec/integration/rels_ext_datastream_spec.rb +0 -82
  225. data/spec/support/mock_fedora.rb +0 -44
  226. data/spec/unit/content_model_spec.rb +0 -86
  227. data/spec/unit/datastream_collections_spec.rb +0 -420
  228. data/spec/unit/datastream_spec.rb +0 -83
  229. data/spec/unit/datastreams_spec.rb +0 -243
  230. data/spec/unit/has_and_belongs_to_many_collection_spec.rb +0 -96
  231. data/spec/unit/has_many_collection_spec.rb +0 -35
  232. data/spec/unit/rdf_vocab_spec.rb +0 -30
  233. data/spec/unit/rdf_xml_writer_spec.rb +0 -63
  234. data/spec/unit/relationship_graph_spec.rb +0 -115
  235. data/spec/unit/reload_on_save_spec.rb +0 -24
  236. data/spec/unit/rels_ext_datastream_spec.rb +0 -170
  237. data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +0 -44
  238. data/spec/unit/rubydora_connection_spec.rb +0 -12
  239. data/spec/unit/semantic_node_spec.rb +0 -112
  240. data/spec/unit/service_definitions_spec.rb +0 -63
  241. data/spec/unit/solr_digital_object_spec.rb +0 -97
  242. data/spec/unit/unsaved_digital_object_spec.rb +0 -48
@@ -1,83 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveFedora::Datastream do
4
-
5
- before(:each) do
6
- @test_object = ActiveFedora::Base.new
7
- @test_datastream = ActiveFedora::Datastream.new(@test_object.inner_object, 'abcd')
8
- @test_datastream.content = "hi there"
9
- end
10
-
11
- its(:metadata?) { should be_falsey}
12
-
13
- it "should escape dots in to_param" do
14
- allow(@test_datastream).to receive(:dsid).and_return('foo.bar')
15
- expect(@test_datastream.to_param).to eq('foo%2ebar')
16
- end
17
-
18
- it "should be inspectable" do
19
- expect(@test_datastream.inspect).to match /#<ActiveFedora::Datastream @pid=\"\" @dsid=\"abcd\" @controlGroup=\"M\" changed=\"true\" @mimeType=\"\" >/
20
- end
21
-
22
- it "should have mimeType accessors" do
23
- ds1 = ActiveFedora::Datastream.new
24
- ds1.mimeType = "text/foo"
25
- expect(ds1.mimeType).to eq("text/foo")
26
- ds2 = ActiveFedora::Datastream.new
27
- ds2.mimeType = "text/bar"
28
- expect(ds2.mimeType).to eq("text/bar")
29
- end
30
-
31
- describe "#generate_dsid" do
32
- subject {ActiveFedora::Datastream.new(@test_object.inner_object) }
33
- let(:digital_object) { double(datastreams: {})}
34
- it "should create an autoincrementing dsid" do
35
- expect(subject.send(:generate_dsid, digital_object, 'FOO')).to eq('FOO1')
36
- end
37
-
38
- describe "when some datastreams exist" do
39
- let(:digital_object) { double(datastreams: {'FOO56' => double})}
40
- it "should start from the highest existing dsid" do
41
- expect(subject.send(:generate_dsid, digital_object, 'FOO')).to eq('FOO57')
42
- end
43
- end
44
- end
45
-
46
- describe ".size" do
47
- it "should lazily load the datastream size attribute from the fedora repository" do
48
- ds_profile = <<-EOS
49
- <datastreamProfile
50
- xmlns=\"http://www.fedora.info/definitions/1/0/management/\"
51
- xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
52
- xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
53
- xsi:schemaLocation=\"http://www.fedora.info/definitions/1/0/management/ http://www.fedora.info/definitions/1/0/datastreamProfile.xsd\"
54
- pid=\"#{@test_object.pid}\"
55
- dsID=\"#{@test_datastream.dsid}\" >
56
- <dsLabel></dsLabel>
57
- <dsVersionID>#{@test_datastream.dsid}.1</dsVersionID>
58
- <dsCreateDate>2011-07-11T16:48:13.536Z</dsCreateDate>
59
- <dsState>A</dsState>
60
- <dsMIME>text/xml</dsMIME>
61
- <dsFormatURI></dsFormatURI>
62
- <dsControlGroup>X</dsControlGroup>
63
- <dsSize>9999</dsSize>
64
- <dsVersionable>true</dsVersionable>
65
- <dsInfoType></dsInfoType>
66
- <dsLocation>#{@test_object.pid}+#{@test_datastream.dsid}+#{@test_datastream.dsid}.1</dsLocation>
67
- <dsLocationType></dsLocationType>
68
- <dsChecksumType>DISABLED</dsChecksumType>
69
- <dsChecksum>none</dsChecksum>
70
- </datastreamProfile>"
71
- EOS
72
-
73
- mock_repo = Rubydora::Repository.new
74
- allow(@test_object.inner_object).to receive(:repository).and_return(mock_repo)
75
- expect(mock_repo.api).to receive(:datastream).with(:dsid => 'abcd', :pid => @test_object.pid).and_return(ds_profile)
76
- expect(@test_datastream.size).to eq(9999)
77
- end
78
-
79
- it "should default to an empty string if ds has not been saved" do
80
- expect(@test_datastream.size).to be_nil
81
- end
82
- end
83
- end
@@ -1,243 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveFedora::Datastreams do
4
- subject { ActiveFedora::Base.new }
5
-
6
- describe '.has_metadata' do
7
- before do
8
- class FooHistory < ActiveFedora::Base
9
- has_metadata :name => 'dsid', type: ActiveFedora::SimpleDatastream
10
- has_metadata 'complex_ds', :versionable => true, :autocreate => true, :type => 'Z', :label => 'My Label', :control_group => 'Z'
11
- end
12
- end
13
-
14
- it "should have a ds_specs entry" do
15
- expect(FooHistory.ds_specs).to have_key('dsid')
16
- end
17
-
18
- it "should have reasonable defaults" do
19
- expect(FooHistory.ds_specs['dsid']).to include(:autocreate => false)
20
- end
21
-
22
- it "should let you override defaults" do
23
- expect(FooHistory.ds_specs['complex_ds']).to include(:versionable => true, :autocreate => true, :type => 'Z', :label => 'My Label', :control_group => 'Z')
24
- end
25
-
26
- it "should raise an error if you don't give a type" do
27
- expect{ FooHistory.has_metadata "bob" }.to raise_error ArgumentError,
28
- "You must provide a :type property for the datastream 'bob'"
29
- end
30
-
31
- it "should raise an error if you don't give a dsid" do
32
- expect{ FooHistory.has_metadata type: ActiveFedora::SimpleDatastream }.to raise_error ArgumentError,
33
- "You must provide a name (dsid) for the datastream"
34
- end
35
- end
36
-
37
- describe '.has_file_datastream' do
38
- before do
39
- class FooHistory < ActiveFedora::Base
40
- has_file_datastream :name => 'dsid'
41
- has_file_datastream 'another'
42
- end
43
- end
44
-
45
- it "should have reasonable defaults" do
46
- expect(FooHistory.ds_specs['dsid']).to include(:type => ActiveFedora::Datastream, :label => 'File Datastream', :control_group => 'M')
47
- expect(FooHistory.ds_specs['another']).to include(:type => ActiveFedora::Datastream, :label => 'File Datastream', :control_group => 'M')
48
- end
49
- end
50
-
51
- describe "#serialize_datastreams" do
52
- it "should touch each datastream" do
53
- m1 = double()
54
- m2 = double()
55
-
56
- expect(m1).to receive(:serialize!)
57
- expect(m2).to receive(:serialize!)
58
- allow(subject).to receive_messages(:datastreams => { :m1 => m1, :m2 => m2})
59
- subject.serialize_datastreams
60
- end
61
- end
62
-
63
- describe "#add_disseminator_location_to_datastreams" do
64
- it "should infer dsLocations for E datastreams without hitting Fedora" do
65
-
66
- mock_specs = {'e' => { :disseminator => 'xyz' }}
67
- mock_ds = double(:controlGroup => 'E')
68
- allow(ActiveFedora::Base).to receive_messages(:ds_specs => mock_specs)
69
- allow(ActiveFedora).to receive_messages(:config_for_environment => { :url => 'http://localhost'})
70
- allow(subject).to receive_messages(:pid => 'test:1', :datastreams => {'e' => mock_ds})
71
- expect(mock_ds).to receive(:dsLocation=).with("http://localhost/objects/test:1/methods/xyz")
72
- subject.add_disseminator_location_to_datastreams
73
- end
74
- end
75
-
76
- describe ".name_for_dsid" do
77
- it "should use the name" do
78
- expect(ActiveFedora::Base.send(:name_for_dsid, 'abc')).to eq('abc')
79
- end
80
-
81
- it "should use the name" do
82
- expect(ActiveFedora::Base.send(:name_for_dsid, 'ARCHIVAL_XML')).to eq('ARCHIVAL_XML')
83
- end
84
-
85
- it "should use the name" do
86
- expect(ActiveFedora::Base.send(:name_for_dsid, 'descMetadata')).to eq('descMetadata')
87
- end
88
-
89
- it "should hash-erize underscores" do
90
- expect(ActiveFedora::Base.send(:name_for_dsid, 'a-b')).to eq('a_b')
91
- end
92
- end
93
-
94
- describe "#datastreams" do
95
- it "should return the datastream hash proxy" do
96
- allow(subject).to receive(:load_datastreams)
97
- expect(subject.datastreams).to be_a_kind_of(ActiveFedora::DatastreamHash)
98
- end
99
-
100
- it "should round-trip to/from YAML" do
101
- expect(YAML.load(subject.datastreams.to_yaml).inspect).to eq(subject.datastreams.inspect)
102
- end
103
- end
104
-
105
- describe "#configure_datastream" do
106
- it "should look up the ds_spec" do
107
- mock_dsspec = { :type => nil }
108
- allow(subject).to receive_messages(:ds_specs => {'abc' => mock_dsspec})
109
- subject.configure_datastream(double(:dsid => 'abc'))
110
- end
111
-
112
- it "should be ok if there is no ds spec" do
113
- mock_dsspec = double()
114
- allow(subject).to receive_messages(:ds_specs => {})
115
- subject.configure_datastream(double(:dsid => 'abc'))
116
- end
117
-
118
- it "should configure RelsExtDatastream" do
119
- mock_dsspec = { :type => ActiveFedora::RelsExtDatastream }
120
- allow(subject).to receive_messages(:ds_specs => {'abc' => mock_dsspec})
121
-
122
- ds = double(:dsid => 'abc')
123
- expect(ds).to receive(:model=).with(subject)
124
-
125
- subject.configure_datastream(ds)
126
- end
127
-
128
- it "should run a Proc" do
129
- ds = double(:dsid => 'abc')
130
- @count = 0
131
- mock_dsspec = { :block => lambda { |x| @count += 1 } }
132
- allow(subject).to receive_messages(:ds_specs => {'abc' => mock_dsspec})
133
-
134
-
135
- expect {
136
- subject.configure_datastream(ds)
137
- }.to change { @count }.by(1)
138
- end
139
- end
140
-
141
- describe "#datastream_from_spec" do
142
- it "should fetch the rubydora datastream" do
143
- expect(subject.inner_object).to receive(:datastream_object_for).with('dsid', {}, {})
144
- subject.datastream_from_spec({}, 'dsid')
145
- end
146
- end
147
-
148
- describe "#add_datastream" do
149
- it "should add the datastream to the object" do
150
- ds = double(:dsid => 'Abc')
151
- subject.add_datastream(ds)
152
- expect(subject.datastreams['Abc']).to eq(ds)
153
- end
154
-
155
- it "should mint a dsid" do
156
- ds = ActiveFedora::Datastream.new(subject.inner_object)
157
- expect(subject.add_datastream(ds)).to eq('DS1')
158
- end
159
- end
160
-
161
- describe "#metadata_streams" do
162
- it "should only be metadata datastreams" do
163
- ds1 = double(:metadata? => true)
164
- ds2 = double(:metadata? => true)
165
- ds3 = double(:metadata? => true)
166
- relsextds = ActiveFedora::RelsExtDatastream.new
167
- file_ds = double(:metadata? => false)
168
- allow(subject).to receive_messages(:datastreams => {:a => ds1, :b => ds2, :c => ds3, :d => relsextds, :e => file_ds})
169
- expect(subject.metadata_streams).to include(ds1, ds2, ds3)
170
- expect(subject.metadata_streams).not_to include(relsextds)
171
- expect(subject.metadata_streams).not_to include(file_ds)
172
- end
173
- end
174
-
175
- describe "#relsext" do
176
- it "should be the RELS-EXT datastream" do
177
- m = double
178
- allow(subject).to receive_messages(:datastreams => { 'RELS-EXT' => m})
179
- expect(subject.rels_ext).to eq(m)
180
- end
181
-
182
- it "should make one up otherwise" do
183
- allow(subject).to receive_messages(:datastreams => {})
184
-
185
- expect(subject.rels_ext).to be_a_kind_of(ActiveFedora::RelsExtDatastream)
186
- end
187
- end
188
-
189
- describe "#add_file_datastream" do
190
- # tested elsewhere :/
191
- end
192
-
193
- describe "#create_datastream" do
194
- it "should mint a DSID" do
195
- ds = subject.create_datastream(ActiveFedora::Datastream, nil, {})
196
- expect(ds.dsid).to eq('DS1')
197
- end
198
-
199
- it "should raise an argument error if the supplied dsid is nonsense" do
200
- expect { subject.create_datastream(ActiveFedora::Datastream, 0) }.to raise_error(ArgumentError)
201
- end
202
-
203
- it "should try to get a mime type from the blob" do
204
- mock_file = double(:content_type => 'x-application/asdf')
205
- ds = subject.create_datastream(ActiveFedora::Datastream, nil, {:blob => mock_file})
206
- expect(ds.mimeType).to eq('x-application/asdf')
207
- end
208
-
209
- it "should provide a default mime type" do
210
- mock_file = double()
211
- ds = subject.create_datastream(ActiveFedora::Datastream, nil, {:blob => mock_file})
212
- expect(ds.mimeType).to eq('application/octet-stream')
213
- end
214
-
215
- it "should use the filename as a default label" do
216
- mock_file = double(:path => '/asdf/fdsa')
217
- ds = subject.create_datastream(ActiveFedora::Datastream, nil, {:blob => mock_file})
218
- expect(ds.dsLabel).to eq('fdsa')
219
- end
220
-
221
- it "should not set content for controlGroup 'E'" do
222
- ds = subject.create_datastream(ActiveFedora::Datastream, nil, {controlGroup: 'E'})
223
- expect(ds.content).to be_nil
224
- end
225
-
226
- it "should not set content for controlGroup 'R'" do
227
- ds = subject.create_datastream(ActiveFedora::Datastream, nil, {controlGroup: 'R'})
228
- expect(ds.content).to be_nil
229
- end
230
- end
231
-
232
- describe "#additional_attributes_for_external_and_redirect_control_groups" do
233
- before(:all) do
234
- @behavior = ActiveFedora::Datastreams.deprecation_behavior
235
- ActiveFedora::Datastreams.deprecation_behavior = :silence
236
- end
237
-
238
- after :all do
239
- ActiveFedora::Datastreams.deprecation_behavior = @behavior
240
- end
241
-
242
- end
243
- end
@@ -1,96 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveFedora::Associations::HasAndBelongsToManyAssociation do
4
- before do
5
- class Book < ActiveFedora::Base
6
- end
7
- class Page < ActiveFedora::Base
8
- end
9
- end
10
-
11
- after do
12
- Object.send(:remove_const, :Book)
13
- Object.send(:remove_const, :Page)
14
- end
15
-
16
- it "should call add_relationship" do
17
- subject = Book.new(pid: 'subject:a')
18
- allow(subject).to receive_messages(:new_record? => false, save: true)
19
- predicate = Book.create_reflection(:has_and_belongs_to_many, 'pages', {:property=>'predicate'}, nil)
20
- allow(ActiveFedora::SolrService).to receive(:query).and_return([])
21
- ac = ActiveFedora::Associations::HasAndBelongsToManyAssociation.new(subject, predicate)
22
- expect(ac).to receive(:callback).twice
23
- object = Page.new(:pid => 'object:b')
24
- allow(object).to receive_messages(:new_record? => false, save: true)
25
-
26
- expect(subject).to receive(:add_relationship).with('predicate', object)
27
-
28
- ac << object
29
-
30
- end
31
-
32
- it "should call add_relationship on subject and object when inverse_of given" do
33
- subject = Book.new(pid: 'subject:a')
34
- allow(subject).to receive_messages(:new_record? => false, save: true)
35
- predicate = Book.create_reflection(:has_and_belongs_to_many, 'pages', {:property=>'predicate', :inverse_of => 'inverse_predicate'}, nil)
36
- allow(ActiveFedora::SolrService).to receive(:query).and_return([])
37
- ac = ActiveFedora::Associations::HasAndBelongsToManyAssociation.new(subject, predicate)
38
- expect(ac).to receive(:callback).twice
39
- object = Page.new(:pid => 'object:b')
40
- allow(object).to receive_messages(:new_record? => false, save: true)
41
-
42
- expect(subject).to receive(:add_relationship).with('predicate', object)
43
-
44
- expect(object).to receive(:add_relationship).with('inverse_predicate', subject)
45
-
46
- ac << object
47
-
48
- end
49
-
50
- it "should call solr query multiple times" do
51
-
52
- subject = Book.new(pid: 'subject:a')
53
- allow(subject).to receive_messages(:new_record? => false, save: true)
54
- predicate = Book.create_reflection(:has_and_belongs_to_many, 'pages', {:property=>'predicate', :solr_page_size => 10}, nil)
55
- ids = []
56
- 0.upto(15) {|i| ids << i.to_s}
57
- query1 = ids.slice(0,10).map {|i| "_query_:\"{!raw f=id}#{i}\""}.join(" OR ")
58
- query2 = ids.slice(10,10).map {|i| "_query_:\"{!raw f=id}#{i}\""}.join(" OR ")
59
- expect(subject).to receive(:ids_for_outbound).and_return(ids)
60
- expect(ActiveFedora::SolrService).to receive(:query).with(query1, {:rows=>10}).and_return([])
61
- expect(ActiveFedora::SolrService).to receive(:query).with(query2, {:rows=>10}).and_return([])
62
-
63
- ac = ActiveFedora::Associations::HasAndBelongsToManyAssociation.new(subject, predicate)
64
- ac.find_target
65
- end
66
-
67
- context "class with association" do
68
- before do
69
- class Collection < ActiveFedora::Base
70
- has_and_belongs_to_many :members, :property => :has_collection_member, :class_name => "ActiveFedora::Base" , :after_remove => :remove_member
71
- def remove_member (m)
72
- end
73
- end
74
-
75
- class Thing < ActiveFedora::Base
76
- has_many :collections, property: :has_collection_member, :class_name => "ActiveFedora::Base"
77
- end
78
- end
79
-
80
- after do
81
- Collection.destroy_all
82
- Thing.destroy_all
83
- Object.send(:remove_const, :Collection)
84
- Object.send(:remove_const, :Thing)
85
- end
86
-
87
- let(:thing) {Thing.create()}
88
- let(:collection) {Collection.create().tap {|c| c.members << thing}}
89
-
90
- it "should call destroy" do
91
- expect { collection.destroy }.to_not raise_error
92
- end
93
-
94
- end
95
-
96
- end
@@ -1,35 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveFedora::Associations::HasManyAssociation do
4
- before do
5
- class Book < ActiveFedora::Base
6
- end
7
- class Page < ActiveFedora::Base
8
- end
9
- end
10
-
11
- after do
12
- Object.send(:remove_const, :Book)
13
- Object.send(:remove_const, :Page)
14
- end
15
-
16
- subject { Book.new(pid: 'subject:a') }
17
- before {
18
- allow(subject).to receive_messages(:new_record? => false, save: true)
19
- }
20
-
21
- it "should call add_relationship" do
22
- reflection = Book.create_reflection(:has_many, 'pages', {:property=>'predicate'}, Book)
23
- allow(ActiveFedora::SolrService).to receive(:query).and_return([])
24
- ac = ActiveFedora::Associations::HasManyAssociation.new(subject, reflection)
25
- expect(ac).to receive(:callback).twice
26
- object = Page.new(:pid => 'object:b')
27
- allow(object).to receive_messages(:new_record? => false, save: true)
28
-
29
- expect(object).to receive(:add_relationship).with('predicate', subject)
30
-
31
- ac << object
32
-
33
- end
34
-
35
- end