Sha256: 50cb9b127a73d2d2126243d93b5585e861944d90011bcb8e7bd192004e6f57e2

Contents?: true

Size: 1.2 KB

Versions: 5

Compression:

Stored size: 1.2 KB

Contents

require 'spec_helper'

describe ActiveRecord::Turntable::Algorithm::RangeAlgorithm 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::RangeAlgorithm.new(ActiveRecord::Base.turntable_config[:clusters][:user_cluster])
    end

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

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

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

    context "#calculate with 10000000" do
      it "raises ActiveRecord::Turntable::CannotSpecifyShardError" do
        lambda { @alg.calculate(10000000) }.should raise_error(ActiveRecord::Turntable::CannotSpecifyShardError)
      end
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activerecord-turntable-1.1.2 spec/active_record/turntable/algorithm/range_algorithm_spec.rb
activerecord-turntable-1.1.1 spec/active_record/turntable/algorithm/range_algorithm_spec.rb
activerecord-turntable-1.1.0 spec/active_record/turntable/algorithm/range_algorithm_spec.rb
activerecord-turntable-1.0.1 spec/active_record/turntable/algorithm/range_algorithm_spec.rb
activerecord-turntable-1.0.0 spec/active_record/turntable/algorithm/range_algorithm_spec.rb