Test env. differs from development env, tests breaking

I just got a new PC at work. My project files were copied from my old
drive. Just to be sure, though, I have erased them and pulled them back
down from source control.

My development database server is MySQL
My test database server is sqlite3

I am having a confusing issue: tests are failing and errors are
happening that weren’t happening before. Furthermore, they aren’t
happening on other developer’s boxes.

Most of the failing tests seem to involve verifying that validations
are working. Take the example of check details:

	create_table( :check_details ) do |t|
		t.column( :check_id, :integer )
		t.column( :description, :string )
		t.column( :amount_in_cents, :integer )
		#t.column( :account_to_credit_id, :integer )
		#t.column( :account_to_debit_id, :integer )
	end

	add_index( :check_details, :check_id )

Now from test/unit/check_detail_test.rb,

	# validates_presence_of :check_id

	cd = CheckDetail.new(
		:amount => 21.21,
		:description => "Services Rendered"
		)

	assert(!cd.save, "Shouldn't be able to save this like this here

thing.")

This fails when I run tests, but when I do it in development, I get the
correct result.

DEVELOPMENT CONSOLE

?> cd = nil
=> nil

?>
?>
?>
?> cd = CheckDetail.new
=> #<CheckDetail:0x365e3e0 @attributes={“check_id”=>nil,
“amount_in_cents”=>nil, “description”=>nil}, @new_record=true>

cd.amount = 21.21
=> 21.21

cd.amount
=> 21.21

cd.amount_in_cents
=> 2121

cd.description = “Services Rendered”
=> “Services Rendered”

cd.save
=> false

TEST CONSOLE

?> cd = nil
=> nil

?>
?>
?>
?> cd = CheckDetail.new
=> #<CheckDetail:0x36ef2dc @attributes={“check_id”=>0,
“amount_in_cents”=>0, “description”=>""}, @new_record=true>

cd.amount = 21.21
=> 21.21

cd.amount
=> 21.21

cd.amount_in_cents
=> 2121

cd.description = “Services Rendered”
=> “Services Rendered”

cd.save
=> true


I’m guessing this has something to do with the database, but I can’t
figure out how to resolve it. Any ideas?

jw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Oct 24, 2006, at 10:06 AM, MustModify wrote:

happening that weren’t happening before. Furthermore, they aren’t
#t.column( :account_to_credit_id, :integer )
cd = CheckDetail.new(
:amount => 21.21,
:description => “Services Rendered”
)

  assert(!cd.save, "Shouldn't be able to save this like this here

thing.")

This fails when I run tests, but when I do it in development, I get
the
correct result.

Take a look at config/environment.rb and look at the following lines:

Use SQL instead of Active Record’s schema dumper when creating

the test database.

This is necessary if your schema can’t be completely dumped by

the schema dumper,

like if you have constraints or database-specific column types

config.active_record.schema_format = :sql

If you overrode this to be “config.active_record.schema_format
= :ruby” then change it back to :sql. The ability to use ruby as an
database-independent description language can lead to the type of
problem you are experiencing.

If you are using sql (i.e. accepted the default) then I’m stumped.

cr

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (Darwin)

iD8DBQFFPjCWtEOEsNMQp04RAiTaAJ4joUzCqziM6+WGwKWCaYfFPBu3IwCbBRaw
UoXSywTseTvYNWH5GXY714Y=
=8GXP
-----END PGP SIGNATURE-----

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