schema_validations 2.2.1 → 2.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/prs.yml +173 -0
- data/.gitignore +1 -0
- data/.simplecov +20 -0
- data/Gemfile +5 -0
- data/README.md +33 -6
- data/Rakefile +2 -0
- data/gemfiles/Gemfile.base +1 -1
- data/gemfiles/activerecord-5.2/Gemfile.base +4 -0
- data/gemfiles/activerecord-5.2/Gemfile.mysql2 +10 -0
- data/gemfiles/activerecord-5.2/Gemfile.postgresql +10 -0
- data/gemfiles/{activerecord-4.2 → activerecord-5.2}/Gemfile.sqlite3 +3 -3
- data/gemfiles/activerecord-6.0/Gemfile.base +4 -0
- data/gemfiles/activerecord-6.0/Gemfile.mysql2 +10 -0
- data/gemfiles/activerecord-6.0/Gemfile.postgresql +10 -0
- data/gemfiles/{activerecord-5.0 → activerecord-6.0}/Gemfile.sqlite3 +3 -3
- data/gemfiles/activerecord-6.1/Gemfile.base +4 -0
- data/gemfiles/activerecord-6.1/Gemfile.mysql2 +10 -0
- data/gemfiles/activerecord-6.1/Gemfile.postgresql +10 -0
- data/gemfiles/activerecord-6.1/Gemfile.sqlite3 +10 -0
- data/gemfiles/activerecord-7.0/Gemfile.base +4 -0
- data/gemfiles/activerecord-7.0/Gemfile.mysql2 +10 -0
- data/gemfiles/activerecord-7.0/Gemfile.postgresql +10 -0
- data/gemfiles/activerecord-7.0/Gemfile.sqlite3 +10 -0
- data/init.rb +2 -0
- data/lib/schema_validations/active_record/type.rb +2 -0
- data/lib/schema_validations/active_record/validations.rb +2 -0
- data/lib/schema_validations/railtie.rb +2 -0
- data/lib/schema_validations/validators/not_nil_validator.rb +11 -3
- data/lib/schema_validations/version.rb +3 -1
- data/lib/schema_validations.rb +2 -0
- data/schema_dev.yml +8 -3
- data/schema_validations.gemspec +23 -27
- data/spec/spec_helper.rb +16 -22
- data/spec/support/active_model.rb +2 -0
- data/spec/validations_spec.rb +32 -20
- metadata +45 -95
- data/.travis.yml +0 -21
- data/gemfiles/activerecord-4.2/Gemfile.base +0 -3
- data/gemfiles/activerecord-4.2/Gemfile.mysql2 +0 -10
- data/gemfiles/activerecord-4.2/Gemfile.postgresql +0 -10
- data/gemfiles/activerecord-5.0/Gemfile.base +0 -3
- data/gemfiles/activerecord-5.0/Gemfile.mysql2 +0 -10
- data/gemfiles/activerecord-5.0/Gemfile.postgresql +0 -10
- data/spec/schema_validations.sqlite3 +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2ab55b81e765e8fb52d2775cdc56d28457a8210770bd78037fc8a05a5c1e3fa0
|
4
|
+
data.tar.gz: a3871e40d193076ad1e8e3144407fa0a87eba01764c96e74d3f35ac8dc61a776
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 452d43d12d06516b2667f601e3b49536a2d4e866a61a9391e2f925cfbbd1ce94b503442fd2cdce092327a93b1ae42c35e789639946680873bd7741a1d105421f
|
7
|
+
data.tar.gz: cb34384da433ae3ddb1a1318b4ad514f72d1b00c2bf6d28a422051b9e872f3f7797c44b10b3333b5845922ef60fd9fe3a242c9b01e40f86c49a007f0dd076566
|
@@ -0,0 +1,173 @@
|
|
1
|
+
# This file was auto-generated by the schema_dev tool, based on the data in
|
2
|
+
# ./schema_dev.yml
|
3
|
+
# Please do not edit this file; any changes will be overwritten next time
|
4
|
+
# schema_dev gets run.
|
5
|
+
---
|
6
|
+
name: CI PR Builds
|
7
|
+
'on':
|
8
|
+
push:
|
9
|
+
branches:
|
10
|
+
- master
|
11
|
+
pull_request:
|
12
|
+
concurrency:
|
13
|
+
group: ci-${{ github.ref }}
|
14
|
+
cancel-in-progress: true
|
15
|
+
jobs:
|
16
|
+
test:
|
17
|
+
runs-on: ubuntu-latest
|
18
|
+
strategy:
|
19
|
+
fail-fast: false
|
20
|
+
matrix:
|
21
|
+
ruby:
|
22
|
+
- '2.5'
|
23
|
+
- '2.7'
|
24
|
+
- '3.0'
|
25
|
+
- '3.1'
|
26
|
+
activerecord:
|
27
|
+
- '5.2'
|
28
|
+
- '6.0'
|
29
|
+
- '6.1'
|
30
|
+
- '7.0'
|
31
|
+
db:
|
32
|
+
- mysql2
|
33
|
+
- sqlite3
|
34
|
+
- skip
|
35
|
+
dbversion:
|
36
|
+
- skip
|
37
|
+
exclude:
|
38
|
+
- ruby: '3.0'
|
39
|
+
activerecord: '5.2'
|
40
|
+
- ruby: '3.1'
|
41
|
+
activerecord: '5.2'
|
42
|
+
- ruby: '2.5'
|
43
|
+
activerecord: '7.0'
|
44
|
+
- db: skip
|
45
|
+
dbversion: skip
|
46
|
+
include:
|
47
|
+
- ruby: '2.5'
|
48
|
+
activerecord: '5.2'
|
49
|
+
db: postgresql
|
50
|
+
dbversion: '9.6'
|
51
|
+
- ruby: '2.5'
|
52
|
+
activerecord: '6.0'
|
53
|
+
db: postgresql
|
54
|
+
dbversion: '9.6'
|
55
|
+
- ruby: '2.5'
|
56
|
+
activerecord: '6.1'
|
57
|
+
db: postgresql
|
58
|
+
dbversion: '9.6'
|
59
|
+
- ruby: '2.7'
|
60
|
+
activerecord: '5.2'
|
61
|
+
db: postgresql
|
62
|
+
dbversion: '9.6'
|
63
|
+
- ruby: '2.7'
|
64
|
+
activerecord: '6.0'
|
65
|
+
db: postgresql
|
66
|
+
dbversion: '9.6'
|
67
|
+
- ruby: '2.7'
|
68
|
+
activerecord: '6.1'
|
69
|
+
db: postgresql
|
70
|
+
dbversion: '9.6'
|
71
|
+
- ruby: '2.7'
|
72
|
+
activerecord: '7.0'
|
73
|
+
db: postgresql
|
74
|
+
dbversion: '9.6'
|
75
|
+
- ruby: '3.0'
|
76
|
+
activerecord: '6.0'
|
77
|
+
db: postgresql
|
78
|
+
dbversion: '9.6'
|
79
|
+
- ruby: '3.0'
|
80
|
+
activerecord: '6.1'
|
81
|
+
db: postgresql
|
82
|
+
dbversion: '9.6'
|
83
|
+
- ruby: '3.0'
|
84
|
+
activerecord: '7.0'
|
85
|
+
db: postgresql
|
86
|
+
dbversion: '9.6'
|
87
|
+
- ruby: '3.1'
|
88
|
+
activerecord: '6.0'
|
89
|
+
db: postgresql
|
90
|
+
dbversion: '9.6'
|
91
|
+
- ruby: '3.1'
|
92
|
+
activerecord: '6.1'
|
93
|
+
db: postgresql
|
94
|
+
dbversion: '9.6'
|
95
|
+
- ruby: '3.1'
|
96
|
+
activerecord: '7.0'
|
97
|
+
db: postgresql
|
98
|
+
dbversion: '9.6'
|
99
|
+
env:
|
100
|
+
BUNDLE_GEMFILE: "${{ github.workspace }}/gemfiles/activerecord-${{ matrix.activerecord }}/Gemfile.${{ matrix.db }}"
|
101
|
+
MYSQL_DB_HOST: 127.0.0.1
|
102
|
+
MYSQL_DB_USER: root
|
103
|
+
MYSQL_DB_PASS: database
|
104
|
+
POSTGRESQL_DB_HOST: 127.0.0.1
|
105
|
+
POSTGRESQL_DB_USER: schema_plus_test
|
106
|
+
POSTGRESQL_DB_PASS: database
|
107
|
+
steps:
|
108
|
+
- uses: actions/checkout@v2
|
109
|
+
- name: Set up Ruby
|
110
|
+
uses: ruby/setup-ruby@v1
|
111
|
+
with:
|
112
|
+
ruby-version: "${{ matrix.ruby }}"
|
113
|
+
bundler-cache: true
|
114
|
+
- name: Run bundle update
|
115
|
+
run: bundle update
|
116
|
+
- name: Start Mysql
|
117
|
+
if: matrix.db == 'mysql2'
|
118
|
+
run: |
|
119
|
+
docker run --rm --detach \
|
120
|
+
-e MYSQL_ROOT_PASSWORD=$MYSQL_DB_PASS \
|
121
|
+
-p 3306:3306 \
|
122
|
+
--health-cmd "mysqladmin ping --host=127.0.0.1 --password=$MYSQL_DB_PASS --silent" \
|
123
|
+
--health-interval 5s \
|
124
|
+
--health-timeout 5s \
|
125
|
+
--health-retries 5 \
|
126
|
+
--name database mysql:5.6
|
127
|
+
- name: Start Postgresql
|
128
|
+
if: matrix.db == 'postgresql'
|
129
|
+
run: |
|
130
|
+
docker run --rm --detach \
|
131
|
+
-e POSTGRES_USER=$POSTGRESQL_DB_USER \
|
132
|
+
-e POSTGRES_PASSWORD=$POSTGRESQL_DB_PASS \
|
133
|
+
-p 5432:5432 \
|
134
|
+
--health-cmd "pg_isready -q" \
|
135
|
+
--health-interval 5s \
|
136
|
+
--health-timeout 5s \
|
137
|
+
--health-retries 5 \
|
138
|
+
--name database postgres:${{ matrix.dbversion }}
|
139
|
+
- name: Wait for database to start
|
140
|
+
if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
|
141
|
+
run: |
|
142
|
+
COUNT=0
|
143
|
+
ATTEMPTS=20
|
144
|
+
until [[ $COUNT -eq $ATTEMPTS ]]; do
|
145
|
+
[ "$(docker inspect -f {{.State.Health.Status}} database)" == "healthy" ] && break
|
146
|
+
echo $(( COUNT++ )) > /dev/null
|
147
|
+
sleep 2
|
148
|
+
done
|
149
|
+
- name: Create testing database
|
150
|
+
if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
|
151
|
+
run: bundle exec rake create_ci_database
|
152
|
+
- name: Run tests
|
153
|
+
run: bundle exec rake spec
|
154
|
+
- name: Shutdown database
|
155
|
+
if: always() && (matrix.db == 'postgresql' || matrix.db == 'mysql2')
|
156
|
+
run: docker stop database
|
157
|
+
- name: Coveralls Parallel
|
158
|
+
if: "${{ !env.ACT }}"
|
159
|
+
uses: coverallsapp/github-action@master
|
160
|
+
with:
|
161
|
+
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
162
|
+
flag-name: run-${{ matrix.ruby }}-${{ matrix.activerecord }}-${{ matrix.db }}-${{ matrix.dbversion }}
|
163
|
+
parallel: true
|
164
|
+
finish:
|
165
|
+
needs: test
|
166
|
+
runs-on: ubuntu-latest
|
167
|
+
steps:
|
168
|
+
- name: Coveralls Finished
|
169
|
+
if: "${{ !env.ACT }}"
|
170
|
+
uses: coverallsapp/github-action@master
|
171
|
+
with:
|
172
|
+
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
173
|
+
parallel-finished: true
|
data/.gitignore
CHANGED
data/.simplecov
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
SimpleCov.configure do
|
4
|
+
enable_coverage :branch
|
5
|
+
add_filter '/spec/'
|
6
|
+
|
7
|
+
add_group 'Binaries', '/bin/'
|
8
|
+
add_group 'Libraries', '/lib/'
|
9
|
+
|
10
|
+
if ENV['CI']
|
11
|
+
require 'simplecov-lcov'
|
12
|
+
|
13
|
+
SimpleCov::Formatter::LcovFormatter.config do |c|
|
14
|
+
c.report_with_single_file = true
|
15
|
+
c.single_report_path = 'coverage/lcov.info'
|
16
|
+
end
|
17
|
+
|
18
|
+
formatter SimpleCov::Formatter::LcovFormatter
|
19
|
+
end
|
20
|
+
end
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -5,8 +5,8 @@ definitions simpler and more DRY, by automatically defining validations based
|
|
5
5
|
on the database schema.
|
6
6
|
|
7
7
|
[![Gem Version](https://badge.fury.io/rb/schema_validations.svg)](http://badge.fury.io/rb/schema_validations)
|
8
|
-
[![Build Status](https://
|
9
|
-
[![Coverage Status](https://coveralls.io/
|
8
|
+
[![Build Status](https://github.com/SchemaPlus/schema_validations/actions/workflows/pr.yml/badge.svg)](http://github.com/SchemaPlus/schema_validations/actions)
|
9
|
+
[![Coverage Status](https://coveralls.io/github/SchemaPlus/schema_validations/badge.svg)](https://coveralls.io/github/SchemaPlus/schema_validations)
|
10
10
|
|
11
11
|
|
12
12
|
## Overview
|
@@ -174,8 +174,19 @@ As of version 1.2.0, SchemaValidations supports and is tested on:
|
|
174
174
|
|
175
175
|
<!-- SCHEMA_DEV: MATRIX - begin -->
|
176
176
|
<!-- These lines are auto-generated by schema_dev based on schema_dev.yml -->
|
177
|
-
* ruby **2.
|
178
|
-
* ruby **2.
|
177
|
+
* ruby **2.5** with activerecord **5.2**, using **mysql2**, **postgresql:9.6** or **sqlite3**
|
178
|
+
* ruby **2.5** with activerecord **6.0**, using **mysql2**, **postgresql:9.6** or **sqlite3**
|
179
|
+
* ruby **2.5** with activerecord **6.1**, using **mysql2**, **postgresql:9.6** or **sqlite3**
|
180
|
+
* ruby **2.7** with activerecord **5.2**, using **mysql2**, **postgresql:9.6** or **sqlite3**
|
181
|
+
* ruby **2.7** with activerecord **6.0**, using **mysql2**, **postgresql:9.6** or **sqlite3**
|
182
|
+
* ruby **2.7** with activerecord **6.1**, using **mysql2**, **postgresql:9.6** or **sqlite3**
|
183
|
+
* ruby **2.7** with activerecord **7.0**, using **mysql2**, **postgresql:9.6** or **sqlite3**
|
184
|
+
* ruby **3.0** with activerecord **6.0**, using **mysql2**, **postgresql:9.6** or **sqlite3**
|
185
|
+
* ruby **3.0** with activerecord **6.1**, using **mysql2**, **postgresql:9.6** or **sqlite3**
|
186
|
+
* ruby **3.0** with activerecord **7.0**, using **mysql2**, **postgresql:9.6** or **sqlite3**
|
187
|
+
* ruby **3.1** with activerecord **6.0**, using **mysql2**, **postgresql:9.6** or **sqlite3**
|
188
|
+
* ruby **3.1** with activerecord **6.1**, using **mysql2**, **postgresql:9.6** or **sqlite3**
|
189
|
+
* ruby **3.1** with activerecord **7.0**, using **mysql2**, **postgresql:9.6** or **sqlite3**
|
179
190
|
|
180
191
|
<!-- SCHEMA_DEV: MATRIX - end -->
|
181
192
|
|
@@ -187,6 +198,23 @@ Earlier versions of SchemaValidations supported:
|
|
187
198
|
|
188
199
|
## Release Notes
|
189
200
|
|
201
|
+
### 2.4.1
|
202
|
+
|
203
|
+
* Add AR 6.1 and 7.0
|
204
|
+
* add ruby 3.1
|
205
|
+
|
206
|
+
### 2.4.0
|
207
|
+
|
208
|
+
* Add AR 6.0
|
209
|
+
* Add Ruby 3.0
|
210
|
+
* Remove support for AR < 5.2
|
211
|
+
* Remove support for Ruby < 2.5
|
212
|
+
|
213
|
+
### 2.3.0
|
214
|
+
|
215
|
+
* Works with AR 5.1.
|
216
|
+
* No longer testing rails 4.2
|
217
|
+
|
190
218
|
### 2.2.1
|
191
219
|
|
192
220
|
* Bug fix: don't create presence validation for `null: false` with a
|
@@ -278,7 +306,7 @@ Some things to know about to help you develop and test:
|
|
278
306
|
* **schema_dev**: SchemaValidations uses [schema_dev](https://github.com/SchemaPlus/schema_dev) to
|
279
307
|
facilitate running rspec tests on the matrix of ruby, activerecord, and database
|
280
308
|
versions that the gem supports, both locally and on
|
281
|
-
[
|
309
|
+
[github actions](https://github.com/SchemaPlus/schema_validations/actions)
|
282
310
|
|
283
311
|
To to run rspec locally on the full matrix, do:
|
284
312
|
|
@@ -290,7 +318,6 @@ Some things to know about to help you develop and test:
|
|
290
318
|
The matrix of configurations is specified in `schema_dev.yml` in
|
291
319
|
the project root.
|
292
320
|
|
293
|
-
|
294
321
|
<!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_DEV - end -->
|
295
322
|
|
296
323
|
Code coverage results will be in coverage/index.html -- it should be at 100% coverage.
|
data/Rakefile
CHANGED
data/gemfiles/Gemfile.base
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
eval
|
1
|
+
base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
|
2
|
+
eval File.read(base_gemfile), binding, base_gemfile
|
3
3
|
|
4
4
|
platform :ruby do
|
5
5
|
gem "sqlite3"
|
@@ -7,4 +7,4 @@ end
|
|
7
7
|
|
8
8
|
platform :jruby do
|
9
9
|
gem 'activerecord-jdbcsqlite3-adapter', '>=1.3.0.beta2'
|
10
|
-
end
|
10
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
eval
|
1
|
+
base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
|
2
|
+
eval File.read(base_gemfile), binding, base_gemfile
|
3
3
|
|
4
4
|
platform :ruby do
|
5
5
|
gem "sqlite3"
|
@@ -7,4 +7,4 @@ end
|
|
7
7
|
|
8
8
|
platform :jruby do
|
9
9
|
gem 'activerecord-jdbcsqlite3-adapter', '>=1.3.0.beta2'
|
10
|
-
end
|
10
|
+
end
|
data/init.rb
CHANGED
@@ -1,11 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SchemaValidations
|
2
4
|
module Validators
|
3
5
|
# Validates that the field is not nil?
|
4
6
|
# (Unlike the standard PresenceValidator which uses #blank?)
|
5
7
|
class NotNilValidator < ActiveModel::EachValidator
|
6
|
-
|
7
|
-
record
|
8
|
+
if Gem::Version.new(::ActiveRecord::VERSION::STRING) < Gem::Version.new('6.1')
|
9
|
+
def validate_each(record, attr_name, value)
|
10
|
+
record.errors.add(attr_name, :blank, options) if value.nil?
|
11
|
+
end
|
12
|
+
else
|
13
|
+
def validate_each(record, attr_name, value)
|
14
|
+
record.errors.add(attr_name, :blank, **options) if value.nil?
|
15
|
+
end
|
8
16
|
end
|
9
17
|
end
|
10
18
|
end
|
11
|
-
end
|
19
|
+
end
|
data/lib/schema_validations.rb
CHANGED
data/schema_dev.yml
CHANGED
data/schema_validations.gemspec
CHANGED
@@ -1,35 +1,31 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
$:.push File.expand_path("../lib", __FILE__)
|
3
4
|
require "schema_validations/version"
|
4
5
|
|
5
|
-
Gem::Specification.new do |
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "schema_validations"
|
8
|
+
gem.version = SchemaValidations::VERSION
|
9
|
+
gem.platform = Gem::Platform::RUBY
|
10
|
+
gem.authors = ["Ronen Barzel", "Michał Łomnicki"]
|
11
|
+
gem.email = ["ronen@barzel.org", "michal.lomnicki@gmail.com"]
|
12
|
+
gem.homepage = "https://github.com/SchemaPlus/schema_validations"
|
13
|
+
gem.summary = "Automatically creates validations basing on the database schema."
|
14
|
+
gem.description = "SchemaValidations extends ActiveRecord to automatically create validations by inspecting the database schema. This makes your models more DRY as you no longer need to duplicate NOT NULL, unique, numeric and varchar constraints on the model level."
|
15
|
+
gem.license = 'MIT'
|
15
16
|
|
16
|
-
|
17
|
+
gem.files = `git ls-files`.split("\n")
|
18
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
gem.require_paths = ["lib"]
|
17
21
|
|
18
|
-
|
19
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
-
s.require_paths = ["lib"]
|
22
|
+
gem.required_ruby_version = '>= 2.5'
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
gem.add_dependency 'schema_plus_columns', '~> 1.0.1'
|
25
|
+
gem.add_dependency 'activerecord', '>= 5.2', '< 7.1'
|
26
|
+
gem.add_dependency 'valuable'
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
s.add_development_dependency("rspec")
|
31
|
-
s.add_development_dependency("simplecov")
|
32
|
-
s.add_development_dependency("simplecov-gem-profile")
|
33
|
-
s.add_development_dependency("database_cleaner")
|
28
|
+
gem.add_development_dependency 'rake', '~> 13.0'
|
29
|
+
gem.add_development_dependency 'rspec', '~> 3.0'
|
30
|
+
gem.add_development_dependency 'schema_dev', '~> 4.2.0'
|
34
31
|
end
|
35
|
-
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'simplecov'
|
2
|
-
|
3
|
-
SimpleCov.start "gem"
|
4
|
+
SimpleCov.start unless SimpleCov.running
|
4
5
|
|
5
6
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
7
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
@@ -9,26 +10,17 @@ require 'rspec'
|
|
9
10
|
require 'active_record'
|
10
11
|
require 'schema_validations'
|
11
12
|
require 'schema_dev/rspec'
|
12
|
-
require 'database_cleaner'
|
13
|
-
DatabaseCleaner.strategy = :truncation
|
14
13
|
|
15
14
|
SchemaDev::Rspec.setup
|
16
15
|
|
17
16
|
RSpec.configure do |config|
|
18
17
|
config.around(:each) do |example|
|
19
|
-
DatabaseCleaner.clean
|
20
|
-
remove_all_models
|
21
|
-
|
22
|
-
class ActiveRecord::InternalMetadata
|
23
|
-
def self.create_table
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.[]=(first, second)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
18
|
ActiveRecord::Migration.suppress_messages do
|
31
19
|
example.run
|
20
|
+
ensure
|
21
|
+
ActiveRecord::Base.connection.tables.each do |table|
|
22
|
+
ActiveRecord::Migration.drop_table table, force: :cascade
|
23
|
+
end
|
32
24
|
end
|
33
25
|
end
|
34
26
|
end
|
@@ -36,14 +28,16 @@ end
|
|
36
28
|
# avoid deprecation warnings
|
37
29
|
I18n.enforce_available_locales = true
|
38
30
|
|
39
|
-
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
|
31
|
+
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each { |f| require f }
|
40
32
|
|
41
|
-
def
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
33
|
+
def define_schema(config={}, &block)
|
34
|
+
ActiveRecord::Migration.suppress_messages do
|
35
|
+
ActiveRecord::Schema.define do
|
36
|
+
connection.tables.each do |table|
|
37
|
+
drop_table table, force: :cascade
|
38
|
+
end
|
39
|
+
instance_eval &block
|
40
|
+
end
|
47
41
|
end
|
48
42
|
end
|
49
43
|
|
data/spec/validations_spec.rb
CHANGED
@@ -1,9 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
4
|
|
3
5
|
describe "Validations" do
|
6
|
+
def stub_model(name, base = ActiveRecord::Base, &block)
|
7
|
+
klass = Class.new(base)
|
8
|
+
|
9
|
+
if block_given?
|
10
|
+
klass.instance_eval(&block)
|
11
|
+
end
|
12
|
+
|
13
|
+
stub_const(name, klass)
|
14
|
+
end
|
4
15
|
|
5
16
|
before(:each) do
|
6
|
-
|
17
|
+
define_schema do
|
7
18
|
|
8
19
|
create_table :articles, force: true do |t|
|
9
20
|
t.string :title, limit: 50
|
@@ -39,15 +50,15 @@ describe "Validations" do
|
|
39
50
|
context "auto-created" do
|
40
51
|
before(:each) do
|
41
52
|
with_auto_validations do
|
42
|
-
|
53
|
+
stub_model('Article')
|
43
54
|
|
44
|
-
|
55
|
+
stub_model('Review') do
|
45
56
|
belongs_to :article
|
46
57
|
belongs_to :news_article, class_name: 'Article', foreign_key: :article_id
|
47
58
|
schema_validations except: :content
|
48
59
|
end
|
49
60
|
|
50
|
-
|
61
|
+
stub_model('ArticleReview') do
|
51
62
|
belongs_to :article
|
52
63
|
belongs_to :review
|
53
64
|
end
|
@@ -185,7 +196,7 @@ describe "Validations" do
|
|
185
196
|
end
|
186
197
|
end
|
187
198
|
with_auto_validations do
|
188
|
-
|
199
|
+
stub_model('AntiNull') do
|
189
200
|
def self.all_blank
|
190
201
|
@all_blank ||= AntiNull.new(
|
191
202
|
no_default: '',
|
@@ -242,8 +253,8 @@ describe "Validations" do
|
|
242
253
|
context "auto-created but changed" do
|
243
254
|
before(:each) do
|
244
255
|
with_auto_validations do
|
245
|
-
|
246
|
-
|
256
|
+
stub_model('Article')
|
257
|
+
stub_model('Review') do
|
247
258
|
belongs_to :article
|
248
259
|
belongs_to :news_article, class_name: 'Article', foreign_key: :article_id
|
249
260
|
end
|
@@ -312,7 +323,8 @@ describe "Validations" do
|
|
312
323
|
end
|
313
324
|
|
314
325
|
before(:each) do
|
315
|
-
|
326
|
+
stub_model('Article')
|
327
|
+
stub_model('Review') do
|
316
328
|
belongs_to :article
|
317
329
|
belongs_to :news_article, class_name: 'Article', foreign_key: :article_id
|
318
330
|
end
|
@@ -337,10 +349,10 @@ describe "Validations" do
|
|
337
349
|
|
338
350
|
context "manually invoked" do
|
339
351
|
before(:each) do
|
340
|
-
|
352
|
+
stub_model('Article')
|
341
353
|
Article.schema_validations only: [:title, :state]
|
342
354
|
|
343
|
-
|
355
|
+
stub_model('Review') do
|
344
356
|
belongs_to :dummy_association
|
345
357
|
schema_validations except: :content
|
346
358
|
end
|
@@ -376,7 +388,7 @@ describe "Validations" do
|
|
376
388
|
|
377
389
|
context "manually invoked" do
|
378
390
|
before(:each) do
|
379
|
-
|
391
|
+
stub_model('Review') do
|
380
392
|
belongs_to :article
|
381
393
|
end
|
382
394
|
@columns = Review.content_columns.dup
|
@@ -397,16 +409,16 @@ describe "Validations" do
|
|
397
409
|
around(:each) { |example| with_auto_validations(&example) }
|
398
410
|
|
399
411
|
it "should set validations on base class" do
|
400
|
-
|
401
|
-
|
412
|
+
stub_model('Review')
|
413
|
+
stub_model('PremiumReview', Review)
|
402
414
|
PremiumReview.new
|
403
415
|
expect(Review.new.error_on(:author).size).to eq(1)
|
404
416
|
end
|
405
417
|
|
406
418
|
it "shouldn't create doubled validations" do
|
407
|
-
|
419
|
+
stub_model('Review')
|
408
420
|
Review.new
|
409
|
-
|
421
|
+
stub_model('PremiumReview', Review)
|
410
422
|
expect(PremiumReview.new.error_on(:author).size).to eq(1)
|
411
423
|
end
|
412
424
|
|
@@ -414,7 +426,7 @@ describe "Validations" do
|
|
414
426
|
|
415
427
|
context "when used with enum" do
|
416
428
|
it "does not validate numericality" do
|
417
|
-
|
429
|
+
stub_model('Article') do
|
418
430
|
enum state: [:happy, :sad]
|
419
431
|
end
|
420
432
|
expect(Article.new(valid_article_attributes.merge(state: :happy))).to be_valid
|
@@ -437,7 +449,7 @@ describe "Validations" do
|
|
437
449
|
end
|
438
450
|
|
439
451
|
with_auto_validations do
|
440
|
-
|
452
|
+
stub_model('Book') do; end
|
441
453
|
end
|
442
454
|
end
|
443
455
|
|
@@ -462,8 +474,8 @@ describe "Validations" do
|
|
462
474
|
end
|
463
475
|
|
464
476
|
with_auto_validations do
|
465
|
-
|
466
|
-
belongs_to :parent, class_name: Folder
|
477
|
+
stub_model('Folder') do
|
478
|
+
belongs_to :parent, class_name: 'Folder'
|
467
479
|
end
|
468
480
|
end
|
469
481
|
end
|
@@ -487,7 +499,7 @@ describe "Validations" do
|
|
487
499
|
end
|
488
500
|
end
|
489
501
|
with_auto_validations do
|
490
|
-
|
502
|
+
stub_model('Optimistic') do; end
|
491
503
|
end
|
492
504
|
end
|
493
505
|
it 'should not crash' do
|
metadata
CHANGED
@@ -1,50 +1,50 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ronen Barzel
|
8
8
|
- Michał Łomnicki
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-06-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: schema_plus_columns
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 1.0.1
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - "
|
25
|
+
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 1.0.1
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: activerecord
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: '5.2'
|
35
35
|
- - "<"
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: '
|
37
|
+
version: '7.1'
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|
42
42
|
- - ">="
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version:
|
44
|
+
version: '5.2'
|
45
45
|
- - "<"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '7.1'
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: valuable
|
50
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -60,103 +60,47 @@ dependencies:
|
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
63
|
+
name: rake
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '13.0'
|
69
69
|
type: :development
|
70
70
|
prerelease: false
|
71
71
|
version_requirements: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
76
|
-
- !ruby/object:Gem::Dependency
|
77
|
-
name: rake
|
78
|
-
requirement: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
type: :development
|
84
|
-
prerelease: false
|
85
|
-
version_requirements: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
- !ruby/object:Gem::Dependency
|
91
|
-
name: rdoc
|
92
|
-
requirement: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
type: :development
|
98
|
-
prerelease: false
|
99
|
-
version_requirements: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
75
|
+
version: '13.0'
|
104
76
|
- !ruby/object:Gem::Dependency
|
105
77
|
name: rspec
|
106
78
|
requirement: !ruby/object:Gem::Requirement
|
107
79
|
requirements:
|
108
|
-
- - "
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
type: :development
|
112
|
-
prerelease: false
|
113
|
-
version_requirements: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
- !ruby/object:Gem::Dependency
|
119
|
-
name: simplecov
|
120
|
-
requirement: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
|
-
type: :development
|
126
|
-
prerelease: false
|
127
|
-
version_requirements: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - ">="
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0'
|
132
|
-
- !ruby/object:Gem::Dependency
|
133
|
-
name: simplecov-gem-profile
|
134
|
-
requirement: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - ">="
|
80
|
+
- - "~>"
|
137
81
|
- !ruby/object:Gem::Version
|
138
|
-
version: '0'
|
82
|
+
version: '3.0'
|
139
83
|
type: :development
|
140
84
|
prerelease: false
|
141
85
|
version_requirements: !ruby/object:Gem::Requirement
|
142
86
|
requirements:
|
143
|
-
- - "
|
87
|
+
- - "~>"
|
144
88
|
- !ruby/object:Gem::Version
|
145
|
-
version: '0'
|
89
|
+
version: '3.0'
|
146
90
|
- !ruby/object:Gem::Dependency
|
147
|
-
name:
|
91
|
+
name: schema_dev
|
148
92
|
requirement: !ruby/object:Gem::Requirement
|
149
93
|
requirements:
|
150
|
-
- - "
|
94
|
+
- - "~>"
|
151
95
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
96
|
+
version: 4.2.0
|
153
97
|
type: :development
|
154
98
|
prerelease: false
|
155
99
|
version_requirements: !ruby/object:Gem::Requirement
|
156
100
|
requirements:
|
157
|
-
- - "
|
101
|
+
- - "~>"
|
158
102
|
- !ruby/object:Gem::Version
|
159
|
-
version:
|
103
|
+
version: 4.2.0
|
160
104
|
description: SchemaValidations extends ActiveRecord to automatically create validations
|
161
105
|
by inspecting the database schema. This makes your models more DRY as you no longer
|
162
106
|
need to duplicate NOT NULL, unique, numeric and varchar constraints on the model
|
@@ -168,21 +112,30 @@ executables: []
|
|
168
112
|
extensions: []
|
169
113
|
extra_rdoc_files: []
|
170
114
|
files:
|
115
|
+
- ".github/workflows/prs.yml"
|
171
116
|
- ".gitignore"
|
172
|
-
- ".
|
117
|
+
- ".simplecov"
|
173
118
|
- Gemfile
|
174
119
|
- MIT-LICENSE
|
175
120
|
- README.md
|
176
121
|
- Rakefile
|
177
122
|
- gemfiles/Gemfile.base
|
178
|
-
- gemfiles/activerecord-
|
179
|
-
- gemfiles/activerecord-
|
180
|
-
- gemfiles/activerecord-
|
181
|
-
- gemfiles/activerecord-
|
182
|
-
- gemfiles/activerecord-
|
183
|
-
- gemfiles/activerecord-
|
184
|
-
- gemfiles/activerecord-
|
185
|
-
- gemfiles/activerecord-
|
123
|
+
- gemfiles/activerecord-5.2/Gemfile.base
|
124
|
+
- gemfiles/activerecord-5.2/Gemfile.mysql2
|
125
|
+
- gemfiles/activerecord-5.2/Gemfile.postgresql
|
126
|
+
- gemfiles/activerecord-5.2/Gemfile.sqlite3
|
127
|
+
- gemfiles/activerecord-6.0/Gemfile.base
|
128
|
+
- gemfiles/activerecord-6.0/Gemfile.mysql2
|
129
|
+
- gemfiles/activerecord-6.0/Gemfile.postgresql
|
130
|
+
- gemfiles/activerecord-6.0/Gemfile.sqlite3
|
131
|
+
- gemfiles/activerecord-6.1/Gemfile.base
|
132
|
+
- gemfiles/activerecord-6.1/Gemfile.mysql2
|
133
|
+
- gemfiles/activerecord-6.1/Gemfile.postgresql
|
134
|
+
- gemfiles/activerecord-6.1/Gemfile.sqlite3
|
135
|
+
- gemfiles/activerecord-7.0/Gemfile.base
|
136
|
+
- gemfiles/activerecord-7.0/Gemfile.mysql2
|
137
|
+
- gemfiles/activerecord-7.0/Gemfile.postgresql
|
138
|
+
- gemfiles/activerecord-7.0/Gemfile.sqlite3
|
186
139
|
- init.rb
|
187
140
|
- lib/schema_validations.rb
|
188
141
|
- lib/schema_validations/active_record/type.rb
|
@@ -192,7 +145,6 @@ files:
|
|
192
145
|
- lib/schema_validations/version.rb
|
193
146
|
- schema_dev.yml
|
194
147
|
- schema_validations.gemspec
|
195
|
-
- spec/schema_validations.sqlite3
|
196
148
|
- spec/spec_helper.rb
|
197
149
|
- spec/support/active_model.rb
|
198
150
|
- spec/validations_spec.rb
|
@@ -200,7 +152,7 @@ homepage: https://github.com/SchemaPlus/schema_validations
|
|
200
152
|
licenses:
|
201
153
|
- MIT
|
202
154
|
metadata: {}
|
203
|
-
post_install_message:
|
155
|
+
post_install_message:
|
204
156
|
rdoc_options: []
|
205
157
|
require_paths:
|
206
158
|
- lib
|
@@ -208,20 +160,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
208
160
|
requirements:
|
209
161
|
- - ">="
|
210
162
|
- !ruby/object:Gem::Version
|
211
|
-
version: '
|
163
|
+
version: '2.5'
|
212
164
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
213
165
|
requirements:
|
214
166
|
- - ">="
|
215
167
|
- !ruby/object:Gem::Version
|
216
168
|
version: '0'
|
217
169
|
requirements: []
|
218
|
-
|
219
|
-
|
220
|
-
signing_key:
|
170
|
+
rubygems_version: 3.1.6
|
171
|
+
signing_key:
|
221
172
|
specification_version: 4
|
222
173
|
summary: Automatically creates validations basing on the database schema.
|
223
174
|
test_files:
|
224
|
-
- spec/schema_validations.sqlite3
|
225
175
|
- spec/spec_helper.rb
|
226
176
|
- spec/support/active_model.rb
|
227
177
|
- spec/validations_spec.rb
|
data/.travis.yml
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# This file was auto-generated by the schema_dev tool, based on the data in
|
2
|
-
# ./schema_dev.yml
|
3
|
-
# Please do not edit this file; any changes will be overwritten next time
|
4
|
-
# schema_dev gets run.
|
5
|
-
---
|
6
|
-
sudo: false
|
7
|
-
rvm:
|
8
|
-
- 2.3.1
|
9
|
-
gemfile:
|
10
|
-
- gemfiles/activerecord-4.2/Gemfile.mysql2
|
11
|
-
- gemfiles/activerecord-4.2/Gemfile.postgresql
|
12
|
-
- gemfiles/activerecord-4.2/Gemfile.sqlite3
|
13
|
-
- gemfiles/activerecord-5.0/Gemfile.mysql2
|
14
|
-
- gemfiles/activerecord-5.0/Gemfile.postgresql
|
15
|
-
- gemfiles/activerecord-5.0/Gemfile.sqlite3
|
16
|
-
env: POSTGRESQL_DB_USER=postgres MYSQL_DB_USER=travis
|
17
|
-
addons:
|
18
|
-
postgresql: '9.4'
|
19
|
-
before_script: bundle exec rake create_databases
|
20
|
-
after_script: bundle exec rake drop_databases
|
21
|
-
script: bundle exec rake travis
|
Binary file
|