Sha256: 25c06846fbe106cf849559f96df7642c9f1f6c227bc29369e3c9b85744ed7f97
Contents?: true
Size: 1.16 KB
Versions: 17
Compression:
Stored size: 1.16 KB
Contents
require 'spec' require 'ruby_ext' require "mongo" require 'mongo_mapper' require "#{File.dirname __FILE__}/../../lib/mongo_mapper_ext/micelaneous" describe "MongoMapper Default Scope" do before :all do @db = Mongo::Connection.new.db('test') end before :each do @db.collection('test').drop @coll = @db.collection('test') end it "upsert should update" do id = @coll.save :count => 2 @coll.upsert id, :$inc => {:count => 1} @coll.find(:_id => id).first['count'].should == 3 end it "upsert should set" do id = @coll.save({}) @coll.upsert id, :$inc => {:count => 1} @coll.find(:_id => id).first['count'].should == 1 end describe "Handy upsert" do class ::UpsertSample include MongoMapper::Document key :counter, Integer, :default => 1 end before :each do @model = UpsertSample.create! end it "class upsert" do UpsertSample.upsert @model.id, :$inc => {:counter => 1} @model.reload @model.counter.should == 2 end it "model upsert" do @model.upsert :$inc => {:counter => 1} @model.reload @model.counter.should == 2 end end end
Version data entries
17 entries across 17 versions & 1 rubygems