active-fedora 13.1.2 → 13.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/.github_changelog_generator +2 -0
  3. data/CHANGELOG.md +3362 -0
  4. data/CONTRIBUTING.md +23 -1
  5. data/README.md +4 -0
  6. data/active-fedora.gemspec +14 -13
  7. data/lib/active_fedora/version.rb +1 -1
  8. metadata +104 -206
  9. data/spec/config_helper.rb +0 -17
  10. data/spec/fixtures/dino.jpg +0 -0
  11. data/spec/fixtures/dino_jpg_no_file_ext +0 -0
  12. data/spec/fixtures/minivan.jpg +0 -0
  13. data/spec/fixtures/rails_root/config/fake_fedora.yml +0 -7
  14. data/spec/fixtures/rails_root/config/fedora.yml +0 -12
  15. data/spec/fixtures/rails_root/config/solr.yml +0 -15
  16. data/spec/fixtures/rails_root/config/solr_mappings.yml +0 -16
  17. data/spec/fixtures/rails_root/config/solr_mappings_af_0.1.yml +0 -9
  18. data/spec/fixtures/rails_root/config/solr_mappings_bl_2.4.yml +0 -17
  19. data/spec/integration/associations/rdf_spec.rb +0 -61
  20. data/spec/integration/associations_spec.rb +0 -680
  21. data/spec/integration/attached_files_spec.rb +0 -146
  22. data/spec/integration/attributes_spec.rb +0 -73
  23. data/spec/integration/autosave_association_spec.rb +0 -24
  24. data/spec/integration/base_spec.rb +0 -184
  25. data/spec/integration/basic_contains_association_spec.rb +0 -121
  26. data/spec/integration/belongs_to_association_spec.rb +0 -260
  27. data/spec/integration/caching_spec.rb +0 -59
  28. data/spec/integration/clean_connection_spec.rb +0 -21
  29. data/spec/integration/collection_association_spec.rb +0 -166
  30. data/spec/integration/date_time_properties_spec.rb +0 -41
  31. data/spec/integration/delete_all_spec.rb +0 -64
  32. data/spec/integration/direct_container_spec.rb +0 -250
  33. data/spec/integration/directly_contains_one_association_spec.rb +0 -96
  34. data/spec/integration/eradicate_spec.rb +0 -52
  35. data/spec/integration/fedora_solr_sync_spec.rb +0 -30
  36. data/spec/integration/file_fixity_spec.rb +0 -36
  37. data/spec/integration/file_spec.rb +0 -221
  38. data/spec/integration/generators/fedora_generator_spec.rb +0 -26
  39. data/spec/integration/generators/solr_generator_spec.rb +0 -23
  40. data/spec/integration/gone_spec.rb +0 -41
  41. data/spec/integration/has_and_belongs_to_many_associations_spec.rb +0 -414
  42. data/spec/integration/has_many_associations_spec.rb +0 -436
  43. data/spec/integration/has_subresource_spec.rb +0 -34
  44. data/spec/integration/indexing/descendant_fetcher_spec.rb +0 -64
  45. data/spec/integration/indexing_spec.rb +0 -110
  46. data/spec/integration/indirect_container_spec.rb +0 -290
  47. data/spec/integration/json_serialization_spec.rb +0 -32
  48. data/spec/integration/marshal_spec.rb +0 -39
  49. data/spec/integration/nested_attribute_spec.rb +0 -177
  50. data/spec/integration/nested_hash_resources_spec.rb +0 -43
  51. data/spec/integration/persistence_spec.rb +0 -37
  52. data/spec/integration/query_result_builder_spec.rb +0 -37
  53. data/spec/integration/rdf_nested_attributes_spec.rb +0 -85
  54. data/spec/integration/relation_delegation_spec.rb +0 -52
  55. data/spec/integration/relation_spec.rb +0 -117
  56. data/spec/integration/scoped_query_spec.rb +0 -134
  57. data/spec/integration/scoping_spec.rb +0 -48
  58. data/spec/integration/solr_hit_spec.rb +0 -32
  59. data/spec/integration/versionable_spec.rb +0 -256
  60. data/spec/integration/with_metadata_spec.rb +0 -111
  61. data/spec/lib/active_fedora/null_logger_spec.rb +0 -10
  62. data/spec/rcov.opts +0 -2
  63. data/spec/spec.opts +0 -5
  64. data/spec/spec_helper.rb +0 -106
  65. data/spec/support/an_active_model.rb +0 -29
  66. data/spec/unit/active_fedora/indexing/inserter_spec.rb +0 -35
  67. data/spec/unit/active_fedora_spec.rb +0 -118
  68. data/spec/unit/aggregation/list_source_spec.rb +0 -134
  69. data/spec/unit/aggregation/ordered_reader_spec.rb +0 -43
  70. data/spec/unit/association_hash_spec.rb +0 -64
  71. data/spec/unit/attached_files_spec.rb +0 -218
  72. data/spec/unit/attributes_spec.rb +0 -146
  73. data/spec/unit/base_active_model_spec.rb +0 -28
  74. data/spec/unit/base_cma_spec.rb +0 -15
  75. data/spec/unit/base_extra_spec.rb +0 -33
  76. data/spec/unit/base_spec.rb +0 -328
  77. data/spec/unit/builder/has_and_belongs_to_many_spec.rb +0 -8
  78. data/spec/unit/callback_spec.rb +0 -65
  79. data/spec/unit/change_set_spec.rb +0 -60
  80. data/spec/unit/checksum_spec.rb +0 -25
  81. data/spec/unit/code_configurator_spec.rb +0 -41
  82. data/spec/unit/collection_proxy_spec.rb +0 -25
  83. data/spec/unit/config_spec.rb +0 -18
  84. data/spec/unit/core/fedora_id_translator_spec.rb +0 -29
  85. data/spec/unit/core/fedora_uri_translator_spec.rb +0 -19
  86. data/spec/unit/core/logger_spec.rb +0 -18
  87. data/spec/unit/core_spec.rb +0 -242
  88. data/spec/unit/default_model_mapper_spec.rb +0 -39
  89. data/spec/unit/fedora_spec.rb +0 -31
  90. data/spec/unit/file/streaming_spec.rb +0 -33
  91. data/spec/unit/file_configurator_spec.rb +0 -295
  92. data/spec/unit/file_io_spec.rb +0 -137
  93. data/spec/unit/file_path_builder_spec.rb +0 -18
  94. data/spec/unit/file_spec.rb +0 -489
  95. data/spec/unit/files_hash_spec.rb +0 -52
  96. data/spec/unit/filter_spec.rb +0 -133
  97. data/spec/unit/finder_methods_spec.rb +0 -154
  98. data/spec/unit/fixity_service_spec.rb +0 -128
  99. data/spec/unit/forbidden_attributes_protection_spec.rb +0 -50
  100. data/spec/unit/has_and_belongs_to_many_association_spec.rb +0 -125
  101. data/spec/unit/has_many_association_spec.rb +0 -131
  102. data/spec/unit/indexers/global_indexer_spec.rb +0 -41
  103. data/spec/unit/indexing/map/index_object_spec.rb +0 -25
  104. data/spec/unit/indexing/map_spec.rb +0 -27
  105. data/spec/unit/indexing_service_spec.rb +0 -28
  106. data/spec/unit/indexing_spec.rb +0 -86
  107. data/spec/unit/inheritance_spec.rb +0 -60
  108. data/spec/unit/ldp_resource_spec.rb +0 -15
  109. data/spec/unit/loadable_from_json_spec.rb +0 -40
  110. data/spec/unit/logger_spec.rb +0 -19
  111. data/spec/unit/model_classifier_spec.rb +0 -49
  112. data/spec/unit/ordered_spec.rb +0 -367
  113. data/spec/unit/orders/list_node_spec.rb +0 -151
  114. data/spec/unit/orders/ordered_list_spec.rb +0 -335
  115. data/spec/unit/orders/reflection_spec.rb +0 -22
  116. data/spec/unit/pathing_spec.rb +0 -35
  117. data/spec/unit/persistence_spec.rb +0 -115
  118. data/spec/unit/property_predicate_spec.rb +0 -35
  119. data/spec/unit/property_spec.rb +0 -25
  120. data/spec/unit/query_result_builder_spec.rb +0 -31
  121. data/spec/unit/query_spec.rb +0 -307
  122. data/spec/unit/querying_spec.rb +0 -24
  123. data/spec/unit/rdf/indexing_service_spec.rb +0 -114
  124. data/spec/unit/rdf_vocab_spec.rb +0 -30
  125. data/spec/unit/readonly_spec.rb +0 -24
  126. data/spec/unit/reflection_spec.rb +0 -42
  127. data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +0 -37
  128. data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +0 -38
  129. data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +0 -38
  130. data/spec/unit/schema_indexing_strategy_spec.rb +0 -68
  131. data/spec/unit/scoping_spec.rb +0 -67
  132. data/spec/unit/serializers_spec.rb +0 -19
  133. data/spec/unit/solr_config_options_spec.rb +0 -57
  134. data/spec/unit/solr_hit_spec.rb +0 -57
  135. data/spec/unit/solr_query_builder_spec.rb +0 -18
  136. data/spec/unit/solr_service_spec.rb +0 -165
  137. data/spec/unit/sparql_insert_spec.rb +0 -31
  138. data/spec/unit/validations_spec.rb +0 -92
  139. data/spec/unit/with_metadata/default_metadata_class_factory_spec.rb +0 -29
  140. data/spec/unit/with_metadata/metadata_node_spec.rb +0 -69
