whiny_validation 0.1.1 → 1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +31 -3
- data/Rakefile +10 -1
- data/lib/whiny_validation/version.rb +1 -1
- data/lib/whiny_validation.rb +17 -4
- data/test/simple_test.rb +35 -0
- data/test/test_helper.rb +11 -0
- data/whiny_validation.gemspec +6 -3
- metadata +57 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 29b7d8158ea77148918fbe3190467de13a42fc6f8f6f982beac6918a3ff38521
|
4
|
+
data.tar.gz: c5547fa0749947d4a4f9d66ed1f3d5fffd444cf3fd58daca8d7d1e3dae451946
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d78905e6eeaf4b159dd248bf4a1497193d6dbd40961598b27f5b7ad97ef798146b37bf5202475566d8cfee43c1c3ef9f9b6130e308217f75fc46b2bee44d58e
|
7
|
+
data.tar.gz: 6dbac61f0b98fadcc58f00afb5290167a05087251aaf4d8871b88cf94ca18d396b5c094e332cd946ad3b4c1a20e442379e351883eb0e5ca27ad88bd4fb9833d5
|
data/README.md
CHANGED
@@ -6,10 +6,10 @@ to figure it out.
|
|
6
6
|
|
7
7
|
WhinyValidation to the rescue.
|
8
8
|
|
9
|
-
When an ActiveRecord model won't save because it's invalid,
|
9
|
+
When an ActiveRecord/ActiveModel model won't save because it's invalid,
|
10
10
|
this gem writes the validation error messages to the log.
|
11
11
|
|
12
|
-
The log shows all the attributes of the ActiveRecord object
|
12
|
+
The log shows all the attributes of the ActiveRecord/ActiveModel object
|
13
13
|
that failed, along with the error message.
|
14
14
|
|
15
15
|
Validation errors are shown in an attractive yellow, which
|
@@ -18,11 +18,14 @@ stands out nicely if your terminal background is dark.
|
|
18
18
|
It can be useful in development and especially in test mode,
|
19
19
|
to understand why a model didn't save.
|
20
20
|
|
21
|
+
[Read more in this blog
|
22
|
+
post on I Like Stuff.](http://ilikestuffblog.com/2014/04/09/whiny-validation/)
|
23
|
+
|
21
24
|
![Whiny Validation](whiny_validation.gif)
|
22
25
|
|
23
26
|
## Compatibility
|
24
27
|
|
25
|
-
Ruby
|
28
|
+
Ruby 2.0 and above.
|
26
29
|
|
27
30
|
Rails 3.2 and above.
|
28
31
|
|
@@ -63,6 +66,31 @@ end
|
|
63
66
|
|
64
67
|
Quit your whining.
|
65
68
|
|
69
|
+
## FAQ
|
70
|
+
|
71
|
+
**Q**: I use Test::Unit because I hate RSpec. Does it work with Test::Unit?<br>
|
72
|
+
**A**: Yes. Quit your whining.
|
73
|
+
|
74
|
+
**Q**: I use RSpec because I hate Test::Unit. Does it work with RSpec?<br>
|
75
|
+
**A**: Yes. Quit your whining.
|
76
|
+
|
77
|
+
**Q**: I use ...<br>
|
78
|
+
**A**: Yes. It is independent of the test framework you use. Quit your whining.
|
79
|
+
|
80
|
+
**Q**: I use ActiveModel but not ActiveRecord. Can I use this gem?<br>
|
81
|
+
**A**: Yes. Now the gem works with any ActiveModel-compatible
|
82
|
+
framework. Quit your whining.
|
83
|
+
|
84
|
+
**Q**: Why not log to the console in addition to the log file? That would make it more obvious that a test is failing.<br>
|
85
|
+
**A**: Because some tests intentionally pass invalid input. You wouldn't want to see those in the console. Quit your whining.
|
86
|
+
|
87
|
+
**Q**: Why not raise an error in tests when input is invalid? That would make it more obvious that a test is failing.<br>
|
88
|
+
**A**: See previous answer. Quit your whining.
|
89
|
+
|
90
|
+
**Q**: I don't want to see validation errors in my production log. Users make mistakes and that shouldn't go in my log.<br>
|
91
|
+
**A**: This gem logs at the `debug` level by default. If you're using `debug` in production and still don't want to see
|
92
|
+
this gem's output, put it in a group in your Gemfile. Quit your whining.
|
93
|
+
|
66
94
|
## Contributing
|
67
95
|
|
68
96
|
1. Fork it
|
data/Rakefile
CHANGED
@@ -1,2 +1,11 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
-
require
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
task :default => :test
|
6
|
+
Rake::TestTask.new do |t|
|
7
|
+
t.libs << 'test'
|
8
|
+
t.test_files = Dir.glob(File.dirname(__FILE__) + '/test/**/*_test.rb').sort
|
9
|
+
t.warning = true
|
10
|
+
t.verbose = true
|
11
|
+
end
|
data/lib/whiny_validation.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require "active_support/concern"
|
2
|
+
require "active_support/notifications"
|
3
|
+
require "active_support/log_subscriber"
|
1
4
|
require "whiny_validation/version"
|
2
5
|
require "whiny_validation/configuration"
|
3
6
|
|
@@ -15,9 +18,17 @@ module WhinyValidation
|
|
15
18
|
end
|
16
19
|
|
17
20
|
class LogSubscriber < ActiveSupport::LogSubscriber
|
21
|
+
def color_mode_options
|
22
|
+
if ActiveSupport.gem_version < Gem::Version.new("7.1.0")
|
23
|
+
true
|
24
|
+
else
|
25
|
+
{ bold: true }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
18
29
|
def validation_failed(event)
|
19
30
|
send(WhinyValidation.configuration.log_level) do
|
20
|
-
name = color("Validation failed", YELLOW,
|
31
|
+
name = color("Validation failed", YELLOW, color_mode_options)
|
21
32
|
object = event.payload[:object]
|
22
33
|
error_messages = color(event.payload[:error_messages].map{|message|" => #{message}"}.join("\n"), YELLOW)
|
23
34
|
|
@@ -29,8 +40,10 @@ module WhinyValidation
|
|
29
40
|
WhinyValidation::LogSubscriber.attach_to :whiny_validation
|
30
41
|
end
|
31
42
|
|
32
|
-
|
33
|
-
|
34
|
-
|
43
|
+
if defined?(ActiveRecord)
|
44
|
+
# ActiveRecord is dependent on ActiveSupport so we are good
|
45
|
+
# with calling ActiveSupport
|
46
|
+
ActiveSupport.on_load(:active_record) do
|
47
|
+
ActiveRecord::Base.send(:include, WhinyValidation)
|
35
48
|
end
|
36
49
|
end
|
data/test/simple_test.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class WhinyValidationTest < ActiveSupport::TestCase
|
4
|
+
class Person
|
5
|
+
include ActiveModel::Model
|
6
|
+
include ActiveModel::Validations::Callbacks
|
7
|
+
include WhinyValidation
|
8
|
+
|
9
|
+
attr_accessor :name
|
10
|
+
validates_presence_of :name
|
11
|
+
end
|
12
|
+
|
13
|
+
setup do
|
14
|
+
@io = StringIO.new
|
15
|
+
ActiveSupport::LogSubscriber.logger = Logger.new @io
|
16
|
+
end
|
17
|
+
|
18
|
+
test "logging via Notifications" do
|
19
|
+
ActiveSupport::Notifications.subscribe do |*args|
|
20
|
+
payload = args.last
|
21
|
+
assert_equal payload[:error_messages], payload[:object].errors.full_messages
|
22
|
+
end
|
23
|
+
|
24
|
+
person.valid?
|
25
|
+
end
|
26
|
+
|
27
|
+
test "logging via LogSubscriber" do
|
28
|
+
person.valid?
|
29
|
+
assert @io.string.include? "Name can't be blank"
|
30
|
+
end
|
31
|
+
|
32
|
+
def person
|
33
|
+
Person.new
|
34
|
+
end
|
35
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
Bundler.require :default
|
3
|
+
require 'minitest'
|
4
|
+
require 'minitest/mock'
|
5
|
+
require 'active_model'
|
6
|
+
require 'active_support/test_case'
|
7
|
+
require 'active_support/testing/autorun'
|
8
|
+
require 'logger'
|
9
|
+
require 'stringio'
|
10
|
+
|
11
|
+
require 'whiny_validation'
|
data/whiny_validation.gemspec
CHANGED
@@ -4,8 +4,8 @@ require File.expand_path('../lib/whiny_validation/version', __FILE__)
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["Brian Morearty"]
|
6
6
|
gem.email = ["brian@morearty.org"]
|
7
|
-
gem.description = %q{When an ActiveRecord model won't save because it's invalid, this gem writes the validation error messages to the log.}
|
8
|
-
gem.summary = %q{Write ActiveRecord validation error messages to the log}
|
7
|
+
gem.description = %q{When an ActiveRecord/ActiveModel model won't save because it's invalid, this gem writes the validation error messages to the log.}
|
8
|
+
gem.summary = %q{Write ActiveRecord/ActiveModel validation error messages to the log}
|
9
9
|
gem.homepage = "https://github.com/BMorearty/whiny_validation"
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($\)
|
@@ -16,7 +16,10 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.version = WhinyValidation::VERSION
|
17
17
|
|
18
18
|
gem.add_dependency 'activesupport'
|
19
|
-
gem.add_dependency '
|
19
|
+
gem.add_dependency 'activemodel'
|
20
20
|
|
21
21
|
gem.add_development_dependency 'rake'
|
22
|
+
gem.add_development_dependency 'activerecord'
|
23
|
+
gem.add_development_dependency 'minitest'
|
24
|
+
gem.add_development_dependency 'pry-byebug'
|
22
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whiny_validation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: '1.1'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Morearty
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: activemodel
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -52,8 +52,50 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
|
56
|
-
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activerecord
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: When an ActiveRecord/ActiveModel model won't save because it's invalid,
|
98
|
+
this gem writes the validation error messages to the log.
|
57
99
|
email:
|
58
100
|
- brian@morearty.org
|
59
101
|
executables: []
|
@@ -68,12 +110,14 @@ files:
|
|
68
110
|
- lib/whiny_validation.rb
|
69
111
|
- lib/whiny_validation/configuration.rb
|
70
112
|
- lib/whiny_validation/version.rb
|
113
|
+
- test/simple_test.rb
|
114
|
+
- test/test_helper.rb
|
71
115
|
- whiny_validation.gemspec
|
72
116
|
- whiny_validation.gif
|
73
117
|
homepage: https://github.com/BMorearty/whiny_validation
|
74
118
|
licenses: []
|
75
119
|
metadata: {}
|
76
|
-
post_install_message:
|
120
|
+
post_install_message:
|
77
121
|
rdoc_options: []
|
78
122
|
require_paths:
|
79
123
|
- lib
|
@@ -88,9 +132,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
132
|
- !ruby/object:Gem::Version
|
89
133
|
version: '0'
|
90
134
|
requirements: []
|
91
|
-
|
92
|
-
|
93
|
-
signing_key:
|
135
|
+
rubygems_version: 3.3.7
|
136
|
+
signing_key:
|
94
137
|
specification_version: 4
|
95
|
-
summary: Write ActiveRecord validation error messages to the log
|
96
|
-
test_files:
|
138
|
+
summary: Write ActiveRecord/ActiveModel validation error messages to the log
|
139
|
+
test_files:
|
140
|
+
- test/simple_test.rb
|
141
|
+
- test/test_helper.rb
|