Sha256: 61f47f99d9f8be3539820f792056bb289d1608ec6e6f0bb6fda7153a1fc2211f

Contents?: true

Size: 1.25 KB

Versions: 35

Compression:

Stored size: 1.25 KB

Contents

require "spec_helper"

describe Mongoid::Shardable do

  describe ".included" do

    let(:klass) do
      Class.new do
        include Mongoid::Shardable
      end
    end

    it "adds an shard_key_fields accessor" do
      expect(klass).to respond_to(:shard_key_fields)
    end

    it "defaults shard_key_fields to an empty array" do
      expect(klass.shard_key_fields).to be_empty
    end
  end

  describe ".shard_key" do

    let(:klass) do
      Band
    end

    before do
      Band.shard_key(:name)
    end

    it "specifies a shard key on the collection" do
      expect(klass.shard_key_fields).to eq([:name])
    end

    context 'when a relation is used as the shard key' do

      let(:klass) do
        Game
      end

      before do
        Game.shard_key(:person)
      end

      it "converts the shard key to the foreign key field" do
        expect(klass.shard_key_fields).to eq([:person_id])
      end
    end
  end

  describe "#shard_key_selector" do

    let(:klass) do
      Band
    end

    let(:object) do
      klass.new
    end

    before do
      klass.shard_key(:name)
      object.name = "Jo"
    end

    it "returns a hash of shard key names and values" do
      expect(object.shard_key_selector).to eq({ "name" => "Jo" })
    end
  end
end

Version data entries

35 entries across 33 versions & 3 rubygems

Version Path
mongoid-6.4.8 spec/mongoid/shardable_spec.rb
mongoid-6.4.7 spec/mongoid/shardable_spec.rb
mongoid-6.4.5 spec/mongoid/shardable_spec.rb
mongoid-5.4.1 spec/mongoid/shardable_spec.rb
mongoid-6.4.4 spec/mongoid/shardable_spec.rb
mongoid-6.4.2 spec/mongoid/shardable_spec.rb
mongoid-6.4.1 spec/mongoid/shardable_spec.rb
mongoid-5.4.0 spec/mongoid/shardable_spec.rb
tdiary-5.0.8 vendor/bundle/gems/mongoid-6.4.0/spec/mongoid/shardable_spec.rb
mongoid-6.4.0 spec/mongoid/shardable_spec.rb
mongoid-6.3.0 spec/mongoid/shardable_spec.rb
mongoid-6.2.1 spec/mongoid/shardable_spec.rb
mongoid-7.0.0.beta spec/mongoid/shardable_spec.rb
tdiary-5.0.5 vendor/bundle/gems/mongoid-6.2.0/spec/mongoid/shardable_spec.rb
tdiary-5.0.5 vendor/bundle/gems/mongoid-6.1.0/spec/mongoid/shardable_spec.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/mongoid-6.1.0/spec/mongoid/shardable_spec.rb
mongoid-6.2.0 spec/mongoid/shardable_spec.rb
mongoid-6.1.1 spec/mongoid/shardable_spec.rb
mongoid-5.2.1 spec/mongoid/shardable_spec.rb
tdiary-5.0.4 vendor/bundle/gems/mongoid-6.1.0/spec/mongoid/shardable_spec.rb