How to test database table manipulation methods?

I have written methods to create/drop tables and add/remove columns of
these tables. This methods will return true/nil depending whether an
error is raised.

I’d like to test these methods, however, when the first time autotest
runs, it return a normal report, but later it repeats “uninitialized
constant Test (NameError)”.

This problem may be caused as the test database has been changed by
those database table manipulation methods, for example, while a table is
created from the test code itself, the second time this test,which try
to add a table with the same name, causes test fails.

Any good idea to test those database table manipulation methods?

On 9/12/07, Nanyang Z. [email protected] wrote:

I have written methods to create/drop tables and add/remove columns of
these tables. This methods will return true/nil depending whether an
error is raised.

AR already has methods to create/drop tables, columns, etc. Are you
re-inventing the wheel?

I’d like to test these methods, however, when the first time autotest
runs, it return a normal report, but later it repeats “uninitialized
constant Test (NameError)”.

This problem may be caused as the test database has been changed by
those database table manipulation methods, for example, while a table is
created from the test code itself, the second time this test,which try
to add a table with the same name, causes test fails.

autotest isn’t expecting DDL to be going on in your tests, so it
doesn’t do the “rake db:test:prepare” step before running each test
(or ever, for that matter, which is why you need to run it yourself
after a migration, etc.). That would really slow autotest down.

I guess the short answer would be to use the setup and/or teardown
methods in your test cases to make sure the database is in a known
state.

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