summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorblackst0ne <blackst0ne.ru@gmail.com>2017-04-10 19:47:33 +1100
committerblackst0ne <blackst0ne.ru@gmail.com>2017-04-10 19:47:33 +1100
commit171eab8123c9f6804e0e2d6104fe8fb7ec959062 (patch)
treeb9dc36f4c40e4ac5e5acade4f7bd7fb88c24bc6f
parent01adf920c4da977328c38836327681eb4c52cbee (diff)
downloadgitlab-ce-171eab8123c9f6804e0e2d6104fe8fb7ec959062.tar.gz
Add spec for schema.rb
-rw-r--r--changelogs/unreleased/spec_for_schema.yml4
-rw-r--r--spec/migrations/schema_spec.rb23
2 files changed, 27 insertions, 0 deletions
diff --git a/changelogs/unreleased/spec_for_schema.yml b/changelogs/unreleased/spec_for_schema.yml
new file mode 100644
index 00000000000..7ea0b8672ce
--- /dev/null
+++ b/changelogs/unreleased/spec_for_schema.yml
@@ -0,0 +1,4 @@
+---
+title: Add spec for schema.rb
+merge_request: 10580
+author: blackst0ne
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