Sha256: 88b0e680168aba81e960406e41e25696e643bb95f8121530db8c5efa014ea418

Contents?: true

Size: 1.47 KB

Versions: 2

Compression:

Stored size: 1.47 KB

Contents

require 'test_helper'

class ForcedTest < ThirdBase::TestCase

  setup do
    run_db :create
    run_db :migrate
    establish_connection
  end

  def test_shared_pool
    assert_equal ThirdBase::Base.connection_pool.object_id,
                 CommentForced.connection_pool.object_id
  end

  def test_shared_connection
    assert_equal ThirdBase::Base.connection.raw_connection.object_id,
                 CommentForced.connection.raw_connection.object_id
  end

  def test_shared_new_connection_in_a_different_thread
    current_base_connection_id = ThirdBase::Base.connection.raw_connection.object_id
    new_base_connection_id, new_forced_connection_id = Thread.new {
      [ ThirdBase::Base.connection.raw_connection.object_id,
        CommentForced.connection.raw_connection.object_id ]
    }.value
    refute_equal new_base_connection_id, current_base_connection_id
    assert_equal new_base_connection_id, new_forced_connection_id
  end

  def test_shared_connected_query
    assert ThirdBase::Base.connected?
    assert CommentForced.connected?
    CommentForced.clear_all_connections!
    refute ThirdBase::Base.connected?
    refute CommentForced.connected?
  end

  def test_can_remove_connection_properly
    base_connection = ThirdBase::Base.connection
    forced_connection = CommentForced.connection
    assert base_connection.active?
    assert forced_connection.active?
    CommentForced.remove_connection
    refute base_connection.active?
    refute forced_connection.active?
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
thirdbase-2.1.2 test/cases/forced_test.rb
thirdbase-2.1.1 test/cases/forced_test.rb