Sha256: f35b71707e7d18da0fe8acf3533f5ca16df068f845557cf2a432603ba82d6645

Contents?: true

Size: 1.91 KB

Versions: 60

Compression:

Stored size: 1.91 KB

Contents

require "spec_helper"

module Switchman
  module ActiveRecord
    describe ConnectionHandler do
      include RSpecHelper

      it "should use different proxies for different categories" do
        expect(Shard.connection_pool).not_to eq User.connection_pool
      end

      it "should share underlying pools for different categories on the same shard" do
        expect(Shard.connection_pool.current_pool).to eq User.connection_pool.current_pool
      end

      it "should insert sharding for connections established after initialization" do
        expect(User.connection_pool).to eq ::ActiveRecord::Base.connection_pool
        begin
          config = { :adapter => 'sqlite3', :database => ':memory:', :something_unique_in_the_spec => true }
          User.establish_connection(config)
          expect(User.connection_pool).not_to eq ::ActiveRecord::Base.connection_pool
          expect(User.connection_pool.spec.config).to eq config
          expect(User.connection_pool).to be_is_a(ConnectionPoolProxy)
          @shard2.activate do
            expect(User.connection_pool.spec.config).to eq ::ActiveRecord::Base.connection_pool.spec.config
            expect(User.connection_pool.spec.config).not_to eq config
          end
        ensure
          User.remove_connection
          expect(User.connection_pool).to eq ::ActiveRecord::Base.connection_pool
          expect(User.connection_pool).to be_is_a(ConnectionPoolProxy)
        end
      end

      it "should set up separate pools for different categories" do
        expect(User.connection_pool).not_to eq MirrorUser.connection_pool
        mu = MirrorUser.create!
        expect(MirrorUser.find(mu.local_id)).to eq mu
        # didn't activate the :mirror_universe category
        @shard1.activate { expect(MirrorUser.find(mu.local_id)).to eq mu }
        @shard1.activate(:mirror_universe) { expect(MirrorUser.where(id: mu.local_id).first).to eq nil }
      end
    end
  end
end

Version data entries

60 entries across 60 versions & 1 rubygems

Version Path
switchman-1.5.2 spec/lib/active_record/connection_handler_spec.rb
switchman-1.5.1 spec/lib/active_record/connection_handler_spec.rb
switchman-1.5.0 spec/lib/active_record/connection_handler_spec.rb
switchman-1.4.4 spec/lib/active_record/connection_handler_spec.rb
switchman-1.4.3 spec/lib/active_record/connection_handler_spec.rb
switchman-1.4.2 spec/lib/active_record/connection_handler_spec.rb
switchman-1.4.1 spec/lib/active_record/connection_handler_spec.rb
switchman-1.4.0 spec/lib/active_record/connection_handler_spec.rb
switchman-1.3.18 spec/lib/active_record/connection_handler_spec.rb
switchman-1.3.17 spec/lib/active_record/connection_handler_spec.rb
switchman-1.3.14.pre.1 spec/lib/active_record/connection_handler_spec.rb
switchman-1.3.13.pre.1 spec/lib/active_record/connection_handler_spec.rb
switchman-1.3.16 spec/lib/active_record/connection_handler_spec.rb
switchman-1.3.15 spec/lib/active_record/connection_handler_spec.rb
switchman-1.3.14 spec/lib/active_record/connection_handler_spec.rb
switchman-1.3.13 spec/lib/active_record/connection_handler_spec.rb
switchman-1.3.12 spec/lib/active_record/connection_handler_spec.rb
switchman-1.3.11 spec/lib/active_record/connection_handler_spec.rb
switchman-1.3.10 spec/lib/active_record/connection_handler_spec.rb
switchman-1.3.9 spec/lib/active_record/connection_handler_spec.rb