Skip to content

Commit fac18b5

Browse files
committed
Fix database statements tests.
1 parent ea1bd82 commit fac18b5

File tree

3 files changed

+51
-62
lines changed

3 files changed

+51
-62
lines changed

lib/active_record/connection_adapters/sqlserver/schema_cache.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def view_information(table_name)
8787
private
8888

8989
def table_name_key(table_name)
90-
SQLServer::Utils.extract_identifiers(table_name).object
90+
SQLServer::Utils.extract_identifiers(table_name).quoted
9191
end
9292

9393
def prepare_views

test/cases/adapter_test_sqlserver.rb

Lines changed: 49 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
class AdapterTestSQLServer < ActiveRecord::TestCase
2020

21+
fixtures :tasks
22+
2123
let(:connection) { ActiveRecord::Base.connection }
2224

2325
let(:basic_insert_sql) { "INSERT INTO [funny_jokes] ([name]) VALUES('Knock knock')" }
@@ -253,77 +255,70 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
253255

254256
end
255257

256-
describe 'For DatabaseStatements' do
257-
258-
describe "finding out what user_options are available" do
258+
describe 'database statements' do
259259

260-
it "run the database consistency checker useroptions command" do
261-
keys = [:textsize, :language, :isolation_level, :dateformat]
262-
user_options = connection.user_options
263-
keys.each do |key|
264-
msg = "Expected key:#{key} in user_options:#{user_options.inspect}"
265-
assert user_options.key?(key), msg
266-
end
260+
it "run the database consistency checker useroptions command" do
261+
keys = [:textsize, :language, :isolation_level, :dateformat]
262+
user_options = connection.user_options
263+
keys.each do |key|
264+
msg = "Expected key:#{key} in user_options:#{user_options.inspect}"
265+
assert user_options.key?(key), msg
267266
end
267+
end
268268

269-
it "return a underscored key hash with indifferent access of the results" do
270-
user_options = connection.user_options
271-
assert_equal 'read committed', user_options['isolation_level']
272-
assert_equal 'read committed', user_options[:isolation_level]
273-
end
269+
it "return a underscored key hash with indifferent access of the results" do
270+
user_options = connection.user_options
271+
assert_equal 'read committed', user_options['isolation_level']
272+
assert_equal 'read committed', user_options[:isolation_level]
273+
end
274+
275+
describe '#run_with_isolation_level' do
274276

275-
end unless sqlserver_azure?
277+
let(:task1) { tasks(:first_task) }
278+
let(:task2) { tasks(:another_task) }
276279

277-
describe "altering isolation levels" do
280+
before do
281+
assert task1, 'Tasks :first_task should be in AR fixtures'
282+
assert task2, 'Tasks :another_task should be in AR fixtures'
283+
good_isolation_level = connection.user_options_isolation_level.blank? || connection.user_options_isolation_level =~ /read committed/i
284+
assert good_isolation_level, "User isolation level is not at a happy starting place: #{connection.user_options_isolation_level.inspect}"
285+
end
278286

279287
it "barf if the requested isolation level is not valid" do
280288
assert_raise(ArgumentError) do
281289
connection.run_with_isolation_level 'INVALID ISOLATION LEVEL' do; end
282290
end
283291
end
284292

285-
describe "with a valid isolation level" do
286-
287-
before do
288-
@t1 = tasks(:first_task)
289-
@t2 = tasks(:another_task)
290-
assert @t1, 'Tasks :first_task should be in AR fixtures'
291-
assert @t2, 'Tasks :another_task should be in AR fixtures'
292-
good_isolation_level = connection.user_options_isolation_level.blank? || connection.user_options_isolation_level =~ /read committed/i
293-
assert good_isolation_level, "User isolation level is not at a happy starting place: #{connection.user_options_isolation_level.inspect}"
294-
end
295-
296-
it 'allow #run_with_isolation_level to not take a block to set it' do
297-
begin
298-
connection.run_with_isolation_level 'READ UNCOMMITTED'
299-
assert_match %r|read uncommitted|i, connection.user_options_isolation_level
300-
ensure
301-
connection.run_with_isolation_level 'READ COMMITTED'
302-
end
293+
it 'allow #run_with_isolation_level to not take a block to set it' do
294+
begin
295+
connection.run_with_isolation_level 'READ UNCOMMITTED'
296+
assert_match %r|read uncommitted|i, connection.user_options_isolation_level
297+
ensure
298+
connection.run_with_isolation_level 'READ COMMITTED'
303299
end
300+
end
304301

305-
it 'return block value using #run_with_isolation_level' do
306-
assert_equal Task.all.sort, connection.run_with_isolation_level('READ UNCOMMITTED') { Task.all.sort }
307-
end
302+
it 'return block value using #run_with_isolation_level' do
303+
assert_equal Task.all.sort, connection.run_with_isolation_level('READ UNCOMMITTED') { Task.all.sort }
304+
end
308305

309-
it 'pass a read uncommitted isolation level test' do
310-
assert_nil @t2.starting, 'Fixture should have this empty.'
311-
begin
312-
Task.transaction do
313-
@t2.starting = Time.now
314-
@t2.save
315-
@dirty_t2 = connection.run_with_isolation_level('READ UNCOMMITTED') { Task.find(@t2.id) }
316-
raise ActiveRecord::ActiveRecordError
317-
end
318-
rescue
319-
'Do Nothing'
306+
it 'pass a read uncommitted isolation level test' do
307+
assert_nil task2.starting, 'Fixture should have this empty.'
308+
begin
309+
Task.transaction do
310+
task2.starting = Time.now
311+
task2.save
312+
@dirty_t2 = connection.run_with_isolation_level('READ UNCOMMITTED') { Task.find(task2.id) }
313+
raise ActiveRecord::ActiveRecordError
320314
end
321-
assert @dirty_t2, 'Should have a Task record from within block above.'
322-
assert @dirty_t2.starting, 'Should have a dirty date.'
323-
assert_nil Task.find(@t2.id).starting, 'Should be nil again from botched transaction above.'
315+
rescue
316+
'Do Nothing'
324317
end
325-
326-
end unless sqlserver_azure?
318+
assert @dirty_t2, 'Should have a Task record from within block above.'
319+
assert @dirty_t2.starting, 'Should have a dirty date.'
320+
assert_nil Task.find(task2.id).starting, 'Should be nil again from botched transaction above.'
321+
end
327322

328323
end
329324

test/schema/sqlserver_specific_schema.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,7 @@
2323

2424

2525

26-
create_table :float_data, force: true do |t|
27-
t.float :temperature
28-
t.float :temperature_8, limit: 8
29-
t.float :temperature_24, limit: 24
30-
t.float :temperature_32, limit: 32
31-
t.float :temperature_53, limit: 53
32-
end
26+
3327

3428
create_table :defaults, force: true do |t|
3529
t.column :positive_integer, :integer, default: 1

0 commit comments

Comments
 (0)