validation_auditor 0.1.0 → 0.1.1

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: e11ee0bdea5ce733ed1a994b32c21c5de80bb239
4
- data.tar.gz: 8d2b38478f274fa566e8691514ca701a932caa2e
3
+ metadata.gz: 411fc2578c6e75c4dd673dcaf450b9d983afee48
4
+ data.tar.gz: d43b3a6365daf49c9ab70203ea90e5dc4fcaa9b8
5
5
  SHA512:
6
- metadata.gz: 80d6eaa8a29043d2d7d6b581469535a263efe1066a238094799028bdf5831045599d029b889ca7e717123a45bd1e3227ace941f91335ecd872ec7dc5de4a4c57
7
- data.tar.gz: 77ef7c6da46f74b9017d049b7042e245138137c98d879f4fd3c20f54392c135adbd5c0b155096d31154fe686d79167b7ba44b2467c103a4d5ff0b67c8c6a637d
6
+ metadata.gz: ed77c23dc4170250a96ab8affc6d9893dc7283418d494a21600d567cd9c1fb941364bf5746e9fe57a214c170f9295c95eda7abf269cd524b8451559e95ff519c
7
+ data.tar.gz: 8e0ccfef2d9faf289a1a896574ae9bf5eb50686f39938478ce1bb55e70e30a14ea2f98d46bfc03e94a50e829f07941e004129abba548b657cb70ae4d5026f747
@@ -2,5 +2,8 @@ language: ruby
2
2
  rvm:
3
3
  - "1.9.3"
4
4
  - "2.0.0"
5
+ - "2.1.2"
5
6
  gemfile:
7
+ - gemfiles/rails_3_2.Gemfile
6
8
  - gemfiles/rails_4_0.Gemfile
9
+ - gemfiles/rails_4_1.Gemfile
@@ -0,0 +1,7 @@
1
+ ## validation_auditor 0.1.1 (Jul 23, 2014) ##
2
+
3
+ * Don't crash in the presence of file uploads when reporting validation errors.
4
+
5
+ ## validation_auditor 0.1.0 (January 8, 2014) ##
6
+
7
+ * Everything
data/Gemfile CHANGED
@@ -1,17 +1,18 @@
1
1
  # encoding: UTF-8
2
- # Copyright © 2014, Watu
2
+ # Copyright © 2013, 2014, Watu
3
3
 
4
4
  source "https://rubygems.org"
5
5
 
6
6
  gem "assert_difference"
7
7
  gem "bundler", "~> 1.3"
8
8
  gem "coveralls", require: false
9
- gem "minitest", "~> 4.7.5"
9
+ gem "minitest"
10
10
  gem "minitest-reporters"
11
+ gem "minitest-rails"
11
12
  gem "rake"
12
13
  gem "simplecov"
13
14
  gem "shoulda"
14
15
  gem "sqlite3"
15
- gem "activerecord", "~> 4.0.0"
16
- gem "actionpack", "~> 4.0.0"
17
- gem "railties", "~> 4.0.0"
16
+ gem "activerecord", "~> 3.2.0"
17
+ gem "actionpack", "~> 3.2.0"
18
+ gem "railties", "~> 3.2.0"
data/README.md CHANGED
@@ -13,9 +13,9 @@ character and won't accept anything else because that's not your name? We all do
13
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
14
  where things are going wrong.
15
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.
16
+ This gem supports
17
+ [Rails 3.2, 4.0 and 4.1 running on Ruby 1.9, 2.0 or 2.1](https://travis-ci.org/watu/validation_auditor) (latest stable
18
+ version of each).
19
19
 
20
20
  ## Installation
21
21
 
@@ -3,14 +3,16 @@
3
3
 
4
4
  source "https://rubygems.org"
5
5
 
6
+ gem "assert_difference"
6
7
  gem "bundler", "~> 1.3"
7
8
  gem "coveralls", require: false
8
- gem "minitest", "~> 2.5.1"
9
+ gem "minitest"
9
10
  gem "minitest-reporters"
10
- gem "mocha"
11
+ gem "minitest-rails"
11
12
  gem "rake"
12
13
  gem "simplecov"
13
14
  gem "shoulda"
14
15
  gem "sqlite3"
15
- gem "activesupport", "~> 3.2.0"
16
16
  gem "activerecord", "~> 3.2.0"
17
+ gem "actionpack", "~> 3.2.0"
18
+ gem "railties", "~> 3.2.0"
@@ -6,8 +6,9 @@ source "https://rubygems.org"
6
6
  gem "assert_difference"
7
7
  gem "bundler", "~> 1.3"
8
8
  gem "coveralls", require: false
9
- gem "minitest", "~> 4.7.5"
9
+ gem "minitest"
10
10
  gem "minitest-reporters"
11
+ gem "minitest-rails"
11
12
  gem "rake"
12
13
  gem "simplecov"
13
14
  gem "shoulda"
@@ -0,0 +1,18 @@
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"
10
+ gem "minitest-reporters"
11
+ gem "minitest-rails"
12
+ gem "rake"
13
+ gem "simplecov"
14
+ gem "shoulda"
15
+ gem "sqlite3"
16
+ gem "activerecord", "~> 4.1.0"
17
+ gem "actionpack", "~> 4.1.0"
18
+ gem "railties", "~> 4.1.0"
@@ -14,10 +14,12 @@ module ValidationAuditor
14
14
  serialize :data, Hash
15
15
  serialize :params, Hash
16
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
17
+
18
+ if respond_to? :attr_accessible # For Rails < 4 or Rails >= 4 with attr_accessible added by a third party library.
19
+ begin
20
+ attr_accessible
21
+ rescue RuntimeError # Rails 4 raises a RuntimeError when you call attr_accessible, but we still want to call it in case you added attr_accessible gem.
22
+ end
21
23
  end
22
24
  end
23
25
 
@@ -37,6 +39,21 @@ module ValidationAuditor
37
39
  def self.request
38
40
  Thread.current[:validation_auditor_request]
39
41
  end
42
+
43
+ # Clean parameters before storing them in the database.
44
+ def self.clean_params(params)
45
+ cleaned_params = {}
46
+ params.each do |k, v|
47
+ cleaned_params[k] = if v.is_a? Hash
48
+ clean_params(v) # clean params recursively.
49
+ elsif v.is_a? ActionDispatch::Http::UploadedFile
50
+ v.inspect # UploadedFiles cannot be yaml-serialized, so, we replace them with a string.
51
+ else
52
+ v
53
+ end
54
+ end
55
+ cleaned_params
56
+ end
40
57
  end
41
58
 
42
59
  module Model
@@ -61,7 +78,7 @@ module ValidationAuditor
61
78
  end
62
79
  if ValidationAuditor::Controller.request.present?
63
80
  request = ValidationAuditor::Controller.request
64
- va.params = request.params
81
+ va.params = ValidationAuditor::Controller.clean_params(request.params)
65
82
  va.url = request.url
66
83
  va.user_agent = request.env["HTTP_USER_AGENT"]
67
84
  end
@@ -2,5 +2,5 @@
2
2
  # Copyright © 2014, Watu
3
3
 
4
4
  module ValidationAuditor
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
@@ -21,7 +21,11 @@ class AuditedRecordsController < ActionController::Base
21
21
  private
22
22
 
23
23
  def audited_record_params
24
- params.require(:audited_record).permit(:name, :email)
24
+ if params.respond_to?(:permit) # strong_parameters is present.
25
+ params.require(:audited_record).permit(:name, :email)
26
+ else
27
+ params[:audited_record]
28
+ end
25
29
  end
26
30
  end
27
31
 
@@ -35,6 +39,12 @@ class ControllerTest < ActionController::TestCase
35
39
  AuditedRecordsController.send(:include, @routes.url_helpers)
36
40
  end
37
41
 
