active-fedora 6.8.0 → 7.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (215) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +15 -5
  4. data/CONTRIBUTING.md +2 -0
  5. data/Gemfile +0 -2
  6. data/History.txt +2 -32
  7. data/README.md +143 -0
  8. data/Rakefile +5 -7
  9. data/active-fedora.gemspec +9 -9
  10. data/gemfiles/rails3.gemfile +11 -0
  11. data/gemfiles/rails4.gemfile +10 -0
  12. data/lib/active_fedora.rb +31 -4
  13. data/lib/active_fedora/association_relation.rb +18 -0
  14. data/lib/active_fedora/associations.rb +38 -171
  15. data/lib/active_fedora/associations/association.rb +163 -0
  16. data/lib/active_fedora/associations/association_scope.rb +39 -0
  17. data/lib/active_fedora/associations/belongs_to_association.rb +47 -25
  18. data/lib/active_fedora/associations/builder/association.rb +55 -0
  19. data/lib/active_fedora/associations/builder/belongs_to.rb +100 -0
  20. data/lib/active_fedora/associations/builder/collection_association.rb +56 -0
  21. data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +30 -0
  22. data/lib/active_fedora/associations/builder/has_many.rb +63 -0
  23. data/lib/active_fedora/associations/builder/singular_association.rb +32 -0
  24. data/lib/active_fedora/associations/{association_collection.rb → collection_association.rb} +203 -53
  25. data/lib/active_fedora/associations/collection_proxy.rb +862 -0
  26. data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +35 -25
  27. data/lib/active_fedora/associations/has_many_association.rb +36 -11
  28. data/lib/active_fedora/associations/singular_association.rb +62 -0
  29. data/lib/active_fedora/attributes.rb +43 -139
  30. data/lib/active_fedora/autosave_association.rb +317 -0
  31. data/lib/active_fedora/base.rb +10 -327
  32. data/lib/active_fedora/callbacks.rb +1 -3
  33. data/lib/active_fedora/content_model.rb +16 -0
  34. data/lib/active_fedora/core.rb +151 -0
  35. data/lib/active_fedora/datastream_attribute.rb +76 -0
  36. data/lib/active_fedora/datastream_hash.rb +8 -13
  37. data/lib/active_fedora/datastreams.rb +39 -26
  38. data/lib/active_fedora/digital_object.rb +2 -2
  39. data/lib/active_fedora/fedora_attributes.rb +45 -0
  40. data/lib/active_fedora/fixture_loader.rb +1 -1
  41. data/lib/active_fedora/indexing.rb +6 -1
  42. data/lib/active_fedora/model.rb +0 -17
  43. data/lib/active_fedora/nested_attributes.rb +2 -2
  44. data/lib/active_fedora/null_relation.rb +7 -0
  45. data/lib/active_fedora/om_datastream.rb +3 -4
  46. data/lib/active_fedora/persistence.rb +41 -29
  47. data/lib/active_fedora/querying.rb +2 -163
  48. data/lib/active_fedora/rdf.rb +1 -0
  49. data/lib/active_fedora/rdf/indexing.rb +67 -0
  50. data/lib/active_fedora/rdf_datastream.rb +2 -50
  51. data/lib/active_fedora/rdf_node.rb +12 -7
  52. data/lib/active_fedora/rdf_node/term_proxy.rb +30 -21
  53. data/lib/active_fedora/rdfxml_rdf_datastream.rb +1 -1
  54. data/lib/active_fedora/reflection.rb +163 -20
  55. data/lib/active_fedora/relation.rb +33 -130
  56. data/lib/active_fedora/relation/calculations.rb +19 -0
  57. data/lib/active_fedora/relation/delegation.rb +22 -0
  58. data/lib/active_fedora/relation/finder_methods.rb +247 -0
  59. data/lib/active_fedora/relation/merger.rb +22 -0
  60. data/lib/active_fedora/relation/query_methods.rb +58 -0
  61. data/lib/active_fedora/relation/spawn_methods.rb +46 -0
  62. data/lib/active_fedora/relationship_graph.rb +0 -2
  63. data/lib/active_fedora/rels_ext_datastream.rb +1 -4
  64. data/lib/active_fedora/rubydora_connection.rb +1 -1
  65. data/lib/active_fedora/scoping.rb +20 -0
  66. data/lib/active_fedora/scoping/default.rb +38 -0
  67. data/lib/active_fedora/scoping/named.rb +32 -0
  68. data/lib/active_fedora/semantic_node.rb +54 -106
  69. data/lib/active_fedora/serialization.rb +19 -0
  70. data/lib/active_fedora/sharding.rb +58 -0
  71. data/lib/active_fedora/solr_digital_object.rb +15 -5
  72. data/lib/active_fedora/solr_instance_loader.rb +1 -1
  73. data/lib/active_fedora/solr_service.rb +1 -1
  74. data/lib/active_fedora/unsaved_digital_object.rb +6 -4
  75. data/lib/active_fedora/version.rb +1 -1
  76. data/lib/tasks/active_fedora.rake +3 -0
  77. data/lib/tasks/active_fedora_dev.rake +6 -5
  78. data/spec/config_helper.rb +14 -14
  79. data/spec/integration/associations_spec.rb +168 -455
  80. data/spec/integration/attributes_spec.rb +12 -11
  81. data/spec/integration/auditable_spec.rb +11 -11
  82. data/spec/integration/autosave_association_spec.rb +25 -0
  83. data/spec/integration/base_spec.rb +163 -163
  84. data/spec/integration/belongs_to_association_spec.rb +166 -0
  85. data/spec/integration/bug_spec.rb +7 -7
  86. data/spec/integration/collection_association_spec.rb +58 -0
  87. data/spec/integration/complex_rdf_datastream_spec.rb +88 -88
  88. data/spec/integration/datastream_collections_spec.rb +69 -69
  89. data/spec/integration/datastream_spec.rb +43 -43
  90. data/spec/integration/datastreams_spec.rb +63 -63
  91. data/spec/integration/delete_all_spec.rb +46 -39
  92. data/spec/integration/fedora_solr_sync_spec.rb +5 -5
  93. data/spec/integration/field_to_solr_name_spec.rb +34 -0
  94. data/spec/integration/full_featured_model_spec.rb +100 -101
  95. data/spec/integration/has_and_belongs_to_many_associations_spec.rb +341 -0
  96. data/spec/integration/has_many_associations_spec.rb +172 -24
  97. data/spec/integration/json_serialization_spec.rb +31 -0
  98. data/spec/integration/load_from_solr_spec.rb +48 -0
  99. data/spec/integration/model_spec.rb +35 -40
  100. data/spec/integration/nested_attribute_spec.rb +42 -43
  101. data/spec/integration/ntriples_datastream_spec.rb +131 -113
  102. data/spec/integration/om_datastream_spec.rb +67 -67
  103. data/spec/integration/persistence_spec.rb +7 -7
  104. data/spec/integration/rdf_nested_attributes_spec.rb +56 -56
  105. data/spec/integration/relation_delegation_spec.rb +26 -25
  106. data/spec/integration/relation_spec.rb +42 -0
  107. data/spec/integration/rels_ext_datastream_spec.rb +20 -20
  108. data/spec/integration/scoped_query_spec.rb +61 -51
  109. data/spec/integration/solr_instance_loader_spec.rb +5 -5
  110. data/spec/integration/solr_service_spec.rb +46 -46
  111. data/spec/samples/hydra-mods_article_datastream.rb +334 -334
  112. data/spec/samples/hydra-rights_metadata_datastream.rb +57 -57
  113. data/spec/samples/marpa-dc_datastream.rb +17 -17
  114. data/spec/samples/models/audio_record.rb +16 -16
  115. data/spec/samples/models/image.rb +2 -2
  116. data/spec/samples/models/mods_article.rb +5 -5
  117. data/spec/samples/models/oral_history.rb +18 -18
  118. data/spec/samples/models/seminar.rb +24 -24
  119. data/spec/samples/models/seminar_audio_file.rb +17 -17
  120. data/spec/samples/oral_history_sample_model.rb +21 -21
  121. data/spec/samples/special_thing.rb +14 -14
  122. data/spec/spec_helper.rb +11 -7
  123. data/spec/support/an_active_model.rb +2 -8
  124. data/spec/support/freeze_mocks.rb +12 -0
  125. data/spec/support/mock_fedora.rb +17 -16
  126. data/spec/unit/active_fedora_spec.rb +58 -60
  127. data/spec/unit/attributes_spec.rb +314 -0
  128. data/spec/unit/base_active_model_spec.rb +28 -27
  129. data/spec/unit/base_cma_spec.rb +5 -5
  130. data/spec/unit/base_datastream_management_spec.rb +27 -27
  131. data/spec/unit/base_extra_spec.rb +76 -48
  132. data/spec/unit/base_spec.rb +277 -348
  133. data/spec/unit/callback_spec.rb +18 -19
  134. data/spec/unit/code_configurator_spec.rb +17 -17
  135. data/spec/unit/config_spec.rb +8 -16
  136. data/spec/unit/content_model_spec.rb +79 -60
  137. data/spec/unit/datastream_collections_spec.rb +229 -229
  138. data/spec/unit/datastream_spec.rb +51 -63
  139. data/spec/unit/datastreams_spec.rb +87 -87
  140. data/spec/unit/file_configurator_spec.rb +217 -217
  141. data/spec/unit/has_and_belongs_to_many_collection_spec.rb +44 -25
  142. data/spec/unit/has_many_collection_spec.rb +26 -8
  143. data/spec/unit/inheritance_spec.rb +13 -12
  144. data/spec/unit/model_spec.rb +39 -45
  145. data/spec/unit/nom_datastream_spec.rb +15 -15
  146. data/spec/unit/ntriples_datastream_spec.rb +123 -118
  147. data/spec/unit/om_datastream_spec.rb +227 -233
  148. data/spec/unit/persistence_spec.rb +34 -15
  149. data/spec/unit/predicates_spec.rb +73 -73
  150. data/spec/unit/property_spec.rb +17 -9
  151. data/spec/unit/qualified_dublin_core_datastream_spec.rb +33 -33
  152. data/spec/unit/query_spec.rb +222 -198
  153. data/spec/unit/rdf_datastream_spec.rb +21 -28
  154. data/spec/unit/rdf_list_nested_attributes_spec.rb +34 -34
  155. data/spec/unit/rdf_list_spec.rb +65 -64
  156. data/spec/unit/rdf_node_spec.rb +7 -7
  157. data/spec/unit/rdf_xml_writer_spec.rb +10 -10
  158. data/spec/unit/rdfxml_rdf_datastream_spec.rb +27 -27
  159. data/spec/unit/relationship_graph_spec.rb +51 -51
  160. data/spec/unit/rels_ext_datastream_spec.rb +68 -74
  161. data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +15 -15
  162. data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +15 -15
  163. data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +15 -15
  164. data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +12 -12
  165. data/spec/unit/rubydora_connection_spec.rb +5 -5
  166. data/spec/unit/semantic_node_spec.rb +48 -107
  167. data/spec/unit/serializers_spec.rb +4 -4
  168. data/spec/unit/service_definitions_spec.rb +26 -26
  169. data/spec/unit/simple_datastream_spec.rb +17 -17
  170. data/spec/unit/solr_config_options_spec.rb +29 -28
  171. data/spec/unit/solr_digital_object_spec.rb +17 -25
  172. data/spec/unit/solr_service_spec.rb +95 -82
  173. data/spec/unit/unsaved_digital_object_spec.rb +24 -23
  174. data/spec/unit/validations_spec.rb +21 -21
  175. metadata +110 -159
  176. data/.rspec +0 -1
  177. data/.rubocop.yml +0 -1
  178. data/.rubocop_todo.yml +0 -938
  179. data/CONSOLE_GETTING_STARTED.textile +0 -1
  180. data/NOKOGIRI_DATASTREAMS.textile +0 -1
  181. data/README.textile +0 -116
  182. data/lib/active_fedora/associations/association_proxy.rb +0 -178
  183. data/lib/active_fedora/delegating.rb +0 -72
  184. data/lib/active_fedora/nokogiri_datastream.rb +0 -11
  185. data/spec/integration/delegating_spec.rb +0 -59
  186. data/spec/rails3_test_app/.gitignore +0 -4
  187. data/spec/rails3_test_app/.rspec +0 -1
  188. data/spec/rails3_test_app/Gemfile +0 -40
  189. data/spec/rails3_test_app/Rakefile +0 -7
  190. data/spec/rails3_test_app/app/controllers/application_controller.rb +0 -3
  191. data/spec/rails3_test_app/app/helpers/application_helper.rb +0 -2
  192. data/spec/rails3_test_app/app/views/layouts/application.html.erb +0 -14
  193. data/spec/rails3_test_app/config.ru +0 -4
  194. data/spec/rails3_test_app/config/application.rb +0 -42
  195. data/spec/rails3_test_app/config/boot.rb +0 -6
  196. data/spec/rails3_test_app/config/database.yml +0 -22
  197. data/spec/rails3_test_app/config/environment.rb +0 -5
  198. data/spec/rails3_test_app/config/environments/development.rb +0 -25
  199. data/spec/rails3_test_app/config/environments/production.rb +0 -49
  200. data/spec/rails3_test_app/config/environments/test.rb +0 -35
  201. data/spec/rails3_test_app/config/initializers/backtrace_silencers.rb +0 -7
  202. data/spec/rails3_test_app/config/initializers/inflections.rb +0 -10
  203. data/spec/rails3_test_app/config/initializers/mime_types.rb +0 -5
  204. data/spec/rails3_test_app/config/initializers/secret_token.rb +0 -7
  205. data/spec/rails3_test_app/config/initializers/session_store.rb +0 -8
  206. data/spec/rails3_test_app/config/locales/en.yml +0 -5
  207. data/spec/rails3_test_app/config/routes.rb +0 -58
  208. data/spec/rails3_test_app/db/seeds.rb +0 -7
  209. data/spec/rails3_test_app/run_tests +0 -3
  210. data/spec/rails3_test_app/script/rails +0 -6
  211. data/spec/rails3_test_app/spec/spec_helper.rb +0 -27
  212. data/spec/rails3_test_app/spec/unit/rails_3_init.rb +0 -15
  213. data/spec/unit/association_proxy_spec.rb +0 -12
  214. data/spec/unit/base_delegate_spec.rb +0 -197
  215. data/spec/unit/base_delegate_to_spec.rb +0 -73
