diff options
author | Lucas Clemente <lucas@clemente.io> | 2014-02-06 22:58:25 +0100 |
---|---|---|
committer | Lucas Clemente <lucas@clemente.io> | 2014-04-19 21:44:24 +0200 |
commit | 8de5f7e8a86292c83f0c202061dcea1d78e4ba09 (patch) | |
tree | 29a70dc24b4aae4ee9855ad9f70893272cb7a208 /activerecord | |
parent | 6642407c168ecee436cda1c82bfa87e58f7d73fc (diff) | |
download | rails-8de5f7e8a86292c83f0c202061dcea1d78e4ba09.tar.gz rails-8de5f7e8a86292c83f0c202061dcea1d78e4ba09.tar.bz2 rails-8de5f7e8a86292c83f0c202061dcea1d78e4ba09.zip |
skip migration check if adapter doesn't support it
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 13 | ||||
-rw-r--r-- | activerecord/test/cases/migration/pending_migrations_test.rb | 50 |
2 files changed, 58 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index b6b02322d7..d0bc4c0af9 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -366,16 +366,19 @@ module ActiveRecord # This class is used to verify that all migrations have been run before # loading a web page if config.active_record.migration_error is set to :page_load class CheckPending - def initialize(app) + def initialize(app, connection = Base.connection) @app = app + @connection = connection @last_check = 0 end def call(env) - mtime = ActiveRecord::Migrator.last_migration.mtime.to_i - if @last_check < mtime - ActiveRecord::Migration.check_pending! - @last_check = mtime + if @connection.supports_migrations? + mtime = ActiveRecord::Migrator.last_migration.mtime.to_i + if @last_check < mtime + ActiveRecord::Migration.check_pending!(@connection) + @last_check = mtime + end end @app.call(env) end diff --git a/activerecord/test/cases/migration/pending_migrations_test.rb b/activerecord/test/cases/migration/pending_migrations_test.rb new file mode 100644 index 0000000000..eff000e1a4 --- /dev/null +++ b/activerecord/test/cases/migration/pending_migrations_test.rb @@ -0,0 +1,50 @@ +require 'cases/helper' +require "minitest/mock" + +module ActiveRecord + class Migration + class PendingMigrationsTest < ActiveRecord::TestCase + def setup + super + @connection = MiniTest::Mock.new + @app = MiniTest::Mock.new + @pending = CheckPending.new(@app, @connection) + @pending.instance_variable_set :@last_check, -1 # Force checking + end + + def teardown + super + assert @connection.verify + assert @app.verify + end + + def test_errors_if_pending + @connection.expect :supports_migrations?, true + + ActiveRecord::Migrator.stub :needs_migration?, true do + assert_raise ActiveRecord::PendingMigrationError do + @pending.call(nil) + end + end + end + + def test_checks_if_supported + @connection.expect :supports_migrations?, true + @app.expect :call, nil, [:foo] + + ActiveRecord::Migrator.stub :needs_migration?, false do + @pending.call(:foo) + end + end + + def test_doesnt_check_if_unsupported + @connection.expect :supports_migrations?, false + @app.expect :call, nil, [:foo] + + ActiveRecord::Migrator.stub :needs_migration?, true do + @pending.call(:foo) + end + end + end + end +end |