Skip to content

Commit

Permalink
Merge pull request #51826 from Shopify/remove-oracle-sqlserver-from-t…
Browse files Browse the repository at this point in the history
…ests

Remove oracle sqlserver from tests
  • Loading branch information
rafaelfranca committed May 17, 2024
2 parents 4964049 + de7bf12 commit 59eb4f4
Show file tree
Hide file tree
Showing 29 changed files with 157 additions and 390 deletions.
2 changes: 1 addition & 1 deletion activerecord/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace :db do
task drop: ["db:mysql:drop", "db:postgresql:drop"]
end

%w( mysql2 trilogy postgresql sqlite3 sqlite3_mem oracle jdbcmysql jdbcpostgresql jdbcsqlite3 jdbcderby jdbch2 jdbchsqldb ).each do |adapter|
%w( mysql2 trilogy postgresql sqlite3 sqlite3_mem ).each do |adapter|
namespace :test do
Rake::TestTask.new(adapter => "#{adapter}:env") do |t|
adapter_short = adapter[/^[a-z0-9]+/]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ def test_belongs_to_with_primary_key_joins_on_correct_column
if current_adapter?(:Mysql2Adapter, :TrilogyAdapter)
assert_no_match(/`firm_with_primary_keys_companies`\.`id`/, sql)
assert_match(/`firm_with_primary_keys_companies`\.`name`/, sql)
elsif current_adapter?(:OracleAdapter)
# on Oracle aliases are truncated to 30 characters and are quoted in uppercase
assert_no_match(/"firm_with_primary_keys_compani"\."id"/i, sql)
assert_match(/"firm_with_primary_keys_compani"\."name"/i, sql)
else
assert_no_match(/"firm_with_primary_keys_companies"\."id"/, sql)
assert_match(/"firm_with_primary_keys_companies"\."name"/, sql)
Expand Down
14 changes: 2 additions & 12 deletions activerecord/test/cases/attribute_methods_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -692,23 +692,13 @@ def topic.approved; false; end

test "typecast attribute from select to false" do
Topic.create(title: "Budget")
# Oracle does not support boolean expressions in SELECT.
if current_adapter?(:OracleAdapter)
topic = Topic.all.merge!(select: "topics.*, 0 as is_test").first
else
topic = Topic.all.merge!(select: "topics.*, 1=2 as is_test").first
end
topic = Topic.all.merge!(select: "topics.*, 1=2 as is_test").first
assert_not_predicate topic, :is_test?
end

test "typecast attribute from select to true" do
Topic.create(title: "Budget")
# Oracle does not support boolean expressions in SELECT.
if current_adapter?(:OracleAdapter)
topic = Topic.all.merge!(select: "topics.*, 1 as is_test").first
else
topic = Topic.all.merge!(select: "topics.*, 2=2 as is_test").first
end
topic = Topic.all.merge!(select: "topics.*, 2=2 as is_test").first
assert_predicate topic, :is_test?
end

Expand Down
40 changes: 8 additions & 32 deletions activerecord/test/cases/autosave_association_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1543,12 +1543,7 @@ def test_should_still_allow_to_bypass_validations_on_the_associated_model
@pirate.catchphrase = ""
@pirate.ship.name = ""
@pirate.save(validate: false)
# Oracle saves empty string as NULL
if current_adapter?(:OracleAdapter)
assert_equal [nil, nil], [@pirate.reload.catchphrase, @pirate.ship.name]
else
assert_equal ["", ""], [@pirate.reload.catchphrase, @pirate.ship.name]
end
assert_equal ["", ""], [@pirate.reload.catchphrase, @pirate.ship.name]
end

def test_should_allow_to_bypass_validations_on_associated_models_at_any_depth
Expand All @@ -1560,12 +1555,7 @@ def test_should_allow_to_bypass_validations_on_associated_models_at_any_depth
@pirate.save(validate: false)

values = [@pirate.reload.catchphrase, @pirate.ship.name, *@pirate.ship.parts.map(&:name)]
# Oracle saves empty string as NULL
if current_adapter?(:OracleAdapter)
assert_equal [nil, nil, nil, nil], values
else
assert_equal ["", "", "", ""], values
end
assert_equal ["", "", "", ""], values
end

def test_should_still_raise_an_ActiveRecordRecord_Invalid_exception_if_we_want_that
Expand Down Expand Up @@ -1732,12 +1722,7 @@ def test_should_still_allow_to_bypass_validations_on_the_associated_model
@ship.pirate.catchphrase = ""
@ship.name = ""
@ship.save(validate: false)
# Oracle saves empty string as NULL
if current_adapter?(:OracleAdapter)
assert_equal [nil, nil], [@ship.reload.name, @ship.pirate.catchphrase]
else
assert_equal ["", ""], [@ship.reload.name, @ship.pirate.catchphrase]
end
assert_equal ["", ""], [@ship.reload.name, @ship.pirate.catchphrase]
end

def test_should_still_raise_an_ActiveRecordRecord_Invalid_exception_if_we_want_that
Expand Down Expand Up @@ -1869,20 +1854,11 @@ def test_should_allow_to_bypass_validations_on_the_associated_models_on_update
@pirate.public_send(@association_name).each { |child| child.name = "" }

assert @pirate.save(validate: false)
# Oracle saves empty string as NULL
if current_adapter?(:OracleAdapter)
assert_equal [nil, nil, nil], [
@pirate.reload.catchphrase,
@pirate.public_send(@association_name).first.name,
@pirate.public_send(@association_name).last.name
]
else
assert_equal ["", "", ""], [
@pirate.reload.catchphrase,
@pirate.public_send(@association_name).first.name,
@pirate.public_send(@association_name).last.name
]
end
assert_equal ["", "", ""], [
@pirate.reload.catchphrase,
@pirate.public_send(@association_name).first.name,
@pirate.public_send(@association_name).last.name
]
end

def test_should_validation_the_associated_models_on_create
Expand Down
60 changes: 18 additions & 42 deletions activerecord/test/cases/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,7 @@ def test_column_names_are_escaped
}

quoted = conn.quote_column_name "foo#{badchar}bar"
if current_adapter?(:OracleAdapter)
# Oracle does not allow double quotes in table and column names at all
# therefore quoting removes them
assert_equal("#{badchar}foobar#{badchar}", quoted)
else
assert_equal("#{badchar}foo#{badchar * 2}bar#{badchar}", quoted)
end
assert_equal("#{badchar}foo#{badchar * 2}bar#{badchar}", quoted)
end

def test_columns_should_obey_set_primary_key
Expand Down Expand Up @@ -545,39 +539,27 @@ def test_default_values
topic = Topic.find(topic.id)
assert_predicate topic, :approved?
assert_nil topic.last_read

# Oracle has some funky default handling, so it requires a bit of
# extra testing. See ticket #2788.
if current_adapter?(:OracleAdapter)
test = TestOracleDefault.new
assert_equal "X", test.test_char
assert_equal "hello", test.test_string
assert_equal 3, test.test_int
end
end

# Oracle does not have a TIME datatype.
unless current_adapter?(:OracleAdapter)
def test_utc_as_time_zone
with_timezone_config default: :utc do
attributes = { "bonus_time" => "5:42:00AM" }
topic = Topic.find(1)
topic.attributes = attributes
assert_equal Time.utc(2000, 1, 1, 5, 42, 0), topic.bonus_time
end
def test_utc_as_time_zone
with_timezone_config default: :utc do
attributes = { "bonus_time" => "5:42:00AM" }
topic = Topic.find(1)
topic.attributes = attributes
assert_equal Time.utc(2000, 1, 1, 5, 42, 0), topic.bonus_time
end
end

def test_utc_as_time_zone_and_new
with_timezone_config default: :utc do
attributes = { "bonus_time(1i)" => "2000",
"bonus_time(2i)" => "1",
"bonus_time(3i)" => "1",
"bonus_time(4i)" => "10",
"bonus_time(5i)" => "35",
"bonus_time(6i)" => "50" }
topic = Topic.new(attributes)
assert_equal Time.utc(2000, 1, 1, 10, 35, 50), topic.bonus_time
end
def test_utc_as_time_zone_and_new
with_timezone_config default: :utc do
attributes = { "bonus_time(1i)" => "2000",
"bonus_time(2i)" => "1",
"bonus_time(3i)" => "1",
"bonus_time(4i)" => "10",
"bonus_time(5i)" => "35",
"bonus_time(6i)" => "50" }
topic = Topic.new(attributes)
assert_equal Time.utc(2000, 1, 1, 10, 35, 50), topic.bonus_time
end
end

Expand Down Expand Up @@ -922,9 +904,6 @@ def test_group_weirds_by_from
end

def test_attributes_on_dummy_time
# Oracle does not have a TIME datatype.
return true if current_adapter?(:OracleAdapter)

with_timezone_config default: :local do
attributes = {
"bonus_time" => "5:42:00AM"
Expand All @@ -939,9 +918,6 @@ def test_attributes_on_dummy_time
end

def test_attributes_on_dummy_time_with_invalid_time
# Oracle does not have a TIME datatype.
return true if current_adapter?(:OracleAdapter)

attributes = {
"bonus_time" => "not a time"
}
Expand Down
12 changes: 1 addition & 11 deletions activerecord/test/cases/calculations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,24 +277,18 @@ def test_count_should_shortcut_with_limit_zero
end

def test_limit_is_kept
return if current_adapter?(:OracleAdapter)

queries = capture_sql { Account.limit(1).count }
assert_equal 1, queries.length
assert_match(/LIMIT/, queries.first)
end

def test_offset_is_kept
return if current_adapter?(:OracleAdapter)

queries = capture_sql { Account.offset(1).count }
assert_equal 1, queries.length
assert_match(/OFFSET/, queries.first)
end

def test_limit_with_offset_is_kept
return if current_adapter?(:OracleAdapter)

queries = capture_sql { Account.limit(1).offset(1).count }
assert_equal 1, queries.length
assert_match(/LIMIT/, queries.first)
Expand Down Expand Up @@ -844,11 +838,7 @@ def test_pluck_with_empty_in
end

def test_pluck_without_column_names
if current_adapter?(:OracleAdapter)
assert_equal [[1, "Firm", 1, nil, "37signals", nil, 1, nil, nil, "active"]], Company.order(:id).limit(1).pluck
else
assert_equal [[1, "Firm", 1, nil, "37signals", nil, 1, nil, "", "active"]], Company.order(:id).limit(1).pluck
end
assert_equal [[1, "Firm", 1, nil, "37signals", nil, 1, nil, "", "active"]], Company.order(:id).limit(1).pluck
end

def test_pluck_type_cast
Expand Down
18 changes: 6 additions & 12 deletions activerecord/test/cases/comment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,9 @@ def test_add_column_with_comment_later
end

def test_add_index_with_comment_later
unless current_adapter?(:OracleAdapter)
@connection.add_index :commenteds, :obvious, name: "idx_obvious", comment: "We need to see obvious comments"
index = @connection.indexes("commenteds").find { |idef| idef.name == "idx_obvious" }
assert_equal "We need to see obvious comments", index.comment
end
@connection.add_index :commenteds, :obvious, name: "idx_obvious", comment: "We need to see obvious comments"
index = @connection.indexes("commenteds").find { |idef| idef.name == "idx_obvious" }
assert_equal "We need to see obvious comments", index.comment
end

def test_add_comment_to_column
Expand Down Expand Up @@ -139,13 +137,9 @@ def test_schema_dump_with_comments
assert_match %r[t\.string\s+"name",\s+comment: "Comment should help clarify the column purpose"], output
assert_match %r[t\.string\s+"obvious"\n], output
assert_match %r[t\.string\s+"content",\s+comment: "Whoa, content describes itself!"], output
if current_adapter?(:OracleAdapter)
assert_match %r[t\.integer\s+"rating",\s+precision: 38,\s+comment: "I am running out of imagination"], output
else
assert_match %r[t\.integer\s+"rating",\s+comment: "I am running out of imagination"], output
assert_match %r[t\.index\s+.+\s+comment: "\\"Very important\\" index that powers all the performance.\\nAnd it's fun!"], output
assert_match %r[t\.index\s+.+\s+name: "idx_obvious",\s+comment: "We need to see obvious comments"], output
end
assert_match %r[t\.integer\s+"rating",\s+comment: "I am running out of imagination"], output
assert_match %r[t\.index\s+.+\s+comment: "\\"Very important\\" index that powers all the performance.\\nAnd it's fun!"], output
assert_match %r[t\.index\s+.+\s+name: "idx_obvious",\s+comment: "We need to see obvious comments"], output
end

def test_schema_dump_omits_blank_comments
Expand Down
22 changes: 5 additions & 17 deletions activerecord/test/cases/connection_adapters/type_lookup_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,29 +83,17 @@ def test_integer_types

def test_bigint_limit
limit = @connection.send(:type_map).lookup("bigint").send(:_limit)
if current_adapter?(:OracleAdapter)
assert_equal 19, limit
else
assert_equal 8, limit
end

assert_equal 8, limit
end

def test_decimal_without_scale
if current_adapter?(:OracleAdapter)
{
decimal: %w{decimal(2) decimal(2,0) numeric(2) numeric(2,0)},
integer: %w{number(2) number(2,0)}
}
else
{ decimal: %w{decimal(2) decimal(2,0) numeric(2) numeric(2,0) number(2) number(2,0)} }
end.each do |expected_type, types|
types.each do |type|
%w{decimal(2) decimal(2,0) numeric(2) numeric(2,0) number(2) number(2,0)}.each do |type|
cast_type = @connection.send(:type_map).lookup(type)

assert_equal expected_type, cast_type.type
assert_equal :decimal, cast_type.type
assert_equal 2, cast_type.cast(2.1)
end
end
end
end

private
Expand Down
17 changes: 4 additions & 13 deletions activerecord/test/cases/database_statements_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ def setup
@connection = ActiveRecord::Base.lease_connection
end

unless current_adapter?(:OracleAdapter)
def test_exec_insert
result = @connection.exec_insert("INSERT INTO accounts (firm_id,credit_limit) VALUES (42,5000)", nil, [])
assert_not_nil @connection.send(:last_inserted_id, result)
end
def test_exec_insert
result = @connection.exec_insert("INSERT INTO accounts (firm_id,credit_limit) VALUES (42,5000)", nil, [])
assert_not_nil @connection.send(:last_inserted_id, result)
end

def test_insert_should_return_the_inserted_id
Expand All @@ -24,13 +22,6 @@ def test_create_should_return_the_inserted_id

private
def return_the_inserted_id(method:)
# Oracle adapter uses prefetched primary key values from sequence and passes them to connection adapter insert method
if current_adapter?(:OracleAdapter)
sequence_name = "accounts_seq"
id_value = @connection.next_sequence_value(sequence_name)
@connection.send(method, "INSERT INTO accounts (id, firm_id,credit_limit) VALUES (accounts_seq.nextval,42,5000)", nil, :id, id_value, sequence_name)
else
@connection.send(method, "INSERT INTO accounts (firm_id,credit_limit) VALUES (42,5000)")
end
@connection.send(method, "INSERT INTO accounts (firm_id,credit_limit) VALUES (42,5000)")
end
end
2 changes: 1 addition & 1 deletion activerecord/test/cases/date_time_precision_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def test_schema_dump_with_without_precision_has_precision_as_nil
assert_match %r{t\.datetime\s+"updated_at",\s+precision: nil,\s+null: false$}, output
end

if current_adapter?(:PostgreSQLAdapter, :SQLServerAdapter)
if current_adapter?(:PostgreSQLAdapter)
def test_datetime_precision_with_zero_should_be_dumped
@connection.create_table(:foos, force: true) do |t|
t.timestamps precision: 0
Expand Down
2 changes: 0 additions & 2 deletions activerecord/test/cases/dup_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ def test_dup_with_default_scope
end

def test_dup_without_primary_key
skip if current_adapter?(:OracleAdapter)

klass = Class.new(ActiveRecord::Base) do
self.table_name = "parrots_pirates"
end
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/invertible_migration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ def test_migrations_can_handle_foreign_keys_to_specific_tables
end

# MySQL 5.7 and Oracle do not allow to create duplicate indexes on the same columns
unless current_adapter?(:Mysql2Adapter, :TrilogyAdapter, :OracleAdapter)
unless current_adapter?(:Mysql2Adapter, :TrilogyAdapter)
def test_migrate_revert_add_index_with_name
RevertNamedIndexMigration1.new.migrate(:up)
RevertNamedIndexMigration2.new.migrate(:up)
Expand Down
6 changes: 1 addition & 5 deletions activerecord/test/cases/json_shared_test_cases.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,6 @@ def assert_type_match(type, sql_type)
end

def insert_statement_per_database(values)
if current_adapter?(:OracleAdapter)
"insert into json_data_type (id, payload) VALUES (json_data_type_seq.nextval, '#{values}')"
else
"insert into json_data_type (payload) VALUES ('#{values}')"
end
"insert into json_data_type (payload) VALUES ('#{values}')"
end
end

0 comments on commit 59eb4f4

Please sign in to comment.