|
18 | 18 |
|
19 | 19 | class AdapterTestSQLServer < ActiveRecord::TestCase |
20 | 20 |
|
| 21 | + fixtures :tasks |
| 22 | + |
21 | 23 | let(:connection) { ActiveRecord::Base.connection } |
22 | 24 |
|
23 | 25 | let(:basic_insert_sql) { "INSERT INTO [funny_jokes] ([name]) VALUES('Knock knock')" } |
@@ -253,77 +255,70 @@ class AdapterTestSQLServer < ActiveRecord::TestCase |
253 | 255 |
|
254 | 256 | end |
255 | 257 |
|
256 | | - describe 'For DatabaseStatements' do |
257 | | - |
258 | | - describe "finding out what user_options are available" do |
| 258 | + describe 'database statements' do |
259 | 259 |
|
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 |
267 | 266 | end |
| 267 | + end |
268 | 268 |
|
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 |
274 | 276 |
|
275 | | - end unless sqlserver_azure? |
| 277 | + let(:task1) { tasks(:first_task) } |
| 278 | + let(:task2) { tasks(:another_task) } |
276 | 279 |
|
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 |
278 | 286 |
|
279 | 287 | it "barf if the requested isolation level is not valid" do |
280 | 288 | assert_raise(ArgumentError) do |
281 | 289 | connection.run_with_isolation_level 'INVALID ISOLATION LEVEL' do; end |
282 | 290 | end |
283 | 291 | end |
284 | 292 |
|
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' |
303 | 299 | end |
| 300 | + end |
304 | 301 |
|
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 |
308 | 305 |
|
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 |
320 | 314 | 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' |
324 | 317 | 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 |
327 | 322 |
|
328 | 323 | end |
329 | 324 |
|
|
0 commit comments