On Thu, Apr 28, 2011 at 3:06 PM, Sergio Ruiz <li...@ruby-forum.com> wrote:
> i just ran into a problem with some test, and i am not exactly sure why,
> but the difference happened when i changed my model validation from:
>
> validate :custom_validation
>
> to:
>
> validate_on_create :custom_validation
>
> can someone give me any ideas on where in the chain the validation takes
> place?

This is really a Rails or ActiveRecord question rather than RSpec.

In any case.

validate :custom_validation
  will run the custom_validation method whether the model is being
created or updated.

validate_on_create :custom_validation
  will only run the custom_validation method when the method is being created.

There's also a validate_on_update method which will run the custom
validation method when the model is being updated but not when it is
created.


http://guides.rubyonrails.org/active_record_validations_callbacks.html#creating-custom-validation-methods
-- 
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Github: http://github.com/rubyredrick
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to