Sha256: de5ef9300c7893353fd8ed9a3b53b852178e038d6debb5cc560d735b6a83f266

Contents?: true

Size: 1.51 KB

Versions: 7

Compression:

Stored size: 1.51 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper.rb"))

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

7 entries across 7 versions & 2 rubygems

Version Path
mongo_doc-0.6.1 spec/finders_spec.rb
mongo_doc-0.6.0 spec/finders_spec.rb
mongo_doc_rails2-0.6.1 spec/finders_spec.rb
mongo_doc-0.5.5 spec/finders_spec.rb
mongo_doc-0.4.2 spec/finders_spec.rb
mongo_doc-0.4.1 spec/finders_spec.rb
mongo_doc-0.4.0 spec/finders_spec.rb