11require 'cases/helper_sqlserver'
22require 'models/topic'
3+ require 'models/task'
34
4- # require 'models/task'
55# require 'models/reply'
66# require 'models/joke'
77# require 'models/subscriber'
1818
1919class AdapterTestSQLServer < ActiveRecord ::TestCase
2020
21- # fixtures :tasks, :posts
22-
2321 let ( :connection ) { ActiveRecord ::Base . connection }
2422
25- before do
26- @basic_insert_sql = "INSERT INTO [funny_jokes] ([name]) VALUES('Knock knock')"
27- @basic_update_sql = "UPDATE [customers] SET [address_street] = NULL WHERE [id] = 2"
28- @basic_select_sql = "SELECT * FROM [customers] WHERE ([customers].[id] = 1)"
29- end
23+ let ( :basic_insert_sql ) { "INSERT INTO [funny_jokes] ([name]) VALUES('Knock knock')" }
24+ let ( :basic_update_sql ) { "UPDATE [customers] SET [address_street] = NULL WHERE [id] = 2" }
25+ let ( :basic_select_sql ) { "SELECT * FROM [customers] WHERE ([customers].[id] = 1)" }
26+
3027
3128 it 'has basic and non-senstive information in the adpaters inspect method' do
3229 string = connection . inspect
@@ -52,40 +49,36 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
5249 assert_equal 'SQLServer' , connection . adapter_name
5350 end
5451
55- it 'support migrations' do
52+ it 'supports migrations' do
5653 assert connection . supports_migrations?
5754 end
5855
5956 it 'support DDL in transactions' do
6057 assert connection . supports_ddl_transactions?
6158 end
6259
63- it 'allow owner table name prefixs like dbo. to still allow table_exists? to return true' do
60+ it 'allow owner table name prefixs like dbo to still allow table exists to return true' do
6461 begin
65- assert_equal 'tasks ' , Task . table_name
66- assert Task . table_exists?
67- Task . table_name = 'dbo.tasks '
68- assert Task . table_exists? , 'Tasks table name of dbo.tasks should return true for exists.'
62+ assert_equal 'topics ' , Topic . table_name
63+ assert Topic . table_exists?
64+ Topic . table_name = 'dbo.topics '
65+ assert Topic . table_exists? , 'Tasks table name of dbo.topics should return true for exists.'
6966 ensure
70- Task . table_name = 'tasks '
67+ Topic . table_name = 'topics '
7168 end
7269 end
7370
74- it 'return true to #insert_sql? for inserts only' do
71+ it 'return true to insert sql query for inserts only' do
7572 assert connection . send ( :insert_sql? , 'INSERT...' )
7673 assert connection . send ( :insert_sql? , "EXEC sp_executesql N'INSERT INTO [fk_test_has_fks] ([fk_id]) VALUES (@0); SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident', N'@0 int', @0 = 0" )
7774 assert !connection . send ( :insert_sql? , 'UPDATE...' )
7875 assert !connection . send ( :insert_sql? , 'SELECT...' )
7976 end
8077
81- describe 'for #get_table_name' do
82-
83- it 'return quoted table name from basic INSERT, UPDATE and SELECT statements' do
84- assert_equal '[funny_jokes]' , connection . send ( :get_table_name , @basic_insert_sql )
85- assert_equal '[customers]' , connection . send ( :get_table_name , @basic_update_sql )
86- assert_equal '[customers]' , connection . send ( :get_table_name , @basic_select_sql )
87- end
88-
78+ it 'return quoted table name from basic INSERT UPDATE and SELECT statements' do
79+ assert_equal '[funny_jokes]' , connection . send ( :get_table_name , basic_insert_sql )
80+ assert_equal '[customers]' , connection . send ( :get_table_name , basic_update_sql )
81+ assert_equal '[customers]' , connection . send ( :get_table_name , basic_select_sql )
8982 end
9083
9184 describe 'with different language' do
@@ -99,22 +92,24 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
9992 connection . send :initialize_dateformatter
10093 end
10194
102- it 'memoize users dateformat' do
95+ it 'memos users dateformat' do
10396 connection . execute ( "SET LANGUAGE us_english" ) rescue nil
10497 dateformat = connection . instance_variable_get ( :@database_dateformat )
10598 assert_equal 'mdy' , dateformat
10699 end
107100
108- it 'have a dateformatter' do
101+ it 'has a dateformatter' do
109102 assert Date ::DATE_FORMATS [ :_sqlserver_dateformat ]
110103 assert Time ::DATE_FORMATS [ :_sqlserver_dateformat ]
111104 end
112105
113- it 'do a date insertion when language is german' do
106+ it 'does a datetime insertion when language is german' do
114107 connection . execute ( "SET LANGUAGE deutsch" )
115108 connection . send :initialize_dateformatter
116109 assert_nothing_raised do
117- Task . create ( starting : Time . utc ( 2000 , 1 , 31 , 5 , 42 , 0 ) , ending : Date . new ( 2006 , 12 , 31 ) )
110+ starting = Time . utc ( 2000 , 1 , 31 , 5 , 42 , 0 )
111+ ending = Date . new ( 2006 , 12 , 31 )
112+ Task . create! starting : starting , ending : ending
118113 end
119114 end
120115
@@ -171,7 +166,7 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
171166 end
172167
173168 it 'return false to #query_requires_identity_insert? for normal SQL' do
174- [ @ basic_insert_sql, @ basic_update_sql, @ basic_select_sql] . each do |sql |
169+ [ basic_insert_sql , basic_update_sql , basic_select_sql ] . each do |sql |
175170 assert !connection . send ( :query_requires_identity_insert? , sql ) , "SQL was #{ sql } "
176171 end
177172 end
0 commit comments