Skip to content

Commit 2ead513

Browse files
committed
Adapter helpers are available as AR::TestCase class methods
in case we need to call them outside of test case
1 parent bcfdfef commit 2ead513

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

activerecord/test/cases/migration_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def change
2222
end
2323

2424
class BigNumber < ActiveRecord::Base
25-
unless current_adapter?(:PostgreSQLAdapter, :SQLite3Adapter)
25+
unless ActiveRecord::TestCase.current_adapter?(:PostgreSQLAdapter, :SQLite3Adapter)
2626
attribute :value_of_e, :integer
2727
end
2828
attribute :my_house_population, :integer
@@ -393,15 +393,15 @@ def test_add_column_with_casted_type_if_not_exists_set_to_true
393393
migration_a = Class.new(ActiveRecord::Migration::Current) {
394394
def version; 100 end
395395
def migrate(x)
396-
type = current_adapter?(:PostgreSQLAdapter) ? :char : :blob
396+
type = ActiveRecord::TestCase.current_adapter?(:PostgreSQLAdapter) ? :char : :blob
397397
add_column "people", "last_name", type
398398
end
399399
}.new
400400

401401
migration_b = Class.new(ActiveRecord::Migration::Current) {
402402
def version; 101 end
403403
def migrate(x)
404-
type = current_adapter?(:PostgreSQLAdapter) ? :char : :blob
404+
type = ActiveRecord::TestCase.current_adapter?(:PostgreSQLAdapter) ? :char : :blob
405405
add_column "people", "last_name", type, if_not_exists: true
406406
end
407407
}.new

activerecord/test/schema/mysql2_specific_schema.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
t.datetime :fixed_time, default: "2004-01-01 00:00:00"
2222
t.column :char1, "char(1)", default: "Y"
2323
t.string :char2, limit: 50, default: "a varchar field"
24-
if supports_default_expression?
24+
if ActiveRecord::TestCase.supports_default_expression?
2525
t.binary :uuid, limit: 36, default: -> { "(uuid())" }
2626
end
2727
end

activerecord/test/schema/postgresql_specific_schema.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# frozen_string_literal: true
22

33
ActiveRecord::Schema.define do
4-
enable_extension!("uuid-ossp", ActiveRecord::Base.connection)
5-
enable_extension!("pgcrypto", ActiveRecord::Base.connection) if ActiveRecord::Base.connection.supports_pgcrypto_uuid?
4+
ActiveRecord::TestCase.enable_extension!("uuid-ossp", ActiveRecord::Base.connection)
5+
ActiveRecord::TestCase.enable_extension!("pgcrypto", ActiveRecord::Base.connection) if ActiveRecord::Base.connection.supports_pgcrypto_uuid?
66

77
uuid_default = connection.supports_pgcrypto_uuid? ? {} : { default: "uuid_generate_v4()" }
88

activerecord/test/schema/schema.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@
199199
create_table :carriers, force: true
200200

201201
create_table :carts, force: true, primary_key: [:shop_id, :id] do |t|
202-
if current_adapter?(:Mysql2Adapter)
202+
if ActiveRecord::TestCase.current_adapter?(:Mysql2Adapter)
203203
t.bigint :id, index: true, auto_increment: true, null: false
204204
else
205205
t.bigint :id, index: true, null: false
@@ -263,7 +263,7 @@
263263
t.integer :post_id, null: false
264264
# use VARCHAR2(4000) instead of CLOB datatype as CLOB data type has many limitations in
265265
# Oracle SELECT WHERE clause which causes many unit test failures
266-
if current_adapter?(:OracleAdapter)
266+
if ActiveRecord::TestCase.current_adapter?(:OracleAdapter)
267267
t.string :body, null: false, limit: 4000
268268
else
269269
t.text :body, null: false
@@ -731,7 +731,7 @@
731731
t.float :temperature
732732
t.decimal :decimal_number_big_precision, precision: 20
733733
# Oracle/SQLServer supports precision up to 38
734-
if current_adapter?(:OracleAdapter, :SQLServerAdapter)
734+
if ActiveRecord::TestCase.current_adapter?(:OracleAdapter, :SQLServerAdapter)
735735
t.decimal :atoms_in_universe, precision: 38, scale: 0
736736
else
737737
t.decimal :atoms_in_universe, precision: 55, scale: 0
@@ -870,7 +870,7 @@
870870
t.string :title, null: false
871871
# use VARCHAR2(4000) instead of CLOB datatype as CLOB data type has many limitations in
872872
# Oracle SELECT WHERE clause which causes many unit test failures
873-
if current_adapter?(:OracleAdapter)
873+
if ActiveRecord::TestCase.current_adapter?(:OracleAdapter)
874874
t.string :body, null: false, limit: 4000
875875
else
876876
t.text :body, null: false
@@ -1107,7 +1107,7 @@
11071107
t.date :last_read
11081108
# use VARCHAR2(4000) instead of CLOB datatype as CLOB data type has many limitations in
11091109
# Oracle SELECT WHERE clause which causes many unit test failures
1110-
if current_adapter?(:OracleAdapter)
1110+
if ActiveRecord::TestCase.current_adapter?(:OracleAdapter)
11111111
t.string :content, limit: 4000
11121112
t.string :important, limit: 4000
11131113
else

0 commit comments

Comments
 (0)