Skip to content

Commit 4520133

Browse files
author
Anna
committed
coerce tests in sqlserver gem rather than rails
1 parent 5ebde7b commit 4520133

File tree

5 files changed

+67
-5
lines changed

5 files changed

+67
-5
lines changed

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ end
2121
def test_files
2222
test_setup = ["test/cases/sqlserver_helper.rb"]
2323

24-
return test_setup+(ENV['TEST_FILES']).split(',') if ENV['TEST_FILES']
24+
return test_setup + (ENV['TEST_FILES']).split(',') if ENV['TEST_FILES']
2525

2626
sqlserver_cases = Dir.glob("test/cases/**/*_test_sqlserver.rb")
2727

test/cases/adapter_test_sqlserver.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,3 +799,12 @@ class AdapterTestSqlserver < ActiveRecord::TestCase
799799
end
800800

801801
end
802+
803+
804+
class AdapterTest < ActiveRecord::TestCase
805+
COERCED_TESTS = [:test_update_prepared_statement]
806+
# Like PostgreSQL, SQL Server does not support null bytes in strings.
807+
# This is not run for PostgreSQL at the rails level and the same should happen for SQL Server
808+
# Until that patch is made to rails we are preventing this test from running in this gem.
809+
include SqlserverCoercedTest
810+
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require 'cases/sqlserver_helper'
2+
require 'models/owner'
3+
4+
class HasManyThroughAssociationsTest < ActiveRecord::TestCase
5+
COERCED_TESTS = [:test_has_many_through_obeys_order_on_through_association]
6+
# Rails does not do a case-insensive comparison
7+
# Until that patch is made to rails we are preventing this test from running in this gem.
8+
9+
include SqlserverCoercedTest
10+
def test_coerced_has_many_through_obeys_order_on_through_association
11+
owner = owners(:blackbeard)
12+
# assert owner.toys.to_sql.include?("pets.name desc") # What's currently in rails
13+
assert owner.toys.to_sql.downcase.include?("pets.name desc")
14+
assert_equal ["parrot", "bulbul"], owner.toys.map { |r| r.pet.name }
15+
end
16+
end

test/cases/base_test_sqlserver.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
class BasicsTest < ActiveRecord::TestCase
66

7-
COERCED_TESTS = [:test_column_names_are_escaped]
7+
COERCED_TESTS = [:test_column_names_are_escaped,
8+
:test_respect_internal_encoding]
9+
# test_respect_internal_encoding is not run for PostgreSQL at the rails level and the same should happen for SQL Server
10+
# Until that patch is made to rails we are preventing this test from running in this gem.
11+
812

913
include SqlserverCoercedTest
1014

test/cases/column_test_sqlserver.rb

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
require 'models_sqlserver/float_data'
44
require 'models_sqlserver/numeric_data'
55
require 'models_sqlserver/sql_server_chronic'
6+
require 'models_sqlserver/sql_server_edge_schema'
67
require 'models_sqlserver/sql_server_string'
78
require 'models_sqlserver/sql_server_unicode'
89
require 'models_sqlserver/table_with_real_column'
10+
911
require 'models_sqlserver/topic'
12+
require "cases/migration/helper"
1013

1114
class ColumnTestSqlserver < ActiveRecord::TestCase
1215

@@ -339,7 +342,37 @@ class ColumnTestSqlserver < ActiveRecord::TestCase
339342
assert_equal 'tinyint(1)', @tinyint.sql_type
340343
end
341344

342-
end
343-
344-
345+
end
345346
end
347+
348+
module ActiveRecord
349+
class Migration
350+
class ColumnsTest < ActiveRecord::TestCase
351+
include ActiveRecord::Migration::TestHelper
352+
353+
COERCED_TESTS = [:test_remove_column_with_multi_column_index]
354+
# The if current_adapter? conditional below should also contain :SQLServerAdapter.
355+
# Until that patch is made to rails we are preventing this test from running in this gem.
356+
357+
include SqlserverCoercedTest
358+
359+
#the only thing we changed in this method was to add :SQLServerAdapter
360+
def test_coerced_remove_column_with_multi_column_index
361+
add_column "test_models", :hat_size, :integer
362+
add_column "test_models", :hat_style, :string, :limit => 100
363+
add_index "test_models", ["hat_style", "hat_size"], :unique => true
364+
365+
assert_equal 1, connection.indexes('test_models').size
366+
remove_column("test_models", "hat_size")
367+
368+
# Every database and/or database adapter has their own behavior
369+
# if it drops the multi-column index when any of the indexed columns dropped by remove_column.
370+
if current_adapter?(:PostgreSQLAdapter, :OracleAdapter, :SQLServerAdapter)
371+
assert_equal [], connection.indexes('test_models').map(&:name)
372+
else
373+
assert_equal ['index_test_models_on_hat_style_and_hat_size'], connection.indexes('test_models').map(&:name)
374+
end
375+
end
376+
end
377+
end
378+
end

0 commit comments

Comments
 (0)