Sha256: 8d26ff5ef537f502419dad396aeaf39cc51c922d0ae759ae77fb9b1e6617ade9

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

require_relative 'spec_helper'

describe 'Mongoid::TimeRange integration' do
  before { Timecop.freeze }


  describe 'create document without any attributes' do
    subject { Document.create }


    it 'sets from to current time and to to nil' do
      subject.range.must_be_nil
    end


    describe 'when default is set to from: Time.now }' do
      subject { DocumentWithImplicitDefault.create }


      it 'sets from to current time and to to ni' do
        subject.range.must_equal from: Time.now, to: nil
      end
    end


    describe 'when default is set to ->{ Mongoid::TimeRange.new(from: Time.now) }' do
      subject { DocumentWithExplicitDefault.create }


      it 'sets from to current time and to to ni' do
        subject.range.must_equal from: Time.now, to: nil
      end
    end
  end


  describe 'create document only with from attribute' do
    subject { Document.create(range: { from: Time.now.beginning_of_year }) }


    it 'sets from to given time and to to nil' do
      subject.range.must_equal from: Time.now.beginning_of_year, to: nil
    end
  end


  describe 'create document with both attributes' do
    subject { Document.create(range: { from: Time.now.beginning_of_year, to: Time.now.end_of_year }) }


    it 'sets from and to to given time' do
      subject.range.must_equal from: Time.now.beginning_of_year, to: Time.now.end_of_year
    end
  end


  after { Timecop.return }
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mongoid-time_range-0.4.1 spec/integration_spec.rb
mongoid-time_range-0.4.0 spec/integration_spec.rb