提交 9a8ea266 编写于 作者: R Rémy Coutable

Merge branch 'spec_for_schema' into 'master'

Add spec for schema.rb

Closes #21978

See merge request !10580
---
title: Add spec for schema.rb
merge_request: 10580
author: blackst0ne
require 'spec_helper'
# Check consistency of db/schema.rb version, migrations' timestamps, and the latest migration timestamp
# stored in the database's schema_migrations table.
describe ActiveRecord::Schema do
let(:latest_migration_timestamp) do
migrations = Dir[Rails.root.join('db', 'migrate', '*'), Rails.root.join('db', 'post_migrate', '*')]
migrations.map { |migration| File.basename(migration).split('_').first.to_i }.max
end
it '> schema version equals last migration timestamp' do
defined_schema_version = File.open(Rails.root.join('db', 'schema.rb')) do |file|
file.find { |line| line =~ /ActiveRecord::Schema.define/ }
end.match(/(\d+)/)[0].to_i
expect(defined_schema_version).to eq(latest_migration_timestamp)
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
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册