Assertions on ActiveRecord errors array

In Rails 2 if I wanted to check if an ActiveRecord attribute had an
error on it I simply called

assert user.errors.on(:name)

Now that this is depreciated what is a clean way to do this check?

This is ugly but it works…
assert !user.errors[:name].empty?

remove the negative logic and it is still a bit verbose
assert user.errors[:name].first

Stealing from the old on method we could use has_key?
assert user.errors.has_key?(:name)

I suspect a lot of people accidentally change their validations to
assert user.errors[:name]
but that always returns true

anyway, what is the preferred way to do this check? I feel like I’m
missing something obvious. :slight_smile:


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs