validation_auditor 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.travis.yml +6 -0
- data/Gemfile +17 -0
- data/LICENSE.txt +22 -0
- data/README.md +61 -0
- data/Rakefile +12 -0
- data/gemfiles/rails_3_2.Gemfile +16 -0
- data/gemfiles/rails_4_0.Gemfile +17 -0
- data/lib/generators/validation_auditor/install_generator.rb +24 -0
- data/lib/generators/validation_auditor/templates/migration.rb +17 -0
- data/lib/validation_auditor.rb +75 -0
- data/lib/validation_auditor/version.rb +6 -0
- data/test/controller_test.rb +80 -0
- data/test/install_generator_test.rb +24 -0
- data/test/model_test.rb +57 -0
- data/test/test_helper.rb +65 -0
- data/validation_auditor.gemspec +26 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e11ee0bdea5ce733ed1a994b32c21c5de80bb239
|
4
|
+
data.tar.gz: 8d2b38478f274fa566e8691514ca701a932caa2e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 80d6eaa8a29043d2d7d6b581469535a263efe1066a238094799028bdf5831045599d029b889ca7e717123a45bd1e3227ace941f91335ecd872ec7dc5de4a4c57
|
7
|
+
data.tar.gz: 77ef7c6da46f74b9017d049b7042e245138137c98d879f4fd3c20f54392c135adbd5c0b155096d31154fe686d79167b7ba44b2467c103a4d5ff0b67c8c6a637d
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# Copyright © 2014, Watu
|
3
|
+
|
4
|
+
source "https://rubygems.org"
|
5
|
+
|
6
|
+
gem "assert_difference"
|
7
|
+
gem "bundler", "~> 1.3"
|
8
|
+
gem "coveralls", require: false
|
9
|
+
gem "minitest", "~> 4.7.5"
|
10
|
+
gem "minitest-reporters"
|
11
|
+
gem "rake"
|
12
|
+
gem "simplecov"
|
13
|
+
gem "shoulda"
|
14
|
+
gem "sqlite3"
|
15
|
+
gem "activerecord", "~> 4.0.0"
|
16
|
+
gem "actionpack", "~> 4.0.0"
|
17
|
+
gem "railties", "~> 4.0.0"
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012, 2013, 2014, Watu
|
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,61 @@
|
|
1
|
+
# Validation Auditor
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/watu/validation_auditor.png?branch=master)](https://travis-ci.org/watu/validation_auditor)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/watu/validation_auditor/badge.png?branch=master)](https://coveralls.io/r/watu/validation_auditor?branch=master)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/watu/validation_auditor.png)](https://codeclimate.com/github/watu/validation_auditor)
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/validation_auditor.png)](http://badge.fury.io/rb/validation_auditor)
|
7
|
+
|
8
|
+
A user visits your web app, tries to do something with it but it fails due to a validation error. Generally, the
|
9
|
+
validation is stopping a user from doing something bad, but every now and then it's the validation that is bad. Don't
|
10
|
+
you hate it when the credit card processor won't accept your name as written in the credit card due to an unexpected
|
11
|
+
character and won't accept anything else because that's not your name? We all do.
|
12
|
+
|
13
|
+
This gem allows you to easily keep a log of validation errors, so you can later inspect them to try to find those cases
|
14
|
+
where things are going wrong.
|
15
|
+
|
16
|
+
This gem was extracted out of a Ruby 1.9 / Rails 3.2 project, but it's being prepared for work with Ruby 2.0 /
|
17
|
+
Rails 4.0. The core functionality should work with Ruby 1.9 / Rails 3.2, if it doesn't, it's a bug. The tests, at the
|
18
|
+
moment, are heavily dependent on Rails 4.0.
|
19
|
+
|
20
|
+
## Installation
|
21
|
+
|
22
|
+
Add this line to your application's Gemfile:
|
23
|
+
|
24
|
+
gem "validation_auditor"
|
25
|
+
|
26
|
+
And then execute:
|
27
|
+
|
28
|
+
$ bundle
|
29
|
+
|
30
|
+
You need to install the migration file in your Rails project, which you can do by:
|
31
|
+
|
32
|
+
$ rails generate validation_auditor:install
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
After you run the migration, you need to enable the validation auditor in each model by calling the class method:
|
37
|
+
`audit_validation_errors`, for example:
|
38
|
+
|
39
|
+
class Blog < ActiveRecord::Base
|
40
|
+
audit_validation_errors
|
41
|
+
end
|
42
|
+
|
43
|
+
From then on, every time saving that record fails, a record will be saved to validation_audits with the failure message
|
44
|
+
and some extra information.
|
45
|
+
|
46
|
+
If you enable validation audit on the controller, by calling `audit_validation_errors` as in:
|
47
|
+
|
48
|
+
class BlogsController < ApplicationController
|
49
|
+
audit_validation_errors
|
50
|
+
end
|
51
|
+
|
52
|
+
then you'll also get params, url and user agent in the validation audit. This breaks the model-controller separation, so
|
53
|
+
it's optional.
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
1. Fork it
|
58
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
59
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
60
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
61
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# Copyright © 2013, 2014, Watu
|
3
|
+
|
4
|
+
source "https://rubygems.org"
|
5
|
+
|
6
|
+
gem "bundler", "~> 1.3"
|
7
|
+
gem "coveralls", require: false
|
8
|
+
gem "minitest", "~> 2.5.1"
|
9
|
+
gem "minitest-reporters"
|
10
|
+
gem "mocha"
|
11
|
+
gem "rake"
|
12
|
+
gem "simplecov"
|
13
|
+
gem "shoulda"
|
14
|
+
gem "sqlite3"
|
15
|
+
gem "activesupport", "~> 3.2.0"
|
16
|
+
gem "activerecord", "~> 3.2.0"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# Copyright © 2014, Watu
|
3
|
+
|
4
|
+
source "https://rubygems.org"
|
5
|
+
|
6
|
+
gem "assert_difference"
|
7
|
+
gem "bundler", "~> 1.3"
|
8
|
+
gem "coveralls", require: false
|
9
|
+
gem "minitest", "~> 4.7.5"
|
10
|
+
gem "minitest-reporters"
|
11
|
+
gem "rake"
|
12
|
+
gem "simplecov"
|
13
|
+
gem "shoulda"
|
14
|
+
gem "sqlite3"
|
15
|
+
gem "activerecord", "~> 4.0.0"
|
16
|
+
gem "actionpack", "~> 4.0.0"
|
17
|
+
gem "railties", "~> 4.0.0"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# Copyright © 2014, Watu
|
3
|
+
|
4
|
+
require "rails/generators"
|
5
|
+
require "rails/generators/migration"
|
6
|
+
require "rails/generators/active_record"
|
7
|
+
|
8
|
+
# Extend the DelayedJobGenerator so that it creates an AR migration
|
9
|
+
module ValidationAuditor
|
10
|
+
class InstallGenerator < Rails::Generators::Base
|
11
|
+
include Rails::Generators::Migration
|
12
|
+
|
13
|
+
self.source_paths << File.join(File.dirname(__FILE__), "templates")
|
14
|
+
|
15
|
+
def create_migration_file
|
16
|
+
migration_template "migration.rb", "db/migrate/create_validation_audits.rb"
|
17
|
+
end
|
18
|
+
|
19
|
+
# Implement the required interface for Rails::Generators::Migration.
|
20
|
+
def self.next_migration_number(dirname)
|
21
|
+
ActiveRecord::Generators::Base.next_migration_number(dirname)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateValidationAudits < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
create_table :validation_audits do |t|
|
4
|
+
t.integer :record_id
|
5
|
+
t.string :record_type
|
6
|
+
t.text :failure_messages
|
7
|
+
t.text :failures
|
8
|
+
t.text :data
|
9
|
+
t.text :params
|
10
|
+
t.text :url
|
11
|
+
t.text :user_agent
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
|
15
|
+
add_index :validation_audits, :created_at
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# Copyright © 2012, 2013, 2014, Watu
|
3
|
+
|
4
|
+
require "validation_auditor/version"
|
5
|
+
require "active_record"
|
6
|
+
require "action_controller"
|
7
|
+
|
8
|
+
module ValidationAuditor
|
9
|
+
class ValidationAudit < ActiveRecord::Base
|
10
|
+
belongs_to :record, :polymorphic => true
|
11
|
+
|
12
|
+
serialize :failures, Hash
|
13
|
+
serialize :failure_messages, Array
|
14
|
+
serialize :data, Hash
|
15
|
+
serialize :params, Hash
|
16
|
+
|
17
|
+
# Define no accessibility to the attributes but don't crash if attr_accessible is the default Rails 4 one, which raises an exception.
|
18
|
+
begin
|
19
|
+
attr_accessible # Nothing
|
20
|
+
rescue RuntimeError
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module Controller
|
25
|
+
extend ActiveSupport::Concern
|
26
|
+
|
27
|
+
module ClassMethods
|
28
|
+
def audit_validation_errors
|
29
|
+
before_filter :make_request_auditable
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def make_request_auditable
|
34
|
+
Thread.current[:validation_auditor_request] = self.request
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.request
|
38
|
+
Thread.current[:validation_auditor_request]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
module Model
|
43
|
+
extend ActiveSupport::Concern
|
44
|
+
|
45
|
+
module ClassMethods
|
46
|
+
def audit_validation_errors
|
47
|
+
after_rollback :audit_validation
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def audit_validation
|
52
|
+
if !errors.empty? # We don't use :valid? to avoid re-running validations
|
53
|
+
va = ValidationAudit.new
|
54
|
+
va.failures = self.errors.to_hash
|
55
|
+
va.failure_messages = self.errors.full_messages.to_a
|
56
|
+
va.data = self.attributes
|
57
|
+
if self.new_record? # For new records
|
58
|
+
va.record_type = self.class.name # we only store the class's name.
|
59
|
+
else
|
60
|
+
va.record = self
|
61
|
+
end
|
62
|
+
if ValidationAuditor::Controller.request.present?
|
63
|
+
request = ValidationAuditor::Controller.request
|
64
|
+
va.params = request.params
|
65
|
+
va.url = request.url
|
66
|
+
va.user_agent = request.env["HTTP_USER_AGENT"]
|
67
|
+
end
|
68
|
+
va.save
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
ActionController::Base.send(:include, ValidationAuditor::Controller)
|
75
|
+
ActiveRecord::Base.send(:include, ValidationAuditor::Model)
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# Copyright © 2014, Watu
|
3
|
+
|
4
|
+
require_relative "test_helper"
|
5
|
+
|
6
|
+
# Controller setup
|
7
|
+
class AuditedRecordsController < ActionController::Base
|
8
|
+
audit_validation_errors
|
9
|
+
|
10
|
+
def create
|
11
|
+
@audited_record = AuditedRecord.create(audited_record_params)
|
12
|
+
render text: ""
|
13
|
+
end
|
14
|
+
|
15
|
+
def update
|
16
|
+
@audited_record = AuditedRecord.find(params[:id])
|
17
|
+
@audited_record.update_attributes(audited_record_params)
|
18
|
+
render text: ""
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def audited_record_params
|
24
|
+
params.require(:audited_record).permit(:name, :email)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class ControllerTest < ActionController::TestCase
|
29
|
+
setup do
|
30
|
+
@controller = AuditedRecordsController.new
|
31
|
+
@request = ActionController::TestRequest.new
|
32
|
+
@response = ActionController::TestResponse.new
|
33
|
+
@routes = ActionDispatch::Routing::RouteSet.new
|
34
|
+
@routes.draw { resources :audited_records }
|
35
|
+
AuditedRecordsController.send(:include, @routes.url_helpers)
|
36
|
+
end
|
37
|
+
|
38
|
+
should "not create a validation audit due to no validation failing when creating a new record" do
|
39
|
+
assert_difference "ValidationAuditor::ValidationAudit.count" => 0 do
|
40
|
+
post :create, audited_record: {name: "John Doe", email: "john.doe@example.com"}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
should "create a validation audit when creating a new record" do
|
45
|
+
assert_difference "ValidationAuditor::ValidationAudit.count" => +1 do
|
46
|
+
post :create, audited_record: {name: "John Doe"} # Missing email
|
47
|
+
end
|
48
|
+
audit = ValidationAuditor::ValidationAudit.order(:id).last
|
49
|
+
assert_nil audit.record # New records cannot be referenced because they don't exist...
|
50
|
+
assert_equal "AuditedRecord", audit.record_type # but we still record the name.
|
51
|
+
assert_equal audit.data["name"], "John Doe"
|
52
|
+
assert_nil audit.data["email"]
|
53
|
+
assert_equal ["can't be blank"], audit.failures[:email]
|
54
|
+
end
|
55
|
+
|
56
|
+
context "With a record" do
|
57
|
+
setup do
|
58
|
+
@audited_record = AuditedRecord.create(name: "John Doe", email: "john.doe@example.com")
|
59
|
+
end
|
60
|
+
|
61
|
+
should "not create a validation audit due to no validation failing when updating an existing record" do
|
62
|
+
assert_difference "ValidationAuditor::ValidationAudit.count" => 0 do
|
63
|
+
put :update, id: @audited_record.id, audited_record: {name: "John Smith", email: "john.smith@example.com"}
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
should "create a validation audit due to no validation failing when updating an existing record" do
|
68
|
+
assert_difference "ValidationAuditor::ValidationAudit.count" => +1 do
|
69
|
+
put :update, id: @audited_record.id, audited_record: {name: "John Smith", email: ""} # Missing email
|
70
|
+
end
|
71
|
+
@audited_record.reload
|
72
|
+
audit = ValidationAuditor::ValidationAudit.order(:id).last
|
73
|
+
assert_equal @audited_record, audit.record
|
74
|
+
assert_equal audit.data["name"], "John Smith"
|
75
|
+
assert audit.data["email"].blank?
|
76
|
+
assert_equal ["can't be blank"], audit.failures[:email]
|
77
|
+
assert_equal audit.params, @request.params
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# Copyright © 2014, Watu
|
3
|
+
|
4
|
+
require_relative "test_helper"
|
5
|
+
|
6
|
+
require "generators/validation_auditor/install_generator"
|
7
|
+
|
8
|
+
class InstallGeneratorTest < Rails::Generators::TestCase
|
9
|
+
tests ValidationAuditor::InstallGenerator
|
10
|
+
destination File.expand_path("../../tmp", __FILE__)
|
11
|
+
|
12
|
+
should "generate migration" do
|
13
|
+
prepare_destination
|
14
|
+
run_generator ["validation_auditor:install"]
|
15
|
+
migration_dir = File.join(destination_root, "db", "migrate")
|
16
|
+
assert File.directory?(migration_dir)
|
17
|
+
migration_files = Dir["#{migration_dir}/*"]
|
18
|
+
assert_equal 1, migration_files.count
|
19
|
+
File.open(migration_files.first) do |migration|
|
20
|
+
assert migration.read.include?("create_table :validation_audits")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
data/test/model_test.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# Copyright © 2014, Watu
|
3
|
+
|
4
|
+
require_relative "test_helper"
|
5
|
+
|
6
|
+
class ModelTest < ActiveSupport::TestCase
|
7
|
+
should "not create a validation audit when no errors occurs" do
|
8
|
+
assert_difference "ValidationAuditor::ValidationAudit.count" => 0 do
|
9
|
+
AuditedRecord.create!(name: "John Doe", email: "john.doe@example.com")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
should "create a validation audit when an errors occur for a new record" do
|
14
|
+
assert_difference "ValidationAuditor::ValidationAudit.count" => +1 do
|
15
|
+
AuditedRecord.create(name: "John Doe") # Missing email.
|
16
|
+
end
|
17
|
+
audit = ValidationAuditor::ValidationAudit.order(:id).last
|
18
|
+
assert_nil audit.record # New records cannot be referenced because they don't exist...
|
19
|
+
assert_equal "AuditedRecord", audit.record_type # but we still record the name.
|
20
|
+
assert_equal audit.data["name"], "John Doe"
|
21
|
+
assert_nil audit.data["email"]
|
22
|
+
assert_equal ["can't be blank"], audit.failures[:email]
|
23
|
+
end
|
24
|
+
|
25
|
+
should "create a validation audit when an errors occur for an existing record" do
|
26
|
+
audited_record = AuditedRecord.create!(name: "John Doe", email: "john.doe@example.com")
|
27
|
+
assert_difference "ValidationAuditor::ValidationAudit.count" => +1 do
|
28
|
+
audited_record.name = "John Smith"
|
29
|
+
audited_record.email = nil # Missing email.
|
30
|
+
audited_record.save
|
31
|
+
end
|
32
|
+
audit = ValidationAuditor::ValidationAudit.order(:id).last
|
33
|
+
assert_equal audited_record, audit.record
|
34
|
+
assert_equal audit.data["name"], "John Smith"
|
35
|
+
assert_nil audit.data["email"]
|
36
|
+
assert_equal ["can't be blank"], audit.failures[:email]
|
37
|
+
end
|
38
|
+
|
39
|
+
should "not create a validation audit when no errors occurs for an existing record" do
|
40
|
+
audited_record = AuditedRecord.create!(name: "John Doe", email: "john.doe@example.com")
|
41
|
+
assert_difference "ValidationAuditor::ValidationAudit.count" => 0 do
|
42
|
+
audited_record.name = "John Smith"
|
43
|
+
audited_record.email = "john.smith@example.com"
|
44
|
+
audited_record.save!
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
should "not create a validation audit for non audited models" do
|
49
|
+
assert_difference "ValidationAuditor::ValidationAudit.count" => 0 do
|
50
|
+
NonAuditedRecord.create(name: "John Doe") # Missing email.
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# Copyright © 2013, 2014, Watu
|
3
|
+
|
4
|
+
require "rubygems"
|
5
|
+
|
6
|
+
# Test coverage
|
7
|
+
require "simplecov"
|
8
|
+
require "coveralls"
|
9
|
+
SimpleCov.start do
|
10
|
+
add_filter "/test/"
|
11
|
+
end
|
12
|
+
Coveralls.wear! # Comment out this line to have the local coverage generated.
|
13
|
+
|
14
|
+
require "minitest/autorun"
|
15
|
+
require "minitest/reporters"
|
16
|
+
MiniTest::Reporters.use!
|
17
|
+
|
18
|
+
require "active_support/test_case"
|
19
|
+
require "action_controller"
|
20
|
+
require "action_controller/test_case"
|
21
|
+
|
22
|
+
require "shoulda"
|
23
|
+
require "shoulda-context"
|
24
|
+
require "shoulda-matchers"
|
25
|
+
|
26
|
+
# Make the code to be tested easy to load.
|
27
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
28
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
29
|
+
|
30
|
+
# Database setup
|
31
|
+
require "active_record"
|
32
|
+
ActiveRecord::Base.logger = Logger.new(STDERR)
|
33
|
+
ActiveRecord::Base.logger.level = Logger::WARN
|
34
|
+
ActiveRecord::Base.configurations = {"sqlite3" => {adapter: "sqlite3", database: ":memory:"}}
|
35
|
+
ActiveRecord::Base.establish_connection("sqlite3")
|
36
|
+
|
37
|
+
# Models setup.
|
38
|
+
require "validation_auditor"
|
39
|
+
ActiveRecord::Schema.define(version: 0) do
|
40
|
+
create_table :audited_records do |t|
|
41
|
+
t.string :name
|
42
|
+
t.string :email
|
43
|
+
end
|
44
|
+
create_table :non_audited_records do |t|
|
45
|
+
t.string :name
|
46
|
+
t.string :email
|
47
|
+
end
|
48
|
+
end
|
49
|
+
class AuditedRecord < ActiveRecord::Base
|
50
|
+
audit_validation_errors
|
51
|
+
validates :email, presence: true
|
52
|
+
end
|
53
|
+
class NonAuditedRecord < ActiveRecord::Base
|
54
|
+
validates :email, presence: true
|
55
|
+
end
|
56
|
+
require "generators/validation_auditor/templates/migration"
|
57
|
+
CreateValidationAudits.migrate("up")
|
58
|
+
|
59
|
+
# Shutup.
|
60
|
+
I18n.enforce_available_locales = false # TODO: remove this line when it's not needed anymore.
|
61
|
+
|
62
|
+
require "assert_difference"
|
63
|
+
class ActiveSupport::TestCase
|
64
|
+
include AssertDifference
|
65
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# Copyright © 2014, Watu
|
3
|
+
|
4
|
+
lib = File.expand_path('../lib', __FILE__)
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
require 'validation_auditor/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = "validation_auditor"
|
10
|
+
spec.version = ValidationAuditor::VERSION
|
11
|
+
spec.authors = ["J. Pablo Fernández"]
|
12
|
+
spec.email = ["pupeno@watuapp.com"]
|
13
|
+
spec.description = %q{Log validation errors to the database for later inspection.}
|
14
|
+
spec.summary = %q{Log validation errors to the database for later inspection.}
|
15
|
+
spec.homepage = "https://github.com/watu/validation_auditor"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = `git ls-files`.split($/)
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_dependency "activerecord", "> 3.2.0"
|
24
|
+
spec.add_dependency "actionpack", "> 3.2.0"
|
25
|
+
spec.add_dependency "railties", "> 3.2.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: validation_auditor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- J. Pablo Fernández
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>'
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>'
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: actionpack
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>'
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>'
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: railties
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>'
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.2.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>'
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.2.0
|
55
|
+
description: Log validation errors to the database for later inspection.
|
56
|
+
email:
|
57
|
+
- pupeno@watuapp.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .travis.yml
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- gemfiles/rails_3_2.Gemfile
|
69
|
+
- gemfiles/rails_4_0.Gemfile
|
70
|
+
- lib/generators/validation_auditor/install_generator.rb
|
71
|
+
- lib/generators/validation_auditor/templates/migration.rb
|
72
|
+
- lib/validation_auditor.rb
|
73
|
+
- lib/validation_auditor/version.rb
|
74
|
+
- test/controller_test.rb
|
75
|
+
- test/install_generator_test.rb
|
76
|
+
- test/model_test.rb
|
77
|
+
- test/test_helper.rb
|
78
|
+
- validation_auditor.gemspec
|
79
|
+
homepage: https://github.com/watu/validation_auditor
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.1.11
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Log validation errors to the database for later inspection.
|
103
|
+
test_files:
|
104
|
+
- test/controller_test.rb
|
105
|
+
- test/install_generator_test.rb
|
106
|
+
- test/model_test.rb
|
107
|
+
- test/test_helper.rb
|