simple_params 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/simple_params/validation_matchers/nested_parameter_matcher.rb +36 -0
- data/lib/simple_params/version.rb +1 -1
- data/lib/simple_params.rb +1 -0
- data/spec/validation_matchers/nested_parameter_matcher_spec.rb +26 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTg5ZjU4NGE5ODRkMmYwMDNlY2E5OTM2ZjgwYTcyYjJlYzk2YTM1MQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OWQ1ODFkYzljM2I5ZmNlOGYwZGU5Mzc3ZTY1Y2I5ZjRiNGMxMzJjMw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjhjZTMzNmUwNzc5NTg5NmNhODQxYjhlYzBiZThjNGVkMWExZDc2NzM4NDI5
|
10
|
+
NzUwNjhhMzExNGFjYzg0NjVlOWE0MzRhNDEwNzAyNzZhZGYyY2ZlMDdmMDFm
|
11
|
+
M2NjZWI2OGM0NWU0ZmYxMWVlYTMzZmM5YTcxZDJkZjQ1YzhjMWU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MjhkZWI0OWVkYTQyMjIwYzk0OTRhNGNjNjM5NTMwMTFmYmYzZjA1ODdlZDRj
|
14
|
+
MmU4ZGZkZTAwN2IwZTcyNTgyMDQ1YTY2ODNhMjFiYTViZWFlMDA2NjAzOWFl
|
15
|
+
YTE3OWZkZmNhMGE4ZTIyMjk0Nzk2ZjNhY2JmYmYyMzIzYTc4MWQ=
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
module SimpleParams
|
2
|
+
module ValidationMatchers
|
3
|
+
def have_nested_parameter(attr)
|
4
|
+
NestedParameterMatcher.new(attr)
|
5
|
+
end
|
6
|
+
|
7
|
+
class NestedParameterMatcher < 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_hashes).has_key?(@attribute)
|
18
|
+
end
|
19
|
+
|
20
|
+
def description
|
21
|
+
"Should have nested param #{@attribute}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def failure_message_for_should
|
25
|
+
"Should have nested param #{@attribute}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def failure_message_for_should_not
|
29
|
+
"Should not have nested param #{@attribute}"
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/simple_params.rb
CHANGED
@@ -13,5 +13,6 @@ require 'simple_params/api_pie_doc/nested_attribute'
|
|
13
13
|
require 'simple_params/validation_matchers/validation_matcher'
|
14
14
|
require 'simple_params/validation_matchers/coercion_matcher'
|
15
15
|
require 'simple_params/validation_matchers/format_matcher'
|
16
|
+
require 'simple_params/validation_matchers/nested_parameter_matcher'
|
16
17
|
require 'simple_params/validation_matchers/required_parameter_matcher'
|
17
18
|
require 'simple_params/validation_matchers/optional_parameter_matcher'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SimpleParams::ValidationMatchers::NestedParameterMatcher do
|
4
|
+
class NestedParameterMatcherTestClass < SimpleParams::Params
|
5
|
+
param :name
|
6
|
+
param :age, optional: true, default: 37
|
7
|
+
param :title, optional: true, default: "programmer"
|
8
|
+
param :account_type, default: "checking", validations: { inclusion: { in: ["checking", "savings"] }}
|
9
|
+
param :account_status, optional: true, validations: { inclusion: { in: ["active", "inactive"] }}
|
10
|
+
nested_param :billing_address do
|
11
|
+
param :first_name
|
12
|
+
param :last_name
|
13
|
+
param :company, optional: true
|
14
|
+
param :street
|
15
|
+
param :city
|
16
|
+
param :state
|
17
|
+
param :zip_code
|
18
|
+
param :country
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
subject { NestedParameterMatcherTestClass.new }
|
23
|
+
|
24
|
+
it { should have_nested_parameter(:billing_address) }
|
25
|
+
it { should_not have_nested_parameter(:broken) }
|
26
|
+
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: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- brycesenz
|
@@ -140,6 +140,7 @@ files:
|
|
140
140
|
- lib/simple_params/type_mappings.rb
|
141
141
|
- lib/simple_params/validation_matchers/coercion_matcher.rb
|
142
142
|
- lib/simple_params/validation_matchers/format_matcher.rb
|
143
|
+
- lib/simple_params/validation_matchers/nested_parameter_matcher.rb
|
143
144
|
- lib/simple_params/validation_matchers/optional_parameter_matcher.rb
|
144
145
|
- lib/simple_params/validation_matchers/required_parameter_matcher.rb
|
145
146
|
- lib/simple_params/validation_matchers/validation_matcher.rb
|
@@ -159,6 +160,7 @@ files:
|
|
159
160
|
- spec/support/shared_examples/base_attribute.rb
|
160
161
|
- spec/validation_matchers/coercion_matcher_spec.rb
|
161
162
|
- spec/validation_matchers/format_matcher_spec.rb
|
163
|
+
- spec/validation_matchers/nested_parameter_matcher_spec.rb
|
162
164
|
- spec/validation_matchers/optional_parameter_matcher_spec.rb
|
163
165
|
- spec/validation_matchers/required_parameter_matcher_spec.rb
|
164
166
|
homepage: https://github.com/brycesenz/simple_params
|
@@ -199,5 +201,6 @@ test_files:
|
|
199
201
|
- spec/support/shared_examples/base_attribute.rb
|
200
202
|
- spec/validation_matchers/coercion_matcher_spec.rb
|
201
203
|
- spec/validation_matchers/format_matcher_spec.rb
|
204
|
+
- spec/validation_matchers/nested_parameter_matcher_spec.rb
|
202
205
|
- spec/validation_matchers/optional_parameter_matcher_spec.rb
|
203
206
|
- spec/validation_matchers/required_parameter_matcher_spec.rb
|