42
+ should "clean params" do
43
+ cleaned_params = ValidationAuditor::Controller.clean_params({name: "John Doe", deep: {structure: {with: {file: ActionDispatch::Http::UploadedFile.new(tempfile: Tempfile.new("test.txt"))}}}})
44
+ assert_equal "John Doe", cleaned_params[:name]
45
+ assert cleaned_params[:deep][:structure][:with][:file].is_a? String
46
+ end
47
+
38
48
  should "not create a validation audit due to no validation failing when creating a new record" do
39
49
  assert_difference "ValidationAuditor::ValidationAudit.count" => 0 do
40
50
  post :create, audited_record: {name: "John Doe", email: "john.doe@example.com"}
@@ -53,6 +63,18 @@ class ControllerTest < ActionController::TestCase
53
63
  assert_equal ["can't be blank"], audit.failures[:email]
54
64
  end
55
65
 
66
+ should "create a validation audit even when an uploaded file is in the params" do
67
+ assert_difference "ValidationAuditor::ValidationAudit.count" => +1 do
68
+ post :create, audited_record: {name: "John Doe"}, deep: {structure: {with: {file: ActionDispatch::Http::UploadedFile.new(tempfile: Tempfile.new("test.txt"))}}} # Missing email and a deep structure with a file in it.
69
+ end
70
+ audit = ValidationAuditor::ValidationAudit.order(:id).last
71
+ assert_nil audit.record # New records cannot be referenced because they don't exist...
72
+ assert_equal "AuditedRecord", audit.record_type # but we still record the name.
73
+ assert_equal audit.data["name"], "John Doe"
74
+ assert_nil audit.data["email"]
75
+ assert_equal ["can't be blank"], audit.failures[:email]
76
+ end
77
+
56
78
  context "With a record" do
57
79
  setup do
58
80
  @audited_record = AuditedRecord.create(name: "John Doe", email: "john.doe@example.com")
@@ -29,6 +29,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
29
29
 
30
30
  # Database setup
31
31
  require "active_record"
32
+ require "logger"
32
33
  ActiveRecord::Base.logger = Logger.new(STDERR)
33
34
  ActiveRecord::Base.logger.level = Logger::WARN
34
35
  ActiveRecord::Base.configurations = {"sqlite3" => {adapter: "sqlite3", database: ":memory:"}}
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validation_auditor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - J. Pablo Fernández
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-08 00:00:00.000000000 Z
11
+ date: 2014-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>'
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>'
24
+ - - ">"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: actionpack
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>'
31
+ - - ">"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 3.2.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>'
38
+ - - ">"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 3.2.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: railties
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>'
45
+ - - ">"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 3.2.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>'
52
+ - - ">"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 3.2.0
55
55
  description: Log validation errors to the database for later inspection.
@@ -59,14 +59,16 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - .gitignore
63
- - .travis.yml
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - CHANGELOG.md
64
65
  - Gemfile
65
66
  - LICENSE.txt
66
67
  - README.md
67
68
  - Rakefile
68
69
  - gemfiles/rails_3_2.Gemfile
69
70
  - gemfiles/rails_4_0.Gemfile
71
+ - gemfiles/rails_4_1.Gemfile
70
72
  - lib/generators/validation_auditor/install_generator.rb
71
73
  - lib/generators/validation_auditor/templates/migration.rb
72
74
  - lib/validation_auditor.rb
@@ -86,17 +88,17 @@ require_paths:
86
88
  - lib
87
89
  required_ruby_version: !ruby/object:Gem::Requirement
88
90
  requirements:
89
- - - '>='
91
+ - - ">="
90
92
  - !ruby/object:Gem::Version
91
93
  version: '0'
92
94
  required_rubygems_version: !ruby/object:Gem::Requirement
93
95
  requirements:
94
- - - '>='
96
+ - - ">="
95
97
  - !ruby/object:Gem::Version
96
98
  version: '0'
97
99
  requirements: []
98
100
  rubyforge_project:
99
- rubygems_version: 2.1.11
101
+ rubygems_version: 2.2.2
100
102
  signing_key:
101
103
  specification_version: 4
102
104
  summary: Log validation errors to the database for later inspection.