Sha256: d4cee6019ad580fa1e9906ae50e4e484a9b827125d94efb5387619b84eb309fa

Contents?: true

Size: 1.72 KB

Versions: 4

Compression:

Stored size: 1.72 KB

Contents

require "spec_helper"

describe Mongoid::State do

  describe "#new_record?" do

    context "when calling new on the document" do

      let(:person) do
        Person.new("_id" => BSON::ObjectId.new)
      end

      it "returns true" do
        expect(person).to be_a_new_record
      end
    end

    context "when the object has been saved" do

      let(:person) do
        Person.instantiate("_id" => BSON::ObjectId.new)
      end

      it "returns false" do
        expect(person).to_not be_a_new_record
      end
    end

    context "when the object has not been saved" do

      let(:person) do
        Person.new
      end

      it "returns true" do
        expect(person).to be_a_new_record
      end
    end
  end

  describe "#persisted?" do

    let(:person) do
      Person.new
    end

    it "delegates to new_record?" do
      expect(person).to_not be_persisted
    end

    context "when the object has been destroyed" do
      before do
        person.save
        person.destroy
      end

      it "returns false" do
        expect(person).to_not be_persisted
      end
    end
  end

  describe "destroyed?" do

    let(:person) do
      Person.new
    end

    context "when destroyed is true" do

      before do
        person.destroyed = true
      end

      it "returns true" do
        expect(person).to be_destroyed
      end
    end

    context "when destroyed is false" do

      before do
        person.destroyed = false
      end

      it "returns true" do
        expect(person).to_not be_destroyed
      end
    end

    context "when destroyed is nil" do

      before do
        person.destroyed = nil
      end

      it "returns false" do
        expect(person).to_not be_destroyed
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
mongoid-4.0.0.alpha2 spec/mongoid/state_spec.rb
mongoid-4.0.0.alpha1 spec/mongoid/state_spec.rb
sepastian-mongoid-rails4-4.0.1.alpha spec/mongoid/state_spec.rb
sepastian-mongoid-rails4-4.0.0.alpha spec/mongoid/state_spec.rb