Sha256: 44fd9fd51ade71795f5c23b01be4fd868e792ef28720d7b8203ef9cde8320ed7

Contents?: true

Size: 896 Bytes

Versions: 24

Compression:

Stored size: 896 Bytes

Contents

# frozen_string_literal: true

require "spec_helper"

describe Mongoid::Timestamps::Created do

  describe ".included" do

    let(:quiz) do
      Quiz.new
    end

    let(:fields) do
      Quiz.fields
    end

    before do
      quiz.run_callbacks(:create)
      quiz.run_callbacks(:save)
    end

    it "adds created_at to the document" do
      expect(fields["created_at"]).to_not be_nil
    end

    it "does not add updated_at to the document" do
      expect(fields["updated_at"]).to be_nil
    end

    it "forces the created_at timestamps to UTC" do
      expect(quiz.created_at).to be_within(10).of(Time.now.utc)
    end
  end

  context "when the document is created" do

    let(:quiz) do
      Quiz.create!
    end

    it "runs the created callbacks" do
      expect(quiz.created_at).to_not be_nil
      expect(quiz.created_at).to be_within(10).of(Time.now.utc)
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
mongoid-8.1.7 spec/mongoid/timestamps/created_spec.rb
mongoid-8.1.6 spec/mongoid/timestamps/created_spec.rb
mongoid-8.0.8 spec/mongoid/timestamps/created_spec.rb
mongoid-8.1.5 spec/mongoid/timestamps/created_spec.rb
mongoid-8.1.4 spec/mongoid/timestamps/created_spec.rb
mongoid-8.0.7 spec/mongoid/timestamps/created_spec.rb
mongoid-8.1.3 spec/mongoid/timestamps/created_spec.rb
mongoid-8.1.2 spec/mongoid/timestamps/created_spec.rb
mongoid-8.0.6 spec/mongoid/timestamps/created_spec.rb
mongoid-7.5.4 spec/mongoid/timestamps/created_spec.rb
mongoid-8.1.1 spec/mongoid/timestamps/created_spec.rb
mongoid-8.0.5 spec/mongoid/timestamps/created_spec.rb
mongoid-8.1.0 spec/mongoid/timestamps/created_spec.rb
mongoid-7.5.3 spec/mongoid/timestamps/created_spec.rb
mongoid-8.0.4 spec/mongoid/timestamps/created_spec.rb
mongoid-8.0.3 spec/mongoid/timestamps/created_spec.rb
mongoid-7.5.2 spec/mongoid/timestamps/created_spec.rb
mongoid-8.0.2 spec/mongoid/timestamps/created_spec.rb
mongoid-7.5.1 spec/mongoid/timestamps/created_spec.rb
mongoid-7.4.3 spec/mongoid/timestamps/created_spec.rb