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
@@ -0,0 +1,166 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveFedora::Base do
4
+ before do
5
+ class Library < ActiveFedora::Base
6
+ has_many :books
7
+ end
8
+
9
+ class Book < ActiveFedora::Base
10
+ belongs_to :library, :property=>:has_constituent
11
+ end
12
+ class SpecialInheritedBook < Book
13
+ end
14
+
15
+ end
16
+ after do
17
+ Object.send(:remove_const, :Library)
18
+ Object.send(:remove_const, :SpecialInheritedBook)
19
+ Object.send(:remove_const, :Book)
20
+ end
21
+
22
+ let(:library) { Library.create }
23
+ let(:book) { Book.new }
24
+
25
+ describe "setting the id property" do
26
+ it "should store it" do
27
+ book.library_id = library.id
28
+ book.library_id.should == library.id
29
+ end
30
+
31
+ describe "reassigning the parent_id" do
32
+ let(:library2) { Library.create}
33
+ before { book.library = library2 }
34
+ it "should update the object" do
35
+ expect(book.library).to eq library2 # cause the association to set @loaded
36
+ library_proxy = book.send(:association_instance_get, :library)
37
+ expect(library_proxy).to_not be_stale_target
38
+ book.library_id = library.id
39
+ expect(library_proxy).to be_stale_target
40
+ expect(book.library).to eq library
41
+ end
42
+ end
43
+
44
+ it "should be settable via []=" do
45
+ book[:library_id] = library.id
46
+ book.library_id.should == library.id
47
+ end
48
+ end
49
+
50
+ describe "getting the id property" do
51
+ it "should be accessable via []" do
52
+ book[:library_id] = library.id
53
+ book[:library_id].should == library.id
54
+ end
55
+ end
56
+
57
+ describe "when dealing with inherited objects" do
58
+ before do
59
+ @library2 = Library.create
60
+ @special_book = SpecialInheritedBook.create
61
+
62
+ book.library = @library2
63
+ book.save
64
+ @special_book.library = @library2
65
+ @special_book.save
66
+ end
67
+
68
+ it "should cast to the most specific class for the association" do
69
+ @library2.books[0].class == Book
70
+ @library2.books[1].class == SpecialInheritedBook
71
+ end
72
+
73
+ after do
74
+ @library2.delete
75
+ @special_book.delete
76
+ end
77
+ end
78
+
79
+ describe "casting inheritance additional test cases" do
80
+ before :all do
81
+ class SimpleObject < ActiveFedora::Base
82
+ belongs_to :simple_collection, property: :is_part_of, class_name: 'SimpleCollection'
83
+ belongs_to :complex_collection, property: :is_part_of, class_name: 'ComplexCollection'
84
+ end
85
+
86
+ class ComplexObject < SimpleObject
87
+ end
88
+
89
+ class SimpleCollection < ActiveFedora::Base
90
+ has_many :objects, property: :is_part_of, class_name: 'SimpleObject'
91
+ has_many :complex_objects, property: :is_part_of, class_name: 'ComplexObject'
92
+ end
93
+
94
+ class ComplexCollection < SimpleCollection
95
+ end
96
+
97
+ end
98
+ after :all do
99
+ Object.send(:remove_const, :SimpleObject)
100
+ Object.send(:remove_const, :ComplexObject)
101
+ Object.send(:remove_const, :SimpleCollection)
102
+ Object.send(:remove_const, :ComplexCollection)
103
+ end
104
+
105
+ describe "saving between the before and after hooks" do
106
+ before do
107
+ @simple_collection = SimpleCollection.create
108
+ @complex_collection = ComplexCollection.create
109
+
110
+ @simple_object = SimpleObject.create
111
+ @simple_object_second = SimpleObject.create
112
+ @complex_object = ComplexObject.create
113
+
114
+ #Need to add the simpler cmodel here as currently inheritance support is read-only.
115
+ #See ActiveFedora pull request 207 on how to do this programmatically.
116
+ @complex_object.add_relationship(:has_model, @complex_object.class.superclass.to_class_uri)
117
+
118
+ @simple_collection.objects = [@simple_object, @simple_object_second, @complex_object]
119
+ @simple_collection.save!
120
+ @complex_collection.objects = [@simple_object, @complex_object]
121
+ @complex_collection.save!
122
+ @complex_object.save!
123
+ @simple_object.save!
124
+ @simple_object_second.save!
125
+ end
126
+
127
+
128
+ it "casted association methods should work and return the most complex class" do
129
+ @complex_object.simple_collection.should be_instance_of SimpleCollection
130
+ @complex_object.complex_collection.should be_instance_of ComplexCollection
131
+
132
+ @simple_object.simple_collection.should be_instance_of SimpleCollection
133
+ @simple_object.complex_collection.should be_instance_of ComplexCollection
134
+ @simple_object_second.simple_collection.should be_instance_of SimpleCollection
135
+ @simple_object_second.complex_collection.should be_nil
136
+
137
+ @complex_collection.objects[0].should be_instance_of SimpleObject
138
+ @complex_collection.objects[1].should be_instance_of ComplexObject
139
+
140
+ @simple_collection.objects[0].should be_instance_of SimpleObject
141
+ @simple_collection.objects[1].should be_instance_of SimpleObject
142
+ @simple_collection.objects[2].should be_instance_of ComplexObject
143
+
144
+ end
145
+
146
+ it "specified ending relationships should ignore classes not specified" do
147
+ @complex_collection.complex_objects.count.should == 1
148
+ @complex_collection.complex_objects[0].should be_instance_of ComplexObject
149
+ @complex_collection.complex_objects[1].should be_nil
150
+
151
+ @simple_collection.complex_objects.count.should == 1
152
+ @simple_collection.complex_objects[0].should be_instance_of ComplexObject
153
+ @simple_collection.complex_objects[1].should be_nil
154
+
155
+ end
156
+
157
+ after do
158
+ @simple_object.delete
159
+ @simple_object_second.delete
160
+ @complex_object.delete
161
+ end
162
+ end
163
+ end
164
+ end
165
+
166
+
@@ -2,14 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  require 'active_fedora'
4
4
  require 'active_fedora/model'
