Sha256: adbedd47d95019a797316f9eabeffcdf14687ae6fad8194c20df6ce0272bab39

Contents?: true

Size: 1.24 KB

Versions: 16

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

require "cases/helper_sqlserver"

class TestDisconnectedAdapter < ActiveRecord::TestCase
  self.use_transactional_tests = false

  def setup
    @connection = ActiveRecord::Base.connection
  end

  teardown do
    return if in_memory_db?
    db_config = ActiveRecord::Base.connection_db_config
    ActiveRecord::Base.establish_connection(db_config)
  end

  test "can't execute procedures while disconnected" do
    @connection.execute_procedure :sp_tables, "sst_datatypes"
    @connection.disconnect!
    assert_raises(ActiveRecord::ConnectionNotEstablished, 'SQL Server client is not connected') do
      @connection.execute_procedure :sp_tables, "sst_datatypes"
    end
  end

  test "can't execute query while disconnected" do
    sql = "SELECT count(*) from products WHERE id IN(@0, @1)"
    binds = [
      ActiveRecord::Relation::QueryAttribute.new("id", 2, ActiveRecord::Type::BigInteger.new),
      ActiveRecord::Relation::QueryAttribute.new("id", 2, ActiveRecord::Type::BigInteger.new)
    ]

    @connection.exec_query sql, "TEST", binds
    @connection.disconnect!
    assert_raises(ActiveRecord::ConnectionNotEstablished, 'SQL Server client is not connected') do
      @connection.exec_query sql, "TEST", binds
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
activerecord-sqlserver-adapter-7.0.7 test/cases/disconnected_test_sqlserver.rb
activerecord-sqlserver-adapter-7.0.6 test/cases/disconnected_test_sqlserver.rb
activerecord-sqlserver-adapter-7.0.5.1 test/cases/disconnected_test_sqlserver.rb
activerecord-sqlserver-adapter-7.0.5.0 test/cases/disconnected_test_sqlserver.rb
activerecord-sqlserver-adapter-7.0.4.0 test/cases/disconnected_test_sqlserver.rb
activerecord-sqlserver-adapter-7.0.3.0 test/cases/disconnected_test_sqlserver.rb
activerecord-sqlserver-adapter-7.0.2.0 test/cases/disconnected_test_sqlserver.rb
activerecord-sqlserver-adapter-6.1.3.0 test/cases/disconnected_test_sqlserver.rb
activerecord-sqlserver-adapter-7.0.1.0 test/cases/disconnected_test_sqlserver.rb
activerecord-sqlserver-adapter-7.0.0.0 test/cases/disconnected_test_sqlserver.rb
activerecord-sqlserver-adapter-7.0.0.0.rc1 test/cases/disconnected_test_sqlserver.rb
activerecord-sqlserver-adapter-6.1.2.1 test/cases/disconnected_test_sqlserver.rb
activerecord-sqlserver-adapter-6.1.2.0 test/cases/disconnected_test_sqlserver.rb
activerecord-sqlserver-adapter-6.1.1.0 test/cases/disconnected_test_sqlserver.rb
activerecord-sqlserver-adapter-6.1.0.0 test/cases/disconnected_test_sqlserver.rb
activerecord-sqlserver-adapter-6.1.0.0.rc1 test/cases/disconnected_test_sqlserver.rb