Sha256: a880a41e3f1bded7d26f849e0a89b9ec2af164e16020bc1c5feb75ae7c159b74

Contents?: true

Size: 1.66 KB

Versions: 4

Compression:

Stored size: 1.66 KB

Contents

require 'spec/mocks'

module DocumentFinderStubs
  include Spec::Mocks::ExampleMethods
  
  def stub_find(result)
    find_result = mock('find result', :to_a => result.map { |doc| doc.to_mongo }, :count => result.size).as_null_object
    collection.stub!(:find).and_return(find_result)
  end
  
  def should_find(expected={}, result=[])
    selector, options = MongoModel::MongoOptions.new(self, expected).to_a
    find_result = mock('find result', :to_a => result.map { |doc| doc.to_mongo }).as_null_object
    collection.should_receive(:find).once.with(selector, options).and_return(find_result)
    yield if block_given?
  end

  def should_not_find
    collection.should_not_receive(:find)
    yield if block_given?
  end

  def should_count(expected={}, result=[])
    selector, options = MongoModel::MongoOptions.new(self, expected).to_a
    find_result = mock('find result', :count => result).as_null_object
    collection.should_receive(:find).once.with(selector, options).and_return(find_result)
    yield if block_given?
  end
  
  def should_not_count
    collection.should_not_receive(:find)
    yield if block_given?
  end
  
  def stub_delete
    collection.stub!(:remove)
  end
  
  def should_delete(conditions={})
    selector, options = MongoModel::MongoOptions.new(self, :conditions => conditions).to_a
    collection.should_receive(:remove).once.with(selector, options)
    yield if block_given?
  end
  
  def should_update(conditions={}, updates={})
    selector, options = MongoModel::MongoOptions.new(self, :conditions => conditions).to_a
    collection.should_receive(:update).once.with(selector, { "$set" => updates }, { :multi => true })
    yield if block_given?
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mongomodel-0.3.3 spec/support/helpers/document_finder_stubs.rb
mongomodel-0.3.2 spec/support/helpers/document_finder_stubs.rb
mongomodel-0.3.1 spec/support/helpers/document_finder_stubs.rb
mongomodel-0.3.0 spec/support/helpers/document_finder_stubs.rb