You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
parlallel_tests, while amazing, doesn't support the Rails 4 feature of automatically reloading the test databases after migration. The following works for me, though it's not elegant:
#lib/tasks/custom.rakenamespace:customdodesc"Reset test database"tasktest_reset: :environmentdosh'RAILS_ENV=test rake parallel:load_schema'enddesc"Hard reset test database"tasktest_reset_hard: :environmentdosh'rake custom:pg_terminate RAILS_ENV=test parallel:drop parallel:create parallel:load_schema'enddesc"Prepare test database"taskparallel_prepare: :environmentdosh'RAILS_ENV=test rake custom:parallel_prepare_complete'enddesc"Finish preparing test databases"taskparallel_prepare_complete: :environmentdoifActiveRecord::Base.maintain_test_schema && ActiveRecord::Migrator.needs_migration?puts'Loading schema.rb into each of the parallel test databases'Rake::Task['parallel:load_schema'].reenableRake::Task['parallel:load_schema'].invokeendenddesc"Show if test migration needed"tasktest_migration_needed: :environmentdocommand=%q{RAILS_ENV=test rails runner 'puts "#{ActiveRecord::Migrator.needs_migration?}"'}shcommandenddesc"Terminate Postgres users to enable db:drop"taskpg_terminate: :environmentdosh"echo 'SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE datname = current_database() AND pg_stat_activity.pid <> pg_backend_pid();' | rails db"endend
Then replace ActiveRecord::Migration.maintain_test_schema! in spec/rails_helper.rb:
I'd be happy to add these as a pull request, but others can probably suggest a less hacky solution. This is a good overview of changing RAILS_ENV in rake tasks.
The text was updated successfully, but these errors were encountered:
As most of these just run a shell command, do you need them to load :environment? Seems like removing that dependency would make them much faster. Especially as the shell command then reloads the Rails environment under test.
parlallel_tests, while amazing, doesn't support the Rails 4 feature of automatically reloading the test databases after migration. The following works for me, though it's not elegant:
Then replace
ActiveRecord::Migration.maintain_test_schema!
inspec/rails_helper.rb
:And redefine the default task in `lib/tasks/default.rake:
I'd be happy to add these as a pull request, but others can probably suggest a less hacky solution. This is a good overview of changing RAILS_ENV in rake tasks.
The text was updated successfully, but these errors were encountered: