Commit 5c02be6c authored by Robert Speicher's avatar Robert Speicher

Merge branch 'test_schema_version_check_directly' into 'master'

Test schema_version_check directly

Closes #63913

See merge request gitlab-org/gitlab-ce!30209
parents 9b005f40 fbd987a9
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require 'spec_helper' require 'spec_helper'
require 'rake' require 'rake'
describe 'schema_version_check rake task', :quarantine do describe 'schema_version_check rake task' do
include StubENV include StubENV
before :all do before :all do
...@@ -15,8 +15,6 @@ describe 'schema_version_check rake task', :quarantine do ...@@ -15,8 +15,6 @@ describe 'schema_version_check rake task', :quarantine do
end end
before do before do
# Stub out db tasks
allow(ActiveRecord::Tasks::DatabaseTasks).to receive(:migrate).and_return(true)
allow(ActiveRecord::Migrator).to receive(:current_version).and_return(Gitlab::Database::MIN_SCHEMA_VERSION) allow(ActiveRecord::Migrator).to receive(:current_version).and_return(Gitlab::Database::MIN_SCHEMA_VERSION)
# Ensure our check can re-run each time # Ensure our check can re-run each time
...@@ -24,23 +22,23 @@ describe 'schema_version_check rake task', :quarantine do ...@@ -24,23 +22,23 @@ describe 'schema_version_check rake task', :quarantine do
end end
it 'allows migrations on databases meeting the min schema version requirement' do it 'allows migrations on databases meeting the min schema version requirement' do
expect { run_rake_task('db:migrate') }.not_to raise_error expect { run_rake_task('schema_version_check') }.not_to raise_error
end end
it 'raises an error when schema version is too old to migrate' do it 'raises an error when schema version is too old to migrate' do
allow(ActiveRecord::Migrator).to receive(:current_version).and_return(25) allow(ActiveRecord::Migrator).to receive(:current_version).and_return(25)
expect { run_rake_task('db:migrate') }.to raise_error(RuntimeError, /current database version is too old to be migrated/) expect { run_rake_task('schema_version_check') }.to raise_error(RuntimeError, /current database version is too old to be migrated/)
end end
it 'skips running validation when passed the skip env variable' do it 'skips running validation when passed the skip env variable' do
stub_env('SKIP_SCHEMA_VERSION_CHECK', 'true') stub_env('SKIP_SCHEMA_VERSION_CHECK', 'true')
allow(ActiveRecord::Migrator).to receive(:current_version).and_return(25) allow(ActiveRecord::Migrator).to receive(:current_version).and_return(25)
expect { run_rake_task('db:migrate') }.not_to raise_error expect { run_rake_task('schema_version_check') }.not_to raise_error
end end
it 'allows migrations on fresh databases' do it 'allows migrations on fresh databases' do
allow(ActiveRecord::Migrator).to receive(:current_version).and_return(0) allow(ActiveRecord::Migrator).to receive(:current_version).and_return(0)
expect { run_rake_task('db:migrate') }.not_to raise_error expect { run_rake_task('schema_version_check') }.not_to raise_error
end end
def run_rake_task(task_name) def run_rake_task(task_name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment