Skip to content

Money.within? fails with ArgumentError when min and max amount are identical #177

Closed
@joewunderlich

Description

@joewunderlich

When the minimum and maximum amounts are identical Money.within? raises an ArgumentError.

Expected Behavior:

Money.within?(Money.new(:ZAR, "20"), Money.new(:ZAR, "20"), Money.new(:ZAR, "20")) should return true.

Current Behavior

Money.within?(Money.new(:ZAR, "20"), Money.new(:ZAR, "20"), Money.new(:ZAR, "20")) raises the following Error instead:

** (ArgumentError) Minimum must be less than maximum. Found Money.new(:ZAR, "20") and Money.new(:ZAR, "20")
(ex_money 5.19.0) lib/money.ex:1576: Money.within?/3

The comparison between min and max should be inclusive and only fail if minimum is greater than maximum but if the amounts are equal no error shoud be raised

Suggested Change

if compare(minimum, maximum) == :lt do -> if compare(minimum, maximum) in [:lt, :eq] do

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