minitest-sequel 0.2.0 → 0.3.0
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/.gitignore +2 -1
- data/Gemfile +1 -1
- data/README.md +247 -78
- data/Rakefile +9 -7
- data/lib/minitest/sequel.rb +13 -12
- data/lib/minitest/sequel/associations.rb +70 -71
- data/lib/minitest/sequel/columns.rb +44 -45
- data/lib/minitest/sequel/helpers.rb +69 -0
- data/lib/minitest/sequel/plugins.rb +166 -0
- data/lib/minitest/sequel/validations.rb +188 -188
- data/lib/minitest/sequel/version.rb +3 -3
- data/minitest-sequel.gemspec +25 -22
- metadata +36 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7cc3f41e0816a1d22ae6bad2782fb0d42bbf59a
|
4
|
+
data.tar.gz: 03d217459d38312dca790b3e34209c1f31384774
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2f994c9c68a41e7459d8905bc46fb977bbe81aa36168b479312e9e77eafc8a163db355ad1ec56d0622e577bb666f09f1828a2cd0f87139f0bd903deea7a9c26
|
7
|
+
data.tar.gz: c253fbe46ca52f6d8f298c6625c5232778cbc2057daa9729e3752caff4bc259b6455988210547e28e570f7a4d410272c475640b92c55a7524e04d779da6e33dd
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# Minitest-Sequel
|
2
2
|
|
3
|
-
[Minitest](https://github.com/seattlerb/minitest) assertions to speed-up development and testing of
|
3
|
+
[Minitest](https://github.com/seattlerb/minitest) assertions to speed-up development and testing of
|
4
4
|
[Sequel](http://sequel.jeremyevans.net/) database setups.
|
5
5
|
|
6
|
-
The general hope is that this gem will contain a variety of useful assertions in all areas of testing Sequel database
|
6
|
+
The general hope is that this gem will contain a variety of useful assertions in all areas of testing Sequel database
|
7
7
|
code within your apps, gems, etc.
|
8
8
|
|
9
9
|
Please help out with missing features / functionality.
|
@@ -23,17 +23,19 @@ let(:m) { Post.first }
|
|
23
23
|
it { assert_have_column(m, :title, type: :string, db_type: 'varchar(250)', allow_null: :false) }
|
24
24
|
|
25
25
|
it { m.must_have_column(:title, type: :string, allow_null: :false) }
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
26
|
+
|
27
|
+
it { m.must_have_column(:title, { type: :string, allow_null: :false }, "Custom messsage goes here") }
|
28
|
+
|
29
|
+
# definition of args
|
30
|
+
# assert_have_column(
|
31
|
+
# <instance>,
|
32
|
+
# <column_name>,
|
33
|
+
# <options>,
|
34
|
+
# <custom_error_message>
|
35
|
+
# )
|
34
36
|
```
|
35
37
|
|
36
|
-
The `assert_have_column()` method first tests if the column name is defined in the Model and then checks all passed options.
|
38
|
+
The `assert_have_column()` method first tests if the column name is defined in the Model and then checks all passed options.
|
37
39
|
|
38
40
|
|
39
41
|
The following options are valid and checked:
|
@@ -47,7 +49,7 @@ The following options are valid and checked:
|
|
47
49
|
* `:auto_increment`
|
48
50
|
|
49
51
|
|
50
|
-
In the event the specs differ from the actual database implementation an extensive error message with the
|
52
|
+
In the event the specs differ from the actual database implementation an extensive error message with the
|
51
53
|
differing option(s) is provided to help speed up debugging the issue:
|
52
54
|
|
53
55
|
```
|
@@ -58,7 +60,7 @@ Expected Post model to have column: :title with: \
|
|
58
60
|
|
59
61
|
**Please NOTE!**
|
60
62
|
|
61
|
-
To test options with a value that is either `nil`, `true` or `false`, please use `:nil`, `:false` or `:true` and provide
|
63
|
+
To test options with a value that is either `nil`, `true` or `false`, please use `:nil`, `:false` or `:true` and provide
|
62
64
|
numbers as 'strings' instead, ie: `'1'` instead of `1`.
|
63
65
|
|
64
66
|
|
@@ -70,7 +72,7 @@ numbers as 'strings' instead, ie: `'1'` instead of `1`.
|
|
70
72
|
<br>
|
71
73
|
|
72
74
|
|
73
|
-
## Associations
|
75
|
+
## Associations
|
74
76
|
|
75
77
|
Conveniently test model associations quickly and easily with these Minitest assertions:
|
76
78
|
|
@@ -104,15 +106,15 @@ Can be easily and quickly tested with `assert_association_one_to_one()` like thi
|
|
104
106
|
|
105
107
|
```ruby
|
106
108
|
let(:m) { Post.first }
|
107
|
-
|
109
|
+
|
108
110
|
it { assert_association_one_to_one(m, :first_comment)
|
109
111
|
# or
|
110
112
|
it { m.must_have_one_to_one_association(:first_comment) }
|
111
|
-
|
112
|
-
|
113
|
+
|
114
|
+
|
113
115
|
# definition of args
|
114
|
-
assert_association_one_to_one(
|
115
|
-
<model_instance>,
|
116
|
+
assert_association_one_to_one(
|
117
|
+
<model_instance>,
|
116
118
|
<association_name>, # ie: :first_comment
|
117
119
|
<options>,
|
118
120
|
<custom_error_message>
|
@@ -123,7 +125,7 @@ In the event of errors an extensive error message is provided:
|
|
123
125
|
|
124
126
|
```
|
125
127
|
# example error message
|
126
|
-
|
128
|
+
|
127
129
|
Expected Author to have a :one_to_one association :key_posts but no association \
|
128
130
|
':key_posts' was found - available associations are: [ \
|
129
131
|
{:attribute=>:posts, :type=>:one_to_many, :class=>:Post, :keys=>[:author_id]}, \
|
@@ -148,7 +150,7 @@ Can be easily and quickly tested with `assert_association_one_to_many()` like th
|
|
148
150
|
|
149
151
|
```ruby
|
150
152
|
let(:p) { Post.first }
|
151
|
-
|
153
|
+
|
152
154
|
it { assert_association_one_to_many(p, :comments) }
|
153
155
|
# or
|
154
156
|
it { m.must_have_one_to_many_association(:comments) }
|
@@ -173,7 +175,7 @@ Can be easily and quickly tested with `assert_association_many_to_one()` like th
|
|
173
175
|
|
174
176
|
```ruby
|
175
177
|
let(:p) { Post.first }
|
176
|
-
|
178
|
+
|
177
179
|
it { assert_association_many_to_one(p, :author) }
|
178
180
|
# or
|
179
181
|
it { m.must_have_many_to_one_association(:author) }
|
@@ -199,7 +201,7 @@ Can be easily and quickly tested with `assert_association_many_to_many()` like t
|
|
199
201
|
|
200
202
|
```ruby
|
201
203
|
let(:p) { Post.first }
|
202
|
-
|
204
|
+
|
203
205
|
it { assert_association_many_to_many(p, :categories) }
|
204
206
|
# or
|
205
207
|
it { m.must_have_many_to_many_association(:categories) }
|
@@ -211,15 +213,15 @@ If something is wrong an extensive error message is provided:
|
|
211
213
|
Expected Category to have a :many_to_many association :posts with given options: \
|
212
214
|
{:class_name=>'Posts'} but should be {:class_name=>'Post' }
|
213
215
|
```
|
214
|
-
|
216
|
+
|
215
217
|
or
|
216
|
-
|
218
|
+
|
217
219
|
```
|
218
220
|
Expected Category to have a :many_to_many association :post but no association \
|
219
221
|
':post' was found - available associations are: [ \
|
220
222
|
{ :attribute=>:posts, :type=>:many_to_many, :class=>:Post, :join_table=>:categories_posts, \
|
221
223
|
:left_keys=>[:category_id], :right_keys=>[:post_id]
|
222
|
-
}
|
224
|
+
}
|
223
225
|
]
|
224
226
|
```
|
225
227
|
|
@@ -240,10 +242,10 @@ end
|
|
240
242
|
|
241
243
|
# definition of args
|
242
244
|
assert_association(
|
243
|
-
<model_class>,
|
244
|
-
<association_type>,
|
245
|
-
<association_name>,
|
246
|
-
<options>,
|
245
|
+
<model_class>,
|
246
|
+
<association_type>,
|
247
|
+
<association_name>,
|
248
|
+
<options>,
|
247
249
|
<custom_error_message>
|
248
250
|
)
|
249
251
|
```
|
@@ -260,38 +262,38 @@ assert_association(
|
|
260
262
|
If you are using the recommended `:validation_class_methods` plugin in your app, the following instance validation methods are supported:
|
261
263
|
|
262
264
|
* `assert_validates_presence()`
|
263
|
-
|
265
|
+
|
264
266
|
* `assert_validates_exact_length()`
|
265
|
-
|
267
|
+
|
266
268
|
* `assert_validates_length_range()`
|
267
|
-
|
269
|
+
|
268
270
|
* `assert_validates_max_length()`
|
269
|
-
|
271
|
+
|
270
272
|
* `assert_validates_min_length()`
|
271
|
-
|
273
|
+
|
272
274
|
* `assert_validates_format()`
|
273
|
-
|
275
|
+
|
274
276
|
* `assert_validates_inclusion()`
|
275
|
-
|
277
|
+
|
276
278
|
* `assert_validates_integer()`
|
277
|
-
|
279
|
+
|
278
280
|
* `assert_validates_numericality()`
|
279
|
-
|
281
|
+
|
280
282
|
* `assert_validates_uniqueness()`
|
281
283
|
|
282
284
|
* `assert_validates_acceptance()`
|
283
|
-
|
285
|
+
|
284
286
|
* `assert_validates_confirmation()`
|
285
287
|
|
286
288
|
With all valid options checked
|
287
289
|
|
288
290
|
---
|
289
291
|
|
290
|
-
|
292
|
+
#### `assert_validates_presence(obj, attribute, opts = {}, msg = nil)`
|
291
293
|
alias: `:assert_validates_presence_of`
|
292
294
|
|
293
295
|
Test for validating presence of a model attribute
|
294
|
-
|
296
|
+
|
295
297
|
```ruby
|
296
298
|
it { assert_validates_presence(model, :title) }
|
297
299
|
it { model.must_validate_presence_of(:title, { message: '...' }) }
|
@@ -299,7 +301,7 @@ it { model.must_validate_presence_of(:title, { message: '...' }) }
|
|
299
301
|
<br>
|
300
302
|
|
301
303
|
|
302
|
-
|
304
|
+
#### `assert_validates_length(obj, attribute, opts = {}, msg = nil)`
|
303
305
|
alias `:assert_validates_length_of`
|
304
306
|
|
305
307
|
Test for validating the length of a model's attribute.
|
@@ -333,7 +335,7 @@ it { model.must_validate_length_of(:title, { within: 4..12 }) }
|
|
333
335
|
<br>
|
334
336
|
|
335
337
|
|
336
|
-
|
338
|
+
#### `assert_validates_exact_length(obj, attribute, exact_length, opts = {}, msg = nil)`
|
337
339
|
alias: `:assert_validates_exact_length_of`
|
338
340
|
|
339
341
|
Test for validating the exact length of a model's attribute.
|
@@ -345,7 +347,7 @@ it { model.must_validate_exact_length_of(:title, 12, { message: '...' }) }
|
|
345
347
|
<br>
|
346
348
|
|
347
349
|
|
348
|
-
|
350
|
+
#### `assert_validates_length_range(obj, attribute, range, opts = {}, msg = nil)`
|
349
351
|
alias: `:assert_validates_length_range_of`
|
350
352
|
|
351
353
|
Test for validating the exact length of a model's attribute.
|
@@ -358,7 +360,7 @@ it { model.must_validate_length_range_of(:title, 4..12, { message: '...' }) }
|
|
358
360
|
<br>
|
359
361
|
|
360
362
|
|
361
|
-
|
363
|
+
#### `assert_validates_max_length(obj, attribute, max_length, opts = {}, msg = nil)`
|
362
364
|
alias: `:assert_validates_max_length_of`
|
363
365
|
|
364
366
|
Test for validating the maximum length of a model's attribute.
|
@@ -371,7 +373,7 @@ it { model.must_validate_max_length_of(:title, 12, { message: '...' }) }
|
|
371
373
|
<br>
|
372
374
|
|
373
375
|
|
374
|
-
|
376
|
+
#### `assert_validates_min_length(obj, attribute, min_length, opts = {}, msg = nil)`
|
375
377
|
alias: `:assert_validates_min_length_of`
|
376
378
|
|
377
379
|
Test for validating the minimum length of a model's attribute.
|
@@ -384,7 +386,7 @@ it { model.must_validate_min_length_of(:title, 12, { message: '...' }) }
|
|
384
386
|
<br>
|
385
387
|
|
386
388
|
|
387
|
-
|
389
|
+
#### `assert_validates_format(obj, attribute, opts = {}, msg = nil)`
|
388
390
|
alias: `:assert_validates_format_of`
|
389
391
|
|
390
392
|
Test for validating the format of a model's attribute with a regexp.
|
@@ -397,7 +399,7 @@ it { model.must_validate_format_of(:title, 12, { with: /[a-z]+/ }) }
|
|
397
399
|
<br>
|
398
400
|
|
399
401
|
|
400
|
-
|
402
|
+
#### `assert_validates_inclusion(obj, attribute, opts = {}, msg = nil)`
|
401
403
|
alias: `:assert_validates_inclusion_of`
|
402
404
|
|
403
405
|
Test for validating that a model's attribute is within a specified range or set of values.
|
@@ -410,7 +412,7 @@ it { model.must_validate_inclusion_of(:status, { in: [:a, :b, :c] }) }
|
|
410
412
|
<br>
|
411
413
|
|
412
414
|
|
413
|
-
|
415
|
+
#### `assert_validates_integer(obj, attribute, opts = {}, msg = nil)`
|
414
416
|
alias: none
|
415
417
|
|
416
418
|
Test for validating that a a model's attribute is an integer.
|
@@ -423,7 +425,7 @@ it { model.must_validate_integer_of(:author_id, { message: '...' }) }
|
|
423
425
|
<br>
|
424
426
|
|
425
427
|
|
426
|
-
|
428
|
+
#### `assert_validates_numericality(obj, attribute, opts = {}, msg = nil)`
|
427
429
|
alias: `:assert_validates_numericality_of`
|
428
430
|
|
429
431
|
Test for validating that a model's attribute is numeric (number).
|
@@ -436,7 +438,7 @@ it { model.must_validate_numericality_of(:author_id, { message: '...' }) }
|
|
436
438
|
<br>
|
437
439
|
|
438
440
|
|
439
|
-
|
441
|
+
#### `assert_validates_uniqueness(obj, attribute, opts = {}, msg = nil)`
|
440
442
|
alias: `:assert_validates_uniqueness_of`
|
441
443
|
|
442
444
|
Test for validating that a model's attribute is unique.
|
@@ -444,12 +446,12 @@ Test for validating that a model's attribute is unique.
|
|
444
446
|
```ruby
|
445
447
|
it { assert_validates_uniqueness(model, :urlslug, { message: '...' }) }
|
446
448
|
it { model.must_validate_uniqueness_of(:urlslug, { message: '...' }) }
|
447
|
-
```
|
449
|
+
```
|
448
450
|
|
449
451
|
<br>
|
450
452
|
|
451
453
|
|
452
|
-
|
454
|
+
#### `assert_validates_acceptance(obj, attribute, opts = {}, msg = nil)`
|
453
455
|
alias: `assert_validates_acceptance_of`
|
454
456
|
|
455
457
|
Test for validating the acceptance of a model's attribute.
|
@@ -462,7 +464,7 @@ it { model.must_validate_acceptance_of(:toc, { message: '...' }) }
|
|
462
464
|
<br>
|
463
465
|
|
464
466
|
|
465
|
-
|
467
|
+
#### `assert_validates_confirmation(obj, attribute, opts = {}, msg = nil)`
|
466
468
|
alias: `:assert_validates_confirmation_of`
|
467
469
|
|
468
470
|
Test for validating the confirmation of a model's attribute.
|
@@ -478,8 +480,6 @@ it { User.new.must_validate_confirmation_of(:password, { message: '...' }) }
|
|
478
480
|
Each validation assertion have a responding negative test, ie: `refute_validate_presence()`
|
479
481
|
|
480
482
|
|
481
|
-
|
482
|
-
|
483
483
|
### Usage
|
484
484
|
|
485
485
|
A model defined with validations like this:
|
@@ -487,7 +487,7 @@ A model defined with validations like this:
|
|
487
487
|
```ruby
|
488
488
|
class Post < Sequel::Model
|
489
489
|
plugin :validation_helpers
|
490
|
-
|
490
|
+
|
491
491
|
def validate
|
492
492
|
super
|
493
493
|
validates_presence(:title)
|
@@ -500,18 +500,188 @@ Can be quickly tested like this:
|
|
500
500
|
|
501
501
|
```ruby
|
502
502
|
# <snip...>
|
503
|
-
|
503
|
+
|
504
504
|
let(:m) { Post.first }
|
505
|
-
|
506
|
-
it "
|
505
|
+
|
506
|
+
it "should validate presence of :title column" do
|
507
507
|
assert_validates_presence(m, :title)
|
508
508
|
end
|
509
|
-
|
510
|
-
it "
|
509
|
+
|
510
|
+
it "should validate format of :title column with regexp" do
|
511
511
|
assert_validates_format(m, :title, /\w+/)
|
512
512
|
end
|
513
513
|
```
|
514
514
|
|
515
|
+
<br>
|
516
|
+
<br>
|
517
|
+
|
518
|
+
----
|
519
|
+
|
520
|
+
<br>
|
521
|
+
|
522
|
+
## Plugins
|
523
|
+
|
524
|
+
This gem also contains a collection of "helpers" that aid working with Sequel models:
|
525
|
+
|
526
|
+
|
527
|
+
#### `assert_timestamped_model(model, opts = {}, msg = nil)`
|
528
|
+
|
529
|
+
Quickly test if a model class is timestamped with .plugin(:timestamps) with [Sequel-Timestamps](http://sequel.jeremyevans.net/rdoc-plugins/classes/Sequel/Plugins/Timestamps.html)
|
530
|
+
|
531
|
+
|
532
|
+
```ruby
|
533
|
+
# Declared locally in the Model
|
534
|
+
class Comment < Sequel::Model
|
535
|
+
plugin(:timestamps)
|
536
|
+
end
|
537
|
+
proc { assert_timestamped_model(Comment) }.wont_have_error
|
538
|
+
|
539
|
+
# on a non-timestamped model
|
540
|
+
class Post < Sequel::Model; end
|
541
|
+
proc { assert_timestamped_model(Post) }.must_have_error(/Not a \.plugin\(:timestamps\) model, available plugins are/)
|
542
|
+
```
|
543
|
+
|
544
|
+
**NOTE!**
|
545
|
+
|
546
|
+
You can also pass attributes to the created model in the tests via the `opts` hash like this:
|
547
|
+
|
548
|
+
```ruby
|
549
|
+
proc { assert_timestamped_model(Comment, {body: "I think...", email: "e@email.com"}) }.wont_have_error
|
550
|
+
```
|
551
|
+
|
552
|
+
Timestamps can be declared globally for all models via `Sequel::Model.plugin(:timestamps)` before the models are migrated.
|
553
|
+
|
554
|
+
|
555
|
+
#### `assert_timestamped_model_instance(model, opts = {}, msg = nil)`
|
556
|
+
|
557
|
+
Test if a model instance is timestamped with the .plugin(:timestamps) via [Sequel-Timestamps](http://sequel.jeremyevans.net/rdoc-plugins/classes/Sequel/Plugins/Timestamps.html)
|
558
|
+
|
559
|
+
```ruby
|
560
|
+
let(:m) { Post.create(title: "Dummy") }
|
561
|
+
proc { assert_timestamped_model_instance(m) }.wont_have_error
|
562
|
+
```
|
563
|
+
|
564
|
+
|
565
|
+
You can also test if an updated record is correctly timestamped
|
566
|
+
|
567
|
+
```ruby
|
568
|
+
m.title = "Updated"
|
569
|
+
m.save
|
570
|
+
proc { assert_timestamped_model_instance(m, updated_record: true) }.wont_have_error
|
571
|
+
```
|
572
|
+
|
573
|
+
Or alternatively test if an updated record is wrongly timestamped
|
574
|
+
|
575
|
+
```ruby
|
576
|
+
let(:m) { Post.create(title: "Dummy", updated_at: Time.now) }
|
577
|
+
proc { assert_timestamped_model_instance(m, updated_record: false) }.must_have_error(/expected #.updated_at to be NIL on new record/)
|
578
|
+
```
|
579
|
+
|
580
|
+
|
581
|
+
<br>
|
582
|
+
|
583
|
+
#### `assert_paranoid_model(model, opts = {}, msg = nil)`
|
584
|
+
|
585
|
+
Test if a model class is paranoid with .plugin(:paranoid) via [Sequel-Paranoid](https://github.com/sdepold/sequel-paranoid)
|
586
|
+
|
587
|
+
```ruby
|
588
|
+
# Declared locally in the Model
|
589
|
+
class Comment < Sequel::Model
|
590
|
+
plugin(:paranoid)
|
591
|
+
end
|
592
|
+
proc { assert_paranoid_model(Comment) }.wont_have_error
|
593
|
+
|
594
|
+
# on a non-paranoid model
|
595
|
+
class Post < Sequel::Model; end
|
596
|
+
proc { assert_paranoid_model(Post) }.must_have_error(/Not a plugin\(:paranoid\) model, available plugins are/)
|
597
|
+
```
|
598
|
+
|
599
|
+
**NOTE!**
|
600
|
+
|
601
|
+
You can also pass attributes to the created model in the tests via the `opts` hash like this:
|
602
|
+
|
603
|
+
```ruby
|
604
|
+
proc { assert_timestamped_model(Comment, {body: "I think...", email: "e@email.com"}) }.wont_have_error
|
605
|
+
```
|
606
|
+
|
607
|
+
|
608
|
+
<br>
|
609
|
+
|
610
|
+
#### `refute_timestamped_model(model, msg = nil)`
|
611
|
+
|
612
|
+
Test to ensure a model is NOT declared with .plugin(:timestamps) using [Sequel-Timestamps](http://sequel.jeremyevans.net/rdoc-plugins/classes/Sequel/Plugins/Timestamps.html)
|
613
|
+
|
614
|
+
|
615
|
+
Test if a model class is paranoid with .plugin(:paranoid) via [Sequel-Paranoid](https://github.com/sdepold/sequel-paranoid)
|
616
|
+
|
617
|
+
```ruby
|
618
|
+
class Comment < Sequel::Model
|
619
|
+
plugin(:timestamps)
|
620
|
+
end
|
621
|
+
proc { refute_timestamped_model(Comment) }.must_have_error(/expected Comment to NOT be a :timestamped model, but it was/)
|
622
|
+
|
623
|
+
# on a non-timestamped model
|
624
|
+
class Post < Sequel::Model; end
|
625
|
+
it { refute_timestamped_model(Post) }
|
626
|
+
```
|
627
|
+
|
628
|
+
<br>
|
629
|
+
|
630
|
+
#### `refute_paranoid_model(model, msg = nil)`
|
631
|
+
|
632
|
+
Test to ensure a model is NOT declared with .plugin(:paranoid) using [Sequel-Paranoid](https://github.com/sdepold/sequel-paranoid)
|
633
|
+
|
634
|
+
```ruby
|
635
|
+
class Comment < Sequel::Model
|
636
|
+
plugin(:paranoid)
|
637
|
+
end
|
638
|
+
proc { refute_paranoid_model(Comment) }.must_have_error(/expected Comment to NOT be a :paranoid model, but it was/)
|
639
|
+
|
640
|
+
# on a non-paranoid model
|
641
|
+
class Post < Sequel::Model; end
|
642
|
+
it { refute_paranoid_model(Post) }
|
643
|
+
```
|
644
|
+
|
645
|
+
|
646
|
+
<br>
|
647
|
+
|
648
|
+
<br>
|
649
|
+
<br>
|
650
|
+
|
651
|
+
----
|
652
|
+
|
653
|
+
<br>
|
654
|
+
|
655
|
+
## Miscellaneous Helpers
|
656
|
+
|
657
|
+
This gem also contains a collection of "helpers" that aid working with Sequel models:
|
658
|
+
|
659
|
+
<br>
|
660
|
+
|
661
|
+
#### `ensure_working_CRUD(obj, attribute)`
|
662
|
+
|
663
|
+
Enables quick tests to ensure that the basic CRUD functionality is working correctly for a Model
|
664
|
+
|
665
|
+
```ruby
|
666
|
+
ensure_working_CRUD(User, :name)
|
667
|
+
```
|
668
|
+
|
669
|
+
**NOTE!**
|
670
|
+
* the passed `_model` argument must be the actual Model class and NOT a string or symbol
|
671
|
+
* the passed attribute `_attr` must be a String attribute or the tests will fail
|
672
|
+
|
673
|
+
**DEPENDENCIES**
|
674
|
+
|
675
|
+
This test depends upon being able to create a new model instance for each test via using
|
676
|
+
[Sequel Factory's](https://github.com/mjackson/sequel-factory) `#make()` method
|
677
|
+
|
678
|
+
|
679
|
+
<br>
|
680
|
+
<br>
|
681
|
+
|
682
|
+
----
|
683
|
+
|
684
|
+
<br>
|
515
685
|
|
516
686
|
## Installation
|
517
687
|
|
@@ -537,28 +707,28 @@ $ gem install minitest-sequel
|
|
537
707
|
|
538
708
|
In your project's `spec/spec_helper.rb` or `test/test_helper.rb` file ensure the following code is present:
|
539
709
|
|
540
|
-
|
710
|
+
|
541
711
|
```ruby
|
542
712
|
gem 'minitest'
|
543
|
-
|
713
|
+
|
544
714
|
require 'minitest/autorun'
|
545
715
|
require 'minitest/sequel' # NB!! can be loaded after minitest/autorun
|
546
|
-
|
716
|
+
|
547
717
|
require 'sqlite3' # using sqlite for tests
|
548
|
-
|
718
|
+
|
549
719
|
# The preferred default validations plugin, which uses class-level methods.
|
550
720
|
Sequel::Model.plugin(:validation_class_methods)
|
551
|
-
|
721
|
+
|
552
722
|
# connect to database
|
553
723
|
DB = Sequel.sqlite # :memory
|
554
|
-
|
724
|
+
|
555
725
|
## add migrations and seeds below
|
556
|
-
|
726
|
+
|
557
727
|
DB.create_table(:posts) do
|
558
728
|
primary_key :id
|
559
729
|
# <snip...>
|
560
730
|
end
|
561
|
-
|
731
|
+
|
562
732
|
# <snip...>
|
563
733
|
```
|
564
734
|
|
@@ -568,24 +738,23 @@ Then in your tests you should be good to go when using the sequel assertions.
|
|
568
738
|
|
569
739
|
## Development
|
570
740
|
|
571
|
-
After checking out the repo, run `bundle install` to install all dependencies. Then, run `rake spec` to run the tests.
|
741
|
+
After checking out the repo, run `bundle install` to install all dependencies. Then, run `rake spec` to run the tests.
|
572
742
|
|
573
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
743
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
574
744
|
|
575
|
-
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`,
|
576
|
-
which will create a git tag for the version, push git commits and tags, and push the `.gem` file to
|
745
|
+
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`,
|
746
|
+
which will create a git tag for the version, push git commits and tags, and push the `.gem` file to
|
577
747
|
[rubygems.org](https://rubygems.org).
|
578
748
|
|
579
749
|
|
580
750
|
## Contributing
|
581
751
|
|
582
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/kematzy/minitest-sequel/issues.
|
752
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kematzy/minitest-sequel/issues.
|
583
753
|
|
584
|
-
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere
|
754
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere
|
585
755
|
to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
586
756
|
|
587
757
|
|
588
758
|
## License
|
589
759
|
|
590
760
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
591
|
-
|