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,23 +1,82 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'When two or more relationships share the same property' do
3
+ describe "Looking up collection members" do
4
+ before :all 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
+ end
13
+ after :all do
14
+ Object.send(:remove_const, :Book)
15
+ Object.send(:remove_const, :Library)
16
+ end
17
+ describe "of has_many" do
18
+ let(:book) { Book.create }
19
+ let(:library) { Library.create() }
20
+ before do
21
+ library.books = [book]
22
+ library.save!
23
+ end
24
+ it "should read book_ids from solr" do
25
+ library.reload.book_ids.should ==[book.pid]
26
+ end
27
+ it "should read books from solr" do
28
+ library.reload.books.should ==[book]
29
+ end
30
+ end
31
+ end
32
+
33
+ describe "After save callbacks" do
34
+ before :all do
35
+ class Library < ActiveFedora::Base
36
+ has_many :books
37
+ end
38
+
39
+ class Book < ActiveFedora::Base
40
+ belongs_to :library, :property=>:has_constituent
41
+ after_save :find_self
42
+ attr_accessor :library_books
43
+
44
+ def find_self
45
+ # It's important we have the to_a so that it fetches the relationship immediately instead of lazy loading
46
+ self.library_books = library.books.to_a
47
+ end
48
+ end
49
+ end
50
+ after :all do
51
+ Object.send(:remove_const, :Book)
52
+ Object.send(:remove_const, :Library)
53
+ end
54
+ let(:library) { Library.create() }
55
+ let(:book) { Book.new(library: library) }
56
+ it "should have the relationship available in after_save" do
57
+ book.save!
58
+ book.library_books.should include book
59
+ end
60
+ end
61
+
62
+ describe "When two or more relationships share the same property" do
4
63
  before do
5
- class Book < ActiveFedora::Base
6
- has_many :collections, :class_name => 'Collection'
64
+ class Book < ActiveFedora::Base
65
+ has_many :collections, :class_name=>'Collection'
7
66
  has_many :people
8
67
  end
9
68
 
10
69
  class Person < ActiveFedora::Base
11
- belongs_to :book, :property => :is_part_of
70
+ belongs_to :book, :property=>:is_part_of
12
71
  end
13
72
 
14
73
  class Collection < ActiveFedora::Base
15
- belongs_to :book, :property => :is_part_of
74
+ belongs_to :book, :property=>:is_part_of
16
75
  end
17
76
 
18
77
  @book = Book.create!
19
- @person1 = Person.create!(:book => @book)
20
- @person2 = Person.create!(:book => @book)
78
+ @person1 = Person.create!(:book=>@book)
79
+ @person2 = Person.create!(:book=>@book)
21
80
  end
22
81
  after do
23
82
  Object.send(:remove_const, :Collection)
@@ -25,25 +84,25 @@ describe 'When two or more relationships share the same property' do
25
84
  Object.send(:remove_const, :Book)
26
85
  end
27
86
 
28
- it 'Should only return relationships of the correct class' do
87
+ it "Should only return relationships of the correct class" do
29
88
  @book.reload
30
- expect(@book.people).to eq([@person1, @person2])
31
- expect(@book.collections).to eq([])
89
+ @book.people.should == [@person1, @person2]
90
+ @book.collections.should == []
32
91
  end
33
92
  end
34
93
 
35
- describe 'When relationship is restricted to AF::Base' do
94
+ describe "When relationship is restricted to AF::Base" do
36
95
  before do
37
- class Email < ActiveFedora::Base
38
- has_many :attachments, :property => :is_part_of, :class_name => 'ActiveFedora::Base'
96
+ class Email < ActiveFedora::Base
97
+ has_many :attachments, :property=>:is_part_of, :class_name=>'ActiveFedora::Base'
39
98
  end
40
99
 
41
100
  class Image < ActiveFedora::Base
42
- belongs_to :email, :property => :is_part_of
101
+ belongs_to :email, :property=>:is_part_of
43
102
  end
44
103
 
45
104
  class PDF < ActiveFedora::Base
46
- belongs_to :email, :property => :is_part_of
105
+ belongs_to :email, :property=>:is_part_of
47
106
  end
48
107
  end
49
108
 
@@ -54,19 +113,19 @@ describe 'When relationship is restricted to AF::Base' do
54
113
  end
55
114
 
56
115
 
57
- describe 'creating new objects with object relationships' do
116
+ describe "creating new objects with object relationships" do
58
117
  before do
59
118
  @book = Email.create!
60
- @image = Image.create!(:email => @book)
61
- @pdf = PDF.create!(:email => @book)
119
+ @image = Image.create!(:email=>@book)
120
+ @pdf = PDF.create!(:email=>@book)
62
121
  end
63
- it 'Should not restrict relationships ' do
122
+ it "Should not restrict relationships " do
64
123
  @book.reload
65
- expect(@book.attachments).to eq([@image, @pdf])
124
+ @book.attachments.should == [@image, @pdf]
66
125
  end
67
126
  end
68
127
 
69
- describe 'creating new objects with id setter' do
128
+ describe "creating new objects with id setter" do
70
129
  let!(:image) { Image.create }
71
130
  let!(:email) { Email.create }
72
131
  let!(:pdf) { PDF.create }
@@ -77,11 +136,100 @@ describe 'When relationship is restricted to AF::Base' do
77
136
  image.destroy
78
137
  end
79
138
 
80
- it 'Should not restrict relationships ' do
81
- expect(Deprecation).not_to receive(:warn) # a deprecation in 6.6.0 that's going away in 7.0.0
139
+ it "Should not restrict relationships " do
82
140
  email.attachment_ids = [image.id, pdf.id]
83
141
  email.reload
84
- expect(email.attachments).to eq([image, pdf])
142
+ email.attachments.should == [image, pdf]
85
143
  end
86
144
  end
87
145
  end
