minitest-sequel 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +20 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +345 -0
- data/Rakefile +10 -0
- data/lib/minitest/sequel.rb +276 -0
- data/lib/minitest/sequel/version.rb +5 -0
- data/minitest-sequel.gemspec +35 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ba7809791b48d3d37abf55385778ff37b31a0743
|
4
|
+
data.tar.gz: eb4eca066d3a6a7e39a975a85f5587ad5f6faecc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 73425aa76579e6118327dc672089e9725451551a00bf80d39b388c666eb31d6f1f26ba905935cf38ed0aad0446813783db0f6cc34d126befdd9b405ad1035007
|
7
|
+
data.tar.gz: 101c5b1c3c9b2d8e0be36353e63f8e9c84e7e371952fb7c7a8b17770e7bdc6f38aacd61e450e8df9b324e0ac9ba143b47035c1c86190daae4c65ad11f993a931
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of
|
6
|
+
level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance,
|
7
|
+
body size, race, ethnicity, age, or religion.
|
8
|
+
|
9
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory
|
10
|
+
comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
11
|
+
|
12
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki
|
13
|
+
edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not
|
14
|
+
follow the Code of Conduct may be removed from the project team.
|
15
|
+
|
16
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or
|
17
|
+
contacting one or more of the project maintainers.
|
18
|
+
|
19
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0,
|
20
|
+
available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Kematzy
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,345 @@
|
|
1
|
+
# Minitest-Sequel
|
2
|
+
|
3
|
+
[Minitest](https://github.com/seattlerb/minitest) assertions to speed-up development and testing of
|
4
|
+
[Sequel](http://sequel.jeremyevans.net/) database setups.
|
5
|
+
|
6
|
+
The general hope is that this gem will contain a variety of useful assertions in all areas of testing Sequel database
|
7
|
+
code within your apps, gems, etc.
|
8
|
+
|
9
|
+
Please help out with missing features / functionality.
|
10
|
+
|
11
|
+
-----
|
12
|
+
|
13
|
+
## Model Definitions
|
14
|
+
|
15
|
+
|
16
|
+
### `assert_have_column ()`
|
17
|
+
|
18
|
+
Conveniently test your Model definitions as follows:
|
19
|
+
|
20
|
+
let(:m) { Post.first }
|
21
|
+
|
22
|
+
it { assert_have_column(m, :title, type: :string, db_type: 'varchar(250)', allow_null: :false ) }
|
23
|
+
|
24
|
+
# definition of args
|
25
|
+
assert_have_column(<instance>, <column_name>, <options>, <custom_error_message>)
|
26
|
+
|
27
|
+
|
28
|
+
The `assert_have_column()` method first tests if the column name is defined in the Model and then checks all passed options.
|
29
|
+
|
30
|
+
|
31
|
+
The following options are valid and checked:
|
32
|
+
|
33
|
+
* :type
|
34
|
+
* :db_type
|
35
|
+
* :allow_null
|
36
|
+
* :max_length
|
37
|
+
* :default
|
38
|
+
* :primary_key
|
39
|
+
* :auto_increment
|
40
|
+
|
41
|
+
|
42
|
+
In the event the specs differ from the actual database implementation an extensive error message with the
|
43
|
+
differing option(s) is provided to help speed up debugging the issue:
|
44
|
+
|
45
|
+
Expected Post model to have column: :title with: \
|
46
|
+
{ type: 'string', db_type: 'varchar(250)', allow_null: 'false' } \
|
47
|
+
but found: { db_type: 'varchar(255)' }
|
48
|
+
|
49
|
+
|
50
|
+
**Please NOTE!**
|
51
|
+
|
52
|
+
To test options with a value that is either `nil`, `true` or `false`, please use `:nil`, `:false` or `:true` and provide
|
53
|
+
numbers as 'strings' instead, ie: '1' instead of 1.
|
54
|
+
|
55
|
+
|
56
|
+
<br>
|
57
|
+
<br>
|
58
|
+
|
59
|
+
----
|
60
|
+
|
61
|
+
<br>
|
62
|
+
|
63
|
+
|
64
|
+
## Associations
|
65
|
+
|
66
|
+
Conveniently test model associations quickly and easily with these Minitest assertions:
|
67
|
+
|
68
|
+
* `assert_association_one_to_one`
|
69
|
+
* `assert_association_one_to_many`
|
70
|
+
* `assert_association_many_to_one`
|
71
|
+
* `assert_association_many_to_many`
|
72
|
+
* `assert_association`
|
73
|
+
|
74
|
+
<br>
|
75
|
+
<br>
|
76
|
+
|
77
|
+
|
78
|
+
### `:one_to_one` association
|
79
|
+
|
80
|
+
|
81
|
+
A model defined with an association like this:
|
82
|
+
|
83
|
+
class Post < Sequel::Model
|
84
|
+
one_to_one :first_comment, :class=>:Comment, :order=>:id
|
85
|
+
end
|
86
|
+
|
87
|
+
Can be easily and quickly tested with `assert_association_one_to_one()` like this:
|
88
|
+
|
89
|
+
let(:m) { Post.first }
|
90
|
+
|
91
|
+
it { assert_association_one_to_one(m, :first_comment) }
|
92
|
+
|
93
|
+
|
94
|
+
# definition of args
|
95
|
+
assert_association_one_to_one(
|
96
|
+
<model_instance>,
|
97
|
+
<association_name>, # ie: :first_comment
|
98
|
+
<options>,
|
99
|
+
<custom_error_message>
|
100
|
+
)
|
101
|
+
|
102
|
+
|
103
|
+
In the event of errors an extensive error message is provided:
|
104
|
+
|
105
|
+
# example error message
|
106
|
+
|
107
|
+
Expected Author to have a :one_to_one association :key_posts but no association ':key_posts' was found -
|
108
|
+
available associations are: [ \
|
109
|
+
{:attribute=>:posts, :type=>:one_to_many, :class=>:Post, :keys=>[:author_id]}, \
|
110
|
+
{:attribute=>:key_post, :type=>:one_to_one, :class=>:Post, :keys=>[:author_id]} \
|
111
|
+
]
|
112
|
+
|
113
|
+
<br>
|
114
|
+
<br>
|
115
|
+
|
116
|
+
### `:one_to_many` association
|
117
|
+
|
118
|
+
A model defined with an association like this:
|
119
|
+
|
120
|
+
class Post < Sequel::Model
|
121
|
+
one_to_many :comments
|
122
|
+
end
|
123
|
+
|
124
|
+
Can be easily and quickly tested with `assert_association_one_to_many()` like this:
|
125
|
+
|
126
|
+
let(:p) { Post.first }
|
127
|
+
|
128
|
+
it { assert_association_one_to_many(p, :comments) }
|
129
|
+
|
130
|
+
|
131
|
+
As above the assertion provides an extensive error message if something is wrong.
|
132
|
+
|
133
|
+
<br>
|
134
|
+
<br>
|
135
|
+
|
136
|
+
### `:many_to_one` association
|
137
|
+
|
138
|
+
A model defined with an association like this:
|
139
|
+
|
140
|
+
class Post < Sequel::Model
|
141
|
+
many_to_one :author
|
142
|
+
end
|
143
|
+
|
144
|
+
Can be easily and quickly tested with `assert_association_many_to_one()` like this:
|
145
|
+
|
146
|
+
let(:p) { Post.first }
|
147
|
+
|
148
|
+
it { assert_association_many_to_one(p, :author) }
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
As above the assertion provides an extensive error message if something is wrong.
|
153
|
+
|
154
|
+
<br>
|
155
|
+
<br>
|
156
|
+
|
157
|
+
### `:many_to_many` association
|
158
|
+
|
159
|
+
A model defined with an association like this:
|
160
|
+
|
161
|
+
class Post < Sequel::Model
|
162
|
+
many_to_many :categories
|
163
|
+
end
|
164
|
+
|
165
|
+
Can be easily and quickly tested with `assert_association_many_to_many()` like this:
|
166
|
+
|
167
|
+
let(:p) { Post.first }
|
168
|
+
|
169
|
+
it { assert_association_many_to_many(p, :categories) }
|
170
|
+
|
171
|
+
|
172
|
+
If something is wrong an extensive error message is provided:
|
173
|
+
|
174
|
+
Expected Category to have a :many_to_many association :posts with given options: \
|
175
|
+
{:class_name=>'Posts'} but should be {:class_name=>'Post' }
|
176
|
+
|
177
|
+
or
|
178
|
+
|
179
|
+
Expected Category to have a :many_to_many association :post but no association ':post' was found - \
|
180
|
+
available associations are: [ \
|
181
|
+
{ :attribute=>:posts, :type=>:many_to_many, :class=>:Post, :join_table=>:categories_posts, \
|
182
|
+
:left_keys=>[:category_id], :right_keys=>[:post_id]
|
183
|
+
}
|
184
|
+
]
|
185
|
+
|
186
|
+
|
187
|
+
<br>
|
188
|
+
<br>
|
189
|
+
|
190
|
+
### `assert_association() assertion`
|
191
|
+
|
192
|
+
if the above assertion methods are insufficient, you can use the base `assert_association` method instead.
|
193
|
+
|
194
|
+
it "should have a :one_through_one association" do
|
195
|
+
assert_association(Post, :one_through_one, :author)
|
196
|
+
end
|
197
|
+
|
198
|
+
|
199
|
+
#
|
200
|
+
assert_association(
|
201
|
+
<model_class>, <association_type>, <association_name>, <options>, <custom_error_message>
|
202
|
+
)
|
203
|
+
|
204
|
+
|
205
|
+
<br>
|
206
|
+
<br>
|
207
|
+
|
208
|
+
----
|
209
|
+
|
210
|
+
<br>
|
211
|
+
|
212
|
+
## Validations
|
213
|
+
|
214
|
+
**NOTE! NOT YET IMPLEMENTED! WORK IN PROGRESS**
|
215
|
+
|
216
|
+
|
217
|
+
If you are using the recommended `:validation_helpers` plugin in your app, the following instance validation methods
|
218
|
+
are supported:
|
219
|
+
|
220
|
+
* `validates_presence`
|
221
|
+
|
222
|
+
* `validates_exact_length`
|
223
|
+
|
224
|
+
* `validates_length_range`
|
225
|
+
|
226
|
+
* `validates_max_length`
|
227
|
+
|
228
|
+
* `validates_min_length`
|
229
|
+
|
230
|
+
* `validates_format`
|
231
|
+
|
232
|
+
* `validates_includes`
|
233
|
+
|
234
|
+
* `validates_integer`
|
235
|
+
|
236
|
+
* `validates_not_string`
|
237
|
+
|
238
|
+
* `validates_numeric`
|
239
|
+
|
240
|
+
* `validates_unique`
|
241
|
+
|
242
|
+
|
243
|
+
The following valid options will be checked:
|
244
|
+
|
245
|
+
* `:allow_blank`
|
246
|
+
* `:allow_missing`
|
247
|
+
* `:allow_nil`
|
248
|
+
* `:message`
|
249
|
+
|
250
|
+
|
251
|
+
### Usage
|
252
|
+
|
253
|
+
A model defined with validations like this:
|
254
|
+
|
255
|
+
class Post < Sequel::Model
|
256
|
+
plugin :validation_helpers
|
257
|
+
|
258
|
+
def validate
|
259
|
+
super
|
260
|
+
validates_presence(:title)
|
261
|
+
validates_format(/\w+/, :title)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
Can be quickly tested like this:
|
266
|
+
|
267
|
+
<snip...>
|
268
|
+
|
269
|
+
let(:m) { Post.first }
|
270
|
+
|
271
|
+
it "shoud validate presence of :title column" do
|
272
|
+
assert_validates_presence(m, :title)
|
273
|
+
end
|
274
|
+
|
275
|
+
it "shoud validate format of :title column with regexp" do
|
276
|
+
assert_validates_format(m, :title, /\w+/)
|
277
|
+
end
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
## Installation
|
282
|
+
|
283
|
+
Add this line to your application's Gemfile:
|
284
|
+
|
285
|
+
gem 'minitest-sequel'
|
286
|
+
|
287
|
+
And then execute:
|
288
|
+
|
289
|
+
$ bundle
|
290
|
+
|
291
|
+
Or install it yourself as:
|
292
|
+
|
293
|
+
$ gem install minitest-sequel
|
294
|
+
|
295
|
+
|
296
|
+
## Usage
|
297
|
+
|
298
|
+
In your project's `spec/spec_helper.rb` or `test/test_helper.rb` file ensure the following code is present:
|
299
|
+
|
300
|
+
|
301
|
+
require 'minitest/autorun'
|
302
|
+
require 'minitest/sequel'
|
303
|
+
require 'sqlite3' # using sqlite for tests
|
304
|
+
|
305
|
+
# The preferred default validations plugin, which uses instance-level methods.
|
306
|
+
Sequel::Model.plugin(:validation_helpers)
|
307
|
+
|
308
|
+
# connect to database
|
309
|
+
DB = Sequel.sqlite # :memory
|
310
|
+
|
311
|
+
## add migrations and seeds below
|
312
|
+
|
313
|
+
DB.create_table(:posts) do
|
314
|
+
primary_key :id
|
315
|
+
<snip...>
|
316
|
+
end
|
317
|
+
|
318
|
+
|
319
|
+
Then in your tests you should be good to go when using the sequel assertions.
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
## Development
|
324
|
+
|
325
|
+
After checking out the repo, run `bundle install` to install all dependencies. Then, run `rake spec` to run the tests.
|
326
|
+
|
327
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
328
|
+
|
329
|
+
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`,
|
330
|
+
which will create a git tag for the version, push git commits and tags, and push the `.gem` file to
|
331
|
+
[rubygems.org](https://rubygems.org).
|
332
|
+
|
333
|
+
|
334
|
+
## Contributing
|
335
|
+
|
336
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kematzy/minitest-sequel/issues.
|
337
|
+
|
338
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere
|
339
|
+
to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
340
|
+
|
341
|
+
|
342
|
+
## License
|
343
|
+
|
344
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
345
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,276 @@
|
|
1
|
+
require "minitest/sequel/version"
|
2
|
+
require 'sequel'
|
3
|
+
|
4
|
+
module Minitest
|
5
|
+
module Sequel
|
6
|
+
|
7
|
+
|
8
|
+
# Conveniently test your Model definitions as follows:
|
9
|
+
#
|
10
|
+
# let(:m) { Post.first }
|
11
|
+
#
|
12
|
+
# it { assert_have_column(m, :title, type: :string, db_type: 'varchar(250)', allow_null: :false ) }
|
13
|
+
#
|
14
|
+
# # assert_have_column(<instance>, <column_name>, <options>, <custom_error_message>)
|
15
|
+
#
|
16
|
+
#
|
17
|
+
# `assert_have_column()` first tests if the column name is defined in the Model and then checks all passed options.
|
18
|
+
# The following options are valid and checked:
|
19
|
+
#
|
20
|
+
# * :type
|
21
|
+
# * :db_type
|
22
|
+
# * :allow_null
|
23
|
+
# * :max_length
|
24
|
+
# * :default
|
25
|
+
# * :primary_key
|
26
|
+
# * :auto_increment
|
27
|
+
#
|
28
|
+
# In the event the specs differ from the actual database implementation an extensive error message
|
29
|
+
# with the differing option(s) is provided to help speed up debugging the issue:
|
30
|
+
#
|
31
|
+
# Expected Post model to have column: :title with: \
|
32
|
+
# { type: 'string', db_type: 'varchar(250)', allow_null: 'false' } \
|
33
|
+
# but found: { db_type: 'varchar(255)' }
|
34
|
+
#
|
35
|
+
#
|
36
|
+
# **Please NOTE!**
|
37
|
+
#
|
38
|
+
# To test options with a value that is either `nil`, `true` or `false`, please use `:nil`,
|
39
|
+
# `:false` or `:true` and provide numbers as 'strings' instead.
|
40
|
+
#
|
41
|
+
#
|
42
|
+
def assert_have_column(obj, attribute, opts={}, msg=nil)
|
43
|
+
msg = msg.nil? ? '' : "#{msg}\n"
|
44
|
+
msg << "Expected #{obj.class} model to have column: :#{attribute.to_s}"
|
45
|
+
err_msg = []; conf_msg = []
|
46
|
+
# check if column exists
|
47
|
+
col = obj.db.schema(obj.class.table_name).detect{|col| col[0]==attribute}
|
48
|
+
matching = !col.nil?
|
49
|
+
|
50
|
+
# bail out if no matching column
|
51
|
+
unless matching
|
52
|
+
msg << " but no such column exists"
|
53
|
+
assert matching, msg
|
54
|
+
end
|
55
|
+
|
56
|
+
# bail out if options provided are invalid
|
57
|
+
valid_opts = [:type, :db_type, :allow_null, :max_length, :default, :primary_key, :auto_increment]
|
58
|
+
invalid_opts = opts.keys.reject { |o| valid_opts.include?(o) }
|
59
|
+
unless invalid_opts.empty?
|
60
|
+
msg << " : ERROR: invalid option(s) provided: { "
|
61
|
+
invalid_opts.each{|o| msg << "#{o.inspect}; " }
|
62
|
+
msg << " } valid options are: #{valid_opts.inspect}"
|
63
|
+
assert false, msg
|
64
|
+
end
|
65
|
+
|
66
|
+
# carry on...
|
67
|
+
|
68
|
+
# check type
|
69
|
+
unless opts[:type].nil?
|
70
|
+
expected = (col[1][:type].to_s == opts[:type].to_s)
|
71
|
+
conf_msg << "type: '#{opts[:type]}'"
|
72
|
+
unless expected
|
73
|
+
err_msg << "type: '#{col[1][:type]}'"
|
74
|
+
end
|
75
|
+
matching &&= expected
|
76
|
+
end
|
77
|
+
|
78
|
+
# check db_type
|
79
|
+
unless opts[:db_type].nil?
|
80
|
+
expected = (col[1][:db_type].to_s == opts[:db_type].to_s)
|
81
|
+
conf_msg << "db_type: '#{opts[:db_type]}'"
|
82
|
+
unless expected
|
83
|
+
err_msg << "db_type: '#{col[1][:db_type]}'"
|
84
|
+
end
|
85
|
+
matching &&= expected
|
86
|
+
end
|
87
|
+
|
88
|
+
# check :allow_null
|
89
|
+
unless opts[:allow_null].nil?
|
90
|
+
_v = _convert_value(opts[:allow_null])
|
91
|
+
expected = (opts[:allow_null] === _v)
|
92
|
+
conf_msg << "allow_null: '#{opts[:allow_null]}'"
|
93
|
+
unless expected
|
94
|
+
err_msg << "allow_null: '#{col[1][:allow_null]}'"
|
95
|
+
end
|
96
|
+
matching &&= expected
|
97
|
+
end
|
98
|
+
|
99
|
+
# check :max_length
|
100
|
+
unless opts[:max_length].nil?
|
101
|
+
expected = (col[1][:max_length] === opts[:max_length])
|
102
|
+
conf_msg << "max_length: '#{opts[:max_length]}'"
|
103
|
+
unless expected
|
104
|
+
err_msg << "max_length: '#{col[1][:max_length]}'"
|
105
|
+
end
|
106
|
+
matching &&= expected
|
107
|
+
end
|
108
|
+
|
109
|
+
# check :default
|
110
|
+
unless opts[:default].nil?
|
111
|
+
_v = _convert_value(opts[:default])
|
112
|
+
expected = (col[1][:default] === _v )
|
113
|
+
conf_msg << "default: '#{opts[:default]}'"
|
114
|
+
unless expected
|
115
|
+
err_msg << "default: '#{col[1][:default].inspect}'"
|
116
|
+
end
|
117
|
+
matching &&= expected
|
118
|
+
end
|
119
|
+
|
120
|
+
# check :primary_key
|
121
|
+
unless opts[:primary_key].nil?
|
122
|
+
_v = _convert_value(opts[:primary_key])
|
123
|
+
expected = (col[1][:primary_key] === _v)
|
124
|
+
conf_msg << "primary_key: '#{opts[:primary_key]}'"
|
125
|
+
unless expected
|
126
|
+
err_msg << "primary_key: '#{col[1][:primary_key]}'"
|
127
|
+
end
|
128
|
+
matching &&= expected
|
129
|
+
end
|
130
|
+
|
131
|
+
# check :auto_increment
|
132
|
+
unless opts[:auto_increment].nil?
|
133
|
+
_v = _convert_value(opts[:auto_increment])
|
134
|
+
expected = (col[1][:auto_increment] === _v)
|
135
|
+
conf_msg << "auto_increment: '#{opts[:auto_increment]}'"
|
136
|
+
unless expected
|
137
|
+
err_msg << "auto_increment: '#{col[1][:auto_increment]}'"
|
138
|
+
end
|
139
|
+
matching &&= expected
|
140
|
+
end
|
141
|
+
|
142
|
+
msg = msg << " with: { #{conf_msg.join(', ')} } but found: { #{err_msg.join(', ')} }"
|
143
|
+
assert matching, msg
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
def assert_association_one_to_one(obj, attribute, opts={}, msg=nil)
|
148
|
+
assert_association(obj.class, :one_to_one, attribute, opts, msg)
|
149
|
+
end
|
150
|
+
|
151
|
+
def assert_association_one_to_many(obj, attribute, opts={}, msg=nil)
|
152
|
+
assert_association(obj.class, :one_to_many, attribute, opts, msg)
|
153
|
+
end
|
154
|
+
|
155
|
+
def assert_association_many_to_one(obj, attribute, opts={}, msg=nil)
|
156
|
+
assert_association(obj.class, :many_to_one, attribute, opts, msg)
|
157
|
+
end
|
158
|
+
|
159
|
+
def assert_association_many_to_many(obj, attribute, opts={}, msg=nil)
|
160
|
+
assert_association(obj.class, :many_to_many, attribute, opts, msg)
|
161
|
+
end
|
162
|
+
|
163
|
+
def assert_association(klass, association_type, attribute, opts={}, msg=nil)
|
164
|
+
msg = msg.nil? ? '' : "#{msg}\n"
|
165
|
+
msg << "Expected #{klass.inspect} to have a #{association_type.inspect} association #{attribute.inspect}"
|
166
|
+
assoc = klass.association_reflection(attribute) || {}
|
167
|
+
if assoc.empty?
|
168
|
+
msg << " but no association '#{attribute.inspect}' was found"
|
169
|
+
arr = []
|
170
|
+
klass.associations.each do |a|
|
171
|
+
o = klass.association_reflection(a)
|
172
|
+
if o[:type] == :many_to_many
|
173
|
+
arr << { attribute: o[:name], type: o[:type], class: o[:class_name].to_sym, join_table: o[:join_table], left_keys: o[:left_keys], right_keys: o[:right_keys] }
|
174
|
+
else
|
175
|
+
arr << { attribute: o[:name], type: o[:type], class: o[:class_name].to_sym, keys: o[:keys] }
|
176
|
+
end
|
177
|
+
end
|
178
|
+
msg << " - \navailable associations are: [ #{arr.join(', ')} ]\n"
|
179
|
+
assert false, msg
|
180
|
+
else
|
181
|
+
matching = assoc[:type] == association_type
|
182
|
+
err_msg = []; conf_msg = []
|
183
|
+
opts.each { |key, value|
|
184
|
+
conf_msg << { key => value }
|
185
|
+
if assoc[key]!= value
|
186
|
+
err_msg << { key => assoc[key] }
|
187
|
+
matching = false
|
188
|
+
end
|
189
|
+
}
|
190
|
+
msg << " with given options: #{conf_msg.join(', ')} but should be #{err_msg.join(', ')}"
|
191
|
+
assert matching, msg
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
## VALIDATIONS
|
196
|
+
|
197
|
+
def assert_validates_presence(obj, attribute, opts={}, msg=nil)
|
198
|
+
assert_validates(obj, :presence, attribute, opts, msg)
|
199
|
+
end
|
200
|
+
|
201
|
+
def assert_validates_length(obj, attribute, opts={}, msg=nil)
|
202
|
+
assert_validates(obj, :length, attribute, opts, msg)
|
203
|
+
end
|
204
|
+
|
205
|
+
def assert_validates_exact_length(obj, attribute, opts={}, msg=nil)
|
206
|
+
assert_validates(obj, :exact_length, attribute, opts, msg)
|
207
|
+
end
|
208
|
+
|
209
|
+
def assert_validates_length_range(obj, attribute, opts={}, msg=nil)
|
210
|
+
assert_validates(obj, :length_range, attribute, opts, msg)
|
211
|
+
end
|
212
|
+
|
213
|
+
def assert_validates_max_length(obj, attribute, opts={}, msg=nil)
|
214
|
+
assert_validates(obj, :max_length, attribute, opts, msg)
|
215
|
+
end
|
216
|
+
|
217
|
+
def assert_validates_min_length(obj, attribute, opts={}, msg=nil)
|
218
|
+
assert_validates(obj, :min_length, attribute, opts, msg)
|
219
|
+
end
|
220
|
+
|
221
|
+
def assert_validates_format(obj, attribute, opts={}, msg=nil)
|
222
|
+
assert_validates(obj, :format, attribute, opts, msg)
|
223
|
+
end
|
224
|
+
|
225
|
+
def assert_validates_includes(obj, attribute, opts={}, msg=nil)
|
226
|
+
assert_validates(obj, :includes, attribute, opts, msg)
|
227
|
+
end
|
228
|
+
|
229
|
+
def assert_validates_integer(obj, attribute, opts={}, msg=nil)
|
230
|
+
assert_validates(obj, :integer, attribute, opts, msg)
|
231
|
+
end
|
232
|
+
|
233
|
+
def assert_validates_numeric(obj, attribute, opts={}, msg=nil)
|
234
|
+
assert_validates(obj, :numeric, attribute, opts, msg)
|
235
|
+
end
|
236
|
+
|
237
|
+
def assert_validates_not_string(obj, attribute, opts={}, msg=nil)
|
238
|
+
assert_validates(obj, :not_string, attribute, opts, msg)
|
239
|
+
end
|
240
|
+
|
241
|
+
def assert_validates_unique(obj, attribute, opts={}, msg=nil)
|
242
|
+
assert_validates(obj, :unique, attribute, opts, msg)
|
243
|
+
end
|
244
|
+
|
245
|
+
def assert_validates(obj, validation_type, attribute, opts={}, msg=nil)
|
246
|
+
|
247
|
+
end
|
248
|
+
|
249
|
+
|
250
|
+
private
|
251
|
+
|
252
|
+
def _convert_value(val)
|
253
|
+
_v = case val
|
254
|
+
when :nil
|
255
|
+
nil
|
256
|
+
when :false
|
257
|
+
false
|
258
|
+
when :true
|
259
|
+
true
|
260
|
+
else
|
261
|
+
val
|
262
|
+
end
|
263
|
+
_v
|
264
|
+
end
|
265
|
+
|
266
|
+
def _valid_validation_options
|
267
|
+
[ :allow_blank, :allow_missing, :allow_nil, :message ]
|
268
|
+
end
|
269
|
+
|
270
|
+
end
|
271
|
+
|
272
|
+
module Assertions
|
273
|
+
include Minitest::Sequel
|
274
|
+
end
|
275
|
+
|
276
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'minitest/sequel/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "minitest-sequel"
|
8
|
+
spec.version = Minitest::Sequel::VERSION
|
9
|
+
spec.authors = ["Kematzy"]
|
10
|
+
spec.email = ["kematzy@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Minitest assertions to speed-up development and testing of Sequel database setups.}
|
13
|
+
spec.description = %q{A collection of convenient assertions to enable faster DRY'er testing of Sequel database apps/gems.}
|
14
|
+
spec.homepage = "https://github.com/kematzy/minitest-sequel"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# # delete this section to allow pushing this gem to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
# end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_runtime_dependency 'minitest', '~> 5.7', '>= 5.7.0'
|
31
|
+
spec.add_runtime_dependency 'sequel', '~> 4.26'
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: minitest-sequel
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kematzy
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.7'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 5.7.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.7'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 5.7.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: sequel
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '4.26'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '4.26'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.10'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1.10'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '10.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '10.0'
|
75
|
+
description: A collection of convenient assertions to enable faster DRY'er testing
|
76
|
+
of Sequel database apps/gems.
|
77
|
+
email:
|
78
|
+
- kematzy@gmail.com
|
79
|
+
executables: []
|
80
|
+
extensions: []
|
81
|
+
extra_rdoc_files: []
|
82
|
+
files:
|
83
|
+
- ".gitignore"
|
84
|
+
- CODE_OF_CONDUCT.md
|
85
|
+
- Gemfile
|
86
|
+
- LICENSE.txt
|
87
|
+
- README.md
|
88
|
+
- Rakefile
|
89
|
+
- lib/minitest/sequel.rb
|
90
|
+
- lib/minitest/sequel/version.rb
|
91
|
+
- minitest-sequel.gemspec
|
92
|
+
homepage: https://github.com/kematzy/minitest-sequel
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.4.5
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Minitest assertions to speed-up development and testing of Sequel database
|
116
|
+
setups.
|
117
|
+
test_files: []
|