Sha256: fab5043f9a1037f3a2d5c9c65e50109548f5af04408e41bef0c56c97cce4e401

Contents?: true

Size: 1.49 KB

Versions: 19

Compression:

Stored size: 1.49 KB

Contents

require "spec_helper"

describe Mongoid::Collections::Master do

  let(:collection) do
    stub.quacks_like(Mongo::Collection.allocate)
  end

  let(:db) do
    stub.quacks_like(Mongo::DB.allocate)
  end

  describe "#empty?" do

    context "when the slaves exist" do

      let(:slave) do
        Mongoid::Collections::Slaves.new([ db ], "people")
      end

      before do
        db.expects(:collection).with("people").returns(collection)
      end

      it "returns false" do
        slave.should_not be_empty
      end
    end

    context "when the slaves do not exist" do

      let(:slave) do
        Mongoid::Collections::Slaves.new([], "people")
      end

      it "returns true" do
        slave.should be_empty
      end
    end

    context "when the slaves are nil" do

      let(:slave) do
        Mongoid::Collections::Slaves.new(nil, "people")
      end

      it "returns true" do
        slave.should be_empty
      end
    end
  end

  context "Mongo::Collection operations" do

    let(:slave) do
      Mongoid::Collections::Slaves.new([ db ], "people")
    end

    before do
      db.expects(:collection).with("people").returns(collection)
    end

    Mongoid::Collections::Operations::READ.each do |name|

      it "defines #{name}" do
        slave.should respond_to(name)
      end

      describe "##{name}" do

        before do
          collection.expects(name)
        end

        it "delegates to the collection" do
          slave.send(name)
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 3 rubygems

Version Path
mongoid-locomotive-2.0.0.beta9 spec/unit/mongoid/collections/slaves_spec.rb
mongoid-pre-2.0.0.beta1 spec/unit/mongoid/collections/slaves_spec.rb
mongoid-2.0.0.alpha spec/unit/mongoid/collections/slaves_spec.rb
mongoid-1.2.14 spec/unit/mongoid/collections/slaves_spec.rb
mongoid-1.2.13 spec/unit/mongoid/collections/slaves_spec.rb
mongoid-1.2.12 spec/unit/mongoid/collections/slaves_spec.rb
mongoid-1.2.11 spec/unit/mongoid/collections/slaves_spec.rb
mongoid-1.2.10 spec/unit/mongoid/collections/slaves_spec.rb
mongoid-1.2.9 spec/unit/mongoid/collections/slaves_spec.rb
mongoid-1.2.8 spec/unit/mongoid/collections/slaves_spec.rb
mongoid-1.2.7 spec/unit/mongoid/collections/slaves_spec.rb
mongoid-pre-2.0.0.pre spec/unit/mongoid/collections/slaves_spec.rb
mongoid-1.2.6 spec/unit/mongoid/collections/slaves_spec.rb
mongoid-1.2.5 spec/unit/mongoid/collections/slaves_spec.rb
mongoid-1.2.4 spec/unit/mongoid/collections/slaves_spec.rb
mongoid-1.2.3 spec/unit/mongoid/collections/slaves_spec.rb
mongoid-1.2.2 spec/unit/mongoid/collections/slaves_spec.rb
mongoid-1.2.1 spec/unit/mongoid/collections/slaves_spec.rb
mongoid-1.2.0 spec/unit/mongoid/collections/slaves_spec.rb