Sha256: 87c378113edff30ce91a622c69f1871028615fee6e8560b2d244d4800fe55661

Contents?: true

Size: 1.46 KB

Versions: 25

Compression:

Stored size: 1.46 KB

Contents

require 'spec_helper'

describe MongoDoc::Finders do
  class FindersTest
    include MongoDoc::Document

    attr_accessor :data
  end

  let(:criteria) { stub('criteria').as_null_object }

  context ".find" do
    before do
      FindersTest.stub(:criteria).and_return(criteria)
    end

    it "delegates to id for the criteria" do
      args = [1, 2, 3]
      criteria.should_receive(:id).with(*args)
      FindersTest.find(*args)
    end
  end

  context ".find_all" do
    it "delegates to an empty criteria" do
      FindersTest.should_receive(:criteria)
      FindersTest.find_all
    end

    it "returns the empty criteria" do
      FindersTest.stub(:criteria).and_return(criteria)
      FindersTest.find_all.should == criteria
    end
  end

  context ".find_one" do
    context "with an id" do
      it "delegates to translate" do
        id = 'an id'
        Mongoid::Criteria.should_receive(:translate).with(FindersTest, id)
        FindersTest.find_one(id)
      end
    end

    context "with conditions" do
      let(:conditions) { {:where => 'this.a > 3'} }

      it "calls translate with the conditions" do
        Mongoid::Criteria.should_receive(:translate).with(FindersTest, conditions).and_return(criteria)
        FindersTest.find_one(conditions)
      end

      it "call one on the result" do
        Mongoid::Criteria.stub(:translate).and_return(criteria)
        criteria.should_receive(:one)
        FindersTest.find_one(conditions)
      end
    end
  end

end

Version data entries

25 entries across 25 versions & 2 rubygems

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