Forum: Ruby on Rails Broken tests after upgrading to Rails 1.2

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Chris S. (Guest)
on 2007-01-22 05:00
Subject says it all. Prior to the upgrade my suite of unit and
functional tests passed without trouble. Now they are broken. Searching
reveals no hints as to why Rails 1.2 causes this. Any input is
appreciated. Below is a description of the behavior I'm noticing (code
is off the cuff, just to get the point across).


0. Sessions don't seem to move properly between functional test method
and the controller method it is testing. Example:

assert session[:cars].drivers.size == 1    # Pass!
post :delete_driver, :driver_id => session[:cars].drivers[0].id
assert session[:cars].drivers.nil?    # Fails! Is still size 1!?!

Method delete_driver is supposed to remove the driver with the passed id
from
session[:cars]. It works perfectly when I step through it while making a
post during development. However, when posting from inside the test
debugging shows me that session[:cars] is empty immediately upon
entering delete_driver. Yet it is size 1 inside the testing method both
before and after posting to delete_driver.


1. Save on assignment. Example:

appointment=Appointment.find 1
appointment.reminder=Reminder.new

Causes Exception: Mysql::Error: Column 'notify' cannot be null: INSERT
INTO reminders (`sent_date`, `appointment_id`, `notify`) VALUES(NULL, 1,
NULL).

It's the second line that causes the exception. I do believe I read
somewhere that when adding an object to a collection associated with an
already persisted object (like appointment) that Rails will immediately
save that new collection member. However, this didn't happen prior to
the 1.2 upgrade. Is this new as of 1.2?

Other tests are failing but I can't yet describe the failures well (need
to debug more). Point #0 is killing me. Please, any help is greatly
appreciated.

Thanks!
Chris S. (Guest)
on 2007-01-24 06:16
Regarding #1, per the API docs for
ActiveRecord::Associations::ClassMethods:

"Assigning an object to a has_one association automatically saves that
object and the object being replaced (if there is one), in order to
update their primary keys - except if the parent object is unsaved
(new_record? == true)."

So #1 is solved, and I've fixed all other tests, but #0 remains
This topic is locked and can not be replied to.