ecto icon indicating copy to clipboard operation
ecto copied to clipboard

No validation of options specified in validate_number()

Open filipabramowicz opened this issue 11 years ago • 4 comments

There is no validation of options specified in validate_number(changeset, field, opts).

According to the documentation, only the following options are allowed:

:less_than
:greater_than
:less_than_or_equal_to
:greater_than_or_equal_to
:equal_to
:message

However when incorrect options are used, such code fails silently (it doesn't validate and it doesn't fail at compilation) - there is no indication that something is wrong:

  def changeset(model, params \\ :empty) do
    model
    |> cast(params, @required_fields, @optional_fields)
    |> validate_number(:duration, min: 10, max: 60000)
  end

Is it for some reason or could it be improved?

filipabramowicz avatar Aug 14 '15 10:08 filipabramowicz

I could definitely be improved.

josevalim avatar Aug 14 '15 11:08 josevalim

Do you plan to implement it or do you need some help?

filipabramowicz avatar Aug 14 '15 11:08 filipabramowicz

Please try a pull request if you would like to. I won't have time to tackle this one soon.

josevalim avatar Aug 14 '15 11:08 josevalim

Fixed in master.

josevalim avatar Aug 15 '15 09:08 josevalim