active-fedora 13.1.2 → 13.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github_changelog_generator +2 -0
- data/CHANGELOG.md +3362 -0
- data/CONTRIBUTING.md +23 -1
- data/README.md +4 -0
- data/active-fedora.gemspec +14 -13
- data/lib/active_fedora/version.rb +1 -1
- metadata +104 -206
- data/spec/config_helper.rb +0 -17
- data/spec/fixtures/dino.jpg +0 -0
- data/spec/fixtures/dino_jpg_no_file_ext +0 -0
- data/spec/fixtures/minivan.jpg +0 -0
- data/spec/fixtures/rails_root/config/fake_fedora.yml +0 -7
- data/spec/fixtures/rails_root/config/fedora.yml +0 -12
- data/spec/fixtures/rails_root/config/solr.yml +0 -15
- data/spec/fixtures/rails_root/config/solr_mappings.yml +0 -16
- data/spec/fixtures/rails_root/config/solr_mappings_af_0.1.yml +0 -9
- data/spec/fixtures/rails_root/config/solr_mappings_bl_2.4.yml +0 -17
- data/spec/integration/associations/rdf_spec.rb +0 -61
- data/spec/integration/associations_spec.rb +0 -680
- data/spec/integration/attached_files_spec.rb +0 -146
- data/spec/integration/attributes_spec.rb +0 -73
- data/spec/integration/autosave_association_spec.rb +0 -24
- data/spec/integration/base_spec.rb +0 -184
- data/spec/integration/basic_contains_association_spec.rb +0 -121
- data/spec/integration/belongs_to_association_spec.rb +0 -260
- data/spec/integration/caching_spec.rb +0 -59
- data/spec/integration/clean_connection_spec.rb +0 -21
- data/spec/integration/collection_association_spec.rb +0 -166
- data/spec/integration/date_time_properties_spec.rb +0 -41
- data/spec/integration/delete_all_spec.rb +0 -64
- data/spec/integration/direct_container_spec.rb +0 -250
- data/spec/integration/directly_contains_one_association_spec.rb +0 -96
- data/spec/integration/eradicate_spec.rb +0 -52
- data/spec/integration/fedora_solr_sync_spec.rb +0 -30
- data/spec/integration/file_fixity_spec.rb +0 -36
- data/spec/integration/file_spec.rb +0 -221
- data/spec/integration/generators/fedora_generator_spec.rb +0 -26
- data/spec/integration/generators/solr_generator_spec.rb +0 -23
- data/spec/integration/gone_spec.rb +0 -41
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +0 -414
- data/spec/integration/has_many_associations_spec.rb +0 -436
- data/spec/integration/has_subresource_spec.rb +0 -34
- data/spec/integration/indexing/descendant_fetcher_spec.rb +0 -64
- data/spec/integration/indexing_spec.rb +0 -110
- data/spec/integration/indirect_container_spec.rb +0 -290
- data/spec/integration/json_serialization_spec.rb +0 -32
- data/spec/integration/marshal_spec.rb +0 -39
- data/spec/integration/nested_attribute_spec.rb +0 -177
- data/spec/integration/nested_hash_resources_spec.rb +0 -43
- data/spec/integration/persistence_spec.rb +0 -37
- data/spec/integration/query_result_builder_spec.rb +0 -37
- data/spec/integration/rdf_nested_attributes_spec.rb +0 -85
- data/spec/integration/relation_delegation_spec.rb +0 -52
- data/spec/integration/relation_spec.rb +0 -117
- data/spec/integration/scoped_query_spec.rb +0 -134
- data/spec/integration/scoping_spec.rb +0 -48
- data/spec/integration/solr_hit_spec.rb +0 -32
- data/spec/integration/versionable_spec.rb +0 -256
- data/spec/integration/with_metadata_spec.rb +0 -111
- data/spec/lib/active_fedora/null_logger_spec.rb +0 -10
- data/spec/rcov.opts +0 -2
- data/spec/spec.opts +0 -5
- data/spec/spec_helper.rb +0 -106
- data/spec/support/an_active_model.rb +0 -29
- data/spec/unit/active_fedora/indexing/inserter_spec.rb +0 -35
- data/spec/unit/active_fedora_spec.rb +0 -118
- data/spec/unit/aggregation/list_source_spec.rb +0 -134
- data/spec/unit/aggregation/ordered_reader_spec.rb +0 -43
- data/spec/unit/association_hash_spec.rb +0 -64
- data/spec/unit/attached_files_spec.rb +0 -218
- data/spec/unit/attributes_spec.rb +0 -146
- data/spec/unit/base_active_model_spec.rb +0 -28
- data/spec/unit/base_cma_spec.rb +0 -15
- data/spec/unit/base_extra_spec.rb +0 -33
- data/spec/unit/base_spec.rb +0 -328
- data/spec/unit/builder/has_and_belongs_to_many_spec.rb +0 -8
- data/spec/unit/callback_spec.rb +0 -65
- data/spec/unit/change_set_spec.rb +0 -60
- data/spec/unit/checksum_spec.rb +0 -25
- data/spec/unit/code_configurator_spec.rb +0 -41
- data/spec/unit/collection_proxy_spec.rb +0 -25
- data/spec/unit/config_spec.rb +0 -18
- data/spec/unit/core/fedora_id_translator_spec.rb +0 -29
- data/spec/unit/core/fedora_uri_translator_spec.rb +0 -19
- data/spec/unit/core/logger_spec.rb +0 -18
- data/spec/unit/core_spec.rb +0 -242
- data/spec/unit/default_model_mapper_spec.rb +0 -39
- data/spec/unit/fedora_spec.rb +0 -31
- data/spec/unit/file/streaming_spec.rb +0 -33
- data/spec/unit/file_configurator_spec.rb +0 -295
- data/spec/unit/file_io_spec.rb +0 -137
- data/spec/unit/file_path_builder_spec.rb +0 -18
- data/spec/unit/file_spec.rb +0 -489
- data/spec/unit/files_hash_spec.rb +0 -52
- data/spec/unit/filter_spec.rb +0 -133
- data/spec/unit/finder_methods_spec.rb +0 -154
- data/spec/unit/fixity_service_spec.rb +0 -128
- data/spec/unit/forbidden_attributes_protection_spec.rb +0 -50
- data/spec/unit/has_and_belongs_to_many_association_spec.rb +0 -125
- data/spec/unit/has_many_association_spec.rb +0 -131
- data/spec/unit/indexers/global_indexer_spec.rb +0 -41
- data/spec/unit/indexing/map/index_object_spec.rb +0 -25
- data/spec/unit/indexing/map_spec.rb +0 -27
- data/spec/unit/indexing_service_spec.rb +0 -28
- data/spec/unit/indexing_spec.rb +0 -86
- data/spec/unit/inheritance_spec.rb +0 -60
- data/spec/unit/ldp_resource_spec.rb +0 -15
- data/spec/unit/loadable_from_json_spec.rb +0 -40
- data/spec/unit/logger_spec.rb +0 -19
- data/spec/unit/model_classifier_spec.rb +0 -49
- data/spec/unit/ordered_spec.rb +0 -367
- data/spec/unit/orders/list_node_spec.rb +0 -151
- data/spec/unit/orders/ordered_list_spec.rb +0 -335
- data/spec/unit/orders/reflection_spec.rb +0 -22
- data/spec/unit/pathing_spec.rb +0 -35
- data/spec/unit/persistence_spec.rb +0 -115
- data/spec/unit/property_predicate_spec.rb +0 -35
- data/spec/unit/property_spec.rb +0 -25
- data/spec/unit/query_result_builder_spec.rb +0 -31
- data/spec/unit/query_spec.rb +0 -307
- data/spec/unit/querying_spec.rb +0 -24
- data/spec/unit/rdf/indexing_service_spec.rb +0 -114
- data/spec/unit/rdf_vocab_spec.rb +0 -30
- data/spec/unit/readonly_spec.rb +0 -24
- data/spec/unit/reflection_spec.rb +0 -42
- data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +0 -37
- data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +0 -38
- data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +0 -38
- data/spec/unit/schema_indexing_strategy_spec.rb +0 -68
- data/spec/unit/scoping_spec.rb +0 -67
- data/spec/unit/serializers_spec.rb +0 -19
- data/spec/unit/solr_config_options_spec.rb +0 -57
- data/spec/unit/solr_hit_spec.rb +0 -57
- data/spec/unit/solr_query_builder_spec.rb +0 -18
- data/spec/unit/solr_service_spec.rb +0 -165
- data/spec/unit/sparql_insert_spec.rb +0 -31
- data/spec/unit/validations_spec.rb +0 -92
- data/spec/unit/with_metadata/default_metadata_class_factory_spec.rb +0 -29
- data/spec/unit/with_metadata/metadata_node_spec.rb +0 -69
|
@@ -1,436 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe ActiveFedora::Associations::HasManyAssociation do
|
|
4
|
-
describe "Collection members" do
|
|
5
|
-
before :all do
|
|
6
|
-
class Library < ActiveFedora::Base
|
|
7
|
-
has_many :books
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
class Book < ActiveFedora::Base
|
|
11
|
-
belongs_to :library, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.hasConstituent
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
after :all do
|
|
15
|
-
Object.send(:remove_const, :Book)
|
|
16
|
-
Object.send(:remove_const, :Library)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
describe "size of has_many" do
|
|
20
|
-
let(:library) { Library.create }
|
|
21
|
-
context "when no members" do
|
|
22
|
-
it "caches the count" do
|
|
23
|
-
expect(library.books).not_to be_loaded
|
|
24
|
-
expect(library.books.size).to eq(0)
|
|
25
|
-
expect(library.books).to be_loaded
|
|
26
|
-
expect(library.books.any?).to be false
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
context "when the owner is not saved, and potential targets (Books) exist" do
|
|
31
|
-
subject { library.books.count }
|
|
32
|
-
let!(:book) { Book.create }
|
|
33
|
-
let(:library) { Library.new }
|
|
34
|
-
# it excludes the books that aren't associated
|
|
35
|
-
it { is_expected.to eq 0 }
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
context "when the owner is saved with associations" do
|
|
39
|
-
subject { library.reload; library.books.count }
|
|
40
|
-
let(:book) { Book.create }
|
|
41
|
-
let!(:library) { Library.create(books: [book]) }
|
|
42
|
-
# it excludes the books that are associated
|
|
43
|
-
it { is_expected.to eq 1 }
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
context "when the owner is not saved after checking the count" do
|
|
47
|
-
let!(:book) { Book.create }
|
|
48
|
-
let(:library) { Library.new }
|
|
49
|
-
it "refreshes the cache" do
|
|
50
|
-
expect(library.books.count).to eq 0
|
|
51
|
-
library.books << book
|
|
52
|
-
library.save!
|
|
53
|
-
expect(library.books.count).to eq 1
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
context "loading the association prior to a save that affects the association" do
|
|
58
|
-
before do
|
|
59
|
-
Book.create
|
|
60
|
-
library.books
|
|
61
|
-
library.save
|
|
62
|
-
end
|
|
63
|
-
subject { library.books.size }
|
|
64
|
-
let(:library) { Library.new }
|
|
65
|
-
it { is_expected.to eq 0 }
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
describe "looking up has_many" do
|
|
70
|
-
let(:book) { Book.create }
|
|
71
|
-
let(:library) { Library.create }
|
|
72
|
-
before do
|
|
73
|
-
library.books = [book]
|
|
74
|
-
library.save!
|
|
75
|
-
library.reload
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
it "reads book_ids from solr" do
|
|
79
|
-
expect(library.book_ids).to eq [book.id]
|
|
80
|
-
end
|
|
81
|
-
it "reads books from solr" do
|
|
82
|
-
expect(library.books).to eq [book]
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "caches the results" do
|
|
86
|
-
expect(library.books).to_not be_loaded
|
|
87
|
-
expect(library.books).to eq [book]
|
|
88
|
-
expect(library.books).to be_loaded
|
|
89
|
-
end
|
|
90
|
-
it "loads from solr" do
|
|
91
|
-
expect(library.books.load_from_solr.map(&:id)).to eq([book.id])
|
|
92
|
-
end
|
|
93
|
-
it "loads from solr with options" do
|
|
94
|
-
expect(library.books.load_from_solr(rows: 0).size).to eq(0)
|
|
95
|
-
end
|
|
96
|
-
it "responds to #any?" do
|
|
97
|
-
expect(library.books.any?).to be true
|
|
98
|
-
expect(library.books.any? { |book| book.library.nil? }).to be false
|
|
99
|
-
expect(library.books.any? { |book| book.library == library }).to be true
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
describe "After save callbacks" do
|
|
105
|
-
before :all do
|
|
106
|
-
class Library < ActiveFedora::Base
|
|
107
|
-
has_many :books
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
class Book < ActiveFedora::Base
|
|
111
|
-
belongs_to :library, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.hasConstituent
|
|
112
|
-
after_save :find_self
|
|
113
|
-
attr_accessor :library_books
|
|
114
|
-
|
|
115
|
-
def find_self
|
|
116
|
-
# It's important we have the to_a so that it fetches the relationship immediately instead of lazy loading
|
|
117
|
-
self.library_books = library.books.to_a
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
after :all do
|
|
122
|
-
Object.send(:remove_const, :Book)
|
|
123
|
-
Object.send(:remove_const, :Library)
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
let(:library) { Library.create }
|
|
127
|
-
let(:book) { Book.new(library: library) }
|
|
128
|
-
|
|
129
|
-
it "has the relationship available in after_save" do
|
|
130
|
-
book.save!
|
|
131
|
-
expect(book.library_books).to include book
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
describe "When two or more relationships share the same property" do
|
|
136
|
-
before do
|
|
137
|
-
class Book < ActiveFedora::Base
|
|
138
|
-
has_many :collections, class_name: 'Collection'
|
|
139
|
-
has_many :people
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
class Person < ActiveFedora::Base
|
|
143
|
-
belongs_to :book, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
class Collection < ActiveFedora::Base
|
|
147
|
-
belongs_to :book, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
@book = Book.create!
|
|
151
|
-
@person1 = Person.create!(book: @book)
|
|
152
|
-
@person2 = Person.create!(book: @book)
|
|
153
|
-
end
|
|
154
|
-
after do
|
|
155
|
-
Object.send(:remove_const, :Collection)
|
|
156
|
-
Object.send(:remove_const, :Person)
|
|
157
|
-
Object.send(:remove_const, :Book)
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
it "only returns relationships of the correct class" do
|
|
161
|
-
@book.reload
|
|
162
|
-
expect(@book.people).to contain_exactly @person1, @person2
|
|
163
|
-
expect(@book.collections).to eq []
|
|
164
|
-
end
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
describe "with an polymorphic association" do
|
|
168
|
-
before do
|
|
169
|
-
class Permissionable1 < ActiveFedora::Base
|
|
170
|
-
has_many :permissions, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, inverse_of: :access_to
|
|
171
|
-
end
|
|
172
|
-
class Permissionable2 < ActiveFedora::Base
|
|
173
|
-
has_many :permissions, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, inverse_of: :access_to
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
class Permission < ActiveFedora::Base
|
|
177
|
-
belongs_to :access_to, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, class_name: 'ActiveFedora::Base'
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
after do
|
|
182
|
-
Permissionable1.destroy_all
|
|
183
|
-
Object.send(:remove_const, :Permissionable1)
|
|
184
|
-
Object.send(:remove_const, :Permissionable2)
|
|
185
|
-
Object.send(:remove_const, :Permission)
|
|
186
|
-
end
|
|
187
|
-
let(:p1) { Permissionable1.create }
|
|
188
|
-
|
|
189
|
-
it "makes an association" do
|
|
190
|
-
expect(p1.permissions.create).to be_kind_of Permission
|
|
191
|
-
end
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
describe "When relationship is restricted to AF::Base" do
|
|
195
|
-
before do
|
|
196
|
-
class Email < ActiveFedora::Base
|
|
197
|
-
has_many :attachments, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, class_name: 'ActiveFedora::Base'
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
class Image < ActiveFedora::Base
|
|
201
|
-
belongs_to :email, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
class PDF < ActiveFedora::Base
|
|
205
|
-
belongs_to :email, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf
|
|
206
|
-
end
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
after do
|
|
210
|
-
Object.send(:remove_const, :Image)
|
|
211
|
-
Object.send(:remove_const, :PDF)
|
|
212
|
-
Object.send(:remove_const, :Email)
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
describe "creating new objects with object relationships" do
|
|
216
|
-
before do
|
|
217
|
-
@book = Email.create!
|
|
218
|
-
@image = Image.create!(email: @book)
|
|
219
|
-
@pdf = PDF.create!(email: @book)
|
|
220
|
-
end
|
|
221
|
-
it "does not restrict relationships" do
|
|
222
|
-
@book.reload
|
|
223
|
-
expect(@book.attachments).to contain_exactly @image, @pdf
|
|
224
|
-
end
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
describe "creating new objects with id setter" do
|
|
228
|
-
let!(:image) { Image.create }
|
|
229
|
-
let!(:email) { Email.create }
|
|
230
|
-
let!(:pdf) { PDF.create }
|
|
231
|
-
|
|
232
|
-
after do
|
|
233
|
-
pdf.destroy
|
|
234
|
-
image.destroy
|
|
235
|
-
email.destroy
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
it "does not restrict relationships" do
|
|
239
|
-
email.attachment_ids = [image.id, pdf.id]
|
|
240
|
-
email.reload
|
|
241
|
-
expect(email.attachments).to contain_exactly image, pdf
|
|
242
|
-
end
|
|
243
|
-
end
|
|
244
|
-
end
|
|
245
|
-
|
|
246
|
-
describe "Deleting a dependent relationship" do
|
|
247
|
-
before do
|
|
248
|
-
class Item < ActiveFedora::Base
|
|
249
|
-
has_many :components
|
|
250
|
-
end
|
|
251
|
-
class Component < ActiveFedora::Base
|
|
252
|
-
belongs_to :item, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf
|
|
253
|
-
end
|
|
254
|
-
end
|
|
255
|
-
|
|
256
|
-
after do
|
|
257
|
-
Object.send(:remove_const, :Item)
|
|
258
|
-
Object.send(:remove_const, :Component)
|
|
259
|
-
end
|
|
260
|
-
|
|
261
|
-
let(:item) { Item.create }
|
|
262
|
-
let(:component) { Component.create }
|
|
263
|
-
|
|
264
|
-
context "when the relationship is set by an id" do
|
|
265
|
-
let(:item_id) { item.id }
|
|
266
|
-
let!(:component1) { Component.create(item_id: item_id) }
|
|
267
|
-
let!(:component2) { Component.create(item_id: item_id) }
|
|
268
|
-
|
|
269
|
-
it "sets the inverse relationship" do
|
|
270
|
-
expect(component1.item.components).to match_array [component1, component2]
|
|
271
|
-
end
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
it "removes relationships" do
|
|
275
|
-
component.item = item
|
|
276
|
-
component.save!
|
|
277
|
-
expect(item.components).to eq [component]
|
|
278
|
-
item.components.delete(component)
|
|
279
|
-
item.reload
|
|
280
|
-
component.reload
|
|
281
|
-
expect(component['item_id']).to be_nil
|
|
282
|
-
expect(item.components).to eq []
|
|
283
|
-
end
|
|
284
|
-
|
|
285
|
-
it "removes the relationships that point at that object" do
|
|
286
|
-
component.item = item
|
|
287
|
-
component.save!
|
|
288
|
-
item.delete
|
|
289
|
-
component.reload
|
|
290
|
-
expect(component['item_id']).to be_nil
|
|
291
|
-
end
|
|
292
|
-
|
|
293
|
-
it "only tries to delete objects that exist in the datastore (not cached objects)" do
|
|
294
|
-
item.components << component
|
|
295
|
-
item.save!
|
|
296
|
-
component.delete
|
|
297
|
-
item.delete
|
|
298
|
-
end
|
|
299
|
-
|
|
300
|
-
it "does not save deleted objects" do
|
|
301
|
-
item.components << component
|
|
302
|
-
item.save!
|
|
303
|
-
c2 = Component.find(component.id)
|
|
304
|
-
c2.delete
|
|
305
|
-
item.delete
|
|
306
|
-
end
|
|
307
|
-
end
|
|
308
|
-
|
|
309
|
-
describe "Autosave" do
|
|
310
|
-
context "with new objects" do
|
|
311
|
-
context "a has_many - belongs_to relationship" do
|
|
312
|
-
before do
|
|
313
|
-
class Item < ActiveFedora::Base
|
|
314
|
-
has_many :components
|
|
315
|
-
property :title, predicate: ::RDF::Vocab::DC.title
|
|
316
|
-
end
|
|
317
|
-
class Component < ActiveFedora::Base
|
|
318
|
-
belongs_to :item, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf
|
|
319
|
-
property :description, predicate: ::RDF::Vocab::DC.description
|
|
320
|
-
end
|
|
321
|
-
end
|
|
322
|
-
|
|
323
|
-
after do
|
|
324
|
-
Object.send(:remove_const, :Item)
|
|
325
|
-
Object.send(:remove_const, :Component)
|
|
326
|
-
end
|
|
327
|
-
|
|
328
|
-
context "From the belongs_to side" do
|
|
329
|
-
let(:component) { Component.create(item: Item.new(title: ['my title'])) }
|
|
330
|
-
|
|
331
|
-
it "saves dependent records" do
|
|
332
|
-
component.reload
|
|
333
|
-
expect(component.item.title).to eq ['my title']
|
|
334
|
-
end
|
|
335
|
-
end
|
|
336
|
-
|
|
337
|
-
context "From the has_many side" do
|
|
338
|
-
let(:item) { Item.create(components: [Component.new(description: ['my description'])]) }
|
|
339
|
-
|
|
340
|
-
it "saves dependent records" do
|
|
341
|
-
item.reload
|
|
342
|
-
expect(item.components.first.description).to eq ['my description']
|
|
343
|
-
end
|
|
344
|
-
end
|
|
345
|
-
end
|
|
346
|
-
|
|
347
|
-
context "a has_many - has_and_belongs_to_many relationship" do
|
|
348
|
-
context "with ActiveFedora::Base as classes" do
|
|
349
|
-
before do
|
|
350
|
-
class Novel < ActiveFedora::Base
|
|
351
|
-
has_many :books, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, class_name: 'ActiveFedora::Base'
|
|
352
|
-
has_and_belongs_to_many :contents, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, class_name: 'ActiveFedora::Base'
|
|
353
|
-
end
|
|
354
|
-
class Text < ActiveFedora::Base
|
|
355
|
-
has_many :books, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, class_name: 'ActiveFedora::Base'
|
|
356
|
-
end
|
|
357
|
-
end
|
|
358
|
-
let(:text) { Text.create }
|
|
359
|
-
let(:novel) { Novel.create }
|
|
360
|
-
|
|
361
|
-
after do
|
|
362
|
-
Object.send(:remove_const, :Novel)
|
|
363
|
-
Object.send(:remove_const, :Text)
|
|
364
|
-
end
|
|
365
|
-
|
|
366
|
-
it "works when added via the has_many" do
|
|
367
|
-
text.books << novel
|
|
368
|
-
novel.save
|
|
369
|
-
expect(novel.reload.contents).to eq [text]
|
|
370
|
-
expect(text.reload.books).to eq [novel]
|
|
371
|
-
end
|
|
372
|
-
|
|
373
|
-
it "works when added via the has_and_belongs_to_many" do
|
|
374
|
-
novel.contents << text
|
|
375
|
-
novel.save!
|
|
376
|
-
text.reload
|
|
377
|
-
expect(text.books).to eq [novel]
|
|
378
|
-
end
|
|
379
|
-
end
|
|
380
|
-
end
|
|
381
|
-
end
|
|
382
|
-
|
|
383
|
-
context "with updated objects" do
|
|
384
|
-
before :all do
|
|
385
|
-
class Library < ActiveFedora::Base
|
|
386
|
-
has_many :books, autosave: true
|
|
387
|
-
end
|
|
388
|
-
|
|
389
|
-
class Book < ActiveFedora::Base
|
|
390
|
-
belongs_to :library, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.hasConstituent
|
|
391
|
-
property :title, predicate: ::RDF::Vocab::DC.title
|
|
392
|
-
end
|
|
393
|
-
end
|
|
394
|
-
after :all do
|
|
395
|
-
Object.send(:remove_const, :Book)
|
|
396
|
-
Object.send(:remove_const, :Library)
|
|
397
|
-
end
|
|
398
|
-
|
|
399
|
-
before do
|
|
400
|
-
library.books.create(title: ["Great Book"])
|
|
401
|
-
library.books.first.title = ["Better book"]
|
|
402
|
-
library.save
|
|
403
|
-
end
|
|
404
|
-
|
|
405
|
-
subject(:books) { library.books(true) }
|
|
406
|
-
let(:library) { Library.create }
|
|
407
|
-
|
|
408
|
-
it "saves the new title" do
|
|
409
|
-
expect(books.first.title).to eq ["Better book"]
|
|
410
|
-
end
|
|
411
|
-
end
|
|
412
|
-
end
|
|
413
|
-
|
|
414
|
-
describe "when destroying the owner" do
|
|
415
|
-
before do
|
|
416
|
-
class Book < ActiveFedora::Base
|
|
417
|
-
has_many :permissions, dependent: :destroy
|
|
418
|
-
end
|
|
419
|
-
|
|
420
|
-
class Permission < ActiveFedora::Base
|
|
421
|
-
belongs_to :book, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.hasConstituent
|
|
422
|
-
end
|
|
423
|
-
end
|
|
424
|
-
let(:book) { Book.create! }
|
|
425
|
-
let!(:permissions) { Permission.create!(book: book) }
|
|
426
|
-
|
|
427
|
-
after do
|
|
428
|
-
Object.send(:remove_const, :Book)
|
|
429
|
-
Object.send(:remove_const, :Permission)
|
|
430
|
-
end
|
|
431
|
-
|
|
432
|
-
it "the object is destroyed" do
|
|
433
|
-
expect { book.destroy }.to change { Permission.count }.by(-1)
|
|
434
|
-
end
|
|
435
|
-
end
|
|
436
|
-
end
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe ActiveFedora::Base do
|
|
4
|
-
before do
|
|
5
|
-
class Source < ActiveFedora::Base
|
|
6
|
-
has_subresource :sub_resource, class_name: "Source"
|
|
7
|
-
property :title, predicate: ::RDF::Vocab::DC.title, multiple: false
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
after do
|
|
11
|
-
Object.send(:remove_const, :Source)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
describe "contains relationships" do
|
|
15
|
-
it "is able to have RDF sources" do
|
|
16
|
-
s = Source.new
|
|
17
|
-
s.sub_resource.title = "Test"
|
|
18
|
-
expect(s.sub_resource).not_to be_persisted
|
|
19
|
-
expect { s.save }.not_to raise_error
|
|
20
|
-
s.reload
|
|
21
|
-
expect(s.sub_resource.title).to eq "Test"
|
|
22
|
-
expect(s.sub_resource.uri).to eq s.uri.to_s + "/sub_resource"
|
|
23
|
-
end
|
|
24
|
-
it "is able to add RDF sources" do
|
|
25
|
-
s = Source.create
|
|
26
|
-
s.sub_resource.title = "Test"
|
|
27
|
-
expect(s.sub_resource).not_to be_persisted
|
|
28
|
-
expect { s.save }.not_to raise_error
|
|
29
|
-
s.reload
|
|
30
|
-
expect(s.sub_resource.title).to eq "Test"
|
|
31
|
-
expect(s.sub_resource.uri).to eq s.uri.to_s + "/sub_resource"
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|