active_sanity 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +18 -0
- data/Gemfile +1 -0
- data/README.md +6 -5
- data/active_sanity.gemspec +2 -3
- data/features/check_sanity.feature +1 -1
- data/features/check_sanity_with_db_storage.feature +4 -4
- data/features/step_definitions/rails_app.rb +15 -6
- data/features/support/env.rb +1 -1
- data/lib/active_sanity/checker.rb +1 -1
- data/lib/active_sanity/version.rb +1 -1
- data/lib/generators/active_sanity/templates/create_invalid_records.rb.erb +3 -3
- metadata +21 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '0558af4db68be1d5ad7994453fee0a5abdfd3a79fd0e01417fa25afa7dc6ad98'
|
4
|
+
data.tar.gz: 7422349844512998be28691efc24d2211554a819f395cc39b0540d4edeedf398
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f825526ec0ee8c0a52ad40beef09c86cb5f64f7a8e61f2ed4beb01e1f22e56a97a77dfc4b7cf3368e147181f33b3829ad631bf9631d6b16fab12805ae11e493
|
7
|
+
data.tar.gz: bee1b677fd834b29b3b8edc1c573372b6de0a3db0b8edf2cf86a88c0ecdc7b89fbb0d576c17525c04fea54de13f8671e009c9f16472b846b1b6b6aa3e403fa1d
|
@@ -0,0 +1,18 @@
|
|
1
|
+
version: 2.1
|
2
|
+
orbs:
|
3
|
+
ruby: circleci/ruby@0.1.2
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
docker:
|
8
|
+
- image: circleci/ruby:2.6.3-stretch-node
|
9
|
+
executor: ruby/default
|
10
|
+
steps:
|
11
|
+
- checkout
|
12
|
+
- run:
|
13
|
+
name: Which bundler?
|
14
|
+
command: bundle -v
|
15
|
+
- ruby/bundle-install
|
16
|
+
- run:
|
17
|
+
name: cucumber
|
18
|
+
command: RAILS_ENV=test bundle exec cucumber
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
# Active Sanity
|
2
2
|
|
3
|
-
[![Build Status](https://
|
3
|
+
[![Build Status](https://circleci.com/gh/pcreux/active_sanity.svg?style=svg)](https://circleci.com/gh/pcreux/active_sanity)
|
4
4
|
|
5
5
|
Perform a sanity check on your database through active record
|
6
6
|
validation.
|
7
7
|
|
8
8
|
## Requirements
|
9
9
|
|
10
|
+
* ActiveSanity ~0.5 Rails ~5.0 or ~6.0
|
10
11
|
* ActiveSanity ~0.3 and ~0.4 requires Rails ~4.0
|
11
12
|
* ActiveSanity ~0.2 requires Rails ~3.1
|
12
13
|
* ActiveSanity ~0.1 requires Rails ~3.0
|
@@ -19,14 +20,14 @@ Add the following line to your Gemfile
|
|
19
20
|
|
20
21
|
If you wish to store invalid records in your database run:
|
21
22
|
|
22
|
-
$ rails generate active_sanity
|
23
|
-
$
|
23
|
+
$ bin/rails generate active_sanity
|
24
|
+
$ bin/rails db:migrate
|
24
25
|
|
25
26
|
## Usage
|
26
27
|
|
27
28
|
Just run:
|
28
29
|
|
29
|
-
|
30
|
+
bin/rails db:check_sanity
|
30
31
|
|
31
32
|
ActiveSanity will iterate over every records of all your models to check
|
32
33
|
whether they're valid or not. It will save invalid records in the table
|
@@ -62,7 +63,7 @@ This gem is quite simple so I experiment using features only. To run the
|
|
62
63
|
acceptance test suite, just run:
|
63
64
|
|
64
65
|
bundle install
|
65
|
-
RAILS_ENV=test cucumber features
|
66
|
+
RAILS_ENV=test bundle exec cucumber features
|
66
67
|
|
67
68
|
Using features only was kinda handsome until I had to deal with two
|
68
69
|
different database schema (with / without the table invalid_records) in
|
data/active_sanity.gemspec
CHANGED
@@ -12,10 +12,9 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.description = 'Performs a Sanity Check of your database by logging all invalid Active Records'
|
13
13
|
s.homepage = 'https://github.com/pcreux/active_sanity'
|
14
14
|
|
15
|
-
s.add_dependency 'rails', '
|
16
|
-
|
17
|
-
s.required_ruby_version = '>= 1.9.3'
|
15
|
+
s.add_dependency 'rails', '>=5.0'
|
18
16
|
|
17
|
+
s.add_development_dependency 'rails', '~>6.0'
|
19
18
|
s.add_development_dependency 'rspec', '~>3.1'
|
20
19
|
s.add_development_dependency 'cucumber', '~>1.3'
|
21
20
|
s.add_development_dependency 'sqlite3', '~>1.3'
|
@@ -23,7 +23,7 @@ Feature: Check sanity
|
|
23
23
|
When I run "rake db:check_sanity"
|
24
24
|
Then I should see the following invalid records:
|
25
25
|
| User | 1 | {:username=>["can't be blank", "is too short (minimum is 3 characters)"]} |
|
26
|
-
| Post | 1 | {:category=>["can't be blank"]} |
|
26
|
+
| Post | 1 | {:category=>["must exist", "can't be blank"]} |
|
27
27
|
|
28
28
|
Scenario: Check sanity on database with invalid records with ignored classes
|
29
29
|
Given the database contains a few valid records
|
@@ -23,7 +23,7 @@ Feature: Check sanity with db storage
|
|
23
23
|
When I run "rake db:check_sanity"
|
24
24
|
Then the table "invalid_records" should contain:
|
25
25
|
| User | 1 | {:username=>["can't be blank", "is too short (minimum is 3 characters)"]} |
|
26
|
-
| Post | 1 | {:category=>["can't be blank"]} |
|
26
|
+
| Post | 1 | {:category=>["must exist", "can't be blank"]} |
|
27
27
|
|
28
28
|
Scenario: Check sanity on database with invalid records now valid
|
29
29
|
Given the database contains a few valid records
|
@@ -31,12 +31,12 @@ Feature: Check sanity with db storage
|
|
31
31
|
When I run "rake db:check_sanity"
|
32
32
|
Then the table "invalid_records" should contain:
|
33
33
|
| User | 1 | {:username=>["can't be blank", "is too short (minimum is 3 characters)"]} |
|
34
|
-
| Post | 1 | {:category=>["can't be blank"]} |
|
34
|
+
| Post | 1 | {:category=>["must exist", "can't be blank"]} |
|
35
35
|
|
36
36
|
Given the first author's username is "Greg"
|
37
37
|
When I run "rake db:check_sanity"
|
38
38
|
Then the table "invalid_records" should contain:
|
39
|
-
| Post | 1 | {:category=>["can't be blank"]} |
|
39
|
+
| Post | 1 | {:category=>["must exist", "can't be blank"]} |
|
40
40
|
Then the table "invalid_records" should not contain errors for "User" "1"
|
41
41
|
|
42
42
|
Scenario: Check sanity on database with invalid records that were invalid for different reasons earlier
|
@@ -45,7 +45,7 @@ Feature: Check sanity with db storage
|
|
45
45
|
When I run "rake db:check_sanity"
|
46
46
|
Then the table "invalid_records" should contain:
|
47
47
|
| User | 1 | {:username=>["can't be blank", "is too short (minimum is 3 characters)"]} |
|
48
|
-
| Post | 1 | {:category=>["can't be blank"]} |
|
48
|
+
| Post | 1 | {:category=>["must exist", "can't be blank"]} |
|
49
49
|
|
50
50
|
Given the first post category is set
|
51
51
|
And the first post title is empty
|
@@ -1,10 +1,19 @@
|
|
1
|
+
SystemCommandFailed = Class.new(StandardError)
|
2
|
+
|
3
|
+
def system!(cmd)
|
4
|
+
system(cmd) || raise(SystemCommandFailed, cmd)
|
5
|
+
end
|
6
|
+
|
1
7
|
def setup_rails_app
|
2
8
|
return if File.directory?('test/rails_app')
|
3
9
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
10
|
+
system! 'bundle exec rails new test/rails_app --skip-sprockets --skip-spring --skip-javascript --skip-turbolinks'
|
11
|
+
system! 'cd ./test/rails_app && bundle'
|
12
|
+
system! 'cd ./test/rails_app && bin/rails app:template LOCATION=../rails_template.rb'
|
13
|
+
system!' cd ./test/rails_app && RAILS_ENV=test bin/rails db:migrate'
|
14
|
+
rescue SystemCommandFailed => e
|
15
|
+
system!('rm -fr test/rails_app')
|
16
|
+
raise e
|
8
17
|
end
|
9
18
|
|
10
19
|
Given /^I have a rails app using 'active_sanity'$/ do
|
@@ -29,14 +38,14 @@ Given /^I have a rails app using 'active_sanity' with db storage$/ do
|
|
29
38
|
|
30
39
|
# Reset connection
|
31
40
|
ActiveRecord::Base.connection.reconnect!
|
32
|
-
InvalidRecord.table_exists
|
41
|
+
InvalidRecord.table_exists?.should be true # Looks up if table exists.
|
33
42
|
end
|
34
43
|
|
35
44
|
Given /^the database contains a few valid records$/ do
|
36
45
|
Author.create!(first_name: 'Greg', last_name: 'Bell', username: 'gregbell')
|
37
46
|
Publisher.create!(first_name: 'Sam', last_name: 'Vincent', username: 'samvincent')
|
38
47
|
Category.create!(name: 'Uncategorized')
|
39
|
-
Post.create!(author: Author.first
|
48
|
+
Post.create!(author: Author.first!, category: Category.first!,
|
40
49
|
title: 'How ActiveAdmin changed the world', body: 'Lot of love.',
|
41
50
|
published_at: 4.years.from_now)
|
42
51
|
end
|
data/features/support/env.rb
CHANGED
@@ -6,7 +6,7 @@ Bundler.setup
|
|
6
6
|
|
7
7
|
if File.directory?('test/rails_app')
|
8
8
|
Dir.chdir('test/rails_app') do
|
9
|
-
fail unless system('rm -f db/migrate/*create_invalid_records.rb && RAILS_ENV=test
|
9
|
+
fail unless system('rm -f db/migrate/*create_invalid_records.rb && RAILS_ENV=test bin/rails db:drop db:create db:migrate')
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -112,7 +112,7 @@ module ActiveSanity
|
|
112
112
|
def store_invalid_record(record)
|
113
113
|
return unless InvalidRecord.table_exists?
|
114
114
|
|
115
|
-
invalid_record = InvalidRecord.where(
|
115
|
+
invalid_record = InvalidRecord.where(record: record).first
|
116
116
|
invalid_record ||= InvalidRecord.new
|
117
117
|
invalid_record.record = record
|
118
118
|
invalid_record.validation_errors = record.errors.messages
|
@@ -1,5 +1,5 @@
|
|
1
|
-
class CreateInvalidRecords < ActiveRecord::Migration<%=
|
2
|
-
def
|
1
|
+
class CreateInvalidRecords < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
|
2
|
+
def up
|
3
3
|
create_table :invalid_records do |t|
|
4
4
|
t.references :record, polymorphic: true, null: false
|
5
5
|
t.text :validation_errors
|
@@ -7,7 +7,7 @@ class CreateInvalidRecords < ActiveRecord::Migration<%= rails_version %>
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
10
|
+
def down
|
11
11
|
drop_table :invalid_records
|
12
12
|
end
|
13
13
|
end
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_sanity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Philippe Creux
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '5.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '6.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '6.0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,6 +88,7 @@ executables: []
|
|
74
88
|
extensions: []
|
75
89
|
extra_rdoc_files: []
|
76
90
|
files:
|
91
|
+
- ".circleci/config.yml"
|
77
92
|
- ".gitignore"
|
78
93
|
- ".rubocop.yml"
|
79
94
|
- CHANGELOG.md
|
@@ -106,15 +121,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
121
|
requirements:
|
107
122
|
- - ">="
|
108
123
|
- !ruby/object:Gem::Version
|
109
|
-
version:
|
124
|
+
version: '0'
|
110
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
126
|
requirements:
|
112
127
|
- - ">="
|
113
128
|
- !ruby/object:Gem::Version
|
114
129
|
version: '0'
|
115
130
|
requirements: []
|
116
|
-
|
117
|
-
rubygems_version: 2.4.5.1
|
131
|
+
rubygems_version: 3.0.3
|
118
132
|
signing_key:
|
119
133
|
specification_version: 4
|
120
134
|
summary: Checks Sanity of Active Record records
|