Rails 4 test helper and migrations

Hey folks,

I’ve noticed an annoying problem with Rails 4, and was wondering if folks had also seen this in action or had solutions.

Rails 4’s test helper will automatically maintain the database schema for tests, which means you don’t need to run rake db:test:load after migrations, Rails just migrates the test database for you. The problem comes if you roll back a migration and then re-run the migration, it seems that Rails doesn’t reflect the change without performing the db:test:load command. Since this functionality is going to be deprecated in future, I’m wondering how folks handle this problem.

One solution I can see other than just creating a new migration to fix your previous migration is to rename your migration file with a new timestamp. 20140714201834_create_things.rb → 20140714201835_create_things.rb. This will force the schema version to change and the tests will load this new version instead.

1 Like

@frank_west_iii, I think I’m way too lazy to edit that timestamp every time, but that is by far the best solution of any of the stuff I’ve read or tried to think up myself. Thanks for the idea!

What a nice leaky abstraction we’ve got there!

Here’s hoping this gets better in future versions. Might be worth opening an issue.

1 Like

@benorenstein, you’re right. I should file the issue. Next task: create a reference application!

It’s unfortunate that when you’re doing commercial work you often have to recreate the problem without giving access to your existing source code.

Turns out there’s already an issue filed: maintain_test_schema doesn't honor reverse migrations · Issue #15787 · rails/rails · GitHub

1 Like

Yes, this is my least favorite new rails “feature”

@derekprior, I think the functionality would be good (assure that development and test are in sync) if it consistently worked, but now that I’m used to debugging spring-related issues this is now one of the most frequent places where I miss a change that’s not due to a problem with the code as it stands in my app.