valid_data 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +3 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +11 -0
- data/lib/tasks/valid_data.rake +11 -0
- data/lib/valid_data.rb +11 -0
- data/lib/valid_data/collector.rb +32 -0
- data/lib/valid_data/printer.rb +22 -0
- data/lib/valid_data/railtie.rb +12 -0
- data/lib/valid_data/runner.rb +29 -0
- data/lib/valid_data/version.rb +3 -0
- data/spec/lib/valid_data/collector_spec.rb +26 -0
- data/spec/lib/valid_data/printer_spec.rb +20 -0
- data/spec/lib/valid_data/runner_spec.rb +19 -0
- data/spec/spec_helper.rb +21 -0
- data/valid_data.gemspec +32 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 730971eefd74cc4c9ff9f2f6fdaae52a3a6ec82f
|
4
|
+
data.tar.gz: 1d64d7563a6f5eaf4b2f8cacb98eba919e95cd4a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c6ef722b0c0cbc715a0049a6b751a1b9a37d89b8f1d480888759f1353eb3a8e2cc2fcc6f4cf46199dd09807ba0b21a23701581428874b57fa8a9be444a56d818
|
7
|
+
data.tar.gz: 83a0b41b0122f67678129dd78b7903c65c327b886c672008aa818339dcdd9ac3e3cf30977091a77f5480437a524f2041629cfbc26ab8d47d10cb8df2d94c30e7
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Stack Builders Inc.
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/stackbuilders/valid_data.png?branch=master)](https://travis-ci.org/stackbuilders/valid_data)
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
gem 'valid_data'
|
8
|
+
|
9
|
+
And then execute:
|
10
|
+
|
11
|
+
$ bundle
|
12
|
+
|
13
|
+
Or install it yourself as:
|
14
|
+
|
15
|
+
$ gem install valid_data
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
Invoke the `Rake Task` that is now at your fingertips:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
rake validate_records[30]
|
23
|
+
```
|
24
|
+
... where the `30` refers to the amount of extra padding in the printed output.
|
25
|
+
|
26
|
+
You should expect to see some output like this:
|
27
|
+
|
28
|
+
```bash
|
29
|
+
Model | Invalid | Total
|
30
|
+
------------------------------------------------------------------------------------------
|
31
|
+
MakeNegativeTemplate | 0 | 0
|
32
|
+
KeywordSet | 0 | 1
|
33
|
+
Placeholder | 0 | 5
|
34
|
+
User | 0 | 0
|
35
|
+
Ad | 1 | 1
|
36
|
+
```
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it ( https://github.com/mecampbellsoup/valid_data/fork )
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
|
4
|
+
# Default directory to look in is `/specs`
|
5
|
+
# Run with `rake spec`
|
6
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
7
|
+
task.rspec_opts = ['--color', '--format', 'nested']
|
8
|
+
end
|
9
|
+
|
10
|
+
# Default task is running the test suite
|
11
|
+
task :default => :spec
|
@@ -0,0 +1,11 @@
|
|
1
|
+
desc "Check for invalid records in the database"
|
2
|
+
task :validate_records, [:padding] => [:environment] do |t, args|
|
3
|
+
# Load all models
|
4
|
+
Rails.application.eager_load!
|
5
|
+
|
6
|
+
# Set padding if not passed in ARGV
|
7
|
+
padding = args[:padding] || 30
|
8
|
+
|
9
|
+
# Instantiate the Runner and call #data on it
|
10
|
+
ValidData::Runner.new(padding, ActiveRecord::Base).run
|
11
|
+
end
|
data/lib/valid_data.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "valid_data/version"
|
2
|
+
require "valid_data/runner"
|
3
|
+
require "valid_data/printer"
|
4
|
+
require "valid_data/collector"
|
5
|
+
|
6
|
+
module ValidData
|
7
|
+
require 'valid_data/railtie' if defined?(Rails)
|
8
|
+
|
9
|
+
# Result serves as a data structure between Runner and Printer
|
10
|
+
Result = Struct.new(:name, :invalid_count, :total)
|
11
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ValidData
|
2
|
+
class Collector
|
3
|
+
def initialize(models)
|
4
|
+
@models = models
|
5
|
+
end
|
6
|
+
|
7
|
+
def each(&block)
|
8
|
+
return enum_for(:each) unless block_given?
|
9
|
+
|
10
|
+
models.each { |model|
|
11
|
+
yield compute_result(model)
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def compute_result(model)
|
16
|
+
invalid_count, total = 0, 0
|
17
|
+
|
18
|
+
model.find_each do |m|
|
19
|
+
invalid_count += 1 if m.invalid?
|
20
|
+
total += 1
|
21
|
+
end
|
22
|
+
|
23
|
+
Result.new(model.name, invalid_count, total)
|
24
|
+
#NOTE: The following line doesn't work for Rails < 4.0!
|
25
|
+
#Result.new(model.name, model.find_each.select(&:valid?), model.count)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :models
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ValidData
|
2
|
+
class Printer
|
3
|
+
#TODO: Auto-scale padding as a function of the longest name being printed.
|
4
|
+
def initialize(padding)
|
5
|
+
@padding = padding
|
6
|
+
puts header
|
7
|
+
end
|
8
|
+
|
9
|
+
def print(result)
|
10
|
+
"%s | %s | %s" % [result.name, result.invalid_count, result.total].map{ |cell| cell.to_s.ljust(padding) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def header
|
14
|
+
"%s | %s | %s" % ["Model", "Invalid", "Total"].map{ |title| title.ljust(padding) } +
|
15
|
+
"\n" + "-" * 3 * padding
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :result, :padding
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module ValidData
|
2
|
+
class Runner
|
3
|
+
def initialize(padding, adapter)
|
4
|
+
@padding = padding.to_i
|
5
|
+
@adapter = adapter
|
6
|
+
@printer = Printer.new(padding.to_i)
|
7
|
+
end
|
8
|
+
|
9
|
+
def run
|
10
|
+
collector.each { |result|
|
11
|
+
puts printer.print(result)
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_reader :padding, :adapter, :printer
|
18
|
+
|
19
|
+
def collector
|
20
|
+
@collector ||= Collector.new(models)
|
21
|
+
end
|
22
|
+
|
23
|
+
def models
|
24
|
+
adapter.descendants.reject do |klass|
|
25
|
+
klass.name.include?("::Translation") || klass.abstract_class?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module ValidData
|
4
|
+
describe Collector do
|
5
|
+
let(:user_model) { double(name: 'User', count: 1) }
|
6
|
+
let(:users) { [double(invalid?: true), double(invalid?: true), double(invalid?: false)] }
|
7
|
+
let(:collector) { Collector.new([user_model]) }
|
8
|
+
let(:result) { Result.new("User", 2, 3) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
user_model.stub(:find_each).and_yield(users[0]).and_yield(users[1]).and_yield(users[2])
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#compute_result" do
|
15
|
+
it "returns a result object with the required information from the model" do
|
16
|
+
expect(collector.compute_result(user_model)).to eq result
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#each" do
|
21
|
+
it "iterates over computed result for each model" do
|
22
|
+
collector.each.to_a.should == [result]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module ValidData
|
4
|
+
describe Printer do
|
5
|
+
let(:printer) { Printer.new(5) }
|
6
|
+
|
7
|
+
describe "#print" do
|
8
|
+
it "writes each row of the table with the appropriate padding" do
|
9
|
+
result = Result.new("User", 5, 20)
|
10
|
+
expect(printer.print(result)).to eq "User | 5 | 20 "
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#header" do
|
15
|
+
it "writes the header with the appropriate padding" do
|
16
|
+
expect(printer.header).to eq "Model | Invalid | Total\n---------------"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module ValidData
|
4
|
+
describe Runner do
|
5
|
+
describe "#run" do
|
6
|
+
let(:user_model) { double(name: 'User', count: 1, find_each: users, abstract_class?: false) }
|
7
|
+
let(:dealer_model) { double(name: 'Dealer', count: 1, find_each: dealers, abstract_class?: false) }
|
8
|
+
let(:users) { [double(valid?: true)] }
|
9
|
+
let(:dealers) { [double(valid?: true)] }
|
10
|
+
let(:adapter) { double(descendants: [user_model, dealer_model]) }
|
11
|
+
let(:runner) { Runner.new(30, adapter) }
|
12
|
+
|
13
|
+
it "prints the report" do
|
14
|
+
pending
|
15
|
+
runner.run
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'valid_data'
|
2
|
+
require 'pry'
|
3
|
+
require 'rails'
|
4
|
+
|
5
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
6
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
7
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
8
|
+
# loaded once.
|
9
|
+
#
|
10
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
13
|
+
config.run_all_when_everything_filtered = true
|
14
|
+
config.filter_run :focus
|
15
|
+
|
16
|
+
# Run specs in random order to surface order dependencies. If you find an
|
17
|
+
# order dependency and want to debug it, you can fix the order by providing
|
18
|
+
# the seed, which is printed after each run.
|
19
|
+
# --seed 1234
|
20
|
+
config.order = 'random'
|
21
|
+
end
|
data/valid_data.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
$:.unshift File.expand_path('../lib', __FILE__)
|
3
|
+
require 'valid_data/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "valid_data"
|
7
|
+
spec.version = ValidData::VERSION
|
8
|
+
spec.platform = Gem::Platform::RUBY
|
9
|
+
spec.authors = ["Matt Campbell", "Wojciech Mach"]
|
10
|
+
spec.email = ["support@stackbuilders.com"]
|
11
|
+
spec.license = "MIT"
|
12
|
+
spec.homepage = "https://github.com/stackbuilders/valid_data"
|
13
|
+
spec.summary = "Quickly check whether the rows in your database are valid according to your ActiveRecord validations."
|
14
|
+
spec.description = <<-DESC
|
15
|
+
As your Rails projects evolve and grow, your model validations tend to change
|
16
|
+
as well. An unfortunate side effect of this evolution is that your table-
|
17
|
+
backed ActiveRecord::Base descendants end up with rows that instantiate invalid
|
18
|
+
model instances. ValidData generates a report for your Rails application,
|
19
|
+
notifying you exactly how many rows in your models are invalid for each model.
|
20
|
+
DESC
|
21
|
+
|
22
|
+
spec.files = `git ls-files -z`.split("\x0")
|
23
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
24
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
28
|
+
spec.add_development_dependency "rake", "~> 10"
|
29
|
+
spec.add_development_dependency "rspec", "~> 2"
|
30
|
+
spec.add_development_dependency "pry", "~> 0.9"
|
31
|
+
spec.add_development_dependency "rails", ">= 3.0"
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: valid_data
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Campbell
|
8
|
+
- Wojciech Mach
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-05-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.6'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.6'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '2'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '2'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: pry
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0.9'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.9'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rails
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '3.0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '3.0'
|
84
|
+
description: |
|
85
|
+
As your Rails projects evolve and grow, your model validations tend to change
|
86
|
+
as well. An unfortunate side effect of this evolution is that your table-
|
87
|
+
backed ActiveRecord::Base descendants end up with rows that instantiate invalid
|
88
|
+
model instances. ValidData generates a report for your Rails application,
|
89
|
+
notifying you exactly how many rows in your models are invalid for each model.
|
90
|
+
email:
|
91
|
+
- support@stackbuilders.com
|
92
|
+
executables: []
|
93
|
+
extensions: []
|
94
|
+
extra_rdoc_files: []
|
95
|
+
files:
|
96
|
+
- ".gitignore"
|
97
|
+
- ".rspec"
|
98
|
+
- ".travis.yml"
|
99
|
+
- Gemfile
|
100
|
+
- LICENSE.txt
|
101
|
+
- README.md
|
102
|
+
- Rakefile
|
103
|
+
- lib/tasks/valid_data.rake
|
104
|
+
- lib/valid_data.rb
|
105
|
+
- lib/valid_data/collector.rb
|
106
|
+
- lib/valid_data/printer.rb
|
107
|
+
- lib/valid_data/railtie.rb
|
108
|
+
- lib/valid_data/runner.rb
|
109
|
+
- lib/valid_data/version.rb
|
110
|
+
- spec/lib/valid_data/collector_spec.rb
|
111
|
+
- spec/lib/valid_data/printer_spec.rb
|
112
|
+
- spec/lib/valid_data/runner_spec.rb
|
113
|
+
- spec/spec_helper.rb
|
114
|
+
- valid_data.gemspec
|
115
|
+
homepage: https://github.com/stackbuilders/valid_data
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
metadata: {}
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 2.2.1
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: Quickly check whether the rows in your database are valid according to your
|
139
|
+
ActiveRecord validations.
|
140
|
+
test_files:
|
141
|
+
- spec/lib/valid_data/collector_spec.rb
|
142
|
+
- spec/lib/valid_data/printer_spec.rb
|
143
|
+
- spec/lib/valid_data/runner_spec.rb
|
144
|
+
- spec/spec_helper.rb
|