Simple app works fine but unit tests don't work as intended

I have a simple rails 2.0.2 app with one model, Portfolio, and
generated CRUD. I've added validation to the model and tested it
thoroughly by hand -- it works fine.

I tried to create a unit test to ensure no inadvertent future changes
break my validations.

The relevant code is at http://www.pastie.org/230714.

Question 1:
ruby test/unit/portfolio_test.rb fails with (essentially)
portfolio_test_rb:13 is not true.

Why did this fail

Question 2:
I thought perhaps the previous failure occurred because I didn't save
the new portfolio. But when I un-comment portfolio_test.rb:8, I get
a new error:
NoMethodError: You have a nil object when you didn't expect it!
The error occurred while evaluating nil.upcase!
[snip] app/models/portfolio.rb:9

Thanks in advance for any light you can shine on my errors,
Richard

I have a simple rails 2.0.2 app with one model, Portfolio, and
generated CRUD. I've added validation to the model and tested it
thoroughly by hand -- it works fine.

I tried to create a unit test to ensure no inadvertent future changes
break my validations.

Because you shouldn't use an attr_accessor with the same name as a
database attributes. Those attributes are not instance variables.
Calling attr_accessor replaces (this is a slight simplification, but
effectively this is what happens) the .symbol method that rails
created to read that attribute with one that reads from an instance
variable. Nothing however populates that instance variable.

Fred

Hi Fred,

Wow! Your reply was substantive, comprehensive and fast!

Many thanks,
Richard

Hi Fred,

Wow! Your reply was substantive, comprehensive and fast!

Many thanks,
Richard