Sha256: dc17574a723c8d51011d74dbe1c737ff8144f7bdda041f37c6bfda4cb2355145

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

require "spec_helper"

describe Mongoid::Persistence::Operations::Upsert do

  describe "#persist" do

    context "when the document is new" do

      let(:band) do
        Band.new
      end

      let(:upsert) do
        described_class.new(band)
      end

      let!(:persisted) do
        upsert.persist
      end

      it "inserts the document in the database" do
        band.reload.should eq(band)
      end

      it "returns true" do
        persisted.should be_true
      end

      it "runs the upsert callbacks" do
        band.upserted.should be_true
      end
    end

    context "when the document is not new" do

      let(:band) do
        Band.create.tap do |b|
          b.name = "Tool"
        end
      end

      let(:upsert) do
        described_class.new(band)
      end

      let!(:persisted) do
        upsert.persist
      end

      it "updates the document in the database" do
        band.reload.name.should eq("Tool")
      end

      it "returns true" do
        persisted.should be_true
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mongoid-3.1.7 spec/mongoid/persistence/operations/upsert_spec.rb
mongoid-3.1.6 spec/mongoid/persistence/operations/upsert_spec.rb
mongoid-3.1.5 spec/mongoid/persistence/operations/upsert_spec.rb