simple_params 1.0.4 → 1.0.5

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MWQxN2I0ZTRlYjM1NmFmMDc0ZGRhNDA5YWQ3ZDhjMWUzZWMzM2QzMw==
4
+ MDJjYTQ5MTFmNzEyZmRlYjViMjQyZDY5YzlmNDQ2ZmJiYzU4ZjQyNg==
5
5
  data.tar.gz: !binary |-
6
- MjA4ZmQ5NDcxMjM1OTRjNzAwZTMzM2Y3MjExMGJlZDIwNDVmY2YwZQ==
6
+ MjYwZTM3OWE3ZjczODI3NzM5YzhhODFiYzU3ZDA5NTRjYTdkZWU4Mg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTI0YjczMDJjMTI0OGQ4NmY4ZDZkZWYwMGNhYTA5NzIyZjZjODRiMGE4ZTZi
10
- NzZkZDJlY2YyMDE4YzQ3OWQ1YWE3Mjg1MDg2MjlhZTAyZTJhMTc3NTRiN2M5
11
- ZGM5MTFlMTE3NjFjZDhjMDFkMjJhMjZjYTEwNTQ0NzViN2JiNWY=
9
+ ZjVlNjMxNDlkZTkwOTdiYTllZTg4MGRmYTZhYTE1OWIzN2Y5NjMzNmE0NzUy
10
+ YzQ2YjM4NGM2ZDc2OTAxNjc2NmU3MjA5YTQzMGI5ZWUyYzU4MDQ0NDhiMDcw
11
+ MmI2Mjg0ZWI3ZDEzOTY1ZGJmMWQyYzI3ZTA1OWJmYzc1Mzk1N2Q=
12
12
  data.tar.gz: !binary |-
13
- YTY4MmRhMWRlYTQ1NmM1N2YzNmMwZjIzNTE3ZTNiZjQ3NDY0ZjhlMTI5MmI5
14
- NTBiMmNjYTAxZWJiNzhkZTIxNThkMDFhMDc5NGE0OTdmYjI3ZTQ0ZmQ4ZDc0
15
- Nzc4MjllNDYyZGZjNTJjM2FiNmFkNTUxMmEwNmM3ODFkODNlZmU=
13
+ NWQxMzE3ZjRlNDM3MmQ0NzU3MmY5NzRjN2Y4Zjk4YzYzZTQxNTc0MWM2ZDgx
14
+ NTliYjIyYTkxMDY4MzE2MGVkZTdmYThmMmQwYmEwMTUwMjIyYThkMzdlZGU4
15
+ ZWZiMzBmYjQyOGRhYWNhNTIwYzAwMjM0NzQ3MzhhY2Y5NmZmMTI=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_params (1.0.3)
4
+ simple_params (1.0.4)
5
5
  activemodel (>= 3.0, < 5.0)
6
6
  shoulda-matchers (~> 2.8)
7
7
  virtus (>= 1.0.0)
data/lib/simple_params.rb CHANGED
@@ -14,6 +14,7 @@ require 'simple_params/api_pie_doc/nested_attribute'
14
14
  require 'simple_params/validation_matchers/validation_matcher'
15
15
  require 'simple_params/validation_matchers/coercion_matcher'
16
16
  require 'simple_params/validation_matchers/format_matcher'
17
+ require 'simple_params/validation_matchers/nested_array_matcher'
17
18
  require 'simple_params/validation_matchers/nested_parameter_matcher'
18
19
  require 'simple_params/validation_matchers/required_parameter_matcher'
19
20
  require 'simple_params/validation_matchers/optional_parameter_matcher'
@@ -169,8 +169,15 @@ module SimpleParams
169
169
  def to_hash
170
170
  hash = {}
171
171
  attributes.each do |attribute|
172
- if send(attribute).is_a?(SimpleParams::Params)
172
+ raw_attribute = send(attribute)
173
+ if raw_attribute.is_a?(SimpleParams::Params)
173
174
  hash[attribute] = send(attribute).to_hash
175
+ elsif raw_attribute.is_a?(Array)
176
+ attribute_array = []
177
+ raw_attribute.each do |r_attr|
178
+ attribute_array << r_attr.to_hash
179
+ end
180
+ hash[attribute] = attribute_array
174
181
  else
175
182
  hash[attribute] = send(attribute)
176
183
  end