146
+
147
+ describe "Deleting a dependent relationship" do
148
+ before do
149
+ class Item < ActiveFedora::Base
150
+ has_many :components, :property => :is_part_of
151
+ end
152
+ class Component < ActiveFedora::Base
153
+ belongs_to :item, :property => :is_part_of
154
+ end
155
+ end
156
+
157
+ after do
158
+ Object.send(:remove_const, :Item)
159
+ Object.send(:remove_const, :Component)
160
+ end
161
+
162
+ let(:item) { Item.create }
163
+ let(:component) { Component.create }
164
+
165
+ it "should remove relationships" do
166
+ component.item = item
167
+ component.save!
168
+ item.components.should == [component]
169
+ item.components.delete(component)
170
+ item.reload
171
+ component.reload
172
+ component.relationships(:is_part_of).should == []
173
+ item.components.should == []
174
+ end
175
+
176
+ it "should remove the relationships that point at that object" do
177
+ component.item = item
178
+ component.save!
179
+ item.delete
180
+ component.reload
181
+ component.relationships(:is_part_of).should == []
182
+ end
183
+
184
+ it "should only try to delete objects that exist in the datastore (not cached objects)" do
185
+ item.components << component
186
+ item.save!
187
+ component.delete
188
+ item.delete
189
+ end
190
+
191
+ end
192
+
193
+ describe "Autosave" do
194
+ before do
195
+ class Item < ActiveFedora::Base
196
+ has_many :components
197
+ has_metadata "foo", type: ActiveFedora::SimpleDatastream do |m|
198
+ m.field "title", :string
199
+ end
200
+ has_attributes :title, datastream: 'foo'
201
+ end
202
+ class Component < ActiveFedora::Base
203
+ belongs_to :item, :property => :is_part_of
204
+ has_metadata "foo", type: ActiveFedora::SimpleDatastream do |m|
205
+ m.field "description", :string
206
+ end
207
+ has_attributes :description, datastream: 'foo'
208
+ end
209
+ end
210
+
211
+ after do
212
+ Object.send(:remove_const, :Item)
213
+ Object.send(:remove_const, :Component)
214
+ end
215
+
216
+ describe "From the belongs_to side" do
217
+ let(:component) { Component.create(item: Item.new(title: 'my title')) }
218
+
219
+ it "should save dependent records" do
220
+ component.reload
221
+ component.item.title.should == 'my title'
222
+ end
223
+ end
224
+ describe "From the has_many side" do
225
+ let(:item) { Item.create(components: [Component.new(description: 'my description')]) }
226
+
227
+ it "should save dependent records" do
228
+ item.reload
229
+ item.components.first.description.should == 'my description'
230
+ end
231
+ end
232
+
233
+ end
234
+
235
+
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Objects should be serialized to JSON" do
4
+ it "should have json results" do
5
+ ActiveFedora::Base.new.to_json.should == "{\"id\":null}"
6
+ end
7
+
8
+ describe "with a more interesting model" do
9
+ before do
10
+ class Foo < ActiveFedora::Base
11
+ has_metadata 'descMetadata', type: ActiveFedora::SimpleDatastream do |m|
12
+ m.field "foo", :text
13
+ m.field "bar", :text
14
+ end
15
+ has_attributes :foo, datastream: 'descMetadata', multiple: true
16
+ has_attributes :bar, datastream: 'descMetadata', multiple: false
17
+ end
18
+ end
19
+ after do
20
+ Object.send(:remove_const, :Foo)
21
+ end
22
+ subject { Foo.new(foo: "baz", bar: 'quix') }
23
+ before { subject.stub(pid: 'test:123') }
24
+ it "should have to_json" do
25
+ json = JSON.parse(subject.to_json)
26
+ expect(json['id']).to eq "test:123"
27
+ expect(json['foo']).to eq ["baz"]
28
+ expect(json['bar']).to eq "quix"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Loading from solr" do
4
+ before do
5
+ class MyDatastream < ActiveFedora::NtriplesRDFDatastream
6
+ map_predicates do |map|
7
+ map.title(in: RDF::DC) do |index|
8
+ index.as :stored_searchable, :facetable
9
+ end
10
+ map.date_uploaded(to: "dateSubmitted", in: RDF::DC) do |index|
11
+ index.type :date
12
+ index.as :stored_searchable, :sortable
13
+ end
14
+ map.identifier(in: RDF::DC) do |index|
15
+ index.type :integer
16
+ index.as :stored_searchable, :sortable
17
+ end
18
+ map.part(to: "hasPart", in: RDF::DC)
19
+ map.based_near(in: RDF::FOAF)
20
+ map.related_url(to: "seeAlso", in: RDF::RDFS)
21
+ end
22
+ end
23
+ class RdfTest < ActiveFedora::Base
24
+ has_metadata :name=>'rdf', :type=>MyDatastream
25
+ has_attributes :based_near, :related_url, :part, :date_uploaded, datastream: 'rdf', multiple: true
26
+ has_attributes :title, :identifier, datastream: 'rdf', multiple: false
27
+ end
28
+ end
29
+
30
+ let!(:original) { RdfTest.create!(title: "PLAN 9 FROM OUTER SPACE",
31
+ date_uploaded: Date.parse('1959-01-01'),
32
+ identifier: 12345) }
33
+
34
+ after do
35
+ original.destroy
36
+ Object.send(:remove_const, :RdfTest)
37
+ Object.send(:remove_const, :MyDatastream)
38
+ end
39
+
40
+ it "should be able to get indexed properties without loading from fedora" do
41
+ expect(RdfTest.connection_for_pid('1')).to receive(:datastream_dissemination).never
42
+ obj = RdfTest.load_instance_from_solr original.pid
43
+ expect(obj.title).to eq "PLAN 9 FROM OUTER SPACE"
44
+ expect(obj.date_uploaded).to eq [Date.parse('1959-01-01')]
45
+ expect(obj.identifier).to eq 12345
46
+ expect(obj.part).to be_nil # since it wasn't indexed
47
+ end
48
+ end
@@ -1,16 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ActiveFedora::Model do
4
-
5
- before(:each) do
4
+
5
+ before(:each) do
6
6
  module ModelIntegrationSpec
7
-
7
+
8
8
  class Base < ActiveFedora::Base
9
9
  include ActiveFedora::Model
10
10
  def self.pid_namespace
11
- 'foo'
11
+ "foo"
12
12
  end
13
- has_metadata :name => 'properties', :type => ActiveFedora::SimpleDatastream, :autocreate => true
13
+ has_metadata :name => "properties", :type => ActiveFedora::SimpleDatastream, :autocreate => true
14
14
  end
15
15
  class Basic < Base
16
16
  end
@@ -18,59 +18,54 @@ describe ActiveFedora::Model do
18
18
 
19
19
  @test_instance = ModelIntegrationSpec::Basic.new
20
20
  @test_instance.save
21
-
21
+
22
22
  end
23
-
23
+
24
24
  after(:each) do
25
25
  @test_instance.delete
26
26
  Object.send(:remove_const, :ModelIntegrationSpec)
27
27
  end
28
-
29
- describe '#find' do
30
- describe 'with :all' do
31
- it 'should return an array of instances of the calling Class' do
32
- result = ModelIntegrationSpec::Basic.find(:all)
33
- expect(result).to be_instance_of(Array)
34
- # this test is meaningless if the array length is zero
35
- expect(result.length).to be > 0
36
- result.each do |obj|
37
- expect(obj.class).to eq(ModelIntegrationSpec::Basic)
38
- end
28
+
29
+ describe "#all" do
30
+ it "should return an array of instances of the calling Class" do
31
+ result = ModelIntegrationSpec::Basic.all.to_a
32
+ result.should be_instance_of(Array)
33
+ # this test is meaningless if the array length is zero
34
+ result.length.should > 0
35
+ result.each do |obj|
36
+ obj.class.should == ModelIntegrationSpec::Basic
39
37
  end
40
38
  end
41
- describe '#find with a valid pid with cast' do
42
- subject { ActiveFedora::Base.find(@test_instance.pid, :cast => true) }
43
- it { is_expected.to be_instance_of ModelIntegrationSpec::Basic}
44
- end
45
- describe '#find with a valid pid without cast on Base' do
39
+ end
40
+
41
+ describe '#find' do
42
+ describe "#find with a valid pid without cast" do
46
43
  subject { ActiveFedora::Base.find(@test_instance.pid) }
47
- before(:each) do
48
- expect(Deprecation).to receive(:warn).at_least(1).times
49
- end
50
- it { is_expected.to be_instance_of ActiveFedora::Base}
44
+ it { should be_instance_of ModelIntegrationSpec::Basic}
45
+ end
46
+ describe "#find with a valid pid with cast of false" do
47
+ subject { ActiveFedora::Base.find(@test_instance.pid, cast: false) }
48
+ it { should be_instance_of ActiveFedora::Base}
51
49
  end
52
- describe '#find with a valid pid without cast on a model extending Base' do
50
+ describe "#find with a valid pid without cast on a model extending Base" do
53
51
  subject { ModelIntegrationSpec::Basic.find(@test_instance.pid) }
54
- before(:each) do
55
- expect(Deprecation).not_to receive(:warn)
56
- end
57
- it { is_expected.to be_instance_of ModelIntegrationSpec::Basic}
52
+ it { should be_instance_of ModelIntegrationSpec::Basic}
58
53
  end
59
54
  end
60
55
 
61
- describe '#load_instance_from_solr' do
62
- describe 'with a valid pid' do
56
+ describe "#load_instance_from_solr" do
57
+ describe "with a valid pid" do
63
58
  subject { ActiveFedora::Base.load_instance_from_solr(@test_instance.pid) }
64
- it { is_expected.to be_instance_of ModelIntegrationSpec::Basic}
59
+ it { should be_instance_of ModelIntegrationSpec::Basic}
65
60
  end
66
- describe 'with metadata datastream spec' do
61
+ describe "with metadata datastream spec" do
67
62
  subject { ActiveFedora::Base.load_instance_from_solr(@test_instance.pid) }
68
- it 'should create an xml datastream' do
69
- expect(subject.datastreams['properties']).to be_kind_of ActiveFedora::SimpleDatastream
63
+ it "should create an xml datastream" do
64
+ subject.datastreams['properties'].should be_kind_of ActiveFedora::SimpleDatastream
70
65
  end
71
66
 
72
- it 'should know the datastreams properties' do
73
- expect(subject.properties.dsSize).to eq(9)
67
+ it "should know the datastreams properties" do
68
+ subject.properties.dsSize.should == 9
74
69
  end
75
70
  end
76
71
  end
@@ -1,36 +1,35 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'NestedAttribute behavior' do
3
+ describe "NestedAttribute behavior" do
4
4
  before do
5
5
  class Bar < ActiveFedora::Base
6
- belongs_to :car, :property => :has_member
7
- has_metadata :type => ActiveFedora::SimpleDatastream, :name => 'someData' do |m|
8
- m.field 'uno', :string
9
- m.field 'dos', :string
6
+ belongs_to :car, :property=>:has_member
7
+ has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"someData" do |m|
8
+ m.field "uno", :string
9
+ m.field "dos", :string
10
10
  end
11
- delegate :uno, to: 'someData', multiple: false
12
- delegate :dos, to: 'someData', multiple: false
11
+ has_attributes :uno, :dos, datastream: 'someData', multiple: false
13
12
  end
14
13
 
15
14
  # base Car class, used in test for association updates and :allow_destroy flag
16
15
  class Car < ActiveFedora::Base
17
- has_many :bars, :property => :has_member
18
- accepts_nested_attributes_for :bars, :allow_destroy => true
16
+ has_many :bars, :property=>:has_member
17
+ accepts_nested_attributes_for :bars, :allow_destroy=>true
19
18
  end
20
19
 
21
20
  # class used in test for :reject_if=>:all_blank
22
21
  class CarAllBlank < Car
23
- accepts_nested_attributes_for :bars, :reject_if => :all_blank
22
+ accepts_nested_attributes_for :bars, :reject_if=>:all_blank
24
23
  end
25
24
 
26
25
  # class used in test for :reject_if with proc object
27
26
  class CarProc < Car
28
- accepts_nested_attributes_for :bars, :reject_if => proc { |attributes| attributes['uno'].blank? }
27
+ accepts_nested_attributes_for :bars, :reject_if=>proc { |attributes| attributes['uno'].blank? }
29
28
  end
30
29
 
31
30
  # class used in test for :reject_if with method name as symbol
32
31
  class CarSymbol < Car
33
- accepts_nested_attributes_for :bars, :reject_if => :uno_blank
32
+ accepts_nested_attributes_for :bars, :reject_if=>:uno_blank
34
33
 
35
34
  def uno_blank(attributes)
36
35
  attributes['uno'].blank?
@@ -43,64 +42,64 @@ describe 'NestedAttribute behavior' do
43
42
  end
44
43
  end
45
44
 
46
- it 'should have _destroy' do
47
- expect(Bar.new._destroy).to be_falsey
45
+ it "should have _destroy" do
46
+ Bar.new._destroy.should be_false
48
47
  end
49
48
 
50
- it 'should update the child objects' do
49
+ it "should update the child objects" do
51
50
  @car, @bar1, @bar2 = create_car_with_bars
52
51
 
53
- @car.attributes = {:bars_attributes => [{:id => @bar1.pid, :uno => 'bar1 uno'}, {:uno => 'newbar uno'}, {:id => @bar2.pid, :_destroy => '1', :uno => 'bar2 uno'}]}
54
- expect(Bar.find(@bar1.pid).uno).to eq('bar1 uno')
55
- expect(Bar.where(:id => @bar2.pid).first).to be_nil
56
- expect(Bar.where(:uno => 'newbar uno').first).not_to be_nil
52
+ @car.attributes = {:bars_attributes=>[{:id=>@bar1.pid, :uno=>"bar1 uno"}, {:uno=>"newbar uno"}, {:id=>@bar2.pid, :_destroy=>'1', :uno=>'bar2 uno'}]}
53
+ Bar.find(@bar1.pid).uno.should == 'bar1 uno'
54
+ Bar.where(:id => @bar2.pid).first.should be_nil
55
+ Bar.where(:uno => "newbar uno").first.should_not be_nil
57
56
 
58
57
  bars = @car.bars(true)
59
- expect(bars).to include(@bar1)
60
- expect(bars).not_to include(@bar2)
58
+ bars.should include(@bar1)
59
+ bars.should_not include(@bar2)
61
60
  end
62
61
 
63
- it 'should reject attributes when all blank' do
62
+ it "should reject attributes when all blank" do
64
63
  @car, @bar1, @bar2 = create_car_with_bars(CarAllBlank)
65
64
 
66
- expect(@car.bars.count).to eq(2)
67
- @car.attributes = {:bars_attributes => [{}, {:id => @bar1.pid, :uno => 'bar1 uno'}]}
68
- expect(@car.bars(true).count).to eq(2)
65
+ @car.bars.count.should == 2
66
+ @car.attributes = {:bars_attributes=>[{}, {:id=>@bar1.pid, :uno=>"bar1 uno"}]}
67
+ @car.bars(true).count.should == 2
69
68
 
70
69
  @bar1.reload
71
- expect(@bar1.uno).to eq('bar1 uno')
70
+ @bar1.uno.should == "bar1 uno"
72
71
  end
73
72
 
74
- it 'should reject attributes based on proc' do
73
+ it "should reject attributes based on proc" do
75
74
  @car, @bar1, @bar2 = create_car_with_bars(CarProc)
76
75
 
77
- @car.attributes = {:bars_attributes => [{}, {:id => @bar1.pid, :uno => 'bar1 uno'}, {:id => @bar2.pid, :dos => 'bar2 dos'}]}
76
+ @car.attributes = {:bars_attributes=>[{}, {:id=>@bar1.pid, :uno=>"bar1 uno"}, {:id=>@bar2.pid, :dos=>"bar2 dos"}]}
78
77
  @bar1.reload
79
78
  @bar2.reload
80
- expect(@bar1.uno).to eq('bar1 uno')
81
- expect(@bar2.dos).to be_nil
79
+ @bar1.uno.should == "bar1 uno"
80
+ @bar2.dos.should be_nil
82
81
  end
83
82
 
84
- it 'should reject attributes base on method name' do
83
+ it "should reject attributes base on method name" do
85
84
  @car, @bar1, @bar2 = create_car_with_bars(CarSymbol)
86
85
 
87
- @car.attributes = {:bars_attributes => [{}, {:id => @bar1.pid, :uno => 'bar1 uno'}, {:id => @bar2.pid, :dos => 'bar2 dos'}]}
86
+ @car.attributes = {:bars_attributes=>[{}, {:id=>@bar1.pid, :uno=>"bar1 uno"}, {:id=>@bar2.pid, :dos=>"bar2 dos"}]}
88
87
  @bar1.reload
89
88
  @bar2.reload
90
- expect(@bar1.uno).to eq('bar1 uno')
91
- expect(@bar2.dos).to be_nil
89
+ @bar1.uno.should == "bar1 uno"
90
+ @bar2.dos.should be_nil
92
91
  end
93
92
 
94
- it 'should throw TooManyRecords' do
93
+ it "should throw TooManyRecords" do
95
94
  @car, @bar1, @bar2 = create_car_with_bars(CarWithLimit)
96
95
 
97
- expect {
98
- @car.attributes = {:bars_attributes => [{}]}
99
- }.not_to raise_exception
96
+ lambda {
97
+ @car.attributes = {:bars_attributes=>[{}]}
98
+ }.should_not raise_exception
100
99
 
101
- expect {
102
- @car.attributes = {:bars_attributes => [{}, {}]}
103
- }.to raise_exception(ActiveFedora::NestedAttributes::TooManyRecords)
100
+ lambda {
101
+ @car.attributes = {:bars_attributes=>[{}, {}]}
102
+ }.should raise_exception(ActiveFedora::NestedAttributes::TooManyRecords)
104
103
  end
105
104
 
106
105
  private
@@ -114,8 +113,8 @@ describe 'NestedAttribute behavior' do
114
113
  def create_car_with_bars(car_class = Car, bar_class = Bar)
115
114
  car = car_class.new; car.save
116
115
 
117
- bar1 = bar_class.new(:car => car); bar1.save
118
- bar2 = bar_class.new(:car => car); bar2.save
116
+ bar1 = bar_class.new(:car=>car); bar1.save
117
+ bar2 = bar_class.new(:car=>car); bar2.save
119
118
  [car, bar1, bar2]
120
119
  end
121
120