Hello all,

I think I have found an interesting bug in the validations.  The
reason I say might is because I don't know if it was intentionally
constructed this way or not.

ActiveRecord docs describe the validates_as_* methods as accepting
the :on argument with the options of :create, :update and :save
(default :save).  If you explicitly set argument to :on => :save that
validation if forever skipped.  The context or state of the model
(:create or :update) does not matter.

class Topic < ActiveRecord::Base
  validates_presence_of :title, :on => :save
end

t = Topic.new(:title => '')
t.valid?  => true

t = Topic.find(1)
t.title = ''
t.valid?  => true

I have verified this with tests in ActiveRecord.

My question is should this be fixed so that :save is a valid option or
should it be left as is and the documentation updated to no longer
show :save as a valid option?

Related to this, if you attempt to send the :on argument to a
validates_* of a class that uses ActiveModel::Validations#valid?
(ActiveRecord overrides it) to do its validation then they will not
work.

class Foo
  include ActiveModel::Validations

  attr_accessor :title

  validates_presence_of :title, :on => :save
end

f = Foo.new
f.title = ''
f.valid? => true

Again, is this expected behaiour?

Peer

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-core+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to