@@ -0,0 +1,36 @@
1
+ module SimpleParams
2
+ module ValidationMatchers
3
+ def have_nested_array(attr)
4
+ NestedArrayMatcher.new(attr)
5
+ end
6
+
7
+ class NestedArrayMatcher < ValidationMatcher
8
+ attr_accessor :attribute
9
+
10
+ def initialize(attribute)
11
+ super(attribute)
12
+ @attribute = attribute
13
+ end
14
+
15
+ def matches?(subject)
16
+ super(subject)
17
+ subject.send(:nested_arrays).has_key?(@attribute)
18
+ end
19
+
20
+ def description
21
+ "Should have nested array #{@attribute}"
22
+ end
23
+
24
+ def failure_message_for_should
25
+ "Should have nested array #{@attribute}"
26
+ end
27
+
28
+ def failure_message_for_should_not
29
+ "Should not have nested array #{@attribute}"
30
+ end
31
+
32
+ private
33
+
34
+ end
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module SimpleParams
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
@@ -59,7 +59,19 @@ describe SimpleParams::Params do
59
59
 
60
60
  describe "to_hash", to_hash: true do
61
61
  it "returns params hash" do
62
- params = AcceptanceParams.new(name: "Tom", address: { "street" => "1 Main St."} )
62
+ params = AcceptanceParams.new(
63
+ name: "Tom",
64
+ address: {
65
+ "street" => "1 Main St."
66
+ },
67
+ dogs: [
68
+ {
69
+ name: "Spot",
70
+ age: 8
71
+ }
72
+ ]
73
+ )
74
+
63
75
  params.to_hash.should eq({
64
76
  reference: nil,
65
77
  name: "Tom",
@@ -73,7 +85,12 @@ describe SimpleParams::Params do
73
85
  state: "North Carolina",
74
86
  company: nil
75
87
  },
76
- dogs: []
88
+ dogs: [
89
+ {
90
+ name: "Spot",
91
+ age: 8
92
+ }
93
+ ]
77
94
  })
78
95
  end
79
96
  end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe SimpleParams::ValidationMatchers::NestedArrayMatcher do
4
+ class NestedArrayMatcherTestClass < SimpleParams::Params
5
+ param :name
6
+ param :age, optional: true, default: 37
7
+ nested_array :dogs do
8
+ param :name
9
+ param :age, type: :integer
10
+ end
11
+ end
12
+
13
+ subject { NestedArrayMatcherTestClass.new }
14
+
15
+ it { should have_nested_array(:dogs) }
16
+ it { should_not have_nested_array(:broken) }
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_params
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - brycesenz
@@ -141,6 +141,7 @@ files:
141
141
  - lib/simple_params/type_mappings.rb
142
142
  - lib/simple_params/validation_matchers/coercion_matcher.rb
143
143
  - lib/simple_params/validation_matchers/format_matcher.rb
144
+ - lib/simple_params/validation_matchers/nested_array_matcher.rb
144
145
  - lib/simple_params/validation_matchers/nested_parameter_matcher.rb
145
146
  - lib/simple_params/validation_matchers/optional_parameter_matcher.rb
146
147
  - lib/simple_params/validation_matchers/required_parameter_matcher.rb
@@ -163,6 +164,7 @@ files:
163
164
  - spec/support/shared_examples/base_attribute.rb
164
165
  - spec/validation_matchers/coercion_matcher_spec.rb
165
166
  - spec/validation_matchers/format_matcher_spec.rb
167
+ - spec/validation_matchers/nested_array_matcher_spec.rb
166
168
  - spec/validation_matchers/nested_parameter_matcher_spec.rb
167
169
  - spec/validation_matchers/optional_parameter_matcher_spec.rb
168
170
  - spec/validation_matchers/required_parameter_matcher_spec.rb
@@ -206,6 +208,7 @@ test_files:
206
208
  - spec/support/shared_examples/base_attribute.rb
207
209
  - spec/validation_matchers/coercion_matcher_spec.rb
208
210
  - spec/validation_matchers/format_matcher_spec.rb
211
+ - spec/validation_matchers/nested_array_matcher_spec.rb
209
212
  - spec/validation_matchers/nested_parameter_matcher_spec.rb
210
213
  - spec/validation_matchers/optional_parameter_matcher_spec.rb
211
214
  - spec/validation_matchers/required_parameter_matcher_spec.rb