@@ -1,82 +1,110 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ActiveFedora::Base do
4
-
4
+
5
5
  before(:each) do
6
6
  @test_object = ActiveFedora::Base.new
7
7
  end
8
8
 
9
- describe '.update_index' do
9
+ describe ".update_index" do
10
10
  before do
11
- mock_conn = double('SolrConnection')
12
- expect(mock_conn).to receive(:add)
13
- expect(mock_conn).to receive(:commit)
14
- mock_ss = double('SolrService')
15
- allow(mock_ss).to receive(:conn).and_return(mock_conn)
16
- allow(ActiveFedora::SolrService).to receive(:instance).and_return(mock_ss)
11
+ mock_conn = double("SolrConnection")
12
+ mock_conn.should_receive(:add)
13
+ mock_conn.should_receive(:commit)
14
+ mock_ss = double("SolrService")
15
+ mock_ss.stub(:conn).and_return(mock_conn)
16
+ ActiveFedora::SolrService.stub(:instance).and_return(mock_ss)
17
17
  end
18
-
19
- it 'should call .to_solr on all SimpleDatastreams AND RelsExtDatastreams and pass the resulting document to solr' do
18
+
19
+ it "should call .to_solr on all SimpleDatastreams AND RelsExtDatastreams and pass the resulting document to solr" do
20
20
  # Actually uses self.to_solr internally to gather solr info from all metadata datastreams
21
- mock1 = double('ds1', :to_solr => {})
22
- mock2 = double('ds2', :to_solr => {})
23
- mock3 = double('RELS-EXT', :to_solr => {})
24
-
21
+ mock1 = double("ds1", :to_solr => {})
22
+ mock2 = double("ds2", :to_solr => {})
23
+ mock3 = double("RELS-EXT", :to_solr => {})
24
+
25
25
  mock_datastreams = {:ds1 => mock1, :ds2 => mock2, :rels_ext => mock3}
26
- expect(mock1).to receive(:solrize_profile).and_return({})
27
- expect(mock2).to receive(:solrize_profile).and_return({})
28
- expect(mock3).to receive(:solrize_profile).and_return({})
29
- expect(@test_object).to receive(:datastreams).twice.and_return(mock_datastreams)
30
- expect(@test_object).to receive(:solrize_relationships)
26
+ mock1.should_receive(:solrize_profile).and_return({})
27
+ mock2.should_receive(:solrize_profile).and_return({})
28
+ mock3.should_receive(:solrize_profile).and_return({})
29
+ @test_object.should_receive(:datastreams).twice.and_return(mock_datastreams)
30
+ @test_object.should_receive(:solrize_relationships)
31
31
  @test_object.update_index
32
32
  end
33
33
 
34
- it 'should call .to_solr on all RDFDatastreams and pass the resulting document to solr' do
34
+ it "should call .to_solr on all RDFDatastreams and pass the resulting document to solr" do
35
35
  # Actually uses self.to_solr internally to gather solr info from all metadata datastreams
36
- mock1 = double('ds1', :to_solr => {})
37
- mock2 = double('ds2', :to_solr => {})
38
- mock3 = double('RELS-EXT', :to_solr => {})
39
-
36
+ mock1 = double("ds1", :to_solr => {})
37
+ mock2 = double("ds2", :to_solr => {})
38
+ mock3 = double("RELS-EXT", :to_solr => {})
39
+
40
40
  mock_datastreams = {:ds1 => mock1, :ds2 => mock2, :rels_ext => mock3}
