@@ -46,6 +46,15 @@ def test_column_names_are_escaped_coerced
4646 assert_equal ( "#{ badchar } foo#{ badchar * 2 } bar#{ badchar } " , quoted )
4747 end
4848
49+ # This test has a few problems. First, it would require that we use
50+ # the `Type::SQLServer::BigInteger.new(limit: 8)` for the `world_population`
51+ # attribute. Second, since we allow the DB to win at casting for TinyTDS,
52+ # it always comes back as a BigDecimal.
53+ coerce_tests! :test_numeric_fields
54+
55+ # Just like PostgreSQLAdapter does.
56+ coerce_tests! :test_respect_internal_encoding
57+
4958end
5059
5160
@@ -68,6 +77,47 @@ def test_belongs_to_with_primary_key_joins_on_correct_column_coerced
6877
6978
7079
80+ module ActiveRecord
81+ class BindParameterTest < ActiveRecord ::TestCase
82+
83+ # Never finds `sql` since we use `EXEC sp_executesql` wrappers.
84+ coerce_tests! :test_binds_are_logged ,
85+ :test_binds_are_logged_after_type_cast
86+
87+ end
88+ end
89+
90+
91+
92+
93+ class CalculationsTest < ActiveRecord ::TestCase
94+
95+ # Are decimal, not integer.
96+ coerce_tests! :test_should_return_decimal_average_of_integer_field
97+ def test_should_return_decimal_average_of_integer_field_coerced
98+ value = Account . average ( :id )
99+ assert_equal BigDecimal ( '3.5' ) . to_s , BigDecimal ( value ) . to_s
100+ end
101+
102+ coerce_tests! :test_limit_is_kept
103+ def test_limit_is_kept_coerced
104+ queries = assert_sql { Account . limit ( 1 ) . count }
105+ assert_equal 1 , queries . length
106+ queries . first . must_match %r{ORDER BY \[ accounts\] \. \[ id\] ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY}
107+ end
108+
109+ coerce_tests! :test_limit_with_offset_is_kept
110+ def test_limit_with_offset_is_kept_coerced
111+ queries = assert_sql { Account . limit ( 1 ) . offset ( 1 ) . count }
112+ assert_equal 1 , queries . length
113+ queries . first . must_match %r{ORDER BY \[ accounts\] \. \[ id\] ASC OFFSET 1 ROWS FETCH NEXT 1 ROWS ONLY}
114+ end
115+
116+ end
117+
118+
119+
120+
71121module ActiveRecord
72122 module ConnectionAdapters
73123
0 commit comments