schema_validations 2.2.0 → 2.4.0
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 +134 -0
- data/.gitignore +1 -0
- data/.simplecov +20 -0
- data/.travis.yml +6 -3
- data/Gemfile +5 -0
- data/README.md +25 -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-5.0 → 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-4.2 → activerecord-6.0}/Gemfile.sqlite3 +3 -3
- data/init.rb +2 -0
- data/lib/schema_validations/active_record/type.rb +2 -0
- data/lib/schema_validations/active_record/validations.rb +8 -1
- data/lib/schema_validations/railtie.rb +2 -0
- data/lib/schema_validations/validators/not_nil_validator.rb +13 -0
- data/lib/schema_validations/version.rb +3 -1
- data/lib/schema_validations.rb +3 -0
- data/schema_dev.yml +5 -3
- data/schema_validations.gemspec +23 -27
- data/spec/spec_helper.rb +22 -18
- data/spec/support/active_model.rb +2 -0
- data/spec/validations_spec.rb +138 -73
- metadata +38 -94
- 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: 1b78d8982bebac58a973056eafde5936834ccca0d4c14d082ce4de1f077a9520
|
4
|
+
data.tar.gz: 929c35cc4a3d93b3442396ed13491b806c2d72915f2125bb16884e65ce4bca9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10650e92299fcb0d86a864587f50f8337bdac03972d195d46eff628ea6de22323c0ef1d0272e840fd8383f8c032413b47eda302dd56bae8cf0163786b4646a69
|
7
|
+
data.tar.gz: 89b78874b3d66ee0fcde0818677aa6cd00cee09d375e9121e016209c64c40be11e4005cf37ea2694c74810326cc34fc0688236b4e8794fab8fed24cf85d248e2
|
@@ -0,0 +1,134 @@
|
|
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
|
+
activerecord:
|
26
|
+
- '5.2'
|
27
|
+
- '6.0'
|
28
|
+
db:
|
29
|
+
- mysql2
|
30
|
+
- sqlite3
|
31
|
+
- skip
|
32
|
+
dbversion:
|
33
|
+
- skip
|
34
|
+
exclude:
|
35
|
+
- ruby: '3.0'
|
36
|
+
activerecord: '5.2'
|
37
|
+
- db: skip
|
38
|
+
dbversion: skip
|
39
|
+
include:
|
40
|
+
- ruby: '2.5'
|
41
|
+
activerecord: '5.2'
|
42
|
+
db: postgresql
|
43
|
+
dbversion: '9.6'
|
44
|
+
- ruby: '2.5'
|
45
|
+
activerecord: '6.0'
|
46
|
+
db: postgresql
|
47
|
+
dbversion: '9.6'
|
48
|
+
- ruby: '2.7'
|
49
|
+
activerecord: '5.2'
|
50
|
+
db: postgresql
|
51
|
+
dbversion: '9.6'
|
52
|
+
- ruby: '2.7'
|
53
|
+
activerecord: '6.0'
|
54
|
+
db: postgresql
|
55
|
+
dbversion: '9.6'
|
56
|
+
- ruby: '3.0'
|
57
|
+
activerecord: '6.0'
|
58
|
+
db: postgresql
|
59
|
+
dbversion: '9.6'
|
60
|
+
env:
|
61
|
+
BUNDLE_GEMFILE: "${{ github.workspace }}/gemfiles/activerecord-${{ matrix.activerecord }}/Gemfile.${{ matrix.db }}"
|
62
|
+
MYSQL_DB_HOST: 127.0.0.1
|
63
|
+
MYSQL_DB_USER: root
|
64
|
+
MYSQL_DB_PASS: database
|
65
|
+
POSTGRESQL_DB_HOST: 127.0.0.1
|
66
|
+
POSTGRESQL_DB_USER: schema_plus_test
|
67
|
+
POSTGRESQL_DB_PASS: database
|
68
|
+
steps:
|
69
|
+
- uses: actions/checkout@v2
|
70
|
+
- name: Set up Ruby
|
71
|
+
uses: ruby/setup-ruby@v1
|
72
|
+
with:
|
73
|
+
ruby-version: "${{ matrix.ruby }}"
|
74
|
+
bundler-cache: true
|
75
|
+
- name: Run bundle update
|
76
|
+
run: bundle update
|
77
|
+
- name: Start Mysql
|
78
|
+
if: matrix.db == 'mysql2'
|
79
|
+
run: |
|
80
|
+
docker run --rm --detach \
|
81
|
+
-e MYSQL_ROOT_PASSWORD=$MYSQL_DB_PASS \
|
82
|
+
-p 3306:3306 \
|
83
|
+
--health-cmd "mysqladmin ping --host=127.0.0.1 --password=$MYSQL_DB_PASS --silent" \
|
84
|
+
--health-interval 5s \
|
85
|
+
--health-timeout 5s \
|
86
|
+
--health-retries 5 \
|
87
|
+
--name database mysql:5.6
|
88
|
+
- name: Start Postgresql
|
89
|
+
if: matrix.db == 'postgresql'
|
90
|
+
run: |
|
91
|
+
docker run --rm --detach \
|
92
|
+
-e POSTGRES_USER=$POSTGRESQL_DB_USER \
|
93
|
+
-e POSTGRES_PASSWORD=$POSTGRESQL_DB_PASS \
|
94
|
+
-p 5432:5432 \
|
95
|
+
--health-cmd "pg_isready -q" \
|
96
|
+
--health-interval 5s \
|
97
|
+
--health-timeout 5s \
|
98
|
+
--health-retries 5 \
|
99
|
+
--name database postgres:${{ matrix.dbversion }}
|
100
|
+
- name: Wait for database to start
|
101
|
+
if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
|
102
|
+
run: |
|
103
|
+
COUNT=0
|
104
|
+
ATTEMPTS=20
|
105
|
+
until [[ $COUNT -eq $ATTEMPTS ]]; do
|
106
|
+
[ "$(docker inspect -f {{.State.Health.Status}} database)" == "healthy" ] && break
|
107
|
+
echo $(( COUNT++ )) > /dev/null
|
108
|
+
sleep 2
|
109
|
+
done
|
110
|
+
- name: Create testing database
|
111
|
+
if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
|
112
|
+
run: bundle exec rake create_ci_database
|
113
|
+
- name: Run tests
|
114
|
+
run: bundle exec rake spec
|
115
|
+
- name: Shutdown database
|
116
|
+
if: always() && (matrix.db == 'postgresql' || matrix.db == 'mysql2')
|
117
|
+
run: docker stop database
|
118
|
+
- name: Coveralls Parallel
|
119
|
+
if: "${{ !env.ACT }}"
|
120
|
+
uses: coverallsapp/github-action@master
|
121
|
+
with:
|
122
|
+
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
123
|
+
flag-name: run-${{ matrix.ruby }}-${{ matrix.activerecord }}-${{ matrix.db }}-${{ matrix.dbversion }}
|
124
|
+
parallel: true
|
125
|
+
finish:
|
126
|
+
needs: test
|
127
|
+
runs-on: ubuntu-latest
|
128
|
+
steps:
|
129
|
+
- name: Coveralls Finished
|
130
|
+
if: "${{ !env.ACT }}"
|
131
|
+
uses: coverallsapp/github-action@master
|
132
|
+
with:
|
133
|
+
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
134
|
+
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/.travis.yml
CHANGED
@@ -7,12 +7,15 @@ sudo: false
|
|
7
7
|
rvm:
|
8
8
|
- 2.3.1
|
9
9
|
gemfile:
|
10
|
-
- gemfiles/activerecord-4.2/Gemfile.mysql2
|
11
|
-
- gemfiles/activerecord-4.2/Gemfile.postgresql
|
12
|
-
- gemfiles/activerecord-4.2/Gemfile.sqlite3
|
13
10
|
- gemfiles/activerecord-5.0/Gemfile.mysql2
|
14
11
|
- gemfiles/activerecord-5.0/Gemfile.postgresql
|
15
12
|
- gemfiles/activerecord-5.0/Gemfile.sqlite3
|
13
|
+
- gemfiles/activerecord-5.1/Gemfile.mysql2
|
14
|
+
- gemfiles/activerecord-5.1/Gemfile.postgresql
|
15
|
+
- gemfiles/activerecord-5.1/Gemfile.sqlite3
|
16
|
+
- gemfiles/activerecord-5.2/Gemfile.mysql2
|
17
|
+
- gemfiles/activerecord-5.2/Gemfile.postgresql
|
18
|
+
- gemfiles/activerecord-5.2/Gemfile.sqlite3
|
16
19
|
env: POSTGRESQL_DB_USER=postgres MYSQL_DB_USER=travis
|
17
20
|
addons:
|
18
21
|
postgresql: '9.4'
|
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,11 @@ 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.7** with activerecord **5.2**, using **mysql2**, **postgresql:9.6** or **sqlite3**
|
180
|
+
* ruby **2.7** with activerecord **6.0**, using **mysql2**, **postgresql:9.6** or **sqlite3**
|
181
|
+
* ruby **3.0** with activerecord **6.0**, using **mysql2**, **postgresql:9.6** or **sqlite3**
|
179
182
|
|
180
183
|
<!-- SCHEMA_DEV: MATRIX - end -->
|
181
184
|
|
@@ -187,6 +190,23 @@ Earlier versions of SchemaValidations supported:
|
|
187
190
|
|
188
191
|
## Release Notes
|
189
192
|
|
193
|
+
### 2.4.0
|
194
|
+
|
195
|
+
* Add AR 6.0
|
196
|
+
* Add Ruby 3.0
|
197
|
+
* Remove support for AR < 5.2
|
198
|
+
* Remove support for Ruby < 2.5
|
199
|
+
|
200
|
+
### 2.3.0
|
201
|
+
|
202
|
+
* Works with AR 5.1.
|
203
|
+
* No longer testing rails 4.2
|
204
|
+
|
205
|
+
### 2.2.1
|
206
|
+
|
207
|
+
* Bug fix: don't create presence validation for `null: false` with a
|
208
|
+
default defined (#18, #49)
|
209
|
+
|
190
210
|
### 2.2.0
|
191
211
|
|
192
212
|
* Works with AR 5.0. Thanks to [@plicjo](https://github.coms/plicjo).
|
@@ -273,7 +293,7 @@ Some things to know about to help you develop and test:
|
|
273
293
|
* **schema_dev**: SchemaValidations uses [schema_dev](https://github.com/SchemaPlus/schema_dev) to
|
274
294
|
facilitate running rspec tests on the matrix of ruby, activerecord, and database
|
275
295
|
versions that the gem supports, both locally and on
|
276
|
-
[
|
296
|
+
[github actions](https://github.com/SchemaPlus/schema_validations/actions)
|
277
297
|
|
278
298
|
To to run rspec locally on the full matrix, do:
|
279
299
|
|
@@ -285,7 +305,6 @@ Some things to know about to help you develop and test:
|
|
285
305
|
The matrix of configurations is specified in `schema_dev.yml` in
|
286
306
|
the project root.
|
287
307
|
|
288
|
-
|
289
308
|
<!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_DEV - end -->
|
290
309
|
|
291
310
|
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,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SchemaValidations
|
2
4
|
module ActiveRecord
|
3
5
|
module Base
|
@@ -123,7 +125,12 @@ module SchemaValidations
|
|
123
125
|
if datatype == :boolean
|
124
126
|
validate_logged :validates_inclusion_of, name, :in => [true, false], :message => :blank
|
125
127
|
else
|
126
|
-
|
128
|
+
if !column.default.nil? && column.default.blank?
|
129
|
+
validate_logged :validates_with, SchemaValidations::Validators::NotNilValidator, attributes: [name]
|
130
|
+
else
|
131
|
+
# Validate presence
|
132
|
+
validate_logged :validates_presence_of, name
|
133
|
+
end
|
127
134
|
end
|
128
135
|
end
|
129
136
|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SchemaValidations
|
4
|
+
module Validators
|
5
|
+
# Validates that the field is not nil?
|
6
|
+
# (Unlike the standard PresenceValidator which uses #blank?)
|
7
|
+
class NotNilValidator < ActiveModel::EachValidator
|
8
|
+
def validate_each(record, attr_name, value)
|
9
|
+
record.errors.add(attr_name, :blank, options) if value.nil?
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/schema_validations.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'valuable'
|
2
4
|
|
3
5
|
require 'schema_plus_columns'
|
4
6
|
require 'schema_validations/version'
|
7
|
+
require 'schema_validations/validators/not_nil_validator'
|
5
8
|
require 'schema_validations/active_record/validations'
|
6
9
|
require 'schema_validations/active_record/type'
|
7
10
|
|
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.0'
|
25
|
+
gem.add_dependency 'activerecord', '>= 5.2', '< 6.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.1'
|
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
|
4
5
|
|
5
6
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
7
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
@@ -9,26 +10,19 @@ 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
18
|
remove_all_models
|
21
19
|
|
22
|
-
class ActiveRecord::InternalMetadata
|
23
|
-
def self.create_table
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.[]=(first, second)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
20
|
ActiveRecord::Migration.suppress_messages do
|
31
21
|
example.run
|
22
|
+
ensure
|
23
|
+
ActiveRecord::Base.connection.tables.each do |table|
|
24
|
+
ActiveRecord::Migration.drop_table table, force: :cascade
|
25
|
+
end
|
32
26
|
end
|
33
27
|
end
|
34
28
|
end
|
@@ -36,15 +30,25 @@ end
|
|
36
30
|
# avoid deprecation warnings
|
37
31
|
I18n.enforce_available_locales = true
|
38
32
|
|
39
|
-
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
|
33
|
+
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each { |f| require f }
|
40
34
|
|
41
35
|
def remove_all_models
|
42
|
-
|
43
|
-
next
|
44
|
-
next if c == ActiveRecord::
|
45
|
-
next if c.name.blank?
|
36
|
+
ActiveRecord::Base.descendants.each do |c|
|
37
|
+
next if c == ActiveRecord::InternalMetadata
|
38
|
+
next if c == ActiveRecord::SchemaMigration
|
46
39
|
ActiveSupport::Dependencies.remove_constant c.name
|
47
40
|
end
|
48
41
|
end
|
49
42
|
|
43
|
+
def define_schema(config={}, &block)
|
44
|
+
ActiveRecord::Migration.suppress_messages do
|
45
|
+
ActiveRecord::Schema.define do
|
46
|
+
connection.tables.each do |table|
|
47
|
+
drop_table table, force: :cascade
|
48
|
+
end
|
49
|
+
instance_eval &block
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
50
54
|
SimpleCov.command_name "[Ruby #{RUBY_VERSION} - ActiveRecord #{::ActiveRecord::VERSION::STRING}]"
|