diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-09-08 23:35:06 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-09-08 23:35:06 +0900 |
commit | 952ae3eca77da4632fd20ff040ca8581dbbad25d (patch) | |
tree | 9ab54d8409079421b95a095e1b47e3237352e008 /activerecord/test | |
parent | 5f35c60f848dda275e34bc055f58031c08d7b416 (diff) | |
download | rails-952ae3eca77da4632fd20ff040ca8581dbbad25d.tar.gz rails-952ae3eca77da4632fd20ff040ca8581dbbad25d.tar.bz2 rails-952ae3eca77da4632fd20ff040ca8581dbbad25d.zip |
`supports_xxx?` returns whether a feature is supported by the backend
Rather than a configuration on the connection.
Diffstat (limited to 'activerecord/test')
4 files changed, 25 insertions, 41 deletions
diff --git a/activerecord/test/cases/adapter_test.rb b/activerecord/test/cases/adapter_test.rb index 1c461a0459..a93e5e2b40 100644 --- a/activerecord/test/cases/adapter_test.rb +++ b/activerecord/test/cases/adapter_test.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "cases/helper" +require "support/connection_helper" require "models/book" require "models/post" require "models/author" @@ -446,3 +447,27 @@ module ActiveRecord end end end + +if ActiveRecord::Base.connection.supports_advisory_locks? + class AdvisoryLocksEnabledTest < ActiveRecord::TestCase + include ConnectionHelper + + def test_advisory_locks_enabled? + assert ActiveRecord::Base.connection.advisory_locks_enabled? + + run_without_connection do |orig_connection| + ActiveRecord::Base.establish_connection( + orig_connection.merge(advisory_locks: false) + ) + + assert_not ActiveRecord::Base.connection.advisory_locks_enabled? + + ActiveRecord::Base.establish_connection( + orig_connection.merge(advisory_locks: true) + ) + + assert ActiveRecord::Base.connection.advisory_locks_enabled? + end + end + end +end diff --git a/activerecord/test/cases/adapters/helpers/test_supports_advisory_locks.rb b/activerecord/test/cases/adapters/helpers/test_supports_advisory_locks.rb deleted file mode 100644 index 4905e17725..0000000000 --- a/activerecord/test/cases/adapters/helpers/test_supports_advisory_locks.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -require "support/connection_helper" - -module TestSupportsAdvisoryLocks - include ConnectionHelper - - def test_supports_advisory_locks? - assert ActiveRecord::Base.connection.supports_advisory_locks? - - run_without_connection do |orig_connection| - ActiveRecord::Base.establish_connection( - orig_connection.merge(advisory_locks: false) - ) - - assert_not ActiveRecord::Base.connection.supports_advisory_locks? - - ActiveRecord::Base.establish_connection( - orig_connection.merge(advisory_locks: true) - ) - - assert ActiveRecord::Base.connection.supports_advisory_locks? - end - end -end diff --git a/activerecord/test/cases/adapters/mysql2/test_advisory_locks_disabled_test.rb b/activerecord/test/cases/adapters/mysql2/test_advisory_locks_disabled_test.rb deleted file mode 100644 index 4857900820..0000000000 --- a/activerecord/test/cases/adapters/mysql2/test_advisory_locks_disabled_test.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -require "cases/helper" -require "cases/adapters/helpers/test_supports_advisory_locks" - -class Mysql2AdvisoryLocksDisabledTest < ActiveRecord::Mysql2TestCase - include TestSupportsAdvisoryLocks -end diff --git a/activerecord/test/cases/adapters/postgresql/advisory_locks_disabled_test.rb b/activerecord/test/cases/adapters/postgresql/advisory_locks_disabled_test.rb deleted file mode 100644 index f14e9baeb9..0000000000 --- a/activerecord/test/cases/adapters/postgresql/advisory_locks_disabled_test.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -require "cases/helper" -require "cases/adapters/helpers/test_supports_advisory_locks" - -class PostgresqlAdvisoryLocksDisabledTest < ActiveRecord::PostgreSQLTestCase - include TestSupportsAdvisoryLocks -end |