# Assertions on ActiveRecord errors array

**URL:** <https://www.ruby-forum.com/t/assertions-on-activerecord-errors-array/195542>\
**Category:** Rails\
**Created:** [September 24, 2010, 8:51pm UTC](https://www.ruby-forum.com/t/assertions-on-activerecord-errors-array/195542 "2010-09-24T20:51:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tnyplz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@tnyplz](https://www.ruby-forum.com/u/tnyplz)\
**Post date:** [September 24, 2010, 8:51pm UTC](https://www.ruby-forum.com/t/assertions-on-activerecord-errors-array/195542/1 "2010-09-24T20:51:59Z")

</div>

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. 🙂

Tony