41
- expect(mock1).to receive(:solrize_profile).and_return({})
42
- expect(mock2).to receive(:solrize_profile).and_return({})
43
- expect(mock3).to receive(:solrize_profile).and_return({})
44
- expect(@test_object).to receive(:datastreams).twice.and_return(mock_datastreams)
45
- expect(@test_object).to receive(:solrize_relationships)
41
+ mock1.should_receive(:solrize_profile).and_return({})
42
+ mock2.should_receive(:solrize_profile).and_return({})
43
+ mock3.should_receive(:solrize_profile).and_return({})
44
+ @test_object.should_receive(:datastreams).twice.and_return(mock_datastreams)
45
+ @test_object.should_receive(:solrize_relationships)
46
46
  @test_object.update_index
47
47
  end
48
48
 
49
- it 'should retrieve a solr Connection and call Connection.add' do
49
+ it "should retrieve a solr Connection and call Connection.add" do
50
50
  @test_object.update_index
51
51
  end
52
52
 
53
53
  end
54
-
55
- describe '.delete' do
56
-
54
+
55
+ describe ".delete" do
56
+
57
57
  before(:each) do
58
58
  end
59
-
60
- it 'should delete object from repository and index' do
61
- allow(@test_object.inner_object).to receive(:delete)
62
- mock_conn = double('SolrConnection')
63
- expect(mock_conn).to receive(:delete_by_id).with(nil)
64
- expect(mock_conn).to receive(:commit)
65
- mock_ss = double('SolrService')
66
- allow(mock_ss).to receive(:conn).and_return(mock_conn)
67
- allow(ActiveFedora::SolrService).to receive(:instance).and_return(mock_ss)
59
+
60
+ it "should delete object from repository and index" do
61
+ @test_object.inner_object.stub(:delete)
62
+ mock_conn = double("SolrConnection")
63
+ mock_conn.should_receive(:delete_by_id).with(nil)
64
+ mock_conn.should_receive(:commit)
65
+ mock_ss = double("SolrService")
66
+ mock_ss.stub(:conn).and_return(mock_conn)
67
+ ActiveFedora::SolrService.stub(:instance).and_return(mock_ss)
68
68
  @test_object.delete
69
69
  end
70
70
 
71
71
  end
72
-
73
- describe '#pids_from_uris' do
74
- it 'should strip the info:fedora/ out of a given string' do
75
- expect(ActiveFedora::Base.pids_from_uris('info:fedora/FOOBAR')).to eq('FOOBAR')
72
+
73
+ describe '#pids_from_uris' do
74
+ it "should strip the info:fedora/ out of a given string" do
75
+ ActiveFedora::Base.pids_from_uris("info:fedora/FOOBAR").should == "FOOBAR"
76
76
  end
77
- it 'should accept an array of strings'do
78
- expect(ActiveFedora::Base.pids_from_uris(['info:fedora/FOOBAR', 'info:fedora/BAZFOO'])).to eq(['FOOBAR', 'BAZFOO'])
77
+ it "should accept an array of strings"do
78
+ ActiveFedora::Base.pids_from_uris(["info:fedora/FOOBAR", "info:fedora/BAZFOO"]).should == ["FOOBAR", "BAZFOO"]
79
79
  end
80
80
  end
81
81
 
82
+ describe "to_class_uri" do
83
+ before :all do
84
+ module SpecModel
85
+ class CamelCased < ActiveFedora::Base
86
+ end
87
+ end
88
+ end
89
+
90
+ after :all do
91
+ SpecModel.send(:remove_const, :CamelCased)
92
+ end
93
+ subject {SpecModel::CamelCased}
94
+
95
+ its(:to_class_uri) {should == 'info:fedora/afmodel:SpecModel_CamelCased' }
96
+
97
+ context "with the namespace declared in the model" do
98
+ before do
99
+ subject.stub(:pid_namespace).and_return("test-cModel")
100
+ end
101
+ its(:to_class_uri) {should == 'info:fedora/test-cModel:SpecModel_CamelCased' }
102
+ end
103
+ context "with the suffix declared in the model" do
104
+ before do
105
+ subject.stub(:pid_suffix).and_return("-TEST-SUFFIX")
106
+ end
107
+ its(:to_class_uri) {should == 'info:fedora/afmodel:SpecModel_CamelCased-TEST-SUFFIX' }
108
+ end
109
+ end
82
110
  end
@@ -1,81 +1,81 @@
1
1
  require 'spec_helper'
2
- @@last_pid = 0
2
+ @@last_pid = 0
3
3
 
4
4
  describe ActiveFedora::Base do
5
- it_behaves_like 'An ActiveModel'
5
+ it_behaves_like "An ActiveModel"
6
6
 
7
7
  describe 'descendants' do
8
- it 'should record the decendants' do
9
- expect(ActiveFedora::Base.descendants).to include(ModsArticle, SpecialThing)
8
+ it "should record the decendants" do
9
+ ActiveFedora::Base.descendants.should include(ModsArticle, SpecialThing)
10
10
  end
11
11
  end
12
12
 
13
- describe 'sharding' do
14
- it 'should have a shard_index' do
15
- expect(ActiveFedora::Base.shard_index(@this_pid)).to eq(0)
13
+ describe "sharding" do
14
+ it "should have a shard_index" do
15
+ ActiveFedora::Base.shard_index(@this_pid).should == 0
16
16
  end
17
17
 
18
- context 'When the repository is NOT sharded' do
18
+ context "When the repository is NOT sharded" do
19
19
  subject {ActiveFedora::Base.connection_for_pid('test:bar')}
20
20
  before(:each) do
21
- allow(ActiveFedora.config).to receive(:sharded?).and_return(false)
21
+ ActiveFedora.config.stub(:sharded?).and_return(false)
22
22
  ActiveFedora::Base.fedora_connection = {}
23
- allow(ActiveFedora.config).to receive(:credentials).and_return(:url => 'myfedora')
23
+ ActiveFedora.config.stub(:credentials).and_return(:url=>'myfedora')
24
24
  end
25
- it { is_expected.to be_kind_of Rubydora::Repository}
26
- it 'should be the standard connection' do
27
- expect(subject.client.url).to eq('myfedora')
25
+ it { should be_kind_of Rubydora::Repository}
26
+ it "should be the standard connection" do
27
+ subject.client.url.should == 'myfedora'
28
28
  end
29
- describe 'assign_pid' do
30
- it 'should use fedora to generate pids' do
29
+ describe "assign_pid" do
30
+ it "should use fedora to generate pids" do
31
31
  # TODO: This juggling of Fedora credentials & establishing connections should be handled by an establish_fedora_connection method,
32
32
  # possibly wrap it all into a fedora_connection method - MZ 06-05-2012
33
- stubfedora = double('Fedora')
34
- expect(stubfedora).to receive(:connection).and_return(double('Connection', :mint => 'sample:newpid'))
33
+ stubfedora = double("Fedora")
34
+ stubfedora.should_receive(:connection).and_return(double("Connection", :mint =>"sample:newpid"))
35
35
  # Should use ActiveFedora.config.credentials as a single hash rather than an array of shards
36
- expect(ActiveFedora::RubydoraConnection).to receive(:new).with(ActiveFedora.config.credentials).and_return(stubfedora)
36
+ ActiveFedora::RubydoraConnection.should_receive(:new).with(ActiveFedora.config.credentials).and_return(stubfedora)
37
37
  ActiveFedora::Base.assign_pid(ActiveFedora::Base.new.inner_object)
38
38
  end
39
39
  end
40
- describe 'shard_index' do
41
- it 'should always return zero (the first and only connection)' do
42
- expect(ActiveFedora::Base.shard_index('test:bar')).to eq(0)
40
+ describe "shard_index" do
41
+ it "should always return zero (the first and only connection)" do
42
+ ActiveFedora::Base.shard_index('test:bar').should == 0
43
43
  end
44
44
  end
45
45
  end
46
- context 'When the repository is sharded' do
46
+ context "When the repository is sharded" do
47
47
  before :each do
48
- allow(ActiveFedora.config).to receive(:sharded?).and_return(true)
48
+ ActiveFedora.config.stub(:sharded?).and_return(true)
49
49
  ActiveFedora::Base.fedora_connection = {}
50
- allow(ActiveFedora.config).to receive(:credentials).and_return([{:url => 'shard1'}, {:url => 'shard2'} ])
51
- end
52
- describe 'assign_pid' do
53
- it 'should always use the first shard to generate pids' do
54
- stubhard1 = double('Shard')
55
- stubhard2 = double('Shard')
56
- expect(stubhard1).to receive(:connection).and_return(double('Connection', :mint => 'sample:newpid'))
57
- expect(stubhard2).to receive(:connection).never
50
+ ActiveFedora.config.stub(:credentials).and_return([{:url=>'shard1'}, {:url=>'shard2'} ])
51
+ end
52
+ describe "assign_pid" do
53
+ it "should always use the first shard to generate pids" do
54
+ stubhard1 = double("Shard")
55
+ stubhard2 = double("Shard")
56
+ stubhard1.should_receive(:connection).and_return(double("Connection", :mint =>"sample:newpid"))
57
+ stubhard2.should_receive(:connection).never
58
58
  ActiveFedora::Base.fedora_connection = {0 => stubhard1, 1 => stubhard2}
