Skip to content

Commit 97659ec

Browse files
committed
Remove badly written test for prequoting column names, Topic.find(:all) blows up using [[topics]] anyway. I'm sure we do not want to support using table_name= with a prequoted value. No other adapter does. Also moved tests around to better home. Added better assert_sql IGNORED regex and also a version of assert_sql that shows what queries were executed.
1 parent 97ff3f6 commit 97659ec

File tree

3 files changed

+41
-48
lines changed

3 files changed

+41
-48
lines changed

test/cases/adapter_test_sqlserver.rb

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ def setup
1414
end
1515

1616
context 'For abstract behavior' do
17-
17+
18+
should 'raise invalid statement error' do
19+
assert_raise(ActiveRecord::StatementInvalid) { Topic.connection.update_sql("UPDATE XXX") }
20+
end
21+
1822
should 'be our adapter_name' do
1923
assert_equal 'SQLServer', @connection.adapter_name
2024
end
@@ -108,6 +112,21 @@ def setup
108112

109113
end
110114

115+
context 'with different language' do
116+
117+
teardown do
118+
@connection.execute("SET LANGUAGE us_english") rescue nil
119+
end
120+
121+
should 'do a date insertion when language is german' do
122+
@connection.execute("SET LANGUAGE deutsch")
123+
assert_nothing_raised do
124+
Task.create(:starting => Time.utc(2000, 1, 31, 5, 42, 0), :ending => Date.new(2006, 12, 31))
125+
end
126+
end
127+
128+
end
129+
111130
end
112131

113132
context 'For identity inserts' do
@@ -173,31 +192,6 @@ def setup
173192

174193
end
175194

176-
177-
178-
should 'raise invalid statement error' do
179-
assert_raise(ActiveRecord::StatementInvalid) { Topic.connection.update_sql("UPDATE XXX") }
180-
end
181-
182-
should 'return real_number as float' do
183-
assert_equal :float, TableWithRealColumn.columns_hash["real_number"].type
184-
end
185-
186-
context 'With different language' do
187-
188-
teardown do
189-
@connection.execute("SET LANGUAGE us_english") rescue nil
190-
end
191-
192-
should 'do a date insertion when language is german' do
193-
@connection.execute("SET LANGUAGE deutsch")
194-
assert_nothing_raised do
195-
Task.create(:starting => Time.utc(2000, 1, 31, 5, 42, 0), :ending => Date.new(2006, 12, 31))
196-
end
197-
end
198-
199-
end
200-
201195
context 'For indexes' do
202196

203197
setup do
@@ -214,25 +208,6 @@ def setup
214208

215209
end
216210

217-
context 'For .table_name' do
218-
219-
setup do
220-
@old_table_name, @new_table_name = Topic.table_name, '[topics]'
221-
Topic.table_name = @new_table_name
222-
end
223-
224-
teardown do
225-
Topic.table_name = @old_table_name
226-
end
227-
228-
should 'escape table name' do
229-
assert_nothing_raised { @connection.select_all "SELECT * FROM #{@new_table_name}" }
230-
assert_equal @new_table_name, Topic.table_name
231-
assert_equal 12, Topic.columns.length
232-
end
233-
234-
end
235-
236211

237212
end
238213

test/cases/column_test_sqlserver.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ def setup
77
@column_klass = ActiveRecord::ConnectionAdapters::SQLServerColumn
88
end
99

10+
should 'return real_number as float' do
11+
assert_equal :float, TableWithRealColumn.columns_hash["real_number"].type
12+
end
1013

1114
context 'For :binary columns' do
1215

test/cases/sqlserver_helper.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,24 @@
1313

1414
class TableWithRealColumn < ActiveRecord::Base; end
1515

16-
# See cases/helper in rails/activerecord. Tell assert_queries to ignore
17-
# our SELECT SCOPE_IDENTITY stuff.
16+
1817
ActiveRecord::Base.connection.class.class_eval do
19-
IGNORED_SQL << /SELECT SCOPE_IDENTITY/
18+
IGNORED_SQL << /SELECT SCOPE_IDENTITY/ << /INFORMATION_SCHEMA.TABLES/ << /INFORMATION_SCHEMA.COLUMNS/
19+
end
20+
21+
module ActiveRecord
22+
class TestCase < ActiveSupport::TestCase
23+
def assert_sql(*patterns_to_match)
24+
$queries_executed = []
25+
yield
26+
ensure
27+
failed_patterns = []
28+
patterns_to_match.each do |pattern|
29+
failed_patterns << pattern unless $queries_executed.any?{ |sql| pattern === sql }
30+
end
31+
assert failed_patterns.empty?, "Query pattern(s) #{failed_patterns.map(&:inspect).join(', ')} not found in:\n#{$queries_executed.inspect}"
32+
end
33+
end
2034
end
2135

36+

0 commit comments

Comments
 (0)