Sha256: 1a52cba0473cf319a5a8eb98aa11f57eef53b3419728150b77ea370546ad512c

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

require "spec_helper"

describe ActiveRecord::Turntable::Algorithm::RangeBsearchAlgorithm do
  before(:all) do
    reload_turntable!(File.join(File.dirname(__FILE__), "../../../config/turntable.yml"))
  end

  context "When initialized" do
    before do
      @alg = ActiveRecord::Turntable::Algorithm::RangeBsearchAlgorithm.new(ActiveRecord::Base.turntable_config[:clusters][:user_cluster])
    end

    context "#calculate with 1" do
      subject { @alg.calculate(1) }
      it { is_expected.to eq(ActiveRecord::Base.turntable_config[:clusters][:user_cluster][:shards][0][:connection]) }
    end

    context "#calculate with 19999" do
      subject { @alg.calculate(19999) }
      it { is_expected.to eq(ActiveRecord::Base.turntable_config[:clusters][:user_cluster][:shards][0][:connection]) }
    end

    context "#calculate with 20000" do
      subject { @alg.calculate(20000) }
      it { is_expected.to eq(ActiveRecord::Base.turntable_config[:clusters][:user_cluster][:shards][1][:connection]) }
    end

    context "#calculate with 10000000" do
      it "raises ActiveRecord::Turntable::CannotSpecifyShardError" do
        expect { @alg.calculate(10_000_000) }.to raise_error(ActiveRecord::Turntable::CannotSpecifyShardError)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
activerecord-turntable-3.0.0.alpha3 spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb
activerecord-turntable-3.0.0.alpha2 spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb
activerecord-turntable-3.0.0.alpha1 spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb