Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

rails-3.2.7 rake test runs against dev database #7174

Closed
dchelimsky opened this Issue · 15 comments

5 participants

@dchelimsky
rails new example
cd example
rails g scaffold thing name:string
rake db:migrate
rake db:test:prepare
rake test # passes
rm db/development.*
rake test # fails

Failure output:

You have 1 pending migrations:
  20120727024035 CreateThings
Run `rake db:migrate` to update your database then try again.
@rafaelfranca

@dchelimsky could you post the output of rake test --trace? I think I found the spot but want to confirm.

@erichmenge

I get this behavior on older versions of Rails as well. I checked down to 3.2.0, unless I'm messing something up.

@erichmenge

@rafaelfranca Here is the trace I get:

➜  issue_7174  rake test --trace
** Invoke test (first_time)
** Execute test
** Invoke test:run (first_time)
** Invoke test:units (first_time)
** Invoke test:prepare (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
You have 1 pending migrations:
  20120727024926 CreateThings
Run `rake db:migrate` to update your database then try again.
@rafaelfranca

This is exactly was I thought. It was introduced at 94489a2

@dchelimsky

This is a red herring. I saw a report that with this release "rake spec" was running against the dev db, and I ran the script above to see if it was working the same way with minitest. It seems, however, that db:abort_if_pending_migrations, however, runs against the dev database even if the tests are subsequently run against the test db.

There is still a problem related to rspec, but it is not as reported in this issue, so closing.

@dchelimsky dchelimsky closed this
@itspriddle

This issue still happens for me on 3.2.8.rc1 with config.active_record.schema_format = :sql. I think it may be related to #4772. I have created a dummy app with the issue here.

@rafaelfranca
Owner

Which issue?

This one?

You have 1 pending migrations:
  20120727024035 CreateThings
Run `rake db:migrate` to update your database then try again.
@itspriddle

The issue is that running rake with config.active_record.schema_format = :sql causes tests to use the development database unless you have ENV['RAILS_ENV'] = 'test' in spec_helper/test_helper. If you remove that line, it uses the test environment as expected.

@rafaelfranca
Owner

So is not this issue is #7175. I'll take a look on this

@rafaelfranca
Owner

@itspriddle could you do me a favor?

run rake --trace with Rails 3.2.8.rc1 and past at #7175 the output like this:

** Invoke db:setup (first_time)
** Invoke db:schema:load_if_ruby (first_time)
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:create
** Execute db:schema:load_if_ruby
SCHEMA FORMAT IS :ruby
** Invoke db:schema:load (first_time)
** Invoke environment (first_time)
** Execute environment
SETTING SCHEMA FORMAT TO :sql
** Execute db:schema:load
@jcoyne

@rafaelfranca I'm also having trouble with the env remaining at "development" when my schema_format is :sql (3.2.8.rc1)

** Invoke default (first_time)
** Invoke spec (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:clone_structure (first_time)
** Invoke db:structure:dump (first_time)
** Invoke environment 
** Invoke db:load_config 
@jcoyne

@rafaelfranca It looks like my problem was because I had:

  config.active_record.schema_format = :sql

set in my development environment. So, this is now looking closed to me.

@rafaelfranca
Owner

Maybe e23b26c should fix this issue. Could you guys try the 3-2-stable branch?

cc @jcoyne @itspriddle

@itspriddle

@rafaelfranca e23b26c fixes it. Thanks!

@rafaelfranca
Owner

Great! Thank you to confirm guys :heart:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.