smart_params 2.0.1 → 2.0.2

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: 1458539488f74741cfe2d72128e13d5d1d69a2319de21d78418bd93b271207f9
4
- data.tar.gz: d19c9e978bb33e4810e29f53da29e8e191d0d0e5fd61cc5f7254b199b1091d8b
3
+ metadata.gz: ec98add977831a04f50ff7b0ca25cd092d22587c79c01ed7da7f44e97811cae1
4
+ data.tar.gz: d5ee94308ecebd7021e50fcde8692365814c512c59591a0ac359aa30641d5c4c
5
5
  SHA512:
6
- metadata.gz: d29f490037927c01a4d7b07a6897487b4db8f6899b4ede1ae51bf0616224abb846579458f8f0bba699ce5bb2615ee9e4b00b933fd861f7d04a066d212e681c88
7
- data.tar.gz: 86f18060913fac28db9b127bbc8904eeead3170cd17551cb854148b6ca87ee49786b6a3bc14c881334764d776901791519afc27944d77e0ed89179c3a63fc3de
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 = type
10
+ @wanted = wanted
11
11
  @raw = raw
12
12
  end
13
13
 
14
14
  def message
15
- "expected #{keychain.inspect} to be wanted of #{wanted.type.name}, but was #{raw.inspect}"
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
@@ -1,3 +1,3 @@
1
1
  module SmartParams
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.2"
3
3
  end
@@ -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 kind of Hash, but was nil")
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 kind of Hash, but was \"\"")
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.1
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