Sha256: 42c3ffab06d91619a2df640c3e62d54e7b01662a4ebb9874f7e3dcb4030f46af

Contents?: true

Size: 1.83 KB

Versions: 7

Compression:

Stored size: 1.83 KB

Contents

require 'spec_helper'
require 'apartment/adapters/mysql2_adapter'

describe Apartment::Adapters::Mysql2Adapter, database: :mysql do
  unless defined?(JRUBY_VERSION)

    subject(:adapter){ Apartment::Tenant.mysql2_adapter config }

    def tenant_names
      ActiveRecord::Base.connection.execute("SELECT schema_name FROM information_schema.schemata").collect { |row| row[0] }
    end

    let(:default_tenant) { subject.switch { ActiveRecord::Base.connection.current_database } }

    context "using - the equivalent of - schemas" do
      before { Apartment.use_schemas = true }

      it_should_behave_like "a generic apartment adapter"

      describe "#default_tenant" do
        it "is set to the original db from config" do
          expect(subject.default_tenant).to eq(config[:database])
        end
      end

      describe "#init" do
        include Apartment::Spec::AdapterRequirements

        before do
          Apartment.configure do |config|
            config.excluded_models = ["Company"]
          end
        end

        after do
          # Apartment::Tenant.init creates per model connection.
          # Remove the connection after testing not to unintentionally keep the connection across tests.
          Apartment.excluded_models.each do |excluded_model|
            excluded_model.constantize.remove_connection
          end
        end

        it "should process model exclusions" do
          Apartment::Tenant.init

          expect(Company.table_name).to eq("#{default_tenant}.companies")
        end
      end
    end

    context "using connections" do
      before { Apartment.use_schemas = false }

      it_should_behave_like "a generic apartment adapter"
      it_should_behave_like "a generic apartment adapter able to handle custom configuration"
      it_should_behave_like "a connection based apartment adapter"
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
ros-apartment-2.3.0 spec/adapters/mysql2_adapter_spec.rb
ros-apartment-2.3.0.alpha2 spec/adapters/mysql2_adapter_spec.rb
ros-apartment-2.3.0.alpha1 spec/adapters/mysql2_adapter_spec.rb
apartment-2.2.1 spec/adapters/mysql2_adapter_spec.rb
apartment-2.2.0 spec/adapters/mysql2_adapter_spec.rb
apartment-2.1.0 spec/adapters/mysql2_adapter_spec.rb
apartment-2.0.0 spec/adapters/mysql2_adapter_spec.rb