adzap / validates_timeliness

Date and time validation plugin for ActiveModel and Rails. Supports multiple ORMs and allows custom date/time formats.
MIT License
1.59k stars 227 forks source link

Different behavior when using ActiveRecord as a hash #137

Closed gvasselai closed 8 years ago

gvasselai commented 8 years ago

Usage: validates_date :dt_from, :dt_to, { allow_nil: true, allow_blank: true }

irb(main):045:0> p.valid?
=> true
irb(main):046:0> p[:dt_to] = nil
=> nil
irb(main):047:0> p.valid?
=> false
irb(main):048:0> p.errors.messages
=> {:dt_to=>["is not a valid date"]}
irb(main):049:0> p.dt_to = nil
=> nil
irb(main):050:0> p.valid?
=> true

Expected the validator to behave the same for p[:dt_to] = nil and p.dt_to = nil.

adzap commented 8 years ago

What version of ActiveRecord?

On 28 Feb 2016, at 2:31 AM, gvasselai notifications@github.com wrote:

Usage: validates_date :dt_from, :dt_to, { allow_nil: true, allow_blank: true }

irb(main):045:0> p.valid? => true irb(main):046:0> p[:dt_to] = nil => nil irb(main):047:0> p.valid? => false irb(main):048:0> p.errors.messages => {:dt_to=>["is not a valid date"]} irb(main):049:0> p.dt_to = nil => nil irb(main):050:0> p.valid? => true Expected the validator to behave the same for p[:dt_to] = nil and p.dt_to = nil.

— Reply to this email directly or view it on GitHub.

gvasselai commented 8 years ago

Hi Adam,

Thank you for your quick response.

My active record / rails version: /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.5

Gabriela

Gabriela Vasselai || +554791767812 || gabriela.vasselai (skype) || linkedin.com/in/gabrielavasselai

2016-02-27 16:15 GMT-03:00 Adam Meehan notifications@github.com:

What version of ActiveRecord?

On 28 Feb 2016, at 2:31 AM, gvasselai notifications@github.com wrote:

Usage: validates_date :dt_from, :dt_to, { allow_nil: true, allow_blank: true }

irb(main):045:0> p.valid? => true irb(main):046:0> p[:dt_to] = nil => nil irb(main):047:0> p.valid? => false irb(main):048:0> p.errors.messages => {:dt_to=>["is not a valid date"]} irb(main):049:0> p.dt_to = nil => nil irb(main):050:0> p.valid? => true Expected the validator to behave the same for p[:dt_to] = nil and p.dt_to = nil.

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub https://github.com/adzap/validates_timeliness/issues/137#issuecomment-189704447 .

adzap commented 8 years ago

It would be great if you could write a failing spec in the active record orm spec file.

On 28 Feb 2016, at 3:56 PM, gvasselai notifications@github.com wrote:

Hi Adam,

Thank you for your quick response.

My active record / rails version: /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.5

Gabriela

Gabriela Vasselai || +554791767812 || gabriela.vasselai (skype) || linkedin.com/in/gabrielavasselai

2016-02-27 16:15 GMT-03:00 Adam Meehan notifications@github.com:

What version of ActiveRecord?

On 28 Feb 2016, at 2:31 AM, gvasselai notifications@github.com wrote:

Usage: validates_date :dt_from, :dt_to, { allow_nil: true, allow_blank: true }

irb(main):045:0> p.valid? => true irb(main):046:0> p[:dt_to] = nil => nil irb(main):047:0> p.valid? => false irb(main):048:0> p.errors.messages => {:dt_to=>["is not a valid date"]} irb(main):049:0> p.dt_to = nil => nil irb(main):050:0> p.valid? => true Expected the validator to behave the same for p[:dt_to] = nil and p.dt_to = nil.

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub https://github.com/adzap/validates_timeliness/issues/137#issuecomment-189704447 .

— Reply to this email directly or view it on GitHub.

adzap commented 8 years ago

thanks @yez

@gvasselai does this spec cover your case? If so, the weird thing is that it passes, so no failure in this case.