59
59
  ActiveFedora::Base.assign_pid(ActiveFedora::Base.new.inner_object)
60
60
  end
61
61
  end
62
- describe 'shard_index' do
63
- it 'should use modulo of md5 of the pid to distribute objects across shards' do
64
- expect(ActiveFedora::Base.shard_index('test:bar')).to eq(0)
65
- expect(ActiveFedora::Base.shard_index('test:nanana')).to eq(1)
62
+ describe "shard_index" do
63
+ it "should use modulo of md5 of the pid to distribute objects across shards" do
64
+ ActiveFedora::Base.shard_index('test:bar').should == 0
65
+ ActiveFedora::Base.shard_index('test:nanana').should == 1
66
66
  end
67
67
  end
68
- describe 'the repository' do
69
- describe 'for test:bar' do
68
+ describe "the repository" do
69
+ describe "for test:bar" do
70
70
  subject {ActiveFedora::Base.connection_for_pid('test:bar')}
71
- it 'should be shard1' do
72
- expect(subject.client.url).to eq('shard1')
71
+ it "should be shard1" do
72
+ subject.client.url.should == 'shard1'
73
73
  end
74
74
  end
75
- describe 'for test:baz' do
75
+ describe "for test:baz" do
76
76
  subject {ActiveFedora::Base.connection_for_pid('test:nanana')}
77
- it 'should be shard1' do
78
- expect(subject.client.url).to eq('shard2')
77
+ it "should be shard1" do
78
+ subject.client.url.should == 'shard2'
79
79
  end
80
80
  end
81
81
  end
@@ -83,53 +83,53 @@ describe ActiveFedora::Base do
83
83
 
84
84
  end
85
85
 
86
- describe 'reindex_everything' do
87
- it 'should call update_index on every object except for the fedora-system objects' do
88
- expect_any_instance_of(Rubydora::Repository).to receive(:search).
89
- and_yield(double(pid: 'XXX')).and_yield(double(pid: 'YYY')).and_yield(double(pid: 'ZZZ')).
90
- and_yield(double(pid: 'fedora-system:ServiceDeployment-3.0')).
91
- and_yield(double(pid: 'fedora-system:ServiceDefinition-3.0')).
92
- and_yield(double(pid: 'fedora-system:FedoraObject-3.0'))
86
+ describe "reindex_everything" do
87
+ it "should call update_index on every object except for the fedora-system objects" do
88
+ Rubydora::Repository.any_instance.should_receive(:search).
89
+ and_yield(double(pid:'XXX')).and_yield(double(pid:'YYY')).and_yield(double(pid:'ZZZ')).
90
+ and_yield(double(pid:'fedora-system:ServiceDeployment-3.0')).
91
+ and_yield(double(pid:'fedora-system:ServiceDefinition-3.0')).
92
+ and_yield(double(pid:'fedora-system:FedoraObject-3.0'))
93
93
 
94
94
  mock_update = double(:mock_obj)
95
- expect(mock_update).to receive(:update_index).exactly(3).times
96
- expect(ActiveFedora::Base).to receive(:find).with('XXX', :cast => true).and_return(mock_update)
97
- expect(ActiveFedora::Base).to receive(:find).with('YYY', :cast => true).and_return(mock_update)
98
- expect(ActiveFedora::Base).to receive(:find).with('ZZZ', :cast => true).and_return(mock_update)
95
+ mock_update.should_receive(:update_index).exactly(3).times
96
+ ActiveFedora::Base.should_receive(:find).with('XXX').and_return(mock_update)
97
+ ActiveFedora::Base.should_receive(:find).with('YYY').and_return(mock_update)
98
+ ActiveFedora::Base.should_receive(:find).with('ZZZ').and_return(mock_update)
99
99
  ActiveFedora::Base.reindex_everything
100
100
  end
101
101
 
102
- it 'should accept a query param for the search' do
103
- query_string = 'pid~*'
104
- expect_any_instance_of(Rubydora::Repository).to receive(:search).with(query_string).
105
- and_yield(double(pid: 'XXX')).and_yield(double(pid: 'YYY')).and_yield(double(pid: 'ZZZ'))
102
+ it "should accept a query param for the search" do
103
+ query_string = "pid~*"
104
+ Rubydora::Repository.any_instance.should_receive(:search).with(query_string).
105
+ and_yield(double(pid:'XXX')).and_yield(double(pid:'YYY')).and_yield(double(pid:'ZZZ'))
106
106
  mock_update = double(:mock_obj)
107
- expect(mock_update).to receive(:update_index).exactly(3).times
108
- expect(ActiveFedora::Base).to receive(:find).with('XXX', :cast => true).and_return(mock_update)
109
- expect(ActiveFedora::Base).to receive(:find).with('YYY', :cast => true).and_return(mock_update)
110
- expect(ActiveFedora::Base).to receive(:find).with('ZZZ', :cast => true).and_return(mock_update)
107
+ mock_update.should_receive(:update_index).exactly(3).times
108
+ ActiveFedora::Base.should_receive(:find).with('XXX').and_return(mock_update)
109
+ ActiveFedora::Base.should_receive(:find).with('YYY').and_return(mock_update)
110
+ ActiveFedora::Base.should_receive(:find).with('ZZZ').and_return(mock_update)
111
111
  ActiveFedora::Base.reindex_everything(query_string)
112
112
  end
113
113
  end
114
114
 
115
- describe 'With a test class' do
115
+ describe "With a test class" do
116
116
  before :all do
117
117
  class FooHistory < ActiveFedora::Base
118
- has_metadata :type => ActiveFedora::SimpleDatastream, :name => 'someData', :autocreate => true do |m|
119
- m.field 'fubar', :string
120
- m.field 'swank', :text
118
+ has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"someData", :autocreate => true do |m|
119
+ m.field "fubar", :string
120
+ m.field "swank", :text
121
121
  end
122
- has_metadata :type => ActiveFedora::SimpleDatastream, :name => 'withText', :autocreate => true do |m|
123
- m.field 'fubar', :text
122
+ has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"withText", :autocreate => true do |m|
123
+ m.field "fubar", :text
124
124
  end
125
- has_metadata :type => ActiveFedora::SimpleDatastream, :name => 'withText2', :label => 'withLabel', :autocreate => true do |m|
126
- m.field 'fubar', :text
127
- end
128
- delegate :fubar, :to => 'withText', multiple: true
129
- delegate :swank, :to => 'someData', multiple: true
125
+ has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"withText2", :label=>"withLabel", :autocreate => true do |m|
126
+ m.field "fubar", :text
127
+ end
128
+ has_attributes :fubar, datastream: 'withText', multiple: true
129
+ has_attributes :swank, datastream: 'someData', multiple: true
130
130
  end
131
131
  class FooAdaptation < ActiveFedora::Base
132
- has_metadata :type => ActiveFedora::OmDatastream, :name => 'someData'
132
+ has_metadata :type=>ActiveFedora::OmDatastream, :name=>'someData'
133
133
  end
134
134
 
135
135
  class FooInherited < FooHistory
@@ -150,15 +150,15 @@ describe ActiveFedora::Base do
150
150
  before(:each) do
151
151
  @this_pid = increment_pid.to_s
152
152
  stub_get(@this_pid)
153
- allow_any_instance_of(Rubydora::Repository).to receive(:client).and_return(@mock_client)
154
- allow(ActiveFedora::Base).to receive(:assign_pid).and_return(@this_pid)
153
+ Rubydora::Repository.any_instance.stub(:client).and_return(@mock_client)
154
+ ActiveFedora::Base.stub(:assign_pid).and_return(@this_pid)
155
155
 
156
156
  @test_object = ActiveFedora::Base.new
157
157
  end
158
158
 
159
159
  after(:each) do
160
160
  begin
161
- allow(ActiveFedora::SolrService).to receive(:instance)
161
+ ActiveFedora::SolrService.stub(:instance)
162
162
  #@test_object.delete
163
163
  rescue
164
164
  end
@@ -166,477 +166,406 @@ describe ActiveFedora::Base do
166
166
 
167
167
 
168
168
  describe '#new' do
169
- it 'should create an inner object' do
169
+ it "should create an inner object" do
170
170
  # for doing AFObject.new(params[:foo]) when nothing is in params[:foo]
171
- expect_any_instance_of(Rubydora::DigitalObject).to receive(:save).never
171
+ Rubydora::DigitalObject.any_instance.should_receive(:save).never
172
172
  result = ActiveFedora::Base.new(nil)
173
- expect(result.inner_object).to be_kind_of(ActiveFedora::UnsavedDigitalObject)
173
+ result.inner_object.should be_kind_of(ActiveFedora::UnsavedDigitalObject)
174
174
  end
175
175
 
176
- it 'should not save or get an pid on init' do
177
- expect_any_instance_of(Rubydora::DigitalObject).to receive(:save).never
178
- expect(ActiveFedora::Base).to receive(:assign_pid).never
176
+ it "should not save or get an pid on init" do
177
+ Rubydora::DigitalObject.any_instance.should_receive(:save).never
178
+ ActiveFedora::Base.should_receive(:assign_pid).never
179
179
  f = FooHistory.new
180
180
  end
