whiny_validation 0.1.1 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32bde23dcbbaca5f53ebc41921b9d92cdde6f15e
4
- data.tar.gz: 0f70d8c5fd63b0b8f50bb4da96db370d38d84a77
3
+ metadata.gz: 1eca817b17163a98a725ccea97ea7b0dbbb68a83
4
+ data.tar.gz: ccc913f2734a282feea927ae07ac094ce0a5bca7
5
5
  SHA512:
6
- metadata.gz: eb51c01721b684a7b130460d05d83dc0828fb95cc3c0db5018c8639010db864804212339619dc6c700145c2441beded541b760550b343697550364749dcbbc28
7
- data.tar.gz: c24c6ee244ca83d0a095869e23886ca00260d2832e501e2bf1c26641ebdc075db302d08867da050f9da636e6644ff21af3614061308bcf6a748007dea51313ac
6
+ metadata.gz: 26c0aa6a13e65f8ce6b49cfc520aac4e279fb4024012b79612b24c83dc6a8929b5ee85a510b24329d744542b6e7af7560455e928024a3802fb77b51cab70b054
7
+ data.tar.gz: ff532993524a4cc2804a328b4af0bbd44b53dde7d034d2c75ff03695b5507cea56bf372de200aab2f0c63c4666826f20ba3f2e34217a2dc4b4aeda7dd398ba53
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 1.9.3 and above.
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 "bundler/gem_tasks"
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
@@ -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
 
@@ -33,4 +36,4 @@ module ActiveRecord
33
36
  class Base
34
37
  include WhinyValidation
35
38
  end
36
- end
39
+ end if defined? ActiveRecord
@@ -1,3 +1,3 @@
1
1
  module WhinyValidation
2
- VERSION = "0.1.1"
2
+ VERSION = "1.0"
3
3
  end
@@ -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
@@ -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'
@@ -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 'activerecord'
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: 0.1.1
4
+ version: '1.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Morearty
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-09 00:00:00.000000000 Z
11
+ date: 2017-11-24 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: activerecord
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
- description: When an ActiveRecord model won't save because it's invalid, this gem
56
- writes the validation error messages to the log.
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,6 +110,8 @@ 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
@@ -89,8 +133,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
133
  version: '0'
90
134
  requirements: []
91
135
  rubyforge_project:
92
- rubygems_version: 2.2.2
136
+ rubygems_version: 2.2.5
93
137
  signing_key:
94
138
  specification_version: 4
95
- summary: Write ActiveRecord validation error messages to the log
96
- test_files: []
139
+ summary: Write ActiveRecord/ActiveModel validation error messages to the log
140
+ test_files:
141
+ - test/simple_test.rb
142
+ - test/test_helper.rb