Sha256: 2035d4e253ecc982232b036e95a828c492c2702ff5c8c46228a52d4eb67618d3

Contents?: true

Size: 1.5 KB

Versions: 14

Compression:

Stored size: 1.5 KB

Contents

require "spec_helper"

describe Mongoid::Cursor do

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

  let(:proxy) do
    stub.quacks_like(Mongo::Cursor.allocate)
  end

  let(:cursor) do
    Mongoid::Cursor.new(Person, collection, proxy)
  end

  (Mongoid::Cursor::OPERATIONS - [ :timeout ]).each do |name|

    describe "##{name}" do

      before do
        proxy.expects(name)
      end

      it "delegates to the proxy" do
        cursor.send(name)
      end
    end
  end

  describe "#collection" do

    it "returns the mongoid collection" do
      cursor.collection.should == collection
    end
  end

  describe "#each" do

    before do
      proxy.expects(:each).yields({ "_type" => "Person" })
    end

    it "yields to the next document" do
      cursor.each do |doc|
        doc.attributes.except(:_id).should == Person.new.attributes.except(:_id)
      end
    end
  end

  describe "#next_document" do

    before do
      proxy.expects(:next_document).returns({ "_type" => "Person" })
    end

    it "returns the next document from the proxied cursor" do
      doc = cursor.next_document
      doc.attributes.except(:_id).should == Person.new.attributes.except(:_id)
    end
  end

  describe "#to_a" do

    before do
      proxy.expects(:to_a).returns([{ "_type" => "Person" }])
    end

    it "converts the proxy cursor to an array of documents" do
      docs = cursor.to_a
      docs[0].attributes.except(:_id).should == Person.new.attributes.except(:_id)
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
mongoid-pre-2.0.0.beta1 spec/unit/mongoid/cursor_spec.rb
mongoid-2.0.0.alpha spec/unit/mongoid/cursor_spec.rb
mongoid-1.2.14 spec/unit/mongoid/cursor_spec.rb
mongoid-1.2.13 spec/unit/mongoid/cursor_spec.rb
mongoid-1.2.12 spec/unit/mongoid/cursor_spec.rb
mongoid-1.2.11 spec/unit/mongoid/cursor_spec.rb
mongoid-1.2.10 spec/unit/mongoid/cursor_spec.rb
mongoid-1.2.9 spec/unit/mongoid/cursor_spec.rb
mongoid-1.2.8 spec/unit/mongoid/cursor_spec.rb
mongoid-1.2.7 spec/unit/mongoid/cursor_spec.rb
mongoid-pre-2.0.0.pre spec/unit/mongoid/cursor_spec.rb
mongoid-1.2.6 spec/unit/mongoid/cursor_spec.rb
mongoid-1.2.5 spec/unit/mongoid/cursor_spec.rb
mongoid-1.2.4 spec/unit/mongoid/cursor_spec.rb