Having trouble fixing assert_invalid_column_on_record deprecations?

Posted by admin, Thu Jan 25 09:38:48 UTC 2007

The current deprecation warning is:

DEPRECATION WARNING: assert_invalid_column_on_record is deprecated and will be 
removed from Rails 2.0 (use assert(record.errors.invalid?(column)) instead)


But it would be much easier to fix this warning if the docs said something like:

DEPRECATION WARNING: assert_invalid_column_on_record is deprecated and will be 
removed from Rails 2.0 (use assert(find_record_in_template(key).errors.invalid?(column)) instead)


So you change your bad/old code that looks like this:

<br />assert_invalid_column_on_record "user", :password<br />


To something like this:

<br />assert(find_record_in_template("user").errors.invalid?(:password))<br />


Filed Under: | Tags:

Comments

  1. Brian Cochran 02.02.07 / 02AM
    Thanks for the help. +1 here.
  2. volkyl 02.27.07 / 13PM
    Thanks for the help. Would have taken this noob a while to figure out how to do that right.
  3. velosa 03.01.07 / 16PM
    Just what I was looking for. I've been working on bringing an account_controller I downloaded a while back up to date. It seems to have a lot of deprecated stuff, but I've tweaked it enough that I'm reluctant to go look for a more up to date one.
  4. Rick Herrick 03.25.07 / 07AM
    w00t, excellent tip! This was the last deprecation error I had to clean up in my inherited legacy code and it was KILLING me! Thanks a lot!
  5. Jacopo 06.21.07 / 23PM
    Many thanks!!!
  6. matt 06.27.07 / 03AM
    Thanks, now I can clean out all the damn warning messages. And you would hope they could have replaced "assert_invalid_column_on_record" with something a little shorter, oh well... god bless the autocomplete in textmate!
  7. matt 06.27.07 / 05AM
    I started using: assert !find_record_in_template(key).errors.invalid?(:all) and it seems to work. Am I just being delusional and the ruby is letting me slide passing that :all in there for the columns, or does it actually work this way? I'd check the code myself, but I have no idea where it is...
  8. lori 06.27.07 / 05AM
    I tried that first, but it didn't work for all my test cases. If it works for you, perhaps it has been updated. I was really only trying to test for specific errors in each assert, so I'll probably leave mine alone.
  9. lori 06.27.07 / 06AM
    As for the code... I hunted through the source of the old, deprecated, assert_invalid_column_on_record to see what it was doing, to figure this out.

Have your say

A name is required. You may use HTML in your comments.