Sha256: f2dcbe400fd20b6b8ebb19bf536b275b98e78cc817b454388ccbf2476a2e5c78

Contents?: true

Size: 1022 Bytes

Versions: 73

Compression:

Stored size: 1022 Bytes

Contents

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

73 entries across 68 versions & 6 rubygems

Version Path
mongoid-7.0.13 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.0.12 spec/mongoid/timestamps/created/short_spec.rb
mongoid-6.4.8 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.0.11 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.0.10 spec/mongoid/timestamps/created/short_spec.rb
mongoid-6.4.7 spec/mongoid/timestamps/created/short_spec.rb
mongoid-6.4.5 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.0.8 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.0.7 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.0.6 spec/mongoid/timestamps/created/short_spec.rb
mongoid-5.4.1 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.0.5 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.0.4 spec/mongoid/timestamps/created/short_spec.rb
mongoid-6.4.4 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.0.3 spec/mongoid/timestamps/created/short_spec.rb
mongoid-6.4.2 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.0.2 spec/mongoid/timestamps/created/short_spec.rb
mongoid-7.0.1 spec/mongoid/timestamps/created/short_spec.rb
mongoid-6.4.1 spec/mongoid/timestamps/created/short_spec.rb
mongoid-5.4.0 spec/mongoid/timestamps/created/short_spec.rb