Skip to content

Commit

Permalink
Fix nil value issue with coercible floats (#30)
Browse files Browse the repository at this point in the history
Fix nil crash issue with CoercibleType definition
  • Loading branch information
TheWudu authored Mar 4, 2022
1 parent 363e7d3 commit 31408ae
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 3 deletions.
Empty file removed .approvals
Empty file.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
/tmp/
/bin/
*.swp
.approvals
spec/examples.txt
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [0.7.1] - 2022-03-04
### Fixed
- Float coercion: check for nil before coercion

## [0.7.0] - 2022-02-25
### Added
- Lambda definitions can now be failed with custom error messages
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
definition (0.7.0)
definition (0.7.1)
activesupport
i18n

Expand Down
2 changes: 1 addition & 1 deletion lib/definition/types/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(name, klass, &coerce)
end

def conform(value)
value = coerce.call(value) if coerce && !valid?(value)
value = coerce.call(value) if value && coerce && !valid?(value)

try_conform(value)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/definition/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Definition
VERSION = "0.7.0"
VERSION = "0.7.1"
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"": "<Definition::ConformError \n\t message: \"Is of type NilClass instead of Float\", \n\t json_pointer: \"/\">"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"": "<Definition::ConformError \n\t message: \"Is of type NilClass instead of Float\", \n\t json_pointer: \"/\">"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Is of type NilClass instead of Float
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Is of type NilClass instead of Float
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[0] <Definition::ConformError
message: "Is of type NilClass instead of Float",
json_pointer: "/">
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[0] <Definition::ConformError
message: "Is of type NilClass instead of Float",
json_pointer: "/">
6 changes: 6 additions & 0 deletions spec/integration/coercible_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@

it_behaves_like "it does not conform"
end

context "with incoercible nil value" do
let(:value) { nil }

it_behaves_like "it does not conform"
end
end

0 comments on commit 31408ae

Please sign in to comment.