Sha256: a1b9ffb5a13e9069069c97396211140c4337f5e196f027e76826d12f4c56df04

Contents?: true

Size: 1.44 KB

Versions: 25

Compression:

Stored size: 1.44 KB

Contents

require 'spec_helper'

describe MongoDoc::Contexts do

  class ContextTest
    include MongoDoc::Document

    embed_many :children
  end

  context ".context_for" do
    let(:criteria) { stub('criteria', :klass => klass) }

    context "when criteria is for a top-level MongoDoc::Document" do
      let(:klass) { ContextTest }

      it "creates a Mongo context" do
        MongoDoc::Contexts::Mongo.should_receive(:new).with(criteria)
        Mongoid::Contexts.context_for(criteria)
      end
    end

    context "when criteria is for an association" do
      let(:klass) { ContextTest.new.children }

      it "creates an Enumerable context" do
        Mongoid::Contexts::Enumerable.should_receive(:new).with(criteria)
        Mongoid::Contexts.context_for(criteria)
      end
    end

    context "when criteria is for a MongoDoc::Collection" do
      let(:klass) { MongoDoc::Collection.new('collection') }

      before do
        MongoDoc::Collection.stub(:mongo_collection).and_return(stub('collection'))
      end

      it "creates a Mongo context" do
        MongoDoc::Contexts::Mongo.should_receive(:new).with(criteria)
        Mongoid::Contexts.context_for(criteria)
      end
    end

    context "when criteria is not recognized" do
      let(:klass) { Object }

      it "raises an exception" do
        expect do
          Mongoid::Contexts.context_for(criteria)
        end.should raise_error(Mongoid::Contexts::UnknownContext)
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
mongo_doc-0.6.26 spec/contexts_spec.rb
mongo_doc-0.6.25 spec/contexts_spec.rb
mongo_doc-0.6.23 spec/contexts_spec.rb
mongo_doc-0.6.22 spec/contexts_spec.rb
mongo_doc-0.6.21 spec/contexts_spec.rb
mongo_doc-0.6.20 spec/contexts_spec.rb
mongo_doc-0.6.19 spec/contexts_spec.rb
mongo_doc-0.6.18 spec/contexts_spec.rb
mongo_doc-0.6.17 spec/contexts_spec.rb
mongo_doc-0.6.16 spec/contexts_spec.rb
mongo_doc-0.6.15 spec/contexts_spec.rb
mongo_doc-0.6.14 spec/contexts_spec.rb
mongo_doc-0.6.13 spec/contexts_spec.rb
mongo_doc-0.6.12 spec/contexts_spec.rb
mongo_doc-0.6.11 spec/contexts_spec.rb
mongo_doc-0.6.10 spec/contexts_spec.rb
mongo_doc-0.6.9 spec/contexts_spec.rb
mongo_doc-0.6.8 spec/contexts_spec.rb
mongo_doc-0.6.7 spec/contexts_spec.rb
mongo_doc-0.6.6 spec/contexts_spec.rb