fixture_validation 0.1.2 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +6 -1
- data/README.md +36 -18
- data/Rakefile +33 -6
- data/bin/rails +13 -0
- data/fixture_validation.gemspec +2 -4
- data/lib/fixture_validation.rb +30 -0
- data/lib/fixture_validation/engine.rb +4 -0
- data/lib/fixture_validation/version.rb +1 -1
- data/lib/generators/fixture_validation_generator.rb +17 -0
- metadata +16 -50
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/lib/fixture_validation_test.rb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e29e73b106e837586ee66cb19f611471e1958dd7
|
4
|
+
data.tar.gz: 8c9145ad617e13e202784447ef463df9a2931a03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85161e55ddba0b53c983e92254586569e0f0d6ec9c9ce1a7afa94eddb8c8ce2a6e30d9d5c577c5e049a8459c4616d588342e69f5ca203cd5036eda3acaa539da
|
7
|
+
data.tar.gz: 8c81993b0a47db8c8144551533590cdef72936fae927eb745470e1449a167230bfa9c6cd0f558b0ddf103aa072d530a5d6d0ed6b830741d66c25220506c31f40
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# FixtureValidation
|
2
2
|
|
3
|
-
Adds a test that validates all your Rails fixtures.
|
3
|
+
Adds a test that validates all your Rails fixtures. Tested with Rails
|
4
|
+
versions 4 and 5.
|
4
5
|
|
5
6
|
As your Rails models grow and change over time, your fixtures may
|
6
7
|
become outdated without anyone noticing. In my code I've found
|
@@ -27,21 +28,23 @@ test 'task must have a name' do
|
|
27
28
|
end
|
28
29
|
```
|
29
30
|
|
30
|
-
With that extra line you can be sure the test will perform as
|
31
|
-
what if you have many tests that use the same fixture?
|
32
|
-
|
33
|
-
|
31
|
+
With that extra line you can be sure the test will perform as
|
32
|
+
expected. But what if you have many tests that use the same fixture?
|
33
|
+
Furthermore, on a project with hundreds or thousands of fixtures, you
|
34
|
+
may find yourself repeating this load/validate pattern constantly.
|
34
35
|
|
35
|
-
This gem adds a test to your test suite that validates all fixtures at
|
36
|
-
|
36
|
+
This gem adds a test to your test suite that validates all fixtures at
|
37
|
+
once. In the above example, if task :one is invalid the fixture
|
38
|
+
validation test will fail with output like this:
|
37
39
|
|
38
40
|
```
|
39
41
|
Expected Task fixture 708419058 to be valid. Errors: Name can't be blank. Attribute values: {"id"=>708419058, "name"=>nil, "created_at"=>Sat, 12 Nov 2016 17:29:02 UTC +00:00, "updated_at"=>Sat, 12 Nov 2016 17:29:02 UTC +00:00}.
|
40
42
|
```
|
41
43
|
|
42
|
-
All fixture errors are printed when the test runs.
|
43
|
-
|
44
|
-
|
44
|
+
All fixture errors are printed when the test runs. It's not possible
|
45
|
+
to look up the YAML name of the fixture based on the database entry,
|
46
|
+
but the attribute values are printed to assist in identifying which
|
47
|
+
fixture is invalid.
|
45
48
|
|
46
49
|
## Installation
|
47
50
|
|
@@ -61,11 +64,10 @@ Or install it yourself as:
|
|
61
64
|
|
62
65
|
$ gem install fixture_validation
|
63
66
|
|
64
|
-
|
67
|
+
Then call the generator to create the test stub:
|
65
68
|
|
66
|
-
```
|
67
|
-
|
68
|
-
require 'fixture_validation_test' # add this line
|
69
|
+
```bash
|
70
|
+
$ rails g fixture_validation
|
69
71
|
```
|
70
72
|
|
71
73
|
## Usage
|
@@ -74,18 +76,34 @@ Run your test suite:
|
|
74
76
|
|
75
77
|
$ rake test
|
76
78
|
|
79
|
+
Or you can run the fixture validation test on its own, which is useful
|
80
|
+
if you want to iterate over several errors:
|
81
|
+
|
82
|
+
$ rake test TEST=test/models/fixture_validation_test.rb
|
83
|
+
|
77
84
|
## Development
|
78
85
|
|
79
|
-
After checking out the repo, run `bin/setup` to install
|
86
|
+
After checking out the repo, run `bin/setup` to install
|
87
|
+
dependencies. Then, run `rake test` to run the tests.
|
80
88
|
|
81
|
-
To install this gem onto your local machine, run `bundle exec rake
|
89
|
+
To install this gem onto your local machine, run `bundle exec rake
|
90
|
+
install`. To release a new version, update the version number in
|
91
|
+
`version.rb`, and then run `bundle exec rake release`, which will
|
92
|
+
create a git tag for the version, push git commits and tags, and push
|
93
|
+
the `.gem` file to [rubygems.org](https://rubygems.org).
|
82
94
|
|
83
95
|
## Contributing
|
84
96
|
|
85
|
-
Bug reports and pull requests are welcome on GitHub at
|
97
|
+
Bug reports and pull requests are welcome on GitHub at
|
98
|
+
https://github.com/[USERNAME]/fixture_validation. This project is
|
99
|
+
intended to be a safe, welcoming space for collaboration, and
|
100
|
+
contributors are expected to adhere to
|
101
|
+
the [Contributor Covenant](http://contributor-covenant.org) code of
|
102
|
+
conduct.
|
86
103
|
|
87
104
|
|
88
105
|
## License
|
89
106
|
|
90
|
-
The gem is available as open source under the terms of
|
107
|
+
The gem is available as open source under the terms of
|
108
|
+
the [MIT License](http://opensource.org/licenses/MIT).
|
91
109
|
|
data/Rakefile
CHANGED
@@ -1,10 +1,37 @@
|
|
1
|
-
|
2
|
-
require
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'FixtureValidation'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
require 'bundler/gem_tasks'
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
3
28
|
|
4
29
|
Rake::TestTask.new(:test) do |t|
|
5
|
-
t.libs <<
|
6
|
-
t.libs <<
|
7
|
-
t.
|
30
|
+
t.libs << 'lib'
|
31
|
+
t.libs << 'test'
|
32
|
+
t.pattern = 'test/**/*_test.rb'
|
33
|
+
t.verbose = false
|
8
34
|
end
|
9
35
|
|
10
|
-
|
36
|
+
|
37
|
+
task default: :test
|
data/bin/rails
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
3
|
+
# installed from the root of your application.
|
4
|
+
|
5
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
6
|
+
ENGINE_PATH = File.expand_path('../../lib/fixture_validation/engine', __FILE__)
|
7
|
+
|
8
|
+
# Set up gems listed in the Gemfile.
|
9
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
10
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
11
|
+
|
12
|
+
require 'rails/all'
|
13
|
+
require 'rails/engine/commands'
|
data/fixture_validation.gemspec
CHANGED
@@ -20,8 +20,6 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ['lib']
|
22
22
|
|
23
|
-
spec.
|
24
|
-
spec.add_development_dependency '
|
25
|
-
spec.add_development_dependency 'minitest', '~> 5.0'
|
26
|
-
spec.add_runtime_dependency 'rails', '~> 4.0', '~> 5.0'
|
23
|
+
spec.add_dependency 'rails', '> 4'
|
24
|
+
spec.add_development_dependency 'sqlite3'
|
27
25
|
end
|
data/lib/fixture_validation.rb
CHANGED
@@ -1,5 +1,35 @@
|
|
1
1
|
require 'fixture_validation/version'
|
2
|
+
require 'active_support/concern'
|
2
3
|
|
3
4
|
module FixtureValidation
|
5
|
+
extend ActiveSupport::Concern
|
4
6
|
|
7
|
+
included do
|
8
|
+
fixtures :all
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_validate_fixtures
|
12
|
+
count = 0
|
13
|
+
klasses = []
|
14
|
+
fixture_table_names.each do |fixture_name|
|
15
|
+
klass_name = fixture_name.classify
|
16
|
+
begin
|
17
|
+
klasses << klass_name.constantize
|
18
|
+
rescue NameError
|
19
|
+
Rails.logger.debug "No model class (#{klass_name}) found for fixture #{fixture_name}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
errors = []
|
24
|
+
klasses.each do |klass|
|
25
|
+
klass.all.each do |obj|
|
26
|
+
errors << "Expected #{klass.to_s} fixture #{obj.id} to be valid. Errors: #{obj.errors.to_a.join(', ')}. Attribute values: #{obj.attributes.to_s}." unless obj.valid?
|
27
|
+
count += 1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
assert errors.empty?, "\n#{errors.join("\n")}"
|
32
|
+
Rails.logger.debug "Validated #{count} fixtures"
|
33
|
+
end
|
5
34
|
end
|
35
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
|
3
|
+
class FixtureValidationGenerator < Rails::Generators::Base
|
4
|
+
def create_test
|
5
|
+
create_file 'test/models/fixture_validation_test.rb' do
|
6
|
+
<<END
|
7
|
+
require 'test_helper'
|
8
|
+
require 'fixture_validation'
|
9
|
+
|
10
|
+
class FixtureValidationTest < ActiveSupport::TestCase
|
11
|
+
include FixtureValidation
|
12
|
+
end
|
13
|
+
|
14
|
+
END
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,77 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fixture_validation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Falcone
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.13'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.13'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
14
|
+
name: rails
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
|
-
- - "
|
17
|
+
- - ">"
|
32
18
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
34
|
-
type: :
|
19
|
+
version: '4'
|
20
|
+
type: :runtime
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
|
-
- - "
|
24
|
+
- - ">"
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
26
|
+
version: '4'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
28
|
+
name: sqlite3
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
|
-
- - "
|
31
|
+
- - ">="
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
33
|
+
version: '0'
|
48
34
|
type: :development
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
|
-
- - "
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '5.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rails
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '4.0'
|
62
|
-
- - "~>"
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
version: '5.0'
|
65
|
-
type: :runtime
|
66
|
-
prerelease: false
|
67
|
-
version_requirements: !ruby/object:Gem::Requirement
|
68
|
-
requirements:
|
69
|
-
- - "~>"
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
version: '4.0'
|
72
|
-
- - "~>"
|
38
|
+
- - ">="
|
73
39
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
40
|
+
version: '0'
|
75
41
|
description:
|
76
42
|
email:
|
77
43
|
- danfalcone@gmail.com
|
@@ -86,12 +52,12 @@ files:
|
|
86
52
|
- LICENSE.txt
|
87
53
|
- README.md
|
88
54
|
- Rakefile
|
89
|
-
- bin/
|
90
|
-
- bin/setup
|
55
|
+
- bin/rails
|
91
56
|
- fixture_validation.gemspec
|
92
57
|
- lib/fixture_validation.rb
|
58
|
+
- lib/fixture_validation/engine.rb
|
93
59
|
- lib/fixture_validation/version.rb
|
94
|
-
- lib/
|
60
|
+
- lib/generators/fixture_validation_generator.rb
|
95
61
|
homepage: https://github.com/falconed/fixture_validation
|
96
62
|
licenses:
|
97
63
|
- MIT
|
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "fixture_validation_test"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start
|
data/bin/setup
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# Requires at least one test in the project
|
2
|
-
# Require 'fixture_validation_test' in test_helper after rails/test_help is required
|
3
|
-
|
4
|
-
class FixtureValidation::Test < ActiveSupport::TestCase
|
5
|
-
fixtures :all
|
6
|
-
|
7
|
-
test 'fixtures are valid' do
|
8
|
-
count = 0
|
9
|
-
klasses = []
|
10
|
-
fixture_table_names.each do |fixture_name|
|
11
|
-
klass_name = fixture_name.classify
|
12
|
-
begin
|
13
|
-
klasses << klass_name.constantize
|
14
|
-
rescue NameError
|
15
|
-
Rails.logger.debug "No model class (#{klass_name}) found for fixture #{fixture_name}"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
errors = []
|
20
|
-
klasses.each do |klass|
|
21
|
-
klass.all.each do |obj|
|
22
|
-
errors << "Expected #{klass.to_s} fixture #{obj.id} to be valid. Errors: #{obj.errors.to_a.join(', ')}. Attribute values: #{obj.attributes.to_s}." unless obj.valid?
|
23
|
-
count += 1
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
assert errors.empty?, "\n#{errors.join("\n")}"
|
28
|
-
Rails.logger.debug "Validated #{count} fixtures"
|
29
|
-
end
|
30
|
-
end
|