Sha256: 5c1ffb6e239d39c310725fd4250051f31f55528e1d1a46895207f24d5668d412

Contents?: true

Size: 1.04 KB

Versions: 7

Compression:

Stored size: 1.04 KB

Contents

require 'spec_helper'

describe ActiveRecord::Base do
  context ".slave_connection" do
    it "return Mysql2Adapter object" do
      expect(User.slave_connection).to be_a(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
    end
  end

  context ".slave_group" do
    class Tel2 < Slave2
      self.table_name = :tel
    end

    it "equal group_name of establish_fresh_connection" do
      expect(User.slave_group).to eq("slave1")
      expect(Tel.slave_group).to eq("slave2")
    end

    it "equal 'slave' when not specific group_name" do
      Tel2.establish_fresh_connection
      expect(Tel2.slave_group).to eq("slave")
    end
  end

  context ".master_db_only?" do
    class User2 < Parent
      self.table_name = :users
    end

    it "childrend of master_db_only class is master_db_only" do
      expect(User2.master_db_only?).to be_falsey
      Parent.master_db_only!
      expect(User2.master_db_only?).to be_truthy
    end

    it "not effect other class" do
      Parent.master_db_only!
      expect(Address.master_db_only?).to be_falsey
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fresh_connection-0.4.0 spec/unit/ar_base_spec.rb
fresh_connection-0.3.0 spec/unit/ar_base_spec.rb
fresh_connection-0.2.6 spec/unit/ar_base_spec.rb
fresh_connection-0.2.5 spec/unit/ar_base_spec.rb
fresh_connection-0.2.4 spec/unit/ar_base_spec.rb
fresh_connection-0.2.3 spec/unit/ar_base_spec.rb
fresh_connection-0.2.2 spec/unit/ar_base_spec.rb