Sha256: 36a46af7583ea1606c3c4189bde053f34686d451d03521935861df8a79e512de

Contents?: true

Size: 813 Bytes

Versions: 2

Compression:

Stored size: 813 Bytes

Contents

require File.dirname(__FILE__) + '/test_helper.rb'

class TestController < ActionController::Base
  
  def current_user
    @current_user ||= ActiveSupport::SecureRandom.hex(32)
  end

end

class ThreadSafeTest < Test::Unit::TestCase
  
  should "is thread safe when dealing with audit logging" do
    blocked = true
    
    blocked_thread = Thread.new do 
      controller = TestController.new
      controller.send(:set_whodunnit)
      begin
        puts "sleep for .001 sec"
        sleep(0.001)
      end while blocked
      PaperTrail.whodunnit
    end

    fast_running_thread = Thread.new do 
      controller = TestController.new
      controller.send(:set_whodunnit)
      blocked = false
      PaperTrail.whodunnit
    end
    assert_not_equal blocked_thread.value, fast_running_thread.value
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
revo-paper_trail-1.4.3 test/thread_safe_test.rb
revo-paper_trail-1.4.2 test/thread_safe_test.rb