diff options
author | blackst0ne <blackst0ne.ru@gmail.com> | 2017-04-10 19:47:33 +1100 |
---|---|---|
committer | blackst0ne <blackst0ne.ru@gmail.com> | 2017-04-10 19:47:33 +1100 |
commit | 171eab8123c9f6804e0e2d6104fe8fb7ec959062 (patch) | |
tree | b9dc36f4c40e4ac5e5acade4f7bd7fb88c24bc6f /spec/migrations | |
parent | 01adf920c4da977328c38836327681eb4c52cbee (diff) | |
download | gitlab-ce-171eab8123c9f6804e0e2d6104fe8fb7ec959062.tar.gz |
Add spec for schema.rb
Diffstat (limited to 'spec/migrations')
-rw-r--r-- | spec/migrations/schema_spec.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/spec/migrations/schema_spec.rb b/spec/migrations/schema_spec.rb new file mode 100644 index 00000000000..e132529d8d8 --- /dev/null +++ b/spec/migrations/schema_spec.rb @@ -0,0 +1,23 @@ +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 |