@@ -1,260 +0,0 @@
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, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.hasConstituent
11
- end
12
- class SpecialInheritedBook < Book
13
- def assert_content_model
14
- self.has_model = [self.class.to_s, self.class.superclass.to_s]
15
- end
16
- end
17
- end
18
- after do
19
- Object.send(:remove_const, :Library)
20
- Object.send(:remove_const, :SpecialInheritedBook)
21
- Object.send(:remove_const, :Book)
22
- end
23
-
24
- let(:library) { Library.create }
25
- let(:book) { Book.new }
26
-
27
- describe "setting the id property" do
28
- it "stores it" do
29
- book.library_id = library.id
30
- expect(book.library_id).to eq library.id
31
- end
32
-
33
- it "marks it as changed" do
34
- expect {
35
- book.library_id = library.id
36
- }.to change { book.changed? }.from(false).to(true)
37
- end
38
-
39
- describe "reassigning the parent_id" do
40
- let(:library2) { Library.create }
41
- before { book.library = library2 }
42
-
43
- it "updates the object" do
44
- expect(book.library).to eq library2 # cause the association to set @loaded
45
- library_proxy = book.send(:association_instance_get, :library)
46
- expect(library_proxy).to_not be_stale_target
47
- book.library_id = library.id
48
- expect(library_proxy).to be_stale_target
49
- expect(book.library).to eq library
50
- end
51
- end
52
-
53
- it "is settable via []=" do
54
- book[:library_id] = library.id
55
- expect(book.library_id).to eq library.id
56
- end
57
- end
58
-
59
- describe "getting the id property" do
60
- it "is accessable via []" do
61
- book[:library_id] = library.id
62
- expect(book[:library_id]).to eq library.id
63
- end
64
- end
65
-
66
- describe "when dealing with inherited objects" do
67
- before do
68
- @library2 = Library.create
69
- @special_book = SpecialInheritedBook.create
70
-
71
- book.library = @library2
72
- book.save
73
- @special_book.library = @library2
74
- @special_book.save
75
- end
76
-
77
- it "casts to the most specific class for the association" do
78
- expect(@library2.books[0]).to be_instance_of Book
79
- expect(@library2.books[1]).to be_instance_of SpecialInheritedBook
80
- end
81
-
82
- after do
83
- @library2.delete
84
- @special_book.delete
85
- end
86
- end
87
-
88
- describe "casting inheritance detailed test cases" do
89
- before :all do
90
- class SimpleObject < ActiveFedora::Base
91
- belongs_to :simple_collection, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, class_name: 'SimpleCollection'
92
- belongs_to :complex_collection, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, class_name: 'ComplexCollection'
93
- end
94
-
95
- # NOTE: As RDF assertions seem to be returned in alphabetical order, the "Z" is to insure this is stored
96
- # after the SimpleObject relationship for this particular case. This is to ensure people don't just change ActiveFedora
97
- # to pick the first content model and it works by alphabetical chance.
98
- class ZComplexObject < SimpleObject
99
- belongs_to :simple_collection, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, class_name: 'SimpleCollection'
100
- belongs_to :complex_collection, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, class_name: 'ComplexCollection'
101
-
102
- def assert_content_model
103
- self.has_model = [self.class.to_s, self.class.superclass.to_s]
104
- end
105
- end
106
-
107
- class SimpleCollection < ActiveFedora::Base
108
- has_many :objects, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, class_name: 'SimpleObject'
109
- has_many :complex_objects, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, class_name: 'ZComplexObject'
110
- end
111
-
112
- class ComplexCollection < SimpleCollection
113
- has_many :objects, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, class_name: 'SimpleObject'
114
- has_many :complex_objects, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, class_name: 'ZComplexObject'
115
-
116
- def assert_content_model
117
- self.has_model = [self.class.to_s, self.class.superclass.to_s]
118
- end
119
- end
120
- end
121
- after :all do
122
- Object.send(:remove_const, :SimpleObject)
123
- Object.send(:remove_const, :ZComplexObject)
124
- Object.send(:remove_const, :SimpleCollection)
125
- Object.send(:remove_const, :ComplexCollection)
126
- end
127
-
128
- describe "saving between the before and after hooks" do
129
- let(:complex_object) { ZComplexObject.find(ZComplexObject.create.id) }
130
- let(:complex_collection) { ComplexCollection.find(ComplexCollection.create.id) }
131
-
132
- context "Verify that an inherited object will save and retrieve with the correct models" do
133
- it "has added the inverse relationship for the correct class" do
134
- expect(complex_object.has_model).to match_array(["SimpleObject", "ZComplexObject"])
135
- expect(complex_collection.has_model).to match_array(["SimpleCollection", "ComplexCollection"])
136
- end
137
- end
138
-
139
- context "Add a complex_object into a simple_collection" do
140
- let(:simple_collection) { SimpleCollection.create }
141
-
142
- before do
143
- simple_collection.objects = [complex_object]
144
- simple_collection.save!
145
- complex_collection.save!
146
- end
147
- it "has added the inverse relationship for the correct class" do
148
- expect(complex_object.simple_collection).to be_instance_of SimpleCollection
149
- expect(complex_object.complex_collection).to be_nil
150
- end
151
- end
152
-
153
- context "Add a complex_object into a complex_collection" do
154
- before do
155
- complex_collection.objects = [complex_object] # this sticks it into the :objects association, but since it is a ZComplexObject it should also be fetched by :complex_collection association
156
- complex_collection.save
157
- end
158
-
159
- it "has added the inverse relationship for the correct class" do
160
- expect(complex_object.complex_collection).to be_instance_of ComplexCollection
161
- expect(complex_object.reload.simple_collection).to be_instance_of ComplexCollection
162
- end
163
- end
164
-
165
- context "Adding mixed types on a base class with a filtered has_many relationship" do
166
- let(:simple_collection) { SimpleCollection.create }
167
- let(:simple_object) { SimpleObject.create }
168
-
169
- before do
170
- simple_collection.objects = [complex_object, simple_object]
171
- simple_collection.save!
172
- end
173
- it "ignores objects whose classes aren't specified" do
174
- expect(simple_collection.complex_objects.size).to eq 1
175
- expect(simple_collection.complex_objects[0]).to be_instance_of ZComplexObject
176
- expect(simple_collection.complex_objects[1]).to be_nil
177
-
178
- expect(simple_collection.objects.size).to eq 2
179
- expect(simple_collection.objects[0]).to be_instance_of ZComplexObject
180
- expect(simple_collection.objects[1]).to be_instance_of SimpleObject
181
-
182
- expect(simple_object.simple_collection).to be_instance_of SimpleCollection
183
- expect(simple_object.complex_collection).to be_nil
184
- end
185
- end
186
-
187
- context "Adding mixed types on a subclass with a filtered has_many relationship" do
188
- let(:simple_object) { SimpleObject.create }
189
-
190
- before do
191
- complex_collection.objects = [complex_object, simple_object]
192
- complex_collection.save!
193
- end
194
- it "ignores objects who's classes aren't specified" do
195
- expect(complex_collection.complex_objects.size).to eq 1
196
- expect(complex_collection.complex_objects[0]).to be_instance_of ZComplexObject
197
- expect(complex_collection.complex_objects[1]).to be_nil
198
-
199
- expect(complex_collection.objects.size).to eq 2
200
- expect(complex_collection.objects[0]).to be_instance_of ZComplexObject
201
- expect(complex_collection.objects[1]).to be_instance_of SimpleObject
202
-
203
- expect(simple_object.complex_collection).to be_instance_of ComplexCollection
204
- expect(simple_object.reload.simple_collection).to be_instance_of ComplexCollection
205
- end
206
- end
207
- end
208
- end
209
-
210
- describe "casting inheritance super class test cases" do
211
- before :all do
212
- class SuperclassObject < ActiveFedora::Base
213
- belongs_to :superclass_collection, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, class_name: 'SuperclassCollection'
214
-
215
- def assert_content_model
216
- self.has_model = [self.class.to_s, self.class.superclass.to_s]
217
- end
218
- end
219
-
220
- class SubclassObject < SuperclassObject
221
- end
222
-
223
- class SuperclassCollection < ActiveFedora::Base
224
- has_many :objects, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, class_name: 'SuperclassObject'
225
- end
226
- end
227
- after :all do
228
- Object.send(:remove_const, :SuperclassObject)
229
- Object.send(:remove_const, :SubclassObject)
230
- Object.send(:remove_const, :SuperclassCollection)
231
- end
232
-
233
- describe "Adding subclass objects" do
234
- let(:superclass_collection) { SuperclassCollection.create }
235
- let(:superclass_object) { SubclassObject.create }
236
-
237
- context "Add a subclass_object into a superclass_collection" do
238
- before do
239
- superclass_collection.objects = [subclass_object]
240
- superclass_collection.save!
241
- end
242
- it "has added the inverse relationship for the correct class" do
243
- expect(subclass_object.superclass_collection).to be_instance_of SuperclassCollection
244
- end
245
- end
246
-
247
- context "Set the superclass_collection of a subclass object"
248
- let(:subclass_object) { SubclassObject.create }
249
-
250
- before do
251
- subclass_object.superclass_collection = superclass_collection
252
- subclass_object.save!
253
- end
254
- it "has added the inverse relationship for the correct class" do
255
- expect(superclass_collection.objects.size).to eq 1
256
- expect(superclass_collection.objects[0]).to be_instance_of SubclassObject
257
- end
258
- end
259
- end
260
- end
@@ -1,59 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Caching" do
4
- before do
5
- class TestClass < ActiveFedora::Base
6
- property :title, predicate: ::RDF::Vocab::DC.title
7
- end
8
- end
9
-
10
- after { Object.send(:remove_const, :TestClass) }
11
-
12
- let!(:object) { TestClass.create(id: '123') }
13
-
14
- describe "#cache" do
15
- it "finds records in the cache" do
16
- expect_any_instance_of(Faraday::Connection).to receive(:get).once.and_call_original
17
- ActiveFedora::Base.cache do
18
- o1 = TestClass.find(object.id)
19
- o2 = TestClass.find(object.id)
20
- expect(o1.ldp_source.get.body.object_id).to eq o2.ldp_source.get.body.object_id
21
- end
22
- end
23
-
24
- it "clears the cache at the end of the block" do
25
- expect_any_instance_of(Faraday::Connection).to receive(:get).twice.and_call_original
26
- ActiveFedora::Base.cache do
27
- TestClass.find(object.id)
28
- end
29
- ActiveFedora::Base.cache do
30
- TestClass.find(object.id)
31
- end
32
- end
33
-
34
- context "an update" do
35
- it "flushes the cache" do
36
- expect_any_instance_of(Faraday::Connection).to receive(:get).twice.and_call_original
37
- ActiveFedora::Base.cache do
38
- TestClass.find(object.id)
39
- object.title = ['foo']
40
- object.save!
41
- TestClass.find(object.id)
42
- end
43
- end
44
- end
45
- end
46
-
47
- describe "#uncached" do
48
- it "does not use the cache" do
49
- expect_any_instance_of(Faraday::Connection).to receive(:get).twice.and_call_original
50
- ActiveFedora::Base.cache do
51
- TestClass.find(object.id)
52
- ActiveFedora::Base.uncached do
53
- TestClass.find(object.id)
54
- end
55
- TestClass.find(object.id)
56
- end
57
- end
58
- end
59
- end
@@ -1,21 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe ActiveFedora::CleanConnection do
4
- subject { ActiveFedora.fedora.clean_connection }
5
- describe "#get" do
6
- context "when given an existing resource uri" do
7
- let(:uri) { asset.rdf_subject }
8
- let(:asset) do
9
- ActiveFedora::Base.create do |a|
10
- a.resource << [a.rdf_subject, RDF::Vocab::DC.title, "test"]
11
- end
12
- end
13
- let(:result) { subject.get(uri) }
14
- it "returns a clean graph" do
15
- graph = result.graph
16
- expect(graph.statements.to_a.length).to eq 1
17
- expect(graph.statements.to_a.first).to contain_exactly asset.rdf_subject, RDF::Vocab::DC.title, RDF::Literal.new("test")
18
- end
19
- end
20
- end
21
- end
@@ -1,166 +0,0 @@
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, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.hasMember
10
- end
11
- end
12
-
13
- let(:library) { Library.create! }
14
-
15
- after do
16
- Object.send(:remove_const, :Library)
17
- Object.send(:remove_const, :Book)
18
- end
19
-
20
- describe "load_from_solr" do
21
- let!(:book1) { Book.create!(library: library) }
22
- let!(:book2) { Book.create!(library: library) }
23
-
24
- it "sets rows to count, if not specified" do
25
- expect(library.books(response_format: :solr).size).to eq 2
26
- end
27
-
28
- it "limits rows returned if option passed" do
29
- expect(library.books(response_format: :solr, rows: 1).size).to eq 1
30
- end
31
-
32
- it "does not query solr if rows is 0" do
33
- expect(ActiveFedora::SolrService).not_to receive(:query)
34
- expect(library.books(response_format: :solr, rows: 0)).to eq []
35
- end
36
- end
37
-
38
- describe "#delete_all" do
39
- let!(:book1) { Book.create!(library: library) }
40
- let!(:book2) { Book.create!(library: library) }
41
- it "deletes em" do
42
- expect {
43
- library.books.delete_all
44
- }.to change { library.books.count }.by(-2)
45
- end
46
- end
47
-
48
- describe "#delete" do
49
- context "when given items not in collection" do
50
- it "returns an empty set" do
51
- expect(library.books.delete(Book.new)).to eq []
52
- end
53
- it "does not act on it" do
54
- b = Book.new
55
- allow(b).to receive(:persisted?).and_return(true)
56
-
57
- library.books.delete(b)
58
-
59
- expect(b).not_to have_received(:persisted?)
60
- end
61
- end
62
- end
63
-
64
- describe "#destroy_all" do
65
- let!(:book1) { Book.create!(library: library) }
66
- let!(:book2) { Book.create!(library: library) }
67
- it "deletes em" do
68
- expect {
69
- library.books.destroy_all
70
- }.to change { library.books.count }.by(-2)
71
- end
72
- end
73
-
74
- describe "#find" do
75
- let!(:book1) { Book.create!(library: library) }
76
- let!(:book2) { Book.create!(library: library) }
77
- it "finds the record that matches" do
78
- expected = library.books.find(book1.id)
79
- expect(expected).to eq book1
80
- end
81
- describe "with some records that aren't part of the collection" do
82
- let!(:book3) { Book.create }
83
- it "finds no records" do
84
- expect(library.books.find(book3.id)).to be_nil
85
- end
86
- end
87
- end
88
-
89
- describe "#select" do
90
- let!(:book1) { Book.create!(library: library) }
91
- let!(:book2) { Book.create!(library: library) }
92
-
93
- # TODO: Bug described in issue #609
94
- xit "chooses a subset of objects in the relationship" do
95
- expect(library.books.select([:id])).to include(book1.id)
96
- end
97
- it "works as a block" do
98
- expect(library.books.select { |x| x.id == book1.id }).to eq [book1]
99
- end
100
- end
101
-
102
- describe "#size" do
103
- context "with associations in memory" do
104
- context "and the association is already loaded" do
105
- before do
106
- library.books.to_a # force the association to be loaded
107
- library.books.build
108
- end
109
- subject { library.books.size }
110
- it { is_expected.to eq 1 }
111
- end
112
-
113
- context "and the association is not loaded" do
114
- before do
115
- library.books.build
116
- end
117
- subject { library.books.size }
118
- it { is_expected.to eq 1 }
119
- end
120
- end
121
- end
122
-
123
- describe "finding the inverse" do
124
- context "when no inverse exists" do
125
- before do
126
- class Item < ActiveFedora::Base
127
- end
128
- class SpecContainer < ActiveFedora::Base
129
- has_many :items
130
- end
131
- end
132
- after do
133
- Object.send(:remove_const, :Item)
134
- Object.send(:remove_const, :SpecContainer)
135
- end
136
-
137
- let(:instance) { SpecContainer.new }
138
-
139
- it "raises an error" do
140
- expect { instance.items }.to raise_error "No :inverse_of or :predicate attribute was set or could be inferred for has_many :items on SpecContainer"
141
- end
142
- end
143
-
144
- context "when classes are namespaced" do
145
- before do
146
- class Item < ActiveFedora::Base
147
- has_and_belongs_to_many :container, predicate: ::RDF::Vocab::DC.extent, class_name: 'Foo::Container'
148
- end
149
- module Foo
150
- class Container < ActiveFedora::Base
151
- has_many :items
152
- end
153
- end
154
- end
155
- after do
156
- Object.send(:remove_const, :Item)
157
- Object.send(:remove_const, :Foo)
158
- end
159
-
160
- subject { instance.items }
161
- let(:instance) { Foo::Container.new }
162
-
163
- it { is_expected.to eq [] }
164
- end
165
- end
166
- end