validation_auditor 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/validation_auditor.rb +13 -11
- data/lib/validation_auditor/version.rb +1 -1
- data/test/controller_test.rb +4 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df3fdbc82541c85c7c13bddebe3a18a4a7b8d50e
|
4
|
+
data.tar.gz: 698944970c971bf99d30eeec61782f75496e6c3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf9fd4135a3a550911658e1670a1bfa16080503dbca7a683c0da183da04553149cb4a0d65267430dd2267b2e1a3e525ff659b88eeea7328e42dbdba7e5cae96a
|
7
|
+
data.tar.gz: 0b93eba5ec3321b8fb09cf5b9e31ea695312a9daf08a31ceb637a083649c770a618b17f555d6adf4a299cbf18185154ca3c7ee63a543eda015de669724417352
|
data/CHANGELOG.md
CHANGED
data/lib/validation_auditor.rb
CHANGED
@@ -41,18 +41,20 @@ module ValidationAuditor
|
|
41
41
|
end
|
42
42
|
|
43
43
|
# Clean parameters before storing them in the database.
|
44
|
-
def self.clean_params(
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
44
|
+
def self.clean_params(param)
|
45
|
+
if param.is_a? Hash
|
46
|
+
cleaned_params = {}
|
47
|
+
param.each do |k, v|
|
48
|
+
cleaned_params[k] = clean_params(v) # clean each value
|
49
|
+
end
|
50
|
+
cleaned_params
|
51
|
+
elsif param.is_a? Array
|
52
|
+
param.map { |v| clean_params(v) } # clean each value
|
53
|
+
elsif param.is_a? ActionDispatch::Http::UploadedFile
|
54
|
+
param.inspect # UploadedFiles cannot be yaml-serialized, so, we replace them with a string.
|
55
|
+
else
|
56
|
+
param
|
54
57
|
end
|
55
|
-
cleaned_params
|
56
58
|
end
|
57
59
|
end
|
58
60
|
|
data/test/controller_test.rb
CHANGED
@@ -40,9 +40,11 @@ class ControllerTest < ActionController::TestCase
|
|
40
40
|
end
|
41
41
|
|
42
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"))}}}})
|
43
|
+
cleaned_params = ValidationAuditor::Controller.clean_params({name: "John Doe", deep: {structure: {with: {file: ActionDispatch::Http::UploadedFile.new(tempfile: Tempfile.new("test.txt")), and_files: [ActionDispatch::Http::UploadedFile.new(tempfile: Tempfile.new("test.txt"))]}}}})
|
44
44
|
assert_equal "John Doe", cleaned_params[:name]
|
45
45
|
assert cleaned_params[:deep][:structure][:with][:file].is_a? String
|
46
|
+
assert cleaned_params[:deep][:structure][:with][:and_files].is_a? Array
|
47
|
+
assert cleaned_params[:deep][:structure][:with][:and_files].first.is_a? String
|
46
48
|
end
|
47
49
|
|
48
50
|
should "not create a validation audit due to no validation failing when creating a new record" do
|
@@ -65,7 +67,7 @@ class ControllerTest < ActionController::TestCase
|
|
65
67
|
|
66
68
|
should "create a validation audit even when an uploaded file is in the params" do
|
67
69
|
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.
|
70
|
+
post :create, audited_record: {name: "John Doe"}, deep: {structure: {with: {file: ActionDispatch::Http::UploadedFile.new(tempfile: Tempfile.new("test.txt")), and_files: [ActionDispatch::Http::UploadedFile.new(tempfile: Tempfile.new("test.txt"))]}}} # Missing email and a deep structure with a file in it.
|
69
71
|
end
|
70
72
|
audit = ValidationAuditor::ValidationAudit.order(:id).last
|
71
73
|
assert_nil audit.record # New records cannot be referenced because they don't exist...
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validation_auditor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.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-
|
11
|
+
date: 2014-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|