Skip to content

Commit e24750e

Browse files
committed
Moving some #type_to_sql tests around. Getting ready to overhaul #type_to_sql and/or test more.
1 parent b101837 commit e24750e

File tree

3 files changed

+31
-30
lines changed

3 files changed

+31
-30
lines changed

lib/active_record/connection_adapters/sqlserver_adapter.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def quoted_false
338338
end
339339

340340
# TODO: I get the feeling this needs to go and that it is patching something else wrong.
341-
def quoted_date(value)
341+
def quoted_date(value)
342342
if value.acts_like?(:time)
343343
value.strftime("%Y%m%d %H:%M:%S")
344344
elsif value.acts_like?(:date)
@@ -588,14 +588,12 @@ def add_order_by_for_association_limiting!(sql, options)
588588
sql << " ORDER BY #{order.join(',')}"
589589
end
590590

591-
def type_to_sql(type, limit = nil, precision = nil, scale = nil) #:nodoc:
591+
def type_to_sql(type, limit = nil, precision = nil, scale = nil)
592592
# Remove limit for data types which do not require it
593593
# Valid: ALTER TABLE sessions ALTER COLUMN [data] varchar(max)
594594
# Invalid: ALTER TABLE sessions ALTER COLUMN [data] varchar(max)(16777215)
595595
limit = nil if %w{text varchar(max) nvarchar(max) ntext varbinary(max) image}.include?(native_database_types[type.to_sym][:name])
596-
597596
return super unless type.to_s == 'integer'
598-
599597
if limit.nil?
600598
'integer'
601599
elsif limit > 4

test/cases/adapter_test_sqlserver.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,34 @@ def setup
195195

196196
context 'For SchemaStatements' do
197197

198+
context 'returning from #type_to_sql' do
199+
200+
should 'create integers when no limit supplied' do
201+
assert_equal 'integer', @connection.type_to_sql(:integer)
202+
end
203+
204+
should 'create integers when limit is 4' do
205+
assert_equal 'integer', @connection.type_to_sql(:integer, 4)
206+
end
207+
208+
should 'create integers when limit is 3' do
209+
assert_equal 'integer', @connection.type_to_sql(:integer, 3)
210+
end
211+
212+
should 'create smallints when limit is less than 3' do
213+
assert_equal 'smallint', @connection.type_to_sql(:integer, 2)
214+
assert_equal 'smallint', @connection.type_to_sql(:integer, 1)
215+
end
216+
217+
should 'create bigints when limit is greateer than 4' do
218+
assert_equal 'bigint', @connection.type_to_sql(:integer, 5)
219+
assert_equal 'bigint', @connection.type_to_sql(:integer, 6)
220+
assert_equal 'bigint', @connection.type_to_sql(:integer, 7)
221+
assert_equal 'bigint', @connection.type_to_sql(:integer, 8)
222+
end
223+
224+
end
225+
198226
end
199227

200228
context 'For indexes' do

test/cases/schema_statement_test_sqlserver.rb

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def setup
77
end
88

99
context 'For #columns' do
10-
10+
1111
# Remove brackets and outer quotes (if quoted) of default value returned by db, i.e:
1212
# "(1)" => "1", "('1')" => "1", "((-1))" => "-1", "('(-1)')" => "(-1)"
1313
# Unicode strings will be prefixed with an N. Remove that too.
@@ -21,30 +21,5 @@ def setup
2121

2222
end
2323

24-
25-
should 'create integers when no limit supplied' do
26-
assert_equal 'integer', @connection.type_to_sql(:integer)
27-
end
28-
29-
should 'create integers when limit is 4' do
30-
assert_equal 'integer', @connection.type_to_sql(:integer, 4)
31-
end
32-
33-
should 'create integers when limit is 3' do
34-
assert_equal 'integer', @connection.type_to_sql(:integer, 3)
35-
end
36-
37-
should 'create smallints when limit is less than 3' do
38-
assert_equal 'smallint', @connection.type_to_sql(:integer, 2)
39-
assert_equal 'smallint', @connection.type_to_sql(:integer, 1)
40-
end
41-
42-
should 'create bigints when limit is greateer than 4' do
43-
assert_equal 'bigint', @connection.type_to_sql(:integer, 5)
44-
assert_equal 'bigint', @connection.type_to_sql(:integer, 6)
45-
assert_equal 'bigint', @connection.type_to_sql(:integer, 7)
46-
assert_equal 'bigint', @connection.type_to_sql(:integer, 8)
47-
end
48-
4924

5025
end

0 commit comments

Comments
 (0)