Loading the schema for Active Record tests

Apologies if this is blatantly obvious and I am wasting your time -
I'm quite an infrequent Rails contributor...

Basically I am looking for an easy way to load the schema definitions
from activerecord/test/schema into my databases. In the
RUNNING_UNIT_TESTS file it says "When you have the database online,
you can import the fixture tables with the test/schema/*.sql files."
This seems to be outdated as all the files in test/schema are now .rb
schema files.

I can't see a rake task to perform this - maybe there should be one?

I'd be happy to create a patch to make this a bit easier for others in
the future.

Cheers,
Jon

Apologies if this is blatantly obvious and I am wasting your time -
I'm quite an infrequent Rails contributor...

Basically I am looking for an easy way to load the schema definitions
from activerecord/test/schema into my databases. In the
RUNNING_UNIT_TESTS file it says "When you have the database online,
you can import the fixture tables with the test/schema/*.sql files."
This seems to be outdated as all the files in test/schema are now .rb
schema files.

I can't see a rake task to perform this - maybe there should be one?

There are a few:

rake build_frontbase_databases # Build the FrontBase test databases
rake build_mysql_databases # Build the MySQL test databases
rake build_postgresql_databases # Build the PostgreSQL test databases
rake drop_mysql_databases # Drop the MySQL test databases
rake drop_postgresql_databases # Drop the PostgreSQL test databases
rake rebuild_frontbase_databases # Rebuild the FrontBase test databases
rake rebuild_mysql_databases # Rebuild the MySQL test databases
rake rebuild_postgresql_databases # Rebuild the PostgreSQL test databases

I guess the advice in that file should be updated to reflect the rake
tasks we have now.

If you run the whole test suite via rake test_mysql, it happens automatically using a dirty trick. If you want to do it manually, you need to run the file aaa_create_tables_test.rb - the 'aaa' forces the file to run before all the other tests, ensuring the schema is loaded.

In directory rails/activerecord:

$ ruby -Ilib:test:test/connections/native_mysql test/cases/aaa_create_tables_test.rb
Using native MySQL
Loaded suite test/cases/aaa_create_tables_test
Started
.-- adapter_name()
    -> 0.0000s
-- create_table(:accounts, {:force=>true})
    -> 0.0076s
# lots of lines omitted...
-- create_table(:binary_fields, {:options=>"CHARACTER SET latin1", :force=>true})
    -> 0.0074s
.
Finished in 1.067615 seconds.

2 tests, 2 assertions, 0 failures, 0 errors

If you use some other db than mysql, just change the -I option to use the correct connection file.

RUNNING_UNIT_TESTS needs updating. I was going to do that at one point but got distracted. If you have time to do a doc patch, I'll +1 it :slight_smile:

Thanks.

I will certainly create a doc patch for RUNNING_UNIT_TESTS, but what
do people thing about doing away with the aaa_create_table_test.rb
file? Instead we could check for the existence of one of the table we
need in helper.rb, and if it's not there we could load the schema.
This would enable the schema to be autoloaded even when running single
test files.

Jon

Jon Leighton wrote: