diff options
author | Chris Arcand <chris@chrisarcand.com> | 2016-03-23 08:39:26 -0400 |
---|---|---|
committer | Chris Arcand <chris@chrisarcand.com> | 2016-03-24 13:17:14 -0400 |
commit | 16dadb1223fcabc9d904456d4b64d6e82f9e1a76 (patch) | |
tree | 95a869da996d916463911200affb17a4caf52eae /activerecord/test/cases | |
parent | 2e8a350c38715787ab79603bf1e4b6296e23d80b (diff) | |
download | rails-16dadb1223fcabc9d904456d4b64d6e82f9e1a76.tar.gz rails-16dadb1223fcabc9d904456d4b64d6e82f9e1a76.tar.bz2 rails-16dadb1223fcabc9d904456d4b64d6e82f9e1a76.zip |
Make 'migrate' clear the schema cache afterward
Without clearing the caches afterward, removals done in migrations would
not be reflected in a separate task in the same process. That is, given
a table with a migration to remove a column, the schema cache would
still reflect that a table has that in something such as the
'db:seed' task:
`rake db:migrate db:seed`
(A common thing to do in a script for a project ala `bin/setup`)
vs
`rake db:migrate && rake db:seed`
(Two processes)
The first would not reflect that the column was removed.
The second would (cache reset).
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/tasks/database_tasks_test.rb | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/activerecord/test/cases/tasks/database_tasks_test.rb b/activerecord/test/cases/tasks/database_tasks_test.rb index 429aeca1d9..0aac5bad31 100644 --- a/activerecord/test/cases/tasks/database_tasks_test.rb +++ b/activerecord/test/cases/tasks/database_tasks_test.rb @@ -309,19 +309,30 @@ module ActiveRecord end class DatabaseTasksMigrateTest < ActiveRecord::TestCase + def setup + ActiveRecord::Tasks::DatabaseTasks.migrations_paths = 'custom/path' + end + + def teardown + ActiveRecord::Tasks::DatabaseTasks.migrations_paths = nil + end + def test_migrate_receives_correct_env_vars verbose, version = ENV['VERBOSE'], ENV['VERSION'] - ActiveRecord::Tasks::DatabaseTasks.migrations_paths = 'custom/path' ENV['VERBOSE'] = 'false' ENV['VERSION'] = '4' ActiveRecord::Migrator.expects(:migrate).with('custom/path', 4) ActiveRecord::Tasks::DatabaseTasks.migrate ensure - ActiveRecord::Tasks::DatabaseTasks.migrations_paths = nil ENV['VERBOSE'], ENV['VERSION'] = verbose, version end + + def test_migrate_clears_schema_cache_afterward + ActiveRecord::Base.expects(:clear_cache!) + ActiveRecord::Tasks::DatabaseTasks.migrate + end end class DatabaseTasksPurgeTest < ActiveRecord::TestCase |