@@ -10,7 +10,7 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
1010 it 'sst_datatypes' do
1111 generate_schema_for_table 'sst_datatypes'
1212 # Exact Numerics
13- assert_line :bigint , type : 'integer' , limit : '8' , precision : nil , scale : nil , default : '42'
13+ assert_line :bigint , type : 'bigint' , limit : '8' , precision : nil , scale : nil , default : '42'
1414 assert_line :int , type : 'integer' , limit : '4' , precision : nil , scale : nil , default : '42'
1515 assert_line :smallint , type : 'integer' , limit : '2' , precision : nil , scale : nil , default : '42'
1616 assert_line :tinyint , type : 'integer' , limit : '1' , precision : nil , scale : nil , default : '42'
@@ -46,6 +46,38 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
4646 assert_line :varbinary_max , type : 'binary' , limit : '2147483647' , precision : nil , scale : nil , default : nil
4747 end
4848
49+ it 'sst_datatypes_migration' do
50+ columns = SSTestDatatypeMigration . columns_hash
51+ generate_schema_for_table 'sst_datatypes_migration'
52+ # Simple Rails conventions
53+ columns [ 'integer_col' ] . sql_type . must_equal 'int(4)'
54+ columns [ 'bigint_col' ] . sql_type . must_equal 'bigint(8)'
55+ columns [ 'boolean_col' ] . sql_type . must_equal 'bit'
56+ columns [ 'decimal_col' ] . sql_type . must_equal 'decimal(18,0)'
57+ columns [ 'float_col' ] . sql_type . must_equal 'real(24)'
58+ columns [ 'string_col' ] . sql_type . must_equal 'nvarchar(4000)'
59+ columns [ 'text_col' ] . sql_type . must_equal 'nvarchar(max)'
60+ columns [ 'datetime_col' ] . sql_type . must_equal 'datetime'
61+ columns [ 'timestamp_col' ] . sql_type . must_equal 'datetime'
62+ columns [ 'time_col' ] . sql_type . must_equal 'time(7)'
63+ columns [ 'date_col' ] . sql_type . must_equal 'date'
64+ columns [ 'binary_col' ] . sql_type . must_equal 'varbinary(max)'
65+ assert_line :integer_col , type : 'integer' , limit : '4' , precision : nil , scale : nil , default : nil
66+ assert_line :bigint_col , type : 'bigint' , limit : '8' , precision : nil , scale : nil , default : nil
67+ assert_line :boolean_col , type : 'boolean' , limit : nil , precision : nil , scale : nil , default : nil
68+ assert_line :decimal_col , type : 'decimal' , limit : nil , precision : '18' , scale : '0' , default : nil
69+ assert_line :float_col , type : 'real' , limit : '24' , precision : nil , scale : nil , default : nil
70+ assert_line :string_col , type : 'string' , limit : '4000' , precision : nil , scale : nil , default : nil
71+ assert_line :text_col , type : 'text' , limit : '2147483647' , precision : nil , scale : nil , default : nil
72+ assert_line :datetime_col , type : 'datetime' , limit : nil , precision : nil , scale : nil , default : nil
73+ assert_line :timestamp_col , type : 'datetime' , limit : nil , precision : nil , scale : nil , default : nil
74+ assert_line :time_col , type : 'time' , limit : nil , precision : '7' , scale : nil , default : nil
75+ assert_line :date_col , type : 'date' , limit : nil , precision : nil , scale : nil , default : nil
76+ assert_line :binary_col , type : 'binary' , limit : '2147483647' , precision : nil , scale : nil , default : nil
77+ end
78+
79+ # Special Cases
80+
4981 it 'primary_key' do
5082 generate_schema_for_table ( 'movies' ) do |output |
5183 match = output . match ( %r{create_table "movies"(.*)do} )
@@ -54,18 +86,6 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
5486 end
5587 end
5688
57- it 'a string type is nvarchar without a limit' do
58- generate_schema_for_table 'sst_datatypes_migration'
59- SSTestDatatypeMigration . columns_hash [ 'string_col' ] . sql_type . must_equal 'nvarchar(4000)'
60- assert_line :string_col , type : 'string' , limit : '4000' , precision : nil , scale : nil , default : nil
61- end
62-
63- it 'a text type is nvarchar max' do
64- generate_schema_for_table 'sst_datatypes_migration'
65- SSTestDatatypeMigration . columns_hash [ 'text_col' ] . sql_type . must_equal 'nvarchar(max)'
66- assert_line :text_col , type : 'text' , limit : '2147483647' , precision : nil , scale : nil , default : nil
67- end
68-
6989
7090 private
7191
@@ -77,7 +97,7 @@ def generate_schema_for_table(*table_names)
7797 @generated_schema = stream . string
7898 yield @generated_schema if block_given?
7999 @schema_lines = Hash . new
80- type_matcher = /\A \s +t\. \w +\s +"(.*?)", /
100+ type_matcher = /\A \s +t\. \w +\s +"(.*?)"[, \n ] /
81101 @generated_schema . each_line do |line |
82102 next unless line =~ type_matcher
83103 @schema_lines [ Regexp . last_match [ 1 ] ] = SchemaLine . new ( line )
@@ -91,7 +111,7 @@ def line(column_name)
91111
92112 def assert_line ( column_name , options = { } )
93113 line = line ( column_name )
94- assert line , "Count not find line with column name: #{ column_name . inspect } "
114+ assert line , "Count not find line with column name: #{ column_name . inspect } in schema: \n #{ schema } "
95115 line . type_method . must_equal options [ :type ] , "Type of #{ options [ :type ] . inspect } not found in:\n #{ line } " if options . key? ( :type )
96116 line . limit . must_equal options [ :limit ] , "Limit of #{ options [ :limit ] . inspect } not found in:\n #{ line } " if options . key? ( :limit )
97117 line . precision . must_equal options [ :precision ] , "Precision of #{ options [ :precision ] . inspect } not found in:\n #{ line } " if options . key? ( :precision )
0 commit comments