181
181
 
182
- it 'should be able to create with a custom pid' do
183
- f = FooHistory.new(:pid => 'numbnuts:1')
184
- expect(f.pid).to eq('numbnuts:1')
182
+ it "should be able to create with a custom pid" do
183
+ f = FooHistory.new(:pid=>'numbnuts:1')
184
+ f.pid.should == 'numbnuts:1'
185
185
  end
186
186
  end
187
187
 
188
- describe '.datastream_class_for_name' do
189
- it 'should return the specifed class' do
190
- expect(FooAdaptation.datastream_class_for_name('someData')).to eq(ActiveFedora::OmDatastream)
188
+ describe ".datastream_class_for_name" do
189
+ it "should return the specifed class" do
190
+ FooAdaptation.datastream_class_for_name('someData').should == ActiveFedora::OmDatastream
191
191
  end
192
- it 'should return the specifed class' do
193
- expect(FooAdaptation.datastream_class_for_name('content')).to eq(ActiveFedora::Datastream)
192
+ it "should return the specifed class" do
193
+ FooAdaptation.datastream_class_for_name('content').should == ActiveFedora::Datastream
194
194
  end
195
195
  end
196
196
 
197
- describe '.internal_uri' do
198
- it 'should return pid as fedors uri' do
199
- expect(@test_object.internal_uri).to eql("info:fedora/#{@test_object.pid}")
197
+ describe ".internal_uri" do
198
+ it "should return pid as fedors uri" do
199
+ @test_object.internal_uri.should eql("info:fedora/#{@test_object.pid}")
200
200
  end
201
201
  end
202
202
 
203
203
  ### Methods for ActiveModel::Conversions
204
204
  it "should have to_param once it's saved" do
205
- expect(@test_object.to_param).to be_nil
205
+ @test_object.to_param.should be_nil
206
206
  @test_object.inner_object.stub(:new? => false, :pid => 'foo:123')
207
- expect(@test_object.to_param).to eq('foo:123')
207
+ @test_object.to_param.should == 'foo:123'
208
208
  end
209
209
 
210
210
  it "should have to_key once it's saved" do
211
- expect(@test_object.to_key).to be_nil
212
- @test_object.inner_object.stub(:new? => false)
213
- expect(@test_object.to_key).to eq([@test_object.pid])
211
+ @test_object.to_key.should be_nil
212
+ @test_object.inner_object.stub(new?: false, pid: 'foo:123')
213
+ @test_object.to_key.should == ['foo:123']
214
214
  end
215
215
 
216
216
  it "should have to_model when it's saved" do
217
- expect(@test_object.to_model).to be @test_object
217
+ @test_object.to_model.should be @test_object
218
218
  end
219
219
  ### end ActiveModel::Conversions
220
220
 
221
221
  ### Methods for ActiveModel::Naming
222
- it 'Should know the model_name' do
223
- expect(FooHistory.model_name).to eq('FooHistory')
224
- expect(FooHistory.model_name.human).to eq('Foo history')
222
+ it "Should know the model_name" do
223
+ FooHistory.model_name.should == 'FooHistory'
224
+ FooHistory.model_name.human.should == 'Foo history'
225
225
  end
226
226
  ### End ActiveModel::Naming
227
227
 
228
228
 
229
- describe '.datastreams' do
230
- before do
231
- @test_history = FooHistory.new
232
- end
233
- it 'should create dynamic accessors' do
234
- expect(@test_history.withText).to eq(@test_history.datastreams['withText'])
229
+ describe ".datastreams" do
230
+ let(:test_history) { FooHistory.new }
231
+ it "should create accessors for datastreams declared with has_metadata" do
232
+ test_history.withText.should == test_history.datastreams['withText']
235
233
  end
236
- it 'dynamic accessors should convert dashes to underscores' do
237
- ds = double('datastream', :dsid => 'eac-cpf')
238
- @test_history.add_datastream(ds)
239
- expect(@test_history.eac_cpf).to eq(ds)
240
- end
241
- it 'dynamic accessors should not convert datastreams named with underscore' do
242
- ds = double('datastream', :dsid => 'foo_bar')
243
- @test_history.add_datastream(ds)
244
- expect(@test_history.foo_bar).to eq(ds)
234
+ describe "dynamic accessors" do
235
+ before do
236
+ test_history.add_datastream(ds)
237
+ test_history.class.build_datastream_accessor(ds.dsid)
238
+ end
239
+ describe "when the datastream is named with dash" do
240
+ let(:ds) {double('datastream', :dsid=>'eac-cpf')}
241
+ it "should convert dashes to underscores" do
242
+ test_history.eac_cpf.should == ds
243
+ end
244
+ end
245
+ describe "when the datastream is named with underscore" do
246
+ let (:ds) { double('datastream', :dsid=>'foo_bar') }
247
+ it "should preserve the underscore" do
248
+ test_history.foo_bar.should == ds
249
+ end
250
+ end
245
251
  end
246
252
  end
247
253
 
248
254
  it 'should provide #find' do
249
- expect(ActiveFedora::Base).to respond_to(:find)
255
+ ActiveFedora::Base.should respond_to(:find)
250
256
  end
251
257
 
252
- it 'should provide .create_date' do
253
- expect(@test_object).to respond_to(:create_date)
258
+ it "should provide .create_date" do
259
+ @test_object.should respond_to(:create_date)
254
260
  end
255
261
 
256
- it 'should provide .modified_date' do
257
- expect(@test_object).to respond_to(:modified_date)
262
+ it "should provide .modified_date" do
263
+ @test_object.should respond_to(:modified_date)
258
264
  end
259
265
 
260
266
  it 'should respond to .rels_ext' do
261
- expect(@test_object).to respond_to(:rels_ext)
267
+ @test_object.should respond_to(:rels_ext)
262
268
  end
263
269
 
264
270
  describe '.rels_ext' do
265
271
 
266
272
  it 'should return the RelsExtDatastream object from the datastreams array' do
267
- @test_object.stub(:datastreams => {'RELS-EXT' => 'foo'})
268
- expect(@test_object.rels_ext).to eq('foo')
273
+ @test_object.stub(:datastreams => {"RELS-EXT" => "foo"})
274
+ @test_object.rels_ext.should == "foo"
269
275
  end
270
276
  end
271
277
 
272
278
  it 'should provide #add_relationship' do
273
- expect(@test_object).to respond_to(:add_relationship)
279
+ @test_object.should respond_to(:add_relationship)
274
280
  end
275
281
 
276
282
  describe '#add_relationship' do
277
283
  it 'should call #add_relationship on the rels_ext datastream' do
278
- @test_object.add_relationship('predicate', 'info:fedora/object')
279
- pred = ActiveFedora::Predicates.vocabularies['info:fedora/fedora-system:def/relations-external#']['predicate']
280
- expect(@test_object.relationships).to have_statement(RDF::Statement.new(RDF::URI.new(@test_object.internal_uri), pred, RDF::URI.new('info:fedora/object')))
284
+ @test_object.add_relationship("predicate", "info:fedora/object")
285
+ pred = ActiveFedora::Predicates.vocabularies["info:fedora/fedora-system:def/relations-external#"]["predicate"]
286
+ @test_object.relationships.should have_statement(RDF::Statement.new(RDF::URI.new(@test_object.internal_uri), pred, RDF::URI.new("info:fedora/object")))
281
287
  end
282
288
 
283
- it 'should update the RELS-EXT datastream and set the datastream as dirty when relationships are added' do
284
- mock_ds = double('Rels-Ext')
285
- allow(mock_ds).to receive(:content_will_change!)
286
- @test_object.datastreams['RELS-EXT'] = mock_ds
287
- @test_object.add_relationship(:is_member_of, 'info:fedora/demo:5')
288
- @test_object.add_relationship(:is_member_of, 'info:fedora/demo:10')
289
+ it "should update the RELS-EXT datastream and set the datastream as dirty when relationships are added" do
290
+ mock_ds = double("Rels-Ext")
291
+ mock_ds.stub(:content_will_change!)
292
+ @test_object.datastreams["RELS-EXT"] = mock_ds
293
+ @test_object.add_relationship(:is_member_of, "info:fedora/demo:5")
294
+ @test_object.add_relationship(:is_member_of, "info:fedora/demo:10")
289
295
  end
290
296
 
291
297
  it 'should add a relationship to an object only if it does not exist already' do
292
298
  next_pid = increment_pid.to_s
293
- allow(ActiveFedora::Base).to receive(:assign_pid).and_return(next_pid)
299
+ ActiveFedora::Base.stub(:assign_pid).and_return(next_pid)
294
300
  stub_get(next_pid)
295
301
 
296
302
  @test_object3 = ActiveFedora::Base.new
297
- @test_object.add_relationship(:has_part, @test_object3)
298
- expect(@test_object.ids_for_outbound(:has_part)).to eq([@test_object3.pid])
303
+ @test_object.add_relationship(:has_part,@test_object3)
304
+ @test_object.ids_for_outbound(:has_part).should == [@test_object3.pid]
299
305
  #try adding again and make sure not there twice
300
- @test_object.add_relationship(:has_part, @test_object3)
301
- expect(@test_object.ids_for_outbound(:has_part)).to eq([@test_object3.pid])
306
+ @test_object.add_relationship(:has_part,@test_object3)
307
+ @test_object.ids_for_outbound(:has_part).should == [@test_object3.pid]
302
308
  end
303
309
 
304
310
  it 'should add literal relationships if requested' do
305
- @test_object.add_relationship(:conforms_to, 'AnInterface', true)
306
- expect(@test_object.ids_for_outbound(:conforms_to)).to eq(['AnInterface'])
311
+ @test_object.add_relationship(:conforms_to,"AnInterface",true)
312
+ @test_object.ids_for_outbound(:conforms_to).should == ["AnInterface"]
307
313
  end
308
314
  end
309
315
 
310
316
  it 'should provide #remove_relationship' do
311
- expect(@test_object).to respond_to(:remove_relationship)
317
+ @test_object.should respond_to(:remove_relationship)
312
318
  end
313
319
 
314
320
  describe '#remove_relationship' do
315
321
  it 'should remove a relationship from the relationships hash' do
316
322
  @test_object3 = ActiveFedora::Base.new()
317
- @test_object3.stub(:pid => '7')
323
+ @test_object3.stub(:pid=>'7')
318
324
  @test_object4 = ActiveFedora::Base.new()
319
- @test_object4.stub(:pid => '8')
320
- @test_object.add_relationship(:has_part, @test_object3)
321
- @test_object.add_relationship(:has_part, @test_object4)
325
+ @test_object4.stub(:pid=>'8')
326
+ @test_object.add_relationship(:has_part,@test_object3)
327
+ @test_object.add_relationship(:has_part,@test_object4)
322
328
  #check both are there
323
- expect(@test_object.ids_for_outbound(:has_part)).to eq([@test_object3.pid, @test_object4.pid])
324
- @test_object.remove_relationship(:has_part, @test_object3)
329
+ @test_object.ids_for_outbound(:has_part).should == [@test_object3.pid,@test_object4.pid]
330
+ @test_object.remove_relationship(:has_part,@test_object3)
325
331
  #check only one item removed
326
- expect(@test_object.ids_for_outbound(:has_part)).to eq([@test_object4.pid])
327
- @test_object.remove_relationship(:has_part, @test_object4)
332
+ @test_object.ids_for_outbound(:has_part).should == [@test_object4.pid]
333
+ @test_object.remove_relationship(:has_part,@test_object4)
328
334
  #check last item removed and predicate removed since now emtpy
329
- expect(@test_object.relationships.size).to eq(0)
335
+ @test_object.relationships.size.should == 0
330
336
  end
331
337
  end
332
338
 
333
339
  it 'should provide #relationships' do
334
- expect(@test_object).to respond_to(:relationships)
340
+ @test_object.should respond_to(:relationships)
335
341
  end
336
342
 
337
343
  describe '#relationships' do
338
344
  it 'should return a graph' do
339
- expect(@test_object.relationships.kind_of?(RDF::Graph)).to be_truthy
340
- expect(@test_object.relationships.size).to eq(0)
345
+ @test_object.relationships.kind_of?(RDF::Graph).should be_true
346
+ @test_object.relationships.size.should == 0
341
347
  end
342
348
  end
343
349
 
344
350
  describe '.assert_content_model' do
345
- it 'should default to the name of the class' do
351
+ it "should default to the name of the class" do
346
352
  stub_get(@this_pid)
347
353
  stub_add_ds(@this_pid, ['RELS-EXT'])
348
354
  @test_object.assert_content_model
349
- expect(@test_object.relationships(:has_model)).to eq(['info:fedora/afmodel:ActiveFedora_Base'])
355
+ @test_object.relationships(:has_model).should == ["info:fedora/afmodel:ActiveFedora_Base"]
350
356
 
351
357
  end
352
358
  end
353
359
 
354
360
  describe '.save' do
355
- it 'should create a new record' do
361
+ it "should create a new record" do
356
362
  @test_object.stub(:new_record? => true)
357
- expect(@test_object).to receive(:create)
358
- expect(@test_object).to receive(:update_index)
363
+ @test_object.should_receive(:assign_pid)
364
+ @test_object.should_receive(:serialize_datastreams)
365
+ @test_object.inner_object.should_receive(:save)
366
+ @test_object.should_receive(:update_index)
359
367
  @test_object.save
360
368
  end
361
369
 
362
- it 'should update an existing record' do
370
+ it "should update an existing record" do
363
371
  @test_object.stub(:new_record? => false)
364
- expect(@test_object).to receive(:update_record)
365
- expect(@test_object).to receive(:update_index)
372
+ @test_object.should_receive(:serialize_datastreams)
373
+ @test_object.inner_object.should_receive(:save)
374
+ @test_object.should_receive(:update_index)
366
375
  @test_object.save
367
376
  end
368
377
  end
369
378
 
370
- describe '#create' do
371
- it 'should build a new record and save it' do
379
+ describe "#create" do
380
+ it "should build a new record and save it" do
372
381
  obj = double()
373
- expect(obj).to receive(:save)
374
- expect(FooHistory).to receive(:new).and_return(obj)
375
- @hist = FooHistory.create(:fubar => 'ta', :swank => 'da')
382
+ obj.should_receive(:save)
383
+ FooHistory.should_receive(:new).and_return(obj)
384
+ @hist = FooHistory.create(:fubar=>'ta', :swank=>'da')
376
385
  end
377
386
 
378
387
  end
379
388
 
380
- describe '.adapt_to' do
381
- it 'should return an adapted object of the requested type' do
389
+ describe ".adapt_to" do
390
+ it "should return an adapted object of the requested type" do
382
391
  @test_object = FooHistory.new()
383
- expect(@test_object.adapt_to(FooAdaptation).class).to eq(FooAdaptation)
392
+ @test_object.adapt_to(FooAdaptation).class.should == FooAdaptation
384
393
  end
385
- it 'should not make an additional call to fedora to create the adapted object' do
394
+ it "should not make an additional call to fedora to create the adapted object" do
386
395
  @test_object = FooHistory.new()
387
396
  adapted = @test_object.adapt_to(FooAdaptation)
388
397
  end
389
- it 'should propagate new datastreams to the adapted object' do
398
+ it "should propagate new datastreams to the adapted object" do
390
399
  @test_object = FooHistory.new()
391
- @test_object.add_file_datastream('XXX', :dsid => 'MY_DSID')
400
+ @test_object.add_file_datastream("XXX", :dsid=>'MY_DSID')
392
401
  adapted = @test_object.adapt_to(FooAdaptation)
393
- expect(adapted.datastreams.keys).to include 'MY_DSID'
394
- expect(adapted.datastreams['MY_DSID'].content).to eq('XXX')
395
- expect(adapted.datastreams['MY_DSID'].changed?).to be_truthy
402
+ adapted.datastreams.keys.should include 'MY_DSID'
403
+ adapted.datastreams['MY_DSID'].content.should == "XXX"
404
+ adapted.datastreams['MY_DSID'].changed?.should be_true
396
405
  end
397
- it 'should propagate modified datastreams to the adapted object' do
406
+ it "should propagate modified datastreams to the adapted object" do
398
407
  @test_object = FooHistory.new()
399
408
  orig_ds = @test_object.datastreams['someData']
400
- orig_ds.content = '<YYY/>'
409
+ orig_ds.content="<YYY/>"
401
410
  adapted = @test_object.adapt_to(FooAdaptation)
402
- expect(adapted.datastreams.keys).to include 'someData'
403
- expect(adapted.datastreams['someData']).to eq(orig_ds)
404
- expect(adapted.datastreams['someData'].content.strip).to eq('<YYY/>')
405
- expect(adapted.datastreams['someData'].changed?).to be_truthy
411
+ adapted.datastreams.keys.should include 'someData'
412
+ adapted.datastreams['someData'].should == orig_ds
413
+ adapted.datastreams['someData'].content.strip.should == "<YYY/>"
414
+ adapted.datastreams['someData'].changed?.should be_true
406
415
  end
407
- it 'should use the datastream definitions from the adapted object' do
416
+ it "should use the datastream definitions from the adapted object" do
408
417
  @test_object = FooHistory.new()
409
418
  adapted = @test_object.adapt_to(FooAdaptation)
410
- expect(adapted.datastreams.keys).to include 'someData'
411
- expect(adapted.datastreams['someData'].class).to eq(ActiveFedora::OmDatastream)
419
+ adapted.datastreams.keys.should include 'someData'
420
+ adapted.datastreams['someData'].class.should == ActiveFedora::OmDatastream
412
421
  end
413
422
  end
414
423
 
415
- describe '.adapt_to_cmodel with implemented (non-ActiveFedora::Base) cmodel' do
424
+ describe ".adapt_to_cmodel with implemented (non-ActiveFedora::Base) cmodel" do
416
425
  subject { FooHistory.new }
417
426
 
418
- it 'should not cast to a random first cmodel if it has a specific cmodel already' do
419
- expect(ActiveFedora::ContentModel).to receive(:known_models_for).with(subject).and_return([FooAdaptation])
420
- expect(subject.adapt_to_cmodel).to be_kind_of FooHistory
427
+ it "should not cast to a random first cmodel if it has a specific cmodel already" do
428
+ ActiveFedora::ContentModel.should_receive(:known_models_for).with(subject).and_return([FooAdaptation])
429
+ subject.adapt_to_cmodel.should be_kind_of FooHistory
421
430
  end
422
- it 'should cast to an inherited model over a random one' do
423
- expect(ActiveFedora::ContentModel).to receive(:known_models_for).with(subject).and_return([FooAdaptation, FooInherited])
424
- expect(subject.adapt_to_cmodel).to be_kind_of FooInherited
431
+ it "should cast to an inherited model over a random one" do
432
+ ActiveFedora::ContentModel.should_receive(:known_models_for).with(subject).and_return([FooAdaptation, FooInherited])
433
+ subject.adapt_to_cmodel.should be_kind_of FooInherited
425
434
  end
426
- it 'should not cast when a cmodel is same as the class' do
427
- expect(ActiveFedora::ContentModel).to receive(:known_models_for).with(subject).and_return([FooHistory])
428
- expect(subject.adapt_to_cmodel).to be === subject
435
+ it "should not cast when a cmodel is same as the class" do
436
+ ActiveFedora::ContentModel.should_receive(:known_models_for).with(subject).and_return([FooHistory])
437
+ subject.adapt_to_cmodel.should === subject
429
438
  end
430
439
  end
431
440
 
432
- describe '.adapt_to_cmodel with ActiveFedora::Base' do
441
+ describe ".adapt_to_cmodel with ActiveFedora::Base" do
433
442
  subject { ActiveFedora::Base.new }
434
443
 
435
- it 'should cast to the first cmodel if ActiveFedora::Base (or no specified cmodel)' do
436
- expect(ActiveFedora::ContentModel).to receive(:known_models_for).with(subject).and_return([FooAdaptation, FooHistory])
437
- expect(subject.adapt_to_cmodel).to be_kind_of FooAdaptation
444
+ it "should cast to the first cmodel if ActiveFedora::Base (or no specified cmodel)" do
445
+ ActiveFedora::ContentModel.should_receive(:known_models_for).with(subject).and_return([FooAdaptation, FooHistory])
446
+ subject.adapt_to_cmodel.should be_kind_of FooAdaptation
438
447
  end
439
448
  end
440
449
 
441
450
 
442
- describe '.to_solr' do
443
- it 'should provide .to_solr' do
444
- expect(@test_object).to respond_to(:to_solr)
451
+ describe ".to_solr" do
452
+ it "should provide .to_solr" do
453
+ @test_object.should respond_to(:to_solr)
445
454
  end
446
455
 
447
- it 'should add pid, system_create_date, system_modified_date and object_state from object attributes' do
448
- expect(@test_object).to receive(:create_date).and_return('2012-03-04T03:12:02Z')
449
- expect(@test_object).to receive(:modified_date).and_return('2012-03-07T03:12:02Z')
456
+ it "should add pid, system_create_date, system_modified_date and object_state from object attributes" do
457
+ @test_object.should_receive(:create_date).and_return("2012-03-04T03:12:02Z")
458
+ @test_object.should_receive(:modified_date).and_return("2012-03-07T03:12:02Z")
450
459
  @test_object.stub(pid: 'changeme:123')
451
- @test_object.state = 'D'
460
+ @test_object.state = "D"
452
461
  solr_doc = @test_object.to_solr
453
- expect(solr_doc[ActiveFedora::SolrService.solr_name('system_create', :stored_sortable, type: :date)]).to eql('2012-03-04T03:12:02Z')
454
- expect(solr_doc[ActiveFedora::SolrService.solr_name('system_modified', :stored_sortable, type: :date)]).to eql('2012-03-07T03:12:02Z')
455
- expect(solr_doc[ActiveFedora::SolrService.solr_name('object_state', :stored_sortable)]).to eql('D')
456
- expect(solr_doc[:id]).to eql('changeme:123')
462
+ solr_doc[ActiveFedora::SolrService.solr_name("system_create", :stored_sortable, type: :date)].should eql("2012-03-04T03:12:02Z")
463
+ solr_doc[ActiveFedora::SolrService.solr_name("system_modified", :stored_sortable, type: :date)].should eql("2012-03-07T03:12:02Z")
464
+ solr_doc[ActiveFedora::SolrService.solr_name("object_state", :stored_sortable)].should eql("D")
465
+ solr_doc[:id].should eql("changeme:123")
457
466
  end
458
467
 
459
- it 'should omit base metadata and RELS-EXT if :model_only==true' do
460
- @test_object.add_relationship(:has_part, 'foo', true)
461
- solr_doc = @test_object.to_solr({}, :model_only => true)
462
- expect(solr_doc[ActiveFedora::SolrService.solr_name('system_create', type: :date)]).to be_nil
463
- expect(solr_doc[ActiveFedora::SolrService.solr_name('system_modified', type: :date)]).to be_nil
464
- expect(solr_doc['id']).to be_nil
465
- expect(solr_doc[ActiveFedora::SolrService.solr_name('has_part', :symbol)]).to be_nil
468
+ it "should omit base metadata and RELS-EXT if :model_only==true" do
469
+ @test_object.add_relationship(:has_part, "foo", true)
470
+ solr_doc = @test_object.to_solr(Hash.new, :model_only => true)
471
+ solr_doc[ActiveFedora::SolrService.solr_name("system_create", type: :date)].should be_nil
472
+ solr_doc[ActiveFedora::SolrService.solr_name("system_modified", type: :date)].should be_nil
473
+ solr_doc["id"].should be_nil
474
+ solr_doc[ActiveFedora::SolrService.solr_name("has_part", :symbol)].should be_nil
466
475
  end
467
476
 
468
- it 'should add self.class as the :active_fedora_model' do
477
+ it "should add self.class as the :active_fedora_model" do
469
478
  stub_get(@this_pid)
470
479
  stub_get_content(@this_pid, ['RELS-EXT', 'someData', 'withText2', 'withText'])
471
480
  @test_history = FooHistory.new()
472
481
  solr_doc = @test_history.to_solr
473
- expect(solr_doc[ActiveFedora::SolrService.solr_name('active_fedora_model', :stored_sortable)]).to eql('FooHistory')
482
+ solr_doc[ActiveFedora::SolrService.solr_name("active_fedora_model", :stored_sortable)].should eql("FooHistory")
474
483
  end
475
484
 
476
- it 'should call .to_solr on all SimpleDatastreams and OmDatastreams, passing the resulting document to solr' do
477
- mock1 = double('ds1', :to_solr => {})
478
- mock2 = double('ds2', :to_solr => {})
479
- ngds = double('ngds', :to_solr => {})
480
- expect(ngds).to receive(:solrize_profile)
481
- expect(mock1).to receive(:solrize_profile)
482
- expect(mock2).to receive(:solrize_profile)
485
+ it "should call .to_solr on all SimpleDatastreams and OmDatastreams, passing the resulting document to solr" do
486
+ mock1 = double("ds1", :to_solr => {})
487
+ mock2 = double("ds2", :to_solr => {})
488
+ ngds = double("ngds", :to_solr => {})
489
+ ngds.should_receive(:solrize_profile)
490
+ mock1.should_receive(:solrize_profile)
491
+ mock2.should_receive(:solrize_profile)
483
492
 
484
- expect(@test_object).to receive(:datastreams).twice.and_return({:ds1 => mock1, :ds2 => mock2, :ngds => ngds})
485
- expect(@test_object).to receive(:solrize_relationships)
493
+ @test_object.should_receive(:datastreams).twice.and_return({:ds1 => mock1, :ds2 => mock2, :ngds => ngds})
494
+ @test_object.should_receive(:solrize_relationships)
486
495
  @test_object.to_solr
487
496
  end
488
- it 'should call .to_solr on all RDFDatastreams, passing the resulting document to solr' do
489
- mock = double('ds1', :to_solr => {})
490
- expect(mock).to receive(:solrize_profile)
497
+ it "should call .to_solr on all RDFDatastreams, passing the resulting document to solr" do
498
+ mock = double("ds1", :to_solr => {})
499
+ mock.should_receive(:solrize_profile)
491
500
 
492
- expect(@test_object).to receive(:datastreams).twice.and_return({:ds1 => mock})
493
- expect(@test_object).to receive(:solrize_relationships)
501
+ @test_object.should_receive(:datastreams).twice.and_return({:ds1 => mock})
502
+ @test_object.should_receive(:solrize_relationships)
494
503
  @test_object.to_solr
495
504
  end
496
505
 
497
- it 'should call .to_solr on the relationships rels-ext is dirty' do
498
- @test_object.add_relationship(:has_collection_member, 'info:fedora/test:member')
506
+ it "should call .to_solr on the relationships rels-ext is dirty" do
507
+ @test_object.add_relationship(:has_collection_member, "info:fedora/test:member")
499
508
  rels_ext = @test_object.rels_ext
500
- expect(rels_ext).to be_changed
501
- expect(@test_object).to receive(:solrize_relationships)
509
+ rels_ext.should be_changed
510
+ @test_object.should_receive(:solrize_relationships)
502
511
  @test_object.to_solr
503
512
  end
504
513
 
505
514
  end
506
515
 
507
- describe '.label' do
508
- it 'should return the label of the inner object' do
509
- expect(@test_object.inner_object).to receive(:label).and_return('foo label')
510
- expect(@test_object.label).to eq('foo label')
516
+ describe ".label" do
517
+ it "should return the label of the inner object" do
518
+ @test_object.inner_object.should_receive(:label).and_return("foo label")
519
+ @test_object.label.should == "foo label"
511
520
  end
512
521
  end
513
522
 
514
- describe '.label=' do
515
- it 'should set the label of the inner object' do
516
- expect(@test_object.label).not_to eq('foo label')
517
- @test_object.label = 'foo label'
518
- expect(@test_object.label).to eq('foo label')
523
+ describe ".label=" do
524
+ it "should set the label of the inner object" do
525
+ @test_object.label.should_not == "foo label"
526
+ @test_object.label = "foo label"
527
+ @test_object.label.should == "foo label"
519
528
  end
520
529
  end
521
-
522
-
523
- describe 'get_values_from_datastream' do
524
- it 'should look up the named datastream and call get_values with the given pointer/field_name' do
525
- mock_ds = double('Datastream', :get_values => ['value1', 'value2'])
526
- allow(@test_object).to receive(:datastreams).and_return({'ds1' => mock_ds})
527
- expect(@test_object.get_values_from_datastream('ds1', '--my xpath--')).to eq(['value1', 'value2'])
528
- end
529
- end
530
-
531
- describe 'update_datastream_attributes' do
532
- it 'should look up any datastreams specified as keys in the given hash and call update_attributes on the datastream' do
533
- mock_desc_metadata = double('descMetadata')
534
- mock_properties = double('properties')
535
- mock_ds_hash = {'descMetadata' => mock_desc_metadata, 'properties' => mock_properties}
536
-
537
- ds_values_hash = {
538
- 'descMetadata' => { [{:person => 0}, :role] => {'0' => 'role1', '1' => 'role2', '2' => 'role3'} },
539
- 'properties' => { 'notes' => 'foo' }
540
- }
541
- m = FooHistory.new
542
- allow(m).to receive(:datastreams).and_return(mock_ds_hash)
543
- expect(mock_desc_metadata).to receive(:update_indexed_attributes).with( ds_values_hash['descMetadata'] )
544
- expect(mock_properties).to receive(:update_indexed_attributes).with( ds_values_hash['properties'] )
545
- m.update_datastream_attributes( ds_values_hash )
546
- end
547
- it 'should not do anything and should return an empty hash if the specified datastream does not exist' do
548
- skip "This is broken, and deprecated. I don't want to fix it - jcoyne"
549
- ds_values_hash = {
550
- 'nonexistentDatastream' => { 'notes' => 'foo' }
551
- }
530
+ describe "update_attributes" do
531
+ it "should set the attributes and save" do
552
532
  m = FooHistory.new
553
- untouched_xml = m.to_xml
554
- expect(m.update_datastream_attributes( ds_values_hash )).to eq({})
555
- expect(m.to_xml).to eq(untouched_xml)
556
- end
557
- end
558
-
559
- describe 'update_attributes' do
560
- it 'should set the attributes and save' do
561
- m = FooHistory.new
562
- att = {'fubar' => '1234', 'baz' => 'stuff'}
533
+ att= {"fubar"=> '1234', "baz" =>'stuff'}
563
534
 
564
- expect(m).to receive(:fubar=).with('1234')
565
- expect(m).to receive(:baz=).with('stuff')
566
- expect(m).to receive(:save)
535
+ m.should_receive(:fubar=).with('1234')
536
+ m.should_receive(:baz=).with('stuff')
537
+ m.should_receive(:save)
567
538
  m.update_attributes(att)
568
539
  end
569
540
  end
570
541
 
571
- describe 'update' do
572
- it 'should set the attributes and save' do
542
+ describe "update" do
543
+ it "should set the attributes and save" do
573
544
  m = FooHistory.new
574
- att = {'fubar' => '1234', 'baz' => 'stuff'}
545
+ att= {"fubar"=> '1234', "baz" =>'stuff'}
575
546
 
576
- expect(m).to receive(:fubar=).with('1234')
577
- expect(m).to receive(:baz=).with('stuff')
578
- expect(m).to receive(:save)
547
+ m.should_receive(:fubar=).with('1234')
548
+ m.should_receive(:baz=).with('stuff')
549
+ m.should_receive(:save)
579
550
  m.update(att)
580
551
  end
581
552
  end
582
553
 
583
- describe 'update_indexed_attributes' do
584
- before do
585
- expect(Deprecation).to receive(:warn).at_least(1).times
586
- end
587
- it 'should call .update_indexed_attributes on all metadata datastreams & nokogiri datastreams' do
588
- m = FooHistory.new
589
- att = {'fubar' => {'-1' => 'mork', '0' => 'york', '1' => 'mangle'}}
590
-
591
- expect(m.datastreams['someData']).to receive(:update_indexed_attributes)
592
- expect(m.datastreams['withText']).to receive(:update_indexed_attributes)
593
- expect(m.datastreams['withText2']).to receive(:update_indexed_attributes)
594
- m.update_indexed_attributes(att)
595
- end
596
- it 'should take a :datastreams argument' do
597
- att = {'fubar' => {'-1' => 'mork', '0' => 'york', '1' => 'mangle'}}
598
- stub_get(@this_pid)
599
- stub_get_content(@this_pid, ['RELS-EXT', 'someData', 'withText2', 'withText'])
600
- m = FooHistory.new()
601
- m.update_indexed_attributes(att, :datastreams => 'withText')
602
- expect(m).not_to be_nil
603
- expect(m.datastreams['someData'].fubar).to eq([])
604
- expect(m.datastreams['withText'].fubar).to eq(['mork', 'york', 'mangle'])
605
- expect(m.datastreams['withText2'].fubar).to eq([])
606
-
607
- att = {'fubar' => {'-1' => 'tork', '0' => 'work', '1' => 'bork'}}
608
- m.update_indexed_attributes(att, :datastreams => ['someData', 'withText2'])
609
- expect(m).not_to be_nil
610
- expect(m.datastreams['someData'].fubar).to eq(['tork', 'work', 'bork'])
611
- expect(m.datastreams['withText2'].fubar).to eq(['tork', 'work', 'bork'])
612
- end
613
- end
614
-
615
- describe '#relationships_by_name' do
616
- before do
617
- class MockNamedRelationships < ActiveFedora::Base
618
- # has_relationship "testing", :has_part, :type=>ActiveFedora::Base
619
- # has_relationship "testing2", :has_member, :type=>ActiveFedora::Base
620
- # has_relationship "testing_inbound", :has_part, :type=>ActiveFedora::Base, :inbound=>true
621
- end
622
- end
623
- end
624
-
625
- describe '.solrize_relationships' do
626
- it 'should serialize the relationships into a Hash' do
554
+ describe ".solrize_relationships" do
555
+ it "should serialize the relationships into a Hash" do
627
556
  graph = RDF::Graph.new
628
- subject = RDF::URI.new 'info:fedora/test:sample_pid'
557
+ subject = RDF::URI.new "info:fedora/test:sample_pid"
629
558
  graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:is_member_of), RDF::URI.new('info:fedora/demo:10'))
630
559
  graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:is_part_of), RDF::URI.new('info:fedora/demo:11'))
631
560
  graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_part), RDF::URI.new('info:fedora/demo:12'))
632
- graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:conforms_to), 'AnInterface')
561
+ graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:conforms_to), "AnInterface")
633
562
 
634
- expect(@test_object).to receive(:relationships).and_return(graph)
563
+ @test_object.should_receive(:relationships).and_return(graph)
635
564
  solr_doc = @test_object.solrize_relationships
636
- expect(solr_doc[ActiveFedora::SolrService.solr_name('is_member_of', :symbol)]).to eq('info:fedora/demo:10')
637
- expect(solr_doc[ActiveFedora::SolrService.solr_name('is_part_of', :symbol)]).to eq('info:fedora/demo:11')
638
- expect(solr_doc[ActiveFedora::SolrService.solr_name('has_part', :symbol)]).to eq('info:fedora/demo:12')
639
- expect(solr_doc[ActiveFedora::SolrService.solr_name('conforms_to', :symbol)]).to eq('AnInterface')
565
+ solr_doc[ActiveFedora::SolrService.solr_name("is_member_of", :symbol)].should == "info:fedora/demo:10"
566
+ solr_doc[ActiveFedora::SolrService.solr_name("is_part_of", :symbol)].should == "info:fedora/demo:11"
567
+ solr_doc[ActiveFedora::SolrService.solr_name("has_part", :symbol)].should == "info:fedora/demo:12"
568
+ solr_doc[ActiveFedora::SolrService.solr_name("conforms_to", :symbol)].should == "AnInterface"
640
569
  end
641
570
  end
642
571
  end