smart_params 2.0.1 → 2.0.2
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,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec98add977831a04f50ff7b0ca25cd092d22587c79c01ed7da7f44e97811cae1
|
4
|
+
data.tar.gz: d5ee94308ecebd7021e50fcde8692365814c512c59591a0ac359aa30641d5c4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b0e8197a145e3a788081b23af7cc491e0f8dc92b9297d1da04cc38a7a285164c061c0a2dfe2035e5b3375ae93561e9cfa5b4eddc44ecbc0de7118bc2ac2b583
|
7
|
+
data.tar.gz: 6a0586b150170cdaa07ecca164a815cf8863ad6bd4afbf236b586a40c548102320b4b64d25a356cb5079ad6a1fdd681bae4704ffbe690a567c59805c0c589320
|
data/lib/smart_params.rb
CHANGED
@@ -19,12 +19,12 @@ module SmartParams
|
|
19
19
|
attr_reader :fields
|
20
20
|
|
21
21
|
def initialize(raw, safe: true)
|
22
|
+
@safe = safe
|
22
23
|
@raw = raw
|
23
24
|
@schema = self.class.instance_variable_get(:@schema)
|
24
25
|
@fields = [@schema, *unfold(@schema.subfields)]
|
25
26
|
.sort_by(&:weight)
|
26
27
|
.each { |field| field.claim(raw) }
|
27
|
-
@safe = safe
|
28
28
|
rescue SmartParams::Error::InvalidPropertyType => invalid_property_type_exception
|
29
29
|
if safe?
|
30
30
|
raise invalid_property_type_exception
|
@@ -7,12 +7,12 @@ module SmartParams
|
|
7
7
|
|
8
8
|
def initialize(keychain:, wanted:, raw:)
|
9
9
|
@keychain = keychain
|
10
|
-
@wanted =
|
10
|
+
@wanted = wanted
|
11
11
|
@raw = raw
|
12
12
|
end
|
13
13
|
|
14
14
|
def message
|
15
|
-
"expected #{keychain.inspect} to be
|
15
|
+
"expected #{keychain.inspect} to be #{wanted.type.name}, but was #{raw.inspect}"
|
16
16
|
end
|
17
17
|
|
18
18
|
def as_json
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe SmartParams::Error::InvalidPropertyType do
|
4
|
+
let(:error) { described_class.new(keychain: [:data], wanted: SmartParams::Strict::Hash, raw: "") }
|
5
|
+
|
6
|
+
describe "#message" do
|
7
|
+
subject { error.message }
|
8
|
+
|
9
|
+
it "returns the message" do
|
10
|
+
expect(subject).to eq("expected [:data] to be Hash, but was \"\"")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/smart_params/version.rb
CHANGED
data/lib/smart_params_spec.rb
CHANGED
@@ -8,7 +8,7 @@ RSpec.describe SmartParams do
|
|
8
8
|
let(:params) { {} }
|
9
9
|
|
10
10
|
it "throws an error with a message detailing the invalid property type and given properties" do
|
11
|
-
expect {schema}.to raise_exception(SmartParams::Error::InvalidPropertyType, "expected [:data] to be
|
11
|
+
expect {schema}.to raise_exception(SmartParams::Error::InvalidPropertyType, "expected [:data] to be Hash, but was nil")
|
12
12
|
end
|
13
13
|
|
14
14
|
it "throws an error with the missing property and given properties" do
|
@@ -22,7 +22,7 @@ RSpec.describe SmartParams do
|
|
22
22
|
let(:params) { {data: ""} }
|
23
23
|
|
24
24
|
it "throws an error with a message detailing the invalid property, expected type, given type, and given value" do
|
25
|
-
expect { schema }.to raise_exception(SmartParams::Error::InvalidPropertyType, "expected [:data] to be
|
25
|
+
expect { schema }.to raise_exception(SmartParams::Error::InvalidPropertyType, "expected [:data] to be Hash, but was \"\"")
|
26
26
|
end
|
27
27
|
|
28
28
|
it "throws an error with the invalid property, expected type, given type, and given value" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_params
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kurtis Rainbolt-Greene
|
@@ -148,6 +148,7 @@ files:
|
|
148
148
|
- lib/smart_params.rb
|
149
149
|
- lib/smart_params/error.rb
|
150
150
|
- lib/smart_params/error/invalid_property_type.rb
|
151
|
+
- lib/smart_params/error/invalid_property_type_spec.rb
|
151
152
|
- lib/smart_params/field.rb
|
152
153
|
- lib/smart_params/version.rb
|
153
154
|
- lib/smart_params/version_spec.rb
|