input_sanitizer 0.5.0 → 0.6.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
  SHA256:
3
- metadata.gz: b17187da279365f142d7fe151cde0475bc79bd906eaa517a394d0345dfa959da
4
- data.tar.gz: ae5b758685cba665827b5616e7bd2af11e9e20199fb38162355876c64df26e7f
3
+ metadata.gz: 42f76190c3f31a2a1cd2a3372fcda7bad0e107b621ec3f34cc46ef5a1724b08e
4
+ data.tar.gz: 4b4400b8f4305308dd076f3a9092a9606fe48860809fadda7a2029cf8fcb57fb
5
5
  SHA512:
6
- metadata.gz: dac569cd500bf5f3c25be2aba2d863b74083d47704aa737fe2670dc8051fbc59e4bcc81de2468d2899dbe1b0d3700d8b6e2446dad0910a0d554aa3fec3f7f888
7
- data.tar.gz: eb1bae9cfa2759748ac63af0f5e582d74e06fc70ebd2e4ffc979b7c62fa36bca0d17780e01ca177be33dc3e7d61511f5926e8581cc977dbfdc926b21ae35af70
6
+ metadata.gz: b5c9fcd7ff42c69d76fe7c266972e12e18a50bd09a325ef8b3dd02321f205a8596c4eab2ac5e8eea4b42a4761198a0f6d7ecdfeb9b052764dfb99d048698c43b
7
+ data.tar.gz: 8137f9b0b246eb3fdbf74d828bab6f3d97fe5c79616eac19821f727bf0229e277e7d6056bbef2836fd1658dc2766955a95786cf9645d927339a81039028661d2
@@ -14,8 +14,9 @@ jobs:
14
14
  - 2.7.6
15
15
  - 3.0.4
16
16
  - 3.1.2
17
+ - 3.2.0
17
18
  steps:
18
- - uses: zendesk/checkout@v2
19
+ - uses: zendesk/checkout@v3
19
20
  - name: Set up Ruby
20
21
  uses: zendesk/setup-ruby@v1
21
22
  with:
data/.gitignore CHANGED
@@ -17,3 +17,5 @@ test/version_tmp
17
17
  tmp
18
18
  /bin
19
19
  Gemfile.lock
20
+ /out
21
+ *iml
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ 0.6.0
2
+ * Validate array of hashes is passed to collection of nested objects
3
+
1
4
  0.5.0
2
5
  * Added support for Ruby 3
3
6
 
@@ -8,10 +8,30 @@ class InputSanitizer::V2::NestedSanitizerFactory
8
8
  true
9
9
  end
10
10
  end
11
+
12
+ class HashExpected
13
+ def initialize(value)
14
+ @value = value
15
+ end
16
+
17
+ def valid?
18
+ false
19
+ end
20
+
21
+ def cleaned
22
+ nil
23
+ end
24
+
25
+ def errors
26
+ [InputSanitizer::TypeMismatchError.new(@value, :hash)]
27
+ end
28
+ end
11
29
 
12
30
  def self.for(nested_sanitizer_klass, value, options)
13
31
  if value.nil? && options[:allow_nil] && !options[:collection]
14
32
  NilAllowed.new
33
+ elsif !value.is_a?(Hash)
34
+ HashExpected.new(value)
15
35
  else
16
36
  nested_sanitizer_klass.new(value, options)
17
37
  end
@@ -1,3 +1,3 @@
1
1
  module InputSanitizer
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -19,4 +19,3 @@ RSpec.configure do |config|
19
19
  end
20
20
 
21
21
  require 'input_sanitizer'
22
- require 'pry'
@@ -484,6 +484,11 @@ describe InputSanitizer::V2::PayloadSanitizer do
484
484
  end
485
485
 
486
486
  describe "array of nested objects" do
487
+ it "is valid when given a collection of nested objects" do
488
+ @params = { :tags => [{:id => 1, :name => "crm", :addresses => []}]}
489
+ sanitizer.should be_valid
490
+ end
491
+
487
492
  it "returns an error when given a nil for a collection" do
488
493
  @params = { :tags => nil }
489
494
  sanitizer.should_not be_valid
@@ -494,6 +499,13 @@ describe InputSanitizer::V2::PayloadSanitizer do
494
499
  sanitizer.should_not be_valid
495
500
  end
496
501
 
502
+ it "returns an error when given an collection of raw values" do
503
+ @params = { :tags => ['nope'] }
504
+ sanitizer.should_not be_valid
505
+ sanitizer.errors.length.should eq(1)
506
+ sanitizer.errors.map(&:field).should contain_exactly('/tags/0')
507
+ end
508
+
497
509
  it "returns an error when given a hash for a collection" do
498
510
  @params = { :tags => { :a => 1 } }
499
511
  sanitizer.should_not be_valid
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: input_sanitizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zendesk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-14 00:00:00.000000000 Z
11
+ date: 2023-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: method_struct