<commit_before>require "spec_helper"

describe Mongoid::Fields::Standard::Date do

  let(:field) do
    described_class.new(:test, :type => Date)
  end

  let!(:time) do
    Time.local(2010, 11, 19)
  end

  describe "#cast_on_read?" do

    it "returns true" do
      field.should be_cast_on_read
    end
  end

  describe "#deserialize" do

    let(:time) { Time.now.utc }

    it "converts the time back to a date" do
      field.deserialize(time).should be_a_kind_of(Date)<commit_msg>Adding spec to ensure serialization of date fields when default is a proc<commit_after>require "spec_helper"

describe Mongoid::Fields::Standard::Date do

  let(:field) do
    described_class.new(:test, :type => Date)
  end

  let!(:time) do
    Time.local(2010, 11, 19)
  end

  describe "#cast_on_read?" do

    it "returns true" do
      field.should be_cast_on_read
    end
  end

  describe "#default" do

    context "when provided a proc" do

      let(:field) do
        described_class.new(
          :test,
          :type => Date,
          :default => lambda { 1.day.ago }
        )
      end

      it "serializes the result of the call" do
        field.default.should be_a(Time)
      end
    end
  end

  describe "#deserialize" do

    let(:time) { Time.now.utc }

    it "converts the time back to a date" do
      field.deserialize(time).should be_a_kind_of(Date)
{'fraction_non_alphanumeric': 0.10364963503649635, 'fraction_numerical': 0.012408759124087591, 'mean_word_length': 2.6954177897574123, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4144735', 'n_tokens_mistral': 478, 'n_tokens_neox': 444, 'n_words': 131}