# Confused by the unit test results

**URL:** <https://www.ruby-forum.com/t/confused-by-the-unit-test-results/125029>\
**Category:** Rails\
**Created:** [January 4, 2008, 5:37pm UTC](https://www.ruby-forum.com/t/confused-by-the-unit-test-results/125029 "2008-01-04T17:37:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![taro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/df705f/32.png) [@taro](https://www.ruby-forum.com/u/taro)\
**Post date:** [January 4, 2008, 5:37pm UTC](https://www.ruby-forum.com/t/confused-by-the-unit-test-results/125029/1 "2008-01-04T17:37:30Z")

</div>

## I’m testing the relation between two of my models: MessageThread (parent), which has\_many Message (children). When I run the following test, it gives me an error:

# test with a valid message

def test\_valid\_message\_new  
thread = MessageThread.new :title =\> ‘awesome thread’  
message = thread.messages.build(:body =\>‘total awesomeness’)  
assert thread.valid?, ‘thread not valid’  
assert (thread.messages.size == 1)  
assert\_equal ‘total awesomeness’, message.body  
assert !thread.messages[0].nil?  
#line 182, and the line below, line 183  
assert thread.messages.find(:first, :conditions =\> {:body =\>  
‘total awesomeness’}), ‘Cannot find message’  
end

* * *

Loaded suite message\_thread\_test  
Started  
…F  
Finished in 0.285501 seconds.

1. Failure:  
test\_valid\_message\_new(MessageThreadTest) [message\_thread\_test.rb:  
183]:  
Cannot find message.  
 is not true.

* * *

Why doesn’t method find() find anything? Is the :condition parameter  
incorrect? I tried saving message, but it still didn’t find the  
message I was looking for. Is the find method deprecated?

---

<div class="post-metadata">

**Author:** ![taro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/df705f/32.png) [@taro](https://www.ruby-forum.com/u/taro)\
**Post date:** [January 4, 2008, 5:41pm UTC](https://www.ruby-forum.com/t/confused-by-the-unit-test-results/125029/2 "2008-01-04T17:41:36Z")

</div>

On 4 Jan 2008, at 16:37, Taro wrote:

> assert (thread.messages.size == 1)  
> …F  
> message I was looking for. Is the find method deprecated?  
> Neither of those objects have been saved, so there is nothing to find.  
> you would have to save both thread & message.

Fred

---

<div class="post-metadata">

**Author:** ![taro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/df705f/32.png) [@taro](https://www.ruby-forum.com/u/taro)\
**Post date:** [January 4, 2008, 5:46pm UTC](https://www.ruby-forum.com/t/confused-by-the-unit-test-results/125029/3 "2008-01-04T17:46:27Z")

</div>

Frederick C. wrote:

> On 4 Jan 2008, at 16:37, Taro wrote:
> 
> > assert (thread.messages.size == 1)  
> > …F  
> > message I was looking for. Is the find method deprecated?  
> > Neither of those objects have been saved, so there is nothing to find.  
> > you would have to save both thread & message.
> 
> Fred

Fred is a genius…

---

<div class="post-metadata">

**Author:** ![taro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/df705f/32.png) [@taro](https://www.ruby-forum.com/u/taro)\
**Post date:** [January 4, 2008, 5:55pm UTC](https://www.ruby-forum.com/t/confused-by-the-unit-test-results/125029/4 "2008-01-04T17:55:44Z")

</div>

Ahhh…I have to save the thread…I see. Thank you.

On Jan 4, 11:46 am, “gemblon (t.b.)” \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![taro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/df705f/32.png) [@taro](https://www.ruby-forum.com/u/taro)\
**Post date:** [January 4, 2008, 10:26pm UTC](https://www.ruby-forum.com/t/confused-by-the-unit-test-results/125029/5 "2008-01-04T22:26:43Z")

</div>

## OK, new problem: This time, I’m using MessageBoard (child) to acts\_as\_list for Forum (parent). The models looks as such:

## class Forum \< ActiveRecord::Base #This is a superset of message boards has\_many :message\_boards, :order =\> :order, :dependent =\> :destroy … end

class MessageBoard \< ActiveRecord::Base  
#This is a subset of forums  
belongs\_to :forum

## #This causes MessageBoard to act as a list #it uses order as its index acts\_as\_list :scope =\> :forum\_id … end

## A slight mistake on my part, I wanted the message boards to be ordered by the MySQL (I use Rails 1.2.5) column :order (as seen in line :order =\> :order). However, this error arises:

Loaded suite message\_board\_test  
Started  
…E.  
Finished in 0.347567 seconds.

1. Error:  
test\_title\_overlap(MessageBoardTest):  
ActiveRecord::StatementInvalid: Mysql::Error: #42S22Unknown column  
‘position’ in ‘order clause’: SELECT \* FROM message\_boards WHERE  
(forum\_id = 2) ORDER BY position DESC LIMIT 1  
…

* * *

Does the column name HAVE to be “position”?

---

<div class="post-metadata">

**Author:** ![taro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/df705f/32.png) [@taro](https://www.ruby-forum.com/u/taro)\
**Post date:** [January 6, 2008, 5:58pm UTC](https://www.ruby-forum.com/t/confused-by-the-unit-test-results/125029/6 "2008-01-06T17:58:13Z")

</div>

On 4 Jan 2008, at 21:26, Taro wrote:

> 1. Error:  
> test\_title\_overlap(MessageBoardTest):  
> ActiveRecord::StatementInvalid: Mysql::Error: #42S22Unknown column  
> ‘position’ in ‘order clause’: SELECT \* FROM message\_boards WHERE  
> (forum\_id = 2) ORDER BY position DESC LIMIT 1  
> …
> 
> * * *
> 
> Does the column name HAVE to be “position”?

No: use the :column option to acts\_as\_list

Fred
