Sha256: 3a0b2f1ecddd7053de070461c85cd7deb875a9b37776a04857120357833d98b6

Contents?: true

Size: 1.05 KB

Versions: 27

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

require "spec_helper"

describe Mongoid::Timestamps::Created::Short do

  describe ".included" do

    let(:quiz) do
      ShortQuiz.new
    end

    let(:fields) do
      ShortQuiz.fields
    end

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

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

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

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

    it "forces the c_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
      ShortQuiz.create
    end

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

    it "allows access via the raw field" do
      expect(quiz.c_at).to eq(quiz.created_at)
    end
  end
end

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
mongoid-7.3.5 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.3.4 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.1.11 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.2.6 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.3.3 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.3.2 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.2.5 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.1.10 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.1.9 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.2.4 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.3.1 spec/mongoid/timestamps/created/short_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/mongoid-7.1.7/spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.3.0 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.2.3 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.1.8 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.2.2 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.2.1 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.1.7 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.2.0 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.1.6 spec/mongoid/timestamps/created/short_spec.rb