2019-12-26 22:10:19 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
# Check consistency of db/structure.sql version, migrations' timestamps, and the latest migration timestamp
|
2017-08-17 22:00:37 +05:30
|
|
|
# stored in the database's schema_migrations table.
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
describe ActiveRecord::Schema, schema: :latest do
|
2020-04-22 19:07:51 +05:30
|
|
|
let(:all_migrations) do
|
2019-09-04 21:01:54 +05:30
|
|
|
migrations_paths = %w[db/migrate db/post_migrate]
|
2018-11-08 19:23:39 +05:30
|
|
|
.map { |path| Rails.root.join(*path, '*') }
|
|
|
|
|
|
|
|
migrations = Dir[*migrations_paths]
|
2020-04-22 19:07:51 +05:30
|
|
|
migrations.map { |migration| File.basename(migration).split('_').first.to_i }.sort
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
let(:latest_migration_timestamp) do
|
|
|
|
all_migrations.max
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it '> schema version should equal the latest migration timestamp stored in schema_migrations table' do
|
|
|
|
expect(latest_migration_timestamp).to eq(ActiveRecord::Migrator.current_version.to_i)
|
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
it 'the schema_migrations table contains all schema versions' do
|
|
|
|
versions = ActiveRecord::Base.connection.execute('SELECT version FROM schema_migrations ORDER BY version').map { |m| Integer(m['version']) }
|
|
|
|
|
|
|
|
expect(versions).to eq(all_migrations)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|