validb 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile +0 -4
- data/README.md +2 -1
- data/lib/tasks/validb.rake +6 -6
- data/lib/validb/batcher.rb +1 -1
- data/lib/validb/checker.rb +2 -2
- data/lib/validb/configuration.rb +11 -2
- data/lib/validb/console_logger.rb +1 -1
- data/lib/validb/finder.rb +2 -2
- data/lib/validb/model_filterer.rb +10 -10
- data/lib/validb/model_validator.rb +4 -3
- data/lib/validb/parameters.rb +3 -0
- data/lib/validb/version.rb +1 -1
- data/lib/validb.rb +1 -0
- data/spec/config/validb.json +2 -1
- data/spec/validb/batcher_spec.rb +1 -1
- data/spec/validb/checker_spec.rb +6 -4
- data/spec/validb/configuration_spec.rb +11 -25
- data/spec/validb/console_logger_spec.rb +1 -1
- data/spec/validb/finder_spec.rb +12 -12
- data/spec/validb/model_filterer_spec.rb +3 -3
- data/spec/validb/model_validator_spec.rb +6 -3
- data/spec/validb/version_spec.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e66a8a7fe86ed39a2a756c8bb8e62e302ee4576
|
4
|
+
data.tar.gz: fc47f3fc3335fd08755b95e3c57df02761d94cc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba05c70df13a9f8268bf6005106feb0e65a961c4a9bac37fb3c552e1b40961c0cc1a3c8a42afad6b2c40f34514385c1b685be12f270ab94cbd44fa02d83f5efa
|
7
|
+
data.tar.gz: 38ef49e1b9fa51db2646d07779038234125d893504d54220daa107396b6ecbbe3693c658cf4952f8bac6e2ec6d28027380152dbc14542d99137f3c8c895154bb
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 1.1.0, released 2013-03-28
|
2
|
+
* CHANGE: Don't check base models if we have decendants
|
3
|
+
* Parameter for the batch size
|
4
|
+
* Sort models to be validated
|
5
|
+
* Fix progress reporting output
|
6
|
+
* Show total model record count
|
7
|
+
* Show model table name
|
8
|
+
|
1
9
|
## 1.0.0, released 2013-03-27
|
2
10
|
* Add rake task to generate config file
|
3
11
|
* Allow filtering of unwanted models
|
data/Gemfile
CHANGED
data/README.md
CHANGED
data/lib/tasks/validb.rake
CHANGED
@@ -2,17 +2,17 @@ namespace :validb do
|
|
2
2
|
desc "Check DB for invalid records"
|
3
3
|
task :validate => :environment do
|
4
4
|
models = ENV["models"] || ""
|
5
|
-
|
5
|
+
logger_class = ENV["logger"] || "Validb::ConsoleLogger"
|
6
6
|
filename = ENV["config"] || default_configuration_file
|
7
7
|
|
8
8
|
# force all models to load so we can find them
|
9
9
|
Rails.application.eager_load!
|
10
10
|
|
11
|
-
|
12
|
-
finder = Validb::Finder.new(
|
11
|
+
params = Validb::Configuration.new(filename).params
|
12
|
+
finder = Validb::Finder.new(params, models)
|
13
13
|
|
14
|
-
|
15
|
-
checker = Validb::Checker.new(
|
14
|
+
logger = logger_class.constantize.new
|
15
|
+
checker = Validb::Checker.new(params, logger)
|
16
16
|
checker.check(finder.models)
|
17
17
|
end
|
18
18
|
|
@@ -31,7 +31,7 @@ namespace :validb do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def default_configuration
|
34
|
-
{ "ignored_models" => [], "ignored_prefixes" => [] }
|
34
|
+
{ "ignored_models" => [], "ignored_prefixes" => [], "batch_size" => 100 }
|
35
35
|
end
|
36
36
|
|
37
37
|
def write_configuration_file
|
data/lib/validb/batcher.rb
CHANGED
data/lib/validb/checker.rb
CHANGED
data/lib/validb/configuration.rb
CHANGED
@@ -6,6 +6,12 @@ module Validb
|
|
6
6
|
print_ignored
|
7
7
|
end
|
8
8
|
|
9
|
+
def params
|
10
|
+
Validb::Parameters.new(ignored_models, ignored_prefixes, batch_size)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
9
15
|
def ignored_models
|
10
16
|
convert_model_name_strings_to_constants
|
11
17
|
end
|
@@ -14,7 +20,9 @@ module Validb
|
|
14
20
|
config["ignored_prefixes"]
|
15
21
|
end
|
16
22
|
|
17
|
-
|
23
|
+
def batch_size
|
24
|
+
config["batch_size"]
|
25
|
+
end
|
18
26
|
|
19
27
|
def print_ignored
|
20
28
|
puts "Ignoring prefixes: #{ignored_prefixes.join(',')}" if ignored_prefixes.any?
|
@@ -28,7 +36,8 @@ module Validb
|
|
28
36
|
else
|
29
37
|
{
|
30
38
|
"ignored_models" => [],
|
31
|
-
"ignored_prefixes" => []
|
39
|
+
"ignored_prefixes" => [],
|
40
|
+
"batch_size" => 100
|
32
41
|
}
|
33
42
|
end
|
34
43
|
end
|
data/lib/validb/finder.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Validb
|
2
2
|
class Finder
|
3
3
|
|
4
|
-
def initialize(
|
5
|
-
@model_filterer = Validb::ModelFilterer.new(
|
4
|
+
def initialize(params, model_name_string)
|
5
|
+
@model_filterer = Validb::ModelFilterer.new(params)
|
6
6
|
@model_name_string = model_name_string || ""
|
7
7
|
end
|
8
8
|
|
@@ -1,25 +1,29 @@
|
|
1
1
|
module Validb
|
2
2
|
class ModelFilterer
|
3
3
|
|
4
|
-
def initialize(
|
5
|
-
@
|
4
|
+
def initialize(params)
|
5
|
+
@params = params
|
6
6
|
end
|
7
7
|
|
8
8
|
def filter(models)
|
9
9
|
filtered_models = validatable_models(models)
|
10
|
-
filtered_models = non_inherited_models(filtered_models)
|
11
10
|
filtered_models = non_ignored_models(filtered_models)
|
12
|
-
non_ignored_prefix_models(filtered_models)
|
11
|
+
filtered_models = non_ignored_prefix_models(filtered_models)
|
12
|
+
non_inherited_models(filtered_models).sort_by(&:name)
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
17
|
def ignored_models
|
18
|
-
@
|
18
|
+
@params.ignored_models
|
19
19
|
end
|
20
20
|
|
21
21
|
def ignored_prefixes
|
22
|
-
@
|
22
|
+
@params.ignored_prefixes
|
23
|
+
end
|
24
|
+
|
25
|
+
def non_inherited_models(models)
|
26
|
+
models.reject { |model| (models & model.descendants).any? }
|
23
27
|
end
|
24
28
|
|
25
29
|
def non_ignored_prefix_models(models)
|
@@ -32,10 +36,6 @@ module Validb
|
|
32
36
|
models - ignored_models
|
33
37
|
end
|
34
38
|
|
35
|
-
def non_inherited_models(models)
|
36
|
-
models.reject { |model| model != model.base_class && models.include?(model.base_class)}
|
37
|
-
end
|
38
|
-
|
39
39
|
def validatable_models(models)
|
40
40
|
models.select { |model| model.validators.any? }
|
41
41
|
end
|
@@ -1,13 +1,14 @@
|
|
1
1
|
module Validb
|
2
2
|
class ModelValidator
|
3
3
|
|
4
|
-
def initialize(logger)
|
4
|
+
def initialize(params, logger)
|
5
|
+
@params = params
|
5
6
|
@batcher = Validb::Batcher.new(logger)
|
6
7
|
end
|
7
8
|
|
8
9
|
def validate(model)
|
9
|
-
|
10
|
-
model.find_in_batches do |record_batch|
|
10
|
+
$stdout.print "\nChecking #{model}(#{model.table_name}) (#{model.count} records)."
|
11
|
+
model.find_in_batches(batch_size: @params.batch_size) do |record_batch|
|
11
12
|
@batcher.validate(record_batch)
|
12
13
|
end
|
13
14
|
end
|
data/lib/validb/version.rb
CHANGED
data/lib/validb.rb
CHANGED
data/spec/config/validb.json
CHANGED
data/spec/validb/batcher_spec.rb
CHANGED
data/spec/validb/checker_spec.rb
CHANGED
@@ -4,17 +4,19 @@ describe Validb::Checker do
|
|
4
4
|
describe "#initialize" do
|
5
5
|
it "creates a checker" do
|
6
6
|
logger = double('logger')
|
7
|
-
|
8
|
-
Validb::
|
7
|
+
params = double('params')
|
8
|
+
Validb::ModelValidator.should_receive(:new).with(params, logger)
|
9
|
+
Validb::Checker.new(params, logger)
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
12
13
|
describe "#check" do
|
13
14
|
it "validates the passed in models records" do
|
14
15
|
logger = double('logger')
|
16
|
+
params = double('params')
|
15
17
|
model_validator = double('model_validator')
|
16
|
-
Validb::ModelValidator.should_receive(:new).with(logger).and_return(model_validator)
|
17
|
-
checker = Validb::Checker.new(logger)
|
18
|
+
Validb::ModelValidator.should_receive(:new).with(params, logger).and_return(model_validator)
|
19
|
+
checker = Validb::Checker.new(params, logger)
|
18
20
|
|
19
21
|
model_validator.should_receive(:validate).with(Blog)
|
20
22
|
model_validator.should_receive(:validate).with(Post)
|
@@ -8,38 +8,24 @@ describe Validb::Configuration do
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
describe "#
|
11
|
+
describe "#params" do
|
12
12
|
context "with a missing configuration file" do
|
13
|
-
it "
|
13
|
+
it "creates a params" do
|
14
14
|
filename = File.expand_path(File.dirname(__FILE__) + '/../config/missing.json')
|
15
|
-
|
16
|
-
|
15
|
+
params = Validb::Configuration.new(filename).params
|
16
|
+
params.ignored_models.should == []
|
17
|
+
params.ignored_prefixes.should == []
|
18
|
+
params.batch_size.should == 100
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
22
|
context "with a configuration file" do
|
21
|
-
it "returns the
|
23
|
+
it "returns the batch size" do
|
22
24
|
filename = File.expand_path(File.dirname(__FILE__) + '/../config/validb.json')
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "#ignored_prefixes" do
|
30
|
-
context "with a missing configuration file" do
|
31
|
-
it "returns an empty array" do
|
32
|
-
filename = File.expand_path(File.dirname(__FILE__) + '/../config/missing.json')
|
33
|
-
configuration = Validb::Configuration.new(filename)
|
34
|
-
configuration.ignored_prefixes.should == []
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context "with a configuration file" do
|
39
|
-
it "returns the ignored models" do
|
40
|
-
filename = File.expand_path(File.dirname(__FILE__) + '/../config/validb.json')
|
41
|
-
configuration = Validb::Configuration.new(filename)
|
42
|
-
configuration.ignored_prefixes.should == ["Api"]
|
25
|
+
params = Validb::Configuration.new(filename).params
|
26
|
+
params.ignored_models.should == [Blog, Post]
|
27
|
+
params.ignored_prefixes.should == ["Api"]
|
28
|
+
params.batch_size.should == 200
|
43
29
|
end
|
44
30
|
end
|
45
31
|
end
|
@@ -6,7 +6,7 @@ describe Validb::ConsoleLogger do
|
|
6
6
|
hash = { model: Blog, id: 1, error_messages: "Error message" }
|
7
7
|
|
8
8
|
console_logger = Validb::ConsoleLogger.new
|
9
|
-
$stdout.should_receive(:puts).with("
|
9
|
+
$stdout.should_receive(:puts).with("\nBlog:1 - Error message")
|
10
10
|
console_logger.out(hash)
|
11
11
|
end
|
12
12
|
end
|
data/spec/validb/finder_spec.rb
CHANGED
@@ -6,34 +6,34 @@ describe Validb::Finder do
|
|
6
6
|
|
7
7
|
describe "#initialize" do
|
8
8
|
it "creates a model filterer" do
|
9
|
-
|
10
|
-
Validb::ModelFilterer.should_receive(:new).with(
|
11
|
-
Validb::Finder.new(
|
9
|
+
params = double('params')
|
10
|
+
Validb::ModelFilterer.should_receive(:new).with(params)
|
11
|
+
Validb::Finder.new(params, "")
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
describe "#models" do
|
16
16
|
context "with an empty string" do
|
17
17
|
it "returns all the models with tables" do
|
18
|
-
|
19
|
-
finder = Validb::Finder.new(
|
20
|
-
finder.models.should
|
18
|
+
params = Validb::Configuration.new("").params
|
19
|
+
finder = Validb::Finder.new(params, "")
|
20
|
+
finder.models.should == [Author, Blog, Comment, Post]
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
context "valid model names" do
|
25
25
|
it "returns all the selected models with tables" do
|
26
|
-
|
27
|
-
finder = Validb::Finder.new(
|
28
|
-
finder.models.should
|
26
|
+
params = Validb::Configuration.new("").params
|
27
|
+
finder = Validb::Finder.new(params, "Post, Blog")
|
28
|
+
finder.models.should == [Blog, Post]
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
context "with invalid model names" do
|
33
33
|
it "returns all the valid models with tables" do
|
34
|
-
|
35
|
-
finder = Validb::Finder.new(
|
36
|
-
finder.models.should
|
34
|
+
params = Validb::Configuration.new("").params
|
35
|
+
finder = Validb::Finder.new(params, "Post, Blog, Fake")
|
36
|
+
finder.models.should == [Blog, Post]
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -14,12 +14,12 @@ describe Validb::ModelFilterer do
|
|
14
14
|
describe "#models" do
|
15
15
|
it "returns all the non filtered models" do
|
16
16
|
filename = File.expand_path(File.dirname(__FILE__) + '/../config/validb.json')
|
17
|
-
|
18
|
-
model_filterer = Validb::ModelFilterer.new(
|
17
|
+
params = Validb::Configuration.new(filename).params
|
18
|
+
model_filterer = Validb::ModelFilterer.new(params)
|
19
19
|
|
20
20
|
models = [User, Author, Blog, Post, Api::Approval, Comment, Person]
|
21
21
|
|
22
|
-
model_filterer.filter(models).should
|
22
|
+
model_filterer.filter(models).should == [Author, Comment]
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -4,8 +4,9 @@ describe Validb::ModelValidator do
|
|
4
4
|
describe "#initialize" do
|
5
5
|
it "creates a model validator" do
|
6
6
|
logger = double('logger')
|
7
|
+
params = double('params')
|
7
8
|
Validb::Batcher.should_receive(:new).with(logger)
|
8
|
-
Validb::ModelValidator.new(logger)
|
9
|
+
Validb::ModelValidator.new(params, logger)
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
@@ -13,9 +14,11 @@ describe Validb::ModelValidator do
|
|
13
14
|
it "validates the records of the model" do
|
14
15
|
model = Blog
|
15
16
|
logger = double('logger')
|
16
|
-
|
17
|
+
params = double('params', batch_size: 200)
|
18
|
+
model_validator = Validb::ModelValidator.new(params, logger)
|
17
19
|
|
18
|
-
$stdout.should_receive(:
|
20
|
+
$stdout.should_receive(:print).with("\nChecking Blog(blogs) (0 records).")
|
21
|
+
model.should_receive(:find_in_batches).with(batch_size: 200)
|
19
22
|
model_validator.validate(model)
|
20
23
|
end
|
21
24
|
end
|
data/spec/validb/version_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joey Geiger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-03-
|
11
|
+
date: 2013-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- lib/validb/finder.rb
|
46
46
|
- lib/validb/model_filterer.rb
|
47
47
|
- lib/validb/model_validator.rb
|
48
|
+
- lib/validb/parameters.rb
|
48
49
|
- lib/validb/railtie.rb
|
49
50
|
- lib/validb/record_validator.rb
|
50
51
|
- lib/validb/version.rb
|