Skip to content

Explicitly passing nil default property fails required check #63

@sambostock

Description

@sambostock

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions