Sha256: 986c7c9906ead0cf5f9a45627254216b666de5c53ae0b667740fe55328a422cf

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

require 'spec_helper'

describe Octoshark::ConnectionManager do
  describe "#with_connection", mysql2: true do
    it "creates temporary connection to database server" do
      manager = Octoshark::ConnectionManager.new
      connection_reference = nil

      config = mysql2_configs[:db1]

      manager.with_connection(config.except(:database)) do |connection|
        connection_reference = connection

        connection.execute("SELECT 1")
        expect(connection.database_name).to be_nil
      end

      expect(connection_reference.active?).to eq(false)
    end

    it "creates temporary connection to specific database", mysql2: true do
      manager = Octoshark::ConnectionManager.new
      connection_reference = nil

      config = mysql2_configs[:db1]
      database_name = config.fetch('database')

      manager.with_connection(config) do |connection|
        connection_reference = connection

        connection.execute("SELECT 1")
        expect(connection.database_name).to eq(database_name)
      end

      expect(connection_reference.active?).to eq(false)
    end

    it "returns query results with temporary connection" do
      manager = Octoshark::ConnectionManager.new
      config = configs[:db1]
      result = manager.with_connection(config) do |connection|
        connection.execute("SELECT 1")
      end

      expect(result).to eq([{"1"=>1, 0=>1}])
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
octoshark-0.2.2 spec/octoshark/connection_manager_spec.rb
octoshark-0.2.1 spec/octoshark/connection_manager_spec.rb
octoshark-0.2.0 spec/octoshark/connection_manager_spec.rb