amoeba 3.4.0 → 3.4.1

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.
@@ -1,598 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe 'amoeba' do
6
- context 'amoeba_dup' do
7
- before { require ::File.dirname(__FILE__) + '/../support/data.rb' }
8
-
9
- context 'with posts' do
10
- subject(:save_post) { new_post.save! }
11
-
12
- let(:old_post) { ::Post.find(1) }
13
- let(:new_post) { old_post.amoeba_dup }
14
-
15
- before do
16
- old_post.class.amoeba do
17
- prepend contents: "Here's a copy: "
18
- end
19
- end
20
-
21
- # Unecessary. Included in refactor for completeness.
22
- it { expect(old_post.comments.map(&:contents).include?('I love it!')).to be_truthy }
23
-
24
- it { is_expected.to be_truthy }
25
-
26
- it do
27
- save_post
28
- expect(new_post.title).to eq("Copy of #{old_post.title}")
29
- end
30
-
31
- it { expect { save_post }.not_to change(Tag.all, :count) }
32
- it { expect { save_post }.not_to change(Category, :count) }
33
-
34
- # The original versions of these tests counted checked that the counts of
35
- # various models were multipled when the new instance is saved. This
36
- # depends on there being no other data in the database, which is not
37
- # reliable. The new versions of these tests check for an increase in the
38
- # count by a certain amount. This depends on how the test data is created.
39
-
40
- # Testing a 'has_one' relation with default amoeba configuration.
41
- it { expect { save_post }.to change(Account, :count).by(1) }
42
-
43
- # Testing a 'has_one ... through' relation with default amoeba
44
- # configuration.
45
- it { expect { save_post }.to change(History.all, :count).by(1) }
46
-
47
- # Testing a 'has_many' relation with default amoeba configuration.
48
- it { expect { save_post }.to change(Supercat.all, :count).by(3) }
49
-
50
- # Testing that a new instance is created when a duplicate is saved.
51
- it { expect { save_post }.to change(Post.all, :count).by(1) }
52
-
53
- # Testing a 'has_one' relation with default amoeba configuration.
54
- it { expect { save_post }.to change(PostConfig.all, :count).by(1) }
55
-
56
- # The dup adds extra comments based on 'customize'. Three comments are
57
- # added and two new ones are created.
58
- it { expect { save_post }.to change(Comment.all, :count).by(5) }
59
-
60
- # Ratings are linked to comments. The dup will duplicate the ratings for
61
- # the existing comments (6 each for the test data) and the new comments
62
- # will have no ratings.
63
- it { expect { save_post }.to change(Rating.all, :count).by(18) }
64
-
65
- # Testing a 'has_and_belongs_to_many' relationship with the default amoeba
66
- # configuration.
67
- # The `tag_count` method fetches the number of records in the join table
68
- # and this tests that the three tags on the post are applied to the new
69
- # post.
70
- it { expect { save_post }.to change(Post, :tag_count).by(3) }
71
-
72
- # Testing a 'has_one ... through' relationship with the 'clone' amoeba
73
- # configuration.
74
- # The three widgets that are linked, via a join table, should be duplicated
75
- # in the Widget model and add corresponding records in the join table,
76
- # PostWidget.
77
- it { expect { save_post }.to change(Widget.all, :count).by(3) }
78
- it { expect { save_post }.to change(PostWidget, :count).by(3) }
79
-
80
- # Testing a 'has_and_belongs_to_many' relationship with the 'clone' amoeba
81
- # configuration.
82
- # There are three notes attached to the post so three new notes should be
83
- # created in the Note model as well as three records in the join table. The
84
- # `note_count` method fetches the number of records in the join table.
85
- it { expect { save_post }.to change(Note.all, :count).by(3) }
86
- it { expect { save_post }.to change(Post, :note_count).by(3) }
87
-
88
- # Testing the 'include_association' amoeba configuration.
89
- # Each Post can have many Supercats and each Supercat can have many
90
- # Supperkitens. In the test data the post has three supercats and each
91
- # supercat has three superkittens (how many were there going to St Ives?).
92
- # As a result 9 extra Superkittens should be generated.
93
- it { expect { save_post }.to change(Superkitten.all, :count).by(9) }
94
-
95
- # Testing 'prepend' configuration on attribute.
96
- # The attribute `ramblings` is configured to prepend 'Copy of '.
97
- it do
98
- expect(new_post.supercats.map(&:ramblings))
99
- .to contain_exactly('Copy of zomg', 'Copy of why', 'Copy of ohnoes')
100
- end
101
-
102
- # Testing 'set' configuration on attribute.
103
- # The attribute 'other_ramblings' is configured to set to 'La la la'.
104
- # The original tests check that (a) the values are unique and (b) the value
105
- # is set correctly. This new test will check that there are three values
106
- # that are all set the same.
107
- it { expect(new_post.supercats.map(&:other_ramblings)).to contain_exactly('La la la', 'La la la', 'La la la') }
108
-
109
- # Testing various string modifications.
110
- # * 'prepend' to add "Here's a copy: ", defined in the 'before' above
111
- # * 'append' to add " (copied version)"
112
- # * 'regext' to replace "dog" with "cat"
113
- it do
114
- expect(new_post.contents)
115
- .to eq("Here's a copy: Lorum ipsum dolor rainbow bright. I like cats, cats are awesome. (copied version)")
116
- end
117
-
118
- # Testing 'customize' configuration.
119
- # Two of the comments in the old post have 'nerf' values that cause lambdas
120
- # to generate additional when the post is duplicated.
121
- # The old post has three comments so the new post will have five comments.
122
- it { expect(new_post.comments.length).to eq(5) }
123
- # When the comment's 'nerf' value is 'ratatat' the new post will have the
124
- # comment duplicated.
125
- # The 'where' will only work once new_post has been saved.
126
- it { expect(new_post.tap(&:save).comments.where(nerf: 'ratatat').length).to eq(2) }
127
- # The duplicate will have a nil 'contents' while the other version is not.
128
- it { expect(new_post.tap(&:save).comments.where(nerf: 'ratatat', contents: nil).length).to eq(1) }
129
- # When the comment's 'nerf' value is 'bonk' the new post will have the
130
- # comment duplicated. The new comment will have a modified 'nerf' value.
131
- # The 'where' will only work once new_post has been saved.
132
- # There will only be a single comment with the original 'nerf' value.
133
- it { expect(new_post.tap(&:save).comments.where(nerf: 'bonk').length).to eq(1) }
134
- # The duplicate will have a modified 'nerf' value.
135
- it { expect(new_post.tap(&:save).comments.where(nerf: 'bonkers', contents: nil).length).to eq(1) }
136
-
137
- # Testing duplicates with a 'has_many ... through' reference and a 'clone'
138
- # amoeba configuration results in new records (with new ids).
139
- it { expect(old_post.widgets.map(&:id) & new_post.tap(&:save).widgets.map(&:id)).to be_empty }
140
-
141
- # Testing with a value that is serialized with a custom serializer.
142
- # The 'value' of a CustomThing is a string that is serialized as an array.
143
- # The test data has three instances of CustomThing; [], [1, 2] and [78]
144
- it { expect(new_post.tap(&:save).custom_things.pluck(:value)).to contain_exactly([], [1, 2], [78]) }
145
- end
146
-
147
- context 'with authors' do
148
- let(:old_author) { Author.find(1) }
149
- let(:new_author) { old_author.amoeba_dup.tap(&:save!) }
150
-
151
- it { expect(new_author.errors.messages).to be_empty }
152
-
153
- # An author has multiple posts (default amoeba configuration) and posts
154
- # in turn have multiple custom things (default amoeba configuration). The
155
- # custom things have a string value field that is serialized via a custom
156
- # serializer into an array.
157
- # The test author has three posts, each of which have three custom
158
- # things. These should be duplicated.
159
- it { expect(new_author.posts.first.custom_things.map(&:value)).to contain_exactly([], [1, 2], [78]) }
160
- end
161
-
162
- context 'with inherited classes' do
163
- # Testing the effect of single-table inheritance on amoeba duplication.
164
- # The Product class has two subclasses, Shirt and Necklace. Each class
165
- # has the same amoeba configuration that is defined with the 'raised'
166
- # option.
167
- # These tests are copied from the original and I do not fully understand
168
- # the purpose of some of them as the behavior appears to be the same for
169
- # all three classes.
170
-
171
- subject(:new_product) { old_product.amoeba_dup.tap(&:save) }
172
-
173
- context 'with the base class' do
174
- let(:old_product) { Product.find(1) }
175
- # The base product class has two relations;
176
- # * image; has_many with default amoeba configuration
177
- # * section; has_and_belongs_to_many with default amoeba configuration
178
- # The amoeba configuration is defined with the propogate option.
179
-
180
- # Duplicating product does not result in errors.
181
- it { expect(new_product.errors.messages).to be_empty }
182
-
183
- # New product copies all images from old product. The old product has
184
- # two images so two new images are created for the new product.
185
- it { expect { new_product }.to change(Image, :count).by(2) }
186
- it { expect { new_product }.not_to change(old_product.images, :count) }
187
- it { expect(new_product.images.count).to eq(old_product.images.count) }
188
-
189
- # New product copies references to all sections from old product. No
190
- # new sections are created and the new product is linked to the same
191
- # number of sections as the old product.
192
- it { expect { new_product }.not_to change(Section.all, :count) }
193
- it { expect { new_product }.not_to change(old_product, :section_count) }
194
- it { expect(new_product.section_count).to eq(old_product.section_count) }
195
- end
196
-
197
- context "with a class inheriting with the 'raised :submissive' configuration" do
198
- let(:old_product) { Shirt.find(2) }
199
-
200
- # Duplicating product does not result in errors.
201
- it { expect(new_product.errors.messages).to be_empty }
202
-
203
- # New product copies all images from old product. The old product has
204
- # two images so two new images are created for the new product.
205
- it { expect { new_product }.to change(Image, :count).by(2) }
206
- it { expect { new_product }.not_to change(old_product.images, :count) }
207
- it { expect(new_product.images.count).to eq(old_product.images.count) }
208
-
209
- # New product copies references to all sections from old product. No
210
- # new sections are created and the new product is linked to the same
211
- # number of sections as the old product.
212
- it { expect { new_product }.not_to change(Section.all, :count) }
213
- it { expect { new_product }.not_to change(old_product, :section_count) }
214
- it { expect(new_product.section_count).to eq(old_product.section_count) }
215
- end
216
-
217
- context "with a class inheriting with the 'raised :relaxed' configuration" do
218
- let(:old_product) { Necklace.find(3) }
219
-
220
- # Duplicating product does not result in errors.
221
- it { expect(new_product.errors.messages).to be_empty }
222
-
223
- # New product copies all images from old product. The old product has
224
- # two images so two new images are created for the new product.
225
- it { expect { new_product }.to change(Image, :count).by(2) }
226
- it { expect { new_product }.not_to change(old_product.images, :count) }
227
- it { expect(new_product.images.count).to eq(old_product.images.count) }
228
-
229
- # New product copies references to all sections from old product. No
230
- # new sections are created and the new product is linked to the same
231
- # number of sections as the old product.
232
- it { expect { new_product }.not_to change(Section.all, :count) }
233
- it { expect { new_product }.not_to change(old_product, :section_count) }
234
- it { expect(new_product.section_count).to eq(old_product.section_count) }
235
- end
236
- end
237
- end
238
-
239
- context 'Using a if condition' do
240
- subject { post.amoeba_dup.save! }
241
-
242
- before(:all) do
243
- require ::File.dirname(__FILE__) + '/../support/data.rb'
244
- end
245
-
246
- before { ::Post.fresh_amoeba }
247
-
248
- let(:post) { Post.first }
249
-
250
- it 'includes an association with truthy condition' do
251
- ::Post.amoeba do
252
- include_association :comments, if: :truthy?
253
- end
254
- expect { subject }.to change(Comment, :count).by(3)
255
- end
256
-
257
- it 'does not include an association with a falsey condition' do
258
- ::Post.amoeba do
259
- include_association :comments, if: :falsey?
260
- end
261
- expect { subject }.not_to change(Comment, :count)
262
- end
263
-
264
- it 'excludes an association with a truthy condition' do
265
- ::Post.amoeba do
266
- exclude_association :comments, if: :truthy?
267
- end
268
- expect { subject }.not_to change(Comment, :count)
269
- end
270
-
271
- it 'does not exclude an association with a falsey condition' do
272
- ::Post.amoeba do
273
- exclude_association :comments, if: :falsey?
274
- end
275
- expect { subject }.to change(Comment, :count).by(3)
276
- end
277
-
278
- it 'includes associations from a given array with a truthy condition' do
279
- ::Post.amoeba do
280
- include_association [:comments], if: :truthy?
281
- end
282
- expect { subject }.to change(Comment, :count).by(3)
283
- end
284
-
285
- it 'does not include associations from a given array with a falsey condition' do
286
- ::Post.amoeba do
287
- include_association [:comments], if: :falsey?
288
- end
289
- expect { subject }.not_to change(Comment, :count)
290
- end
291
-
292
- it 'does exclude associations from a given array with a truthy condition' do
293
- ::Post.amoeba do
294
- exclude_association [:comments], if: :truthy?
295
- end
296
- expect { subject }.not_to change(Comment, :count)
297
- end
298
-
299
- it 'does not exclude associations from a given array with a falsey condition' do
300
- ::Post.amoeba do
301
- exclude_association [:comments], if: :falsey?
302
- end
303
- expect { subject }.to change(Comment, :count).by(3)
304
- end
305
- end
306
-
307
- context 'when there is an override configured' do
308
- subject(:image_dup) { image.amoeba_dup }
309
-
310
- let(:image) { Image.create(filename: 'test.jpg', product_id: 12) }
311
-
312
- before do
313
- Image.fresh_amoeba
314
- Image.amoeba do
315
- override ->(old, new) { new.product_id = 13 if old.filename == 'test.jpg' }
316
- end
317
- end
318
-
319
- it { is_expected.to be_truthy }
320
- it { expect(image_dup.product_id).to eq(13) }
321
- end
322
-
323
- context 'when there is an override configured that does not apply' do
324
- subject(:image_dup) { image.amoeba_dup }
325
-
326
- let(:image) { Image.create(filename: 'test2.jpg', product_id: 12) }
327
-
328
- before do
329
- Image.fresh_amoeba
330
- Image.amoeba do
331
- override ->(old, new) { new.product_id = 13 if old.filename == 'test.jpg' }
332
- end
333
- end
334
-
335
- it { is_expected.to be_truthy }
336
- it { expect(image_dup.product_id).to eq(12) }
337
- end
338
-
339
- context 'with a field configured with nullify' do
340
- subject(:image_dup) { image.amoeba_dup }
341
-
342
- let(:image) { ::Image.create(filename: 'test.jpg', product_id: 12) }
343
-
344
- before { ::Image.fresh_amoeba }
345
-
346
- context 'without a condition' do
347
- before do
348
- ::Image.amoeba do
349
- nullify :product_id
350
- end
351
- end
352
-
353
- it { is_expected.to be_truthy }
354
- it { expect(image_dup.product_id).to be_nil }
355
-
356
- it 'stores the field with no options' do
357
- expect(::Image.amoeba.null_fields).to eq(product_id: {})
358
- end
359
- end
360
-
361
- context 'with a truthy if condition' do
362
- before do
363
- ::Image.amoeba do
364
- nullify :product_id, if: :truthy?
365
- end
366
- end
367
-
368
- it { expect(image_dup.product_id).to be_nil }
369
- end
370
-
371
- context 'with a falsey if condition' do
372
- before do
373
- ::Image.amoeba do
374
- nullify :product_id, if: :falsey?
375
- end
376
- end
377
-
378
- it { expect(image_dup.product_id).to eq(12) }
379
-
380
- it 'stores the condition alongside the field' do
381
- expect(::Image.amoeba.null_fields).to eq(product_id: { if: :falsey? })
382
- end
383
- end
384
-
385
- context 'with an array of fields and a falsey if condition' do
386
- before do
387
- ::Image.amoeba do
388
- nullify %i[filename product_id], if: :falsey?
389
- end
390
- end
391
-
392
- it { expect(image_dup.filename).to eq('test.jpg') }
393
- it { expect(image_dup.product_id).to eq(12) }
394
- end
395
-
396
- context 'when an array of fields replaces the previously configured ones' do
397
- before do
398
- ::Image.amoeba do
399
- nullify :filename
400
- nullify [:product_id]
401
- end
402
- end
403
-
404
- it { expect(image_dup.filename).to eq('test.jpg') }
405
- it { expect(image_dup.product_id).to be_nil }
406
-
407
- it 'drops the replaced field from null_fields' do
408
- expect(::Image.amoeba.null_fields).to eq(product_id: {})
409
- end
410
- end
411
-
412
- context 'when a field is redeclared without a condition' do
413
- before do
414
- ::Image.amoeba do
415
- nullify :product_id, if: :falsey?
416
- nullify :product_id
417
- end
418
- end
419
-
420
- it { expect(image_dup.product_id).to be_nil }
421
-
422
- it 'clears the previous condition' do
423
- expect(::Image.amoeba.null_fields).to eq(product_id: {})
424
- end
425
- end
426
- end
427
-
428
- context 'strict propagate' do
429
- it 'calls #reset_amoeba' do
430
- allow(SuperBlackBox).to receive(:reset_amoeba).and_call_original
431
- box = SuperBlackBox.create(title: 'Super Black Box', price: 9.99, length: 1, metal: '1')
432
- new_box = box.amoeba_dup
433
- expect(new_box.save).to be_truthy
434
- end
435
- end
436
-
437
- context 'remapping and custom dup method' do
438
- let(:prototype) { ObjectPrototype.new }
439
-
440
- context 'through' do
441
- it do
442
- real_object = prototype.amoeba_dup
443
- expect(real_object).to be_a(::RealObject)
444
- end
445
- end
446
-
447
- context 'remapper' do
448
- it do
449
- prototype.subobject_prototypes << SubobjectPrototype.new
450
- real_object = prototype.amoeba_dup
451
- expect(real_object.subobjects.length).to eq(1)
452
- end
453
- end
454
- end
455
-
456
- context 'preprocessing fields' do
457
- subject { super_admin.amoeba_dup }
458
-
459
- let(:super_admin) do
460
- ::SuperAdmin.create!(email: 'user@example.com', active: true, password: 'password')
461
- end
462
-
463
- it 'accepts "set" to set false to attribute' do
464
- expect(subject.active).to be false
465
- end
466
-
467
- it 'skips "prepend" if it equal to false' do
468
- expect(subject.password).to eq('password')
469
- end
470
- end
471
-
472
- context 'with inheritance' do
473
- # Box
474
- # has_many :products, class_name: 'BoxProduct'
475
- # has_many :sub_products, class_name: 'BoxSubProduct'
476
- #
477
- # BoxProduct
478
- # belongs_to :box, class_name: 'Box'
479
- # amoeba do
480
- # enable
481
- # propagate
482
- # end
483
- #
484
- # BoxSubProduct < BoxProduct
485
- # has_one :another_product, class_name: 'BoxAnotherProduct'
486
- #
487
- # BoxSubSubProduct < BoxSubProduct
488
- #
489
- # BoxAnotherProduct < BoxProduct
490
- # belongs_to :sub_product, class_name: 'BoxSubProduct'
491
- #
492
- # This test, from the original suite, appears to be testing
493
- # * BoxProduct has amoeba configured with 'propagate'
494
- # * BoxSubProduct inherits (STI) from BoxProduct
495
- # * BoxSubSubProduct inherits (STI) from BoxSubProduct
496
- #
497
- # When the instance of BoxSubProduct is duplicated as a result of an
498
- # an instance of Box being duplicated then amoeba also acts on it to make
499
- # a duplicate of the instance of `another_product`.
500
- #
501
- # This test could be improved to also test the behaviour when `propagate`
502
- # is not used.
503
-
504
- let(:box) { Box.create }
505
- let(:sub_sub_product) { BoxSubSubProduct.create(title: 'Awesome shoes') }
506
- let(:another_product) { BoxAnotherProduct.create(title: 'Cleaning product') }
507
-
508
- before { sub_sub_product.update(box: box, another_product: another_product) }
509
-
510
- it { expect(box.amoeba_dup.sub_products.first.another_product.title).to eq('Cleaning product') }
511
- end
512
-
513
- context 'with inheritance extended' do
514
- subject(:stage_dup) { stage.amoeba_dup }
515
-
516
- # CustomStage inherits from Stage
517
- # Stage has amoeba configured with `propagate`
518
- # These tests are not exactly equivalent to the previous verison. Formerly
519
- # all the expectations were in a single block and `save!` was executed on
520
- # the subject. This does not need to be done in some cases.
521
-
522
- let(:stage) { CustomStage.new(title: 'My Stage', external_id: 213) }
523
-
524
- before do
525
- stage.listeners.build(name: 'John')
526
- stage.listeners.build(name: 'Helen')
527
- stage.specialists.build(name: 'Jack')
528
- stage.custom_rules.build(description: 'Kill all humans')
529
- stage.save!
530
- end
531
-
532
- # Stage has the listeners and specialist has_many attributes configured
533
- # with amoeba with `include_association`. This is inherited by CustomStage.
534
- it { expect { stage_dup.save! }.to change(Listener, :count).by(2) }
535
- it { expect(stage_dup.tap(&:save!).listeners.find_by(name: 'John')).not_to be_nil }
536
- it { expect(stage_dup.tap(&:save!).listeners.find_by(name: 'Helen')).not_to be_nil }
537
- it { expect { stage_dup.save! }.to change(Specialist, :count).by(1) }
538
- it { expect(stage_dup.tap(&:save!).specialists.find_by(name: 'Jack')).not_to be_nil }
539
-
540
- # CustomStage has the custom_rules has_many attribute configured with
541
- # amoeba with `include_association`. This attribute does not exist for
542
- # Stage.
543
- it { expect { stage_dup.save! }.to change(CustomRule, :count).by(1) }
544
- # save! is not required here as it is testing the unsaved instance of
545
- # CustomRule. This differs from the tests above for listeners and
546
- # specialists which uses find_by. This is testing the same thing but needs
547
- # the instances to be in the database.
548
- it { expect(stage_dup.custom_rules.first.description).to eq 'Kill all humans' }
549
-
550
- # Stage has an attribute title that is not explicitly configured for amoeba
551
- # and so has the default configuration. CustomStage inherits this
552
- # configuration.
553
- it { expect(stage_dup.title).to eq 'My Stage' }
554
-
555
- # Stage has an attribute external_id that is configured for amoeba with
556
- # nullify. CustomStage inherits this configuration.
557
- it { expect(stage_dup.external_id).to be_nil }
558
- end
559
-
560
- context 'polymorphic' do
561
- let(:company) { Company.find_by(name: 'ABC Industries') }
562
- let(:new_company) { company.amoeba_dup }
563
-
564
- it 'does not fail with a deep inheritance' do
565
- # employee = company.employees.where(name:'Joe').first
566
- start_company_count = Company.count
567
- start_customer_count = Customer.count
568
- start_employee_count = Employee.count
569
- start_address_count = Address.count
570
- start_photo_count = Photo.count
571
- new_company.name = "Copy of #{new_company.name}"
572
- new_company.save
573
- expect(Company.count).to eq(start_company_count + 1)
574
- expect(Customer.count).to eq(start_customer_count + 1)
575
- expect(Employee.count).to eq(start_employee_count + 1)
576
- expect(Address.count).to eq(start_address_count + 4)
577
- expect(Photo.count).to eq(start_photo_count + 2)
578
-
579
- new_company.reload # fully reload from database
580
- new_company_employees = new_company.employees
581
- expect(new_company_employees.count).to eq(1)
582
- new_company_employee_joe = new_company_employees.find_by(name: 'Joe')
583
- expect(new_company_employee_joe.photos.count).to eq(1)
584
- expect(new_company_employee_joe.photos.first.size).to eq(12_345)
585
- expect(new_company_employee_joe.addresses.count).to eq(2)
586
- expect(new_company_employee_joe.addresses.where(street: '123 My Street').count).to eq(1)
587
- expect(new_company_employee_joe.addresses.where(street: '124 My Street').count).to eq(1)
588
- new_company_customers = new_company.customers
589
- expect(new_company_customers.count).to eq(1)
590
- new_company_customer_my = new_company_customers.where(email: 'my@email.address').first
591
- expect(new_company_customer_my.photos.count).to eq(1)
592
- expect(new_company_customer_my.photos.first.size).to eq(54_321)
593
- expect(new_company_customer_my.addresses.count).to eq(2)
594
- expect(new_company_customer_my.addresses.where(street: '321 My Street').count).to eq(1)
595
- expect(new_company_customer_my.addresses.where(street: '321 My Drive').count).to eq(1)
596
- end
597
- end
598
- end
data/spec/spec_helper.rb DELETED
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'simplecov'
4
-
5
- SimpleCov.start do
6
- add_filter 'spec'
7
- minimum_coverage(76)
8
-
9
- if ENV['CI']
10
- require 'simplecov-lcov'
11
-
12
- SimpleCov::Formatter::LcovFormatter.config do |c|
13
- c.report_with_single_file = true
14
- c.single_report_path = 'coverage/lcov.info'
15
- end
16
-
17
- formatter SimpleCov::Formatter::LcovFormatter
18
- end
19
- end
20
-
21
- require 'active_record'
22
- require 'amoeba'
23
-
24
- adapter = if defined?(JRuby)
25
- require 'activerecord-jdbcsqlite3-adapter'
26
- 'jdbcsqlite3'
27
- else
28
- require 'sqlite3'
29
- 'sqlite3'
30
- end
31
-
32
- ActiveRecord::Base.establish_connection(adapter: adapter, database: ':memory:')
33
-
34
- ::RSpec.configure do |config|
35
- config.order = :defined
36
- end
37
-
38
- load File.dirname(__FILE__) + '/support/schema.rb'
39
- load File.dirname(__FILE__) + '/support/models.rb'