smart_properties
smart_properties copied to clipboard
Explicitly passing nil default property fails required check
Given a property defined as follows:
class Foo
include SmartProperties
property :bar, required: true, default: true
end
The following code works, as expected:
Foo.new # => #<Thing @bar=true>
Foo.new(bar: true) # => #<Thing @bar=true>
Foo.new(bar: false) # => #<Thing @bar=false>
However, explicitly providing the bar property as nil fails:
Foo.new(bar: nil)
# SmartProperties::MissingValueError: Foo requires the property bar to be set
Is this desired behaviour? It would seem logical that explicitly passing in nil should fall through to the default, which would satisfy the required constraint.
This is indeed specified behaviour: https://github.com/t6d/smart_properties/blob/master/spec/required_values_spec.rb. That said, I'm currently working towards a 2.0 release and will investigate whether making the behaviour configurable is an option.