Sha256: dfa2a02e579425f0e8e9a6a75954a772064e8486e3c9e1114996a88c6d9149c5

Contents?: true

Size: 1.37 KB

Versions: 5

Compression:

Stored size: 1.37 KB

Contents

RSpec.describe Gorynich::Switcher do
  let(:config) do
    {
      'test' => {
        'default' => {
          'db_config' => {},
          'secrets'   =>   {}
        }
      }
    }
  end
  let(:fetcher) { HashFetcher.new(**config) }
  let(:gorynich_config) { Gorynich::Config.new(fetcher: fetcher) }

  subject { described_class.new(config: gorynich_config) }

  describe '#with_database' do
    context 'when tenant not found' do
      it do
        expect(::ActiveRecord::Base).to receive(:connected_to).with(role: :test).and_raise(
          ::ActiveRecord::ConnectionNotEstablished
        )
        expect { subject.with_database('test') }.to raise_error(Gorynich::TenantNotFound)
      end
    end

    context 'when have tenant but ConnectionNotEstablished' do
      before(:each) do
        allow(::Gorynich).to receive(:instance).and_return(gorynich_config)
      end

      it do
        expect(::ActiveRecord::Base).to receive(:connected_to).with(role: :default).and_raise(
          ::ActiveRecord::ConnectionNotEstablished
        )
        expect_any_instance_of(
          ::ActiveRecord::ConnectionAdapters::ConnectionHandler
        ).to receive(:establish_connection).with(
          gorynich_config.database('default'), role: :default
        )
        expect(::ActiveRecord::Base).to receive(:connected_to)
        subject.with_database('default')
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gorynich-1.3.4.273062 spec/lib/gorynich/switcher_spec.rb
gorynich-1.3.3.231946 spec/lib/gorynich/switcher_spec.rb
gorynich-1.3.2.231715 spec/lib/gorynich/switcher_spec.rb
gorynich-1.3.1.213701 spec/lib/gorynich/switcher_spec.rb
gorynich-1.3.0.213297 spec/lib/gorynich/switcher_spec.rb