5
- require 'rexml/document'
5
+ require "rexml/document"
6
6
  include ActiveFedora::Model
7
7
 
8
8
  describe 'bugs' do
9
9
  before do
10
10
  class FooHistory < ActiveFedora::Base
11
- has_metadata :type => ActiveFedora::SimpleDatastream, :name => 'someData' do |m|
12
- m.field 'fubar', :string
11
+ has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"someData" do |m|
12
+ m.field "fubar", :string
13
13
  end
14
14
  end
15
15
  @test_object = FooHistory.new
@@ -26,17 +26,17 @@ describe 'bugs' do
26
26
  }.to raise_error(ActiveFedora::ObjectNotFoundError)
27
27
  end
28
28
 
29
- it 'should not clobber everything when setting a value' do
30
- @test_object.someData.fubar = ['initial']
29
+ it "should not clobber everything when setting a value" do
30
+ @test_object.someData.fubar=['initial']
31
31
  @test_object.save!
32
32
 
33
33
  x = FooHistory.find(@test_object.pid)
34
- x.someData.fubar = ['replacement'] # set a new value
34
+ x.someData.fubar = ["replacement"] # set a new value
35
35
  x.save!
36
36
 
37
37
 
38
38
  x = FooHistory.find(@test_object.pid)
39
- expect(x.someData.fubar).to eq(['replacement']) # recall the value
39
+ x.someData.fubar.should == ["replacement"] # recall the value
40
40
  x.save
41
41
  end
42
42
  end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveFedora::Base do
4
+ before do
5
+ class Library < ActiveFedora::Base
6
+ has_many :books
7
+ end
8
+ class Book < ActiveFedora::Base
9
+ belongs_to :library, property: :has_member
10
+ end
11
+ end
12
+ let(:library) { Library.create! }
13
+ let!(:book1) { Book.create!(library: library) }
14
+ let!(:book2) { Book.create!(library: library) }
15
+ after do
16
+ Book.delete_all
17
+ Library.delete_all
18
+ Object.send(:remove_const, :Library)
19
+ Object.send(:remove_const, :Book)
20
+ end
21
+ describe "load_from_solr" do
22
+ it "should set rows to count, if not specified" do
23
+ library.books(response_format: :solr).size.should == 2
24
+ end
25
+ it "should limit rows returned if option passed" do
26
+ library.books(response_format: :solr, rows: 1).size.should == 1
27
+ end
28
+ end
29
+
30
+ describe "#delete_all" do
31
+ it "should delete em" do
32
+ expect {
33
+ library.books.delete_all
34
+ }.to change { library.books.count }.by(-2)
35
+ end
36
+ end
37
+
38
+ describe "#destroy_all" do
39
+ it "should delete em" do
40
+ expect {
41
+ library.books.destroy_all
42
+ }.to change { library.books.count }.by(-2)
43
+ end
44
+ end
45
+
46
+ describe "#find" do
47
+ it "should find the record that matches" do
48
+ expected = library.books.find(book1.id)
49
+ expect(expected).to eq book1
50
+ end
51
+ describe "with some records that aren't part of the collection" do
52
+ let!(:book3) { Book.create }
53
+ it "should find no records" do
54
+ expect(library.books.find(book3.id)).to be_nil
55
+ end
56
+ end
57
+ end
58
+ end
@@ -1,258 +1,258 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Nested Rdf Objects' do
4
- describe 'without type' do
5
- before(:each) do
3
+ describe "Nested Rdf Objects" do
4
+ describe "without type" do
5
+ before(:each) do
6
6
  class SpecDatastream < ActiveFedora::NtriplesRDFDatastream
7
7
  map_predicates do |map|
8
- map.parts(:in => RDF::DC, :to => 'hasPart', :class_name => 'Component')
8
+ map.parts(:in=> RDF::DC, :to=>'hasPart', :class_name=>'Component')
9
9
  end
10
10
 
11
11
  class Component
12
12
  include ActiveFedora::RdfObject
13
13
  map_predicates do |map|
14
- map.label(:in => RDF::DC, :to => 'title')
14
+ map.label(:in=> RDF::DC, :to=>'title')
15
15
  end
16
16
  end
17
17
  end
18
18
 
19
19
  end
20
-
20
+
21
21
  after(:each) do
22
22
  Object.send(:remove_const, :SpecDatastream)
23
23
  end
24
24
 
25
25
  let (:ds) do
26
- mock_obj = double(:mock_obj, :pid => 'test:124', :new_record? => true)
26
+ mock_obj = double(:mock_obj, :pid=>'test:124', :new_record? => true)
27
27
  ds = SpecDatastream.new(mock_obj)
28
28
  end
29
29
 
30
- describe '#new_record?' do
31
- it 'should be true when its built' do
30
+ describe "#new_record?" do
31
+ it "should be true when its built" do
32
32
  v = ds.parts.build(label: 'Alternator')
33
- expect(v).to be_new_record
33
+ v.should be_new_record
34
34
  end
35
35
 
36
36
  it "should not be new when it's loaded from fedora" do
37
37
  ds.content = '_:g70324142325120 <http://purl.org/dc/terms/title> "Alternator" .
38
38
  <info:fedora/test:124> <http://purl.org/dc/terms/hasPart> _:g70324142325120 .'
39
- expect(ds.parts.first).not_to be_new_record
39
+ ds.parts.first.should_not be_new_record
40
40
  end
41
41
  end
42
42
 
43
- it 'should not choke on invalid data' do
43
+ it "should not choke on invalid data" do
44
44
  # set a string in the graph where model expects a node
45
- ds.parts = ['foo']
45
+ ds.parts = ["foo"]
46
46
  expect {ds.parts.inspect}.to raise_error(ArgumentError, "Expected the value of http://purl.org/dc/terms/hasPart to be an RDF object but it is a String \"foo\"")
47
47
  end
48
-
49
- it 'should be able to nest a complex object' do
48
+
49
+ it "should be able to nest a complex object" do
50
50
  comp = SpecDatastream::Component.new(ds.graph)
51
- comp.label = ['Alternator']
51
+ comp.label = ["Alternator"]
52
52
  ds.parts = comp
53
- expect(ds.parts.first.label).to eq(['Alternator'])
53
+ ds.parts.first.label.should == ["Alternator"]
54
54
  end
55
55
 
56
- it 'should be able to replace attributes' do
56
+ it "should be able to replace attributes" do
57
57
  v = ds.parts.build(label: 'Alternator')
58
- expect(ds.parts.first.label).to eq(['Alternator'])
58
+ ds.parts.first.label.should == ['Alternator']
59
59
  ds.parts.first.label = ['Distributor']
60
- expect(ds.parts.first.label).to eq(['Distributor'])
60
+ ds.parts.first.label.should == ['Distributor']
61
61
  end
