summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-04-10 12:49:14 +0000
committerRémy Coutable <remy@rymai.me>2017-04-10 12:49:14 +0000
commit9a8ea26670999a4cf3ba2ac284e951f30bc6a1fe (patch)
tree96327b66dd56abf7cb2bbfa7cbd06e3b63be466e /spec
parentce6a48cbd0b297bf955206f6acb1da86c1fa4529 (diff)
parent171eab8123c9f6804e0e2d6104fe8fb7ec959062 (diff)
downloadgitlab-ce-9a8ea26670999a4cf3ba2ac284e951f30bc6a1fe.tar.gz
Merge branch 'spec_for_schema' into 'master'
Add spec for schema.rb Closes #21978 See merge request !10580
Diffstat (limited to 'spec')
-rw-r--r--spec/migrations/schema_spec.rb23
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