Sha256: c67fbd7160de09510cb0b46055092af301fe8d1a4d871f11bde1b5675c98ce63

Contents?: true

Size: 1.23 KB

Versions: 23

Compression:

Stored size: 1.23 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(10000000) }.to raise_error(ActiveRecord::Turntable::CannotSpecifyShardError)
      end
    end
  end

end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
activerecord-turntable-2.5.0 spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb
activerecord-turntable-2.4.0 spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb
activerecord-turntable-2.3.3 spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb
activerecord-turntable-2.3.2 spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb
activerecord-turntable-2.3.1 spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb
activerecord-turntable-2.3.0 spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb
activerecord-turntable-2.2.2 spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb
activerecord-turntable-2.2.1 spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb
activerecord-turntable-2.2.0 spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb
activerecord-turntable-2.1.1 spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb
activerecord-turntable-2.1.0 spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb
activerecord-turntable-2.1.0.rc2 spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb
activerecord-turntable-2.1.0.rc1 spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb
activerecord-turntable-2.1.0.beta2 spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb
activerecord-turntable-2.1.0.beta1 spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb
activerecord-turntable-2.0.6 spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb
activerecord-turntable-2.0.5 spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb
activerecord-turntable-2.0.4 spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb
activerecord-turntable-2.0.3 spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb
activerecord-turntable-2.0.2 spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb