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

Version Path
rails-ext-0.3.25 spec/mongo_mapper_ext/micelaneous_spec.rb
rails-ext-0.3.24 spec/mongo_mapper_ext/micelaneous_spec.rb
rails-ext-0.3.23 spec/mongo_mapper_ext/micelaneous_spec.rb
rails-ext-0.3.22 spec/mongo_mapper_ext/micelaneous_spec.rb
rails-ext-0.3.21 spec/mongo_mapper_ext/micelaneous_spec.rb
rails-ext-0.3.20 spec/mongo_mapper_ext/micelaneous_spec.rb
rails-ext-0.3.19 spec/mongo_mapper_ext/micelaneous_spec.rb
rails-ext-0.3.18 spec/mongo_mapper_ext/micelaneous_spec.rb
rails-ext-0.3.17 spec/mongo_mapper_ext/micelaneous_spec.rb
rails-ext-0.3.16 spec/mongo_mapper_ext/micelaneous_spec.rb
rails-ext-0.3.15 spec/mongo_mapper_ext/micelaneous_spec.rb
rails-ext-0.3.14 spec/mongo_mapper_ext/micelaneous_spec.rb
rails-ext-0.3.13 spec/mongo_mapper_ext/micelaneous_spec.rb
rails-ext-0.3.12 spec/mongo_mapper_ext/micelaneous_spec.rb
rails-ext-0.3.11 spec/mongo_mapper_ext/micelaneous_spec.rb
rails-ext-0.3.10 spec/mongo_mapper_ext/micelaneous_spec.rb
rails-ext-0.3.9 spec/mongo_mapper_ext/micelaneous_spec.rb