62
62
 
63
- it 'should be able to replace objects' do
63
+ it "should be able to replace objects" do
64
64
  ds.parts.build(label: 'Alternator')
65
65
  ds.parts.build(label: 'Distributor')
66
- expect(ds.parts.size).to eq(2)
66
+ ds.parts.size.should == 2
67
67
  comp = SpecDatastream::Component.new(ds.graph)
68
- comp.label = 'Injector port'
68
+ comp.label = "Injector port"
69
69
  ds.parts = [comp]
70
- expect(ds.parts.size).to eq(1)
70
+ ds.parts.size.should == 1
71
71
  end
72
72
 
73
- it 'should be able to nest many complex objects' do
73
+ it "should be able to nest many complex objects" do
74
74
  comp1 = SpecDatastream::Component.new ds.graph
75
- comp1.label = ['Alternator']
75
+ comp1.label = ["Alternator"]
76
76
  comp2 = SpecDatastream::Component.new ds.graph
77
- comp2.label = ['Crankshaft']
77
+ comp2.label = ["Crankshaft"]
78
78
  ds.parts = [comp1, comp2]
79
- expect(ds.parts.first.label).to eq(['Alternator'])
80
- expect(ds.parts.last.label).to eq(['Crankshaft'])
79
+ ds.parts.first.label.should == ["Alternator"]
80
+ ds.parts.last.label.should == ["Crankshaft"]
81
81
  end
82
82
 
83
- it 'should be able to clear complex objects' do
83
+ it "should be able to clear complex objects" do
84
84
  comp1 = SpecDatastream::Component.new ds.graph
85
- comp1.label = ['Alternator']
85
+ comp1.label = ["Alternator"]
86
86
  comp2 = SpecDatastream::Component.new ds.graph
87
- comp2.label = ['Crankshaft']
87
+ comp2.label = ["Crankshaft"]
88
88
  ds.parts = [comp1, comp2]
89
89
  ds.parts = []
90
- expect(ds.parts).to eq([])
90
+ ds.parts.should == []
91
91
  end
92
92
 
93
- it 'should load complex objects' do
93
+ it "should load complex objects" do
94
94
  ds.content = <<END
95
95
  _:g70350851837440 <http://purl.org/dc/terms/title> "Alternator" .
96
96
  <info:fedora/test:124> <http://purl.org/dc/terms/hasPart> _:g70350851837440 .
97
97
  <info:fedora/test:124> <http://purl.org/dc/terms/hasPart> _:g70350851833380 .
98
98
  _:g70350851833380 <http://purl.org/dc/terms/title> "Crankshaft" .
99
99
  END
100
- expect(ds.parts.first.label).to eq(['Alternator'])
100
+ ds.parts.first.label.should == ["Alternator"]
101
101
  end
102
102
 
103
103
  it "should build complex objects when a parent node doesn't exist" do
104
104
  part = ds.parts.build
105
- expect(part).to be_kind_of SpecDatastream::Component
106
- part.label = 'Wheel bearing'
107
- expect(ds.parts.first.label).to eq(['Wheel bearing'])
105
+ part.should be_kind_of SpecDatastream::Component
106
+ part.label = "Wheel bearing"
107
+ ds.parts.first.label.should == ['Wheel bearing']
108
108
  end
109
109
 
110
- it 'should not create a child node when hitting the accessor' do
110
+ it "should not create a child node when hitting the accessor" do
111
111
  ds.parts
112
- expect(ds.parts.first).to be_nil
113
- expect(ds.serialize).to eq('')
112
+ ds.parts.first.should be_nil
113
+ ds.serialize.should == ''
114
114
  end
115
115
 
116
- it 'should build complex objects when a parent node exists' do
116
+ it "should build complex objects when a parent node exists" do
117
117
  part = ds.parts.build
118
- expect(part).to be_kind_of SpecDatastream::Component
119
- part.label = 'Wheel bearing'
120
- expect(ds.parts.first.label).to eq(['Wheel bearing'])
118
+ part.should be_kind_of SpecDatastream::Component
119
+ part.label = "Wheel bearing"
120
+ ds.parts.first.label.should == ['Wheel bearing']
121
121
  end
122
122
 
123
- describe '#first_or_create' do
124
- it 'should return a result if the predicate exists' do
123
+ describe "#first_or_create" do
124
+ it "should return a result if the predicate exists" do
125
125
  part1 = ds.parts.build
126
126
  part2 = ds.parts.build
127
- expect(ds.parts.first_or_create).to eq(part1)
127
+ ds.parts.first_or_create.should == part1
128
128
  end
129
129
 
130
130
  it "should create a new result if the predicate doesn't exist" do
131
- expect(ds.parts).to eq([])
131
+ ds.parts.should == []
132
132
  part = ds.parts.first_or_create(label: 'Front control arm bushing')
133
- expect(part.label).to eq(['Front control arm bushing'])
134
- expect(ds.parts).to eq([part])
133
+ part.label.should == ['Front control arm bushing']
134
+ ds.parts.should == [part]
135
135
  end
136
136
 
137
137
  end
138
138
  end
139
139
 
140
140
 
141
- describe 'with type' do
142
- describe 'one class per assertion' do
143
- before(:each) do
141
+ describe "with type" do
142
+ describe "one class per assertion" do
143
+ before(:each) do
144
144
  class SpecDatastream < ActiveFedora::NtriplesRDFDatastream
145
145
  map_predicates do |map|
146
- map.mediator(:in => RDF::DC, :class_name => 'MediatorUser')
146
+ map.mediator(:in=> RDF::DC, :class_name=>'MediatorUser')
147
147
  end
148
148
 
149
149
  class MediatorUser
150
150
  include ActiveFedora::RdfObject
151
151
  rdf_type RDF::DC.AgentClass
152
152
  map_predicates do |map|
153
- map.title(:in => RDF::DC)
153
+ map.title(:in=> RDF::DC)
154
154
  end
155
155
  end
156
156
  end
157
157
  end
158
-
158
+
159
159
  after(:each) do
160
160
  Object.send(:remove_const, :SpecDatastream)
161
161
  end
162
162
 
163
163
  let (:ds) do
164
- mock_obj = double(:mock_obj, :pid => 'test:124', :new_record? => true)
164
+ mock_obj = double(:mock_obj, :pid=>'test:124', :new_record? => true)
165
165
  ds = SpecDatastream.new(mock_obj)
166
166
  end
167
167
 
168
168
 
169
- it 'should store the type of complex objects when type is specified' do
169
+ it "should store the type of complex objects when type is specified" do
170
170
  comp = SpecDatastream::MediatorUser.new ds.graph
171
- comp.title = ['Doctor']
171
+ comp.title = ["Doctor"]
172
172
  ds.mediator = comp
173
- expect(ds.mediator.first.type.first).to be_instance_of RDF::Vocabulary::Term
174
- expect(ds.mediator.first.type.first.to_s).to eq('http://purl.org/dc/terms/AgentClass')
175
- expect(ds.mediator.first.title.first).to eq('Doctor')
173
+ ds.mediator.first.type.first.should be_instance_of RDF::URI
174
+ ds.mediator.first.type.first.to_s.should == "http://purl.org/dc/terms/AgentClass"
175
+ ds.mediator.first.title.first.should == 'Doctor'
176
176
  end
177
177
 
178
- it 'should add the type of complex object when it is not provided' do
178
+ it "should add the type of complex object when it is not provided" do
179
179
  ds.content = <<END
180
180
  _:g70350851837440 <http://purl.org/dc/terms/title> "Mediation Person" .
181
181
  <info:fedora/test:124> <http://purl.org/dc/terms/mediator> _:g70350851837440 .
182
182
  END
183
- expect(ds.mediator.first.type.first.to_s).to eq('http://purl.org/dc/terms/AgentClass')
183
+ ds.mediator.first.type.first.to_s.should == "http://purl.org/dc/terms/AgentClass"
184
184
  end
185
185
 
186
- it 'should add load the type of complex objects when provided (superceeding what is specified by the class)' do
186
+ it "should add load the type of complex objects when provided (superceeding what is specified by the class)" do
187
187
  ds.content = <<END
188
188
  _:g70350851837440 <http://purl.org/dc/terms/title> "Mediation Orgainzation" .
189
189
  _:g70350851837440 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.ebu.ch/metadata/ontologies/ebucore#Organisation> .
190
190
  <info:fedora/test:124> <http://purl.org/dc/terms/mediator> _:g70350851837440 .
191
191
  END
192
- expect(ds.mediator.first.type.first.to_s).to eq('http://www.ebu.ch/metadata/ontologies/ebucore#Organisation')
192
+ ds.mediator.first.type.first.to_s.should == "http://www.ebu.ch/metadata/ontologies/ebucore#Organisation"
193
193
  end
194
194
  end
195
195
 
196
- describe 'shared assertion to different classes' do
197
- before(:each) do
198
- class EbuCore < RDF::Vocabulary('http://www.ebu.ch/metadata/ontologies/ebucore#')
196
+ describe "shared assertion to different classes" do
197
+ before(:each) do
198
+ class EbuCore < RDF::Vocabulary("http://www.ebu.ch/metadata/ontologies/ebucore#")
199
199
  property :isEpisodeOf
200
200
  property :title
201
201
  end
202
-
202
+
203
203
  class SpecDatastream < ActiveFedora::NtriplesRDFDatastream
204
204
  map_predicates do |map|
205
- map.series(:to => 'isEpisodeOf', :in => EbuCore, :class_name => 'Series')
206
- map.program(:to => 'isEpisodeOf', :in => EbuCore, :class_name => 'Program')
205
+ map.series(:to => 'isEpisodeOf', :in=> EbuCore, :class_name=>'Series')
206
+ map.program(:to => 'isEpisodeOf', :in=> EbuCore, :class_name=>'Program')
207
207
  end
208
208
 
209
209
  class Series
210
210
  include ActiveFedora::RdfObject
211
211
  rdf_type 'http://www.ebu.ch/metadata/ontologies/ebucore#Series'
212
212
  map_predicates do |map|
213
- map.title(:in => EbuCore)
213
+ map.title(:in=> EbuCore)
214
214
  end
215
215
  end
216
216
 
217
- class Program
217
+ class Program
218
218
  include ActiveFedora::RdfObject
219
219
  rdf_type 'http://www.ebu.ch/metadata/ontologies/ebucore#Programme'
220
220
  map_predicates do |map|
221
- map.title(:in => EbuCore)
221
+ map.title(:in=> EbuCore)
222
222
  end
223
223
  end
224
224
  end
225
225
 
226
226
  end
227
-
227
+
228
228
  after(:each) do
229
229
  Object.send(:remove_const, :SpecDatastream)
230
230
  end
231
231
 
232
232
  let (:ds) do
233
- mock_obj = double(:mock_obj, :pid => 'test:124', :new_record? => true)
233
+ mock_obj = double(:mock_obj, :pid=>'test:124', :new_record? => true)
234
234
  ds = SpecDatastream.new(mock_obj)
235
235
  end
236
236
 
237
237
 
238
- it 'should store the type of complex objects when type is specified' do
238
+ it "should store the type of complex objects when type is specified" do
239
239
  series = SpecDatastream::Series.new ds.graph
240
- series.title = ['renovating bathrooms']
240
+ series.title = ["renovating bathrooms"]
241
241
  ds.series = series
242
242
 
243
243
  program = SpecDatastream::Program.new ds.graph
244
- program.title = ['This old House']
244
+ program.title = ["This old House"]
245
245
  ds.program = program
246
246
 
247
- expect(ds.program.first.type.size).to eq(1)
248
- expect(ds.program.first.type.first.to_s).to eq('http://www.ebu.ch/metadata/ontologies/ebucore#Programme')
249
- expect(ds.series.first.type.size).to eq(1)
250
- expect(ds.series.first.type.first.to_s).to eq('http://www.ebu.ch/metadata/ontologies/ebucore#Series')
247
+ ds.program.first.type.size.should == 1
248
+ ds.program.first.type.first.to_s.should == 'http://www.ebu.ch/metadata/ontologies/ebucore#Programme'
249
+ ds.series.first.type.size.should == 1
250
+ ds.series.first.type.first.to_s.should == 'http://www.ebu.ch/metadata/ontologies/ebucore#Series'
251
251
  end
252
252
 
253
- it 'should create an object of the correct type' do
254
- expect(ds.program.build).to be_kind_of SpecDatastream::Program
255
- expect(ds.series.build).to be_kind_of SpecDatastream::Series
253
+ it "should create an object of the correct type" do
254
+ ds.program.build.should be_kind_of SpecDatastream::Program
255
+ ds.series.build.should be_kind_of SpecDatastream::Series
256
256
  end
257
257
  end
258
258
  end