Sha256: 74b78b4d259e9e4e7628789ed429970cc7e4cdd59ecfbf7238a4d767cea95d09

Contents?: true

Size: 1.61 KB

Versions: 18

Compression:

Stored size: 1.61 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)
    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 })
    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)
    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)
    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

18 entries across 18 versions & 1 rubygems

Version Path
mongomodel-0.2.20 spec/support/helpers/document_finder_stubs.rb
mongomodel-0.2.19 spec/support/helpers/document_finder_stubs.rb
mongomodel-0.2.18 spec/support/helpers/document_finder_stubs.rb
mongomodel-0.2.17 spec/support/helpers/document_finder_stubs.rb
mongomodel-0.2.16 spec/support/helpers/document_finder_stubs.rb
mongomodel-0.2.15 spec/support/helpers/document_finder_stubs.rb
mongomodel-0.2.14 spec/support/helpers/document_finder_stubs.rb
mongomodel-0.2.13 spec/support/helpers/document_finder_stubs.rb
mongomodel-0.2.12 spec/support/helpers/document_finder_stubs.rb
mongomodel-0.2.11 spec/support/helpers/document_finder_stubs.rb
mongomodel-0.2.10 spec/support/helpers/document_finder_stubs.rb
mongomodel-0.2.9 spec/support/helpers/document_finder_stubs.rb
mongomodel-0.2.8 spec/support/helpers/document_finder_stubs.rb
mongomodel-0.2.7 spec/support/helpers/document_finder_stubs.rb
mongomodel-0.2.6 spec/support/helpers/document_finder_stubs.rb
mongomodel-0.2.5 spec/support/helpers/document_finder_stubs.rb
mongomodel-0.2.4 spec/support/helpers/document_finder_stubs.rb
mongomodel-0.2.3 spec/support/helpers/document_finder_stubs.rb