Sha256: a347912956755623fe16f79ccdf6594c7fe9e2188d27ee437c19052e3b173993

Contents?: true

Size: 1.36 KB

Versions: 6

Compression:

Stored size: 1.36 KB

Contents

$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
require 'test/unit'
require 'active_record'
require 'rack/connection_release'

class ConnectionReleaseTest < Test::Unit::TestCase
  def setup
    ActiveRecord::Base.establish_connection(
        :adapter => "mysql",
        :host => "localhost",
        :username => "root",
        :password => "",
        :database => "mysql"
    )
  end

  def test_should_release_active_connections_after_app_call_is_done
    app = lambda { |env|
      assert ! ActiveRecord::Base.connection_handler.active_connections?
      ActiveRecord::Base.connection
      assert ActiveRecord::Base.connection_handler.active_connections?
      [200, {}, ["I've checked-out a connection."]]
    }

    Rack::ConnectionRelease.new(app).call({})

    assert !ActiveRecord::Base.connection_handler.active_connections?, "connection wasn't released"
  end

  def test_should_release_active_connections_even_if_the_app_raises_an_exception
    app = lambda { |env|
      assert ! ActiveRecord::Base.connection_handler.active_connections?
      ActiveRecord::Base.connection
      assert ActiveRecord::Base.connection_handler.active_connections?
      raise "crashing!"
    }

    assert_raise(RuntimeError) { Rack::ConnectionRelease.new(app).call({}) }

    assert !ActiveRecord::Base.connection_handler.active_connections?, "connection wasn't released"
  end
end

Version data entries

6 entries across 1 versions & 1 rubygems

Version Path
apl-library-0.0.90 vendor/bundle/ruby/1.8/gems/sc-core-0.0.210/test/connection_release_test.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/sc-core-0.0.210/test/connection_release_test.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.8/gems/sc-core-0.0.210/test/connection_release_test.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/sc-core-0.0.210/test/connection_release_test.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/sc-core-0.0.210/test/connection_release_test.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/sc-core-0.0.210/test/connection_release_test.rb