Sha256: 04ab51a13359036f827fa837b09d6cf64bfe5ccf766afeba3093dcdc6ab68870

Contents?: true

Size: 1.87 KB

Versions: 18

Compression:

Stored size: 1.87 KB

Contents

require 'spec_helper'

describe MongoDoc::Criteria do

  class CriteriaTest
    extend MongoDoc::Criteria

    def self.collection; end
  end

  context ".criteria" do
    it "creates a new CriteriaWrapper for the document" do
      CriteriaTest.criteria.should be_a_kind_of(MongoDoc::Criteria::CriteriaWrapper)
    end
  end

  context "CriteriaWrapper" do
    let(:wrapper) { MongoDoc::Criteria::CriteriaWrapper.new(CriteriaTest) }

    it "is a Criteria" do
      Mongoid::Criteria.should === wrapper
    end

    it "sets the criteria klass" do
      wrapper.klass.should == CriteriaTest
    end

    %w(all and any_in cache enslave excludes fuse in limit offset only order_by skip where).each do |wrapping_method|
      it "#{wrapping_method} returns a new CriteriaWrapper" do
        wrapper.send(wrapping_method).object_id.should_not == wrapper.object_id
      end
    end

    it "extras returns a new CriteriaWrapper" do
      wrapper.extras({}).object_id.should_not == wrapper.object_id
    end

    it "not_in returns a new CriteriaWrapper" do
      wrapper.not_in({}).object_id.should_not == wrapper.object_id
    end

  end

  context "criteria delegates" do
    let(:criteria) { stub('criteria').as_null_object }

    before do
      CriteriaTest.stub(:criteria).and_return(criteria)
    end

    %w(aggregate all and any_in blank? count empty? excludes extras first group id in last limit max min not_in offset one only order_by page paginate per_page skip sum where).each do |criteria_op|
      it "#{criteria_op} delegates to the criteria" do
        criteria.should_receive(criteria_op)
        CriteriaTest.send(criteria_op)
      end
    end
  end

  context "criteria are reusable" do
    it "creates a new instance on each invocation" do
      original = CriteriaTest.any_in(:name => 'Les Hill')
      chained = original.only(:name)
      original.should_not == chained
    end
  end



end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
mongo_doc-0.6.10 spec/criteria_spec.rb
mongo_doc-0.6.9 spec/criteria_spec.rb
mongo_doc-0.6.8 spec/criteria_spec.rb
mongo_doc-0.6.7 spec/criteria_spec.rb
mongo_doc-0.6.6 spec/criteria_spec.rb
mongo_doc-0.6.5 spec/criteria_spec.rb
mongo_doc-0.6.4 spec/criteria_spec.rb
mongo_doc_rails2-0.6.2 spec/criteria_spec.rb
mongo_doc-0.6.3 spec/criteria_spec.rb
mongo_doc-0.6.2 spec/criteria_spec.rb
mongo_doc-0.6.1 spec/criteria_spec.rb
mongo_doc-0.6.0 spec/criteria_spec.rb
mongo_doc_rails2-0.6.1 spec/criteria_spec.rb
mongo_doc-0.5.5 spec/criteria_spec.rb
mongo_doc-0.4.2 spec/criteria_spec.rb
mongo_doc-0.4.1 spec/criteria_spec.rb
mongo_doc-0.4.0 spec/criteria_spec.rb
mongo_doc-0.3.2 spec/criteria_spec.rb