Sha256: 40580e03dce2b863ec273939892341638ddf8a6ee75b13bcfa93faa87ba3b560

Contents?: true

Size: 1.81 KB

Versions: 2

Compression:

Stored size: 1.81 KB

Contents

require 'timespan/mongoid/spec_helper'

describe Timespan do
	subject { account }

  let(:from) { Chronic.parse("1 day ago") }
  let(:to)   { Time.now }

  context '2 days duration using factory method' do
    let(:account) do 
      Account.create_it! '2 days'
    end

    describe '.start_date' do
      it 'should default to today' do
        DateTime.parse(subject.period.start_date.to_s).strftime('%d %b %Y').should == Date.today.strftime('%d %b %Y')
      end
    end
  end

  context '2 days duration using integer' do
    let(:account) do 
      Account.create :period => {:duration => 2.days }
    end

    describe '.start_date' do
      it 'should default to today' do
        DateTime.parse(subject.period.start_date.to_s).strftime('%d %b %Y').should == Date.today.strftime('%d %b %Y')
      end
    end
  end

  context '2 days using integer' do
    let(:account) do 
      Account.create :period => 2.days
    end

    describe '.start_date' do
      it 'should default to today' do
        DateTime.parse(subject.period.start_date.to_s).strftime('%d %b %Y').should == Date.today.strftime('%d %b %Y')
      end
    end
  end

  context '2 days duration (from now - default)' do
    let(:account) do 
      Account.create :period => {:duration => '2 days'}
    end

    describe '.start_date' do
      it 'should default to today' do
        DateTime.parse(subject.period.start_date.to_s).strftime('%d %b %Y').should == Date.today.strftime('%d %b %Y')
      end
    end
  end

  context '2 days duration (from 1 day ago)' do
    let(:account) do 
      Account.create :period => {:duration => '2 days', :from => from }
    end

    describe '.start_date' do
      it 'should default to today' do
        DateTime.parse(subject.period.start_date.to_s).strftime('%d %b %Y').should == 1.day.ago.strftime('%d %b %Y') 
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
timespan-0.2.8 spec/timespan/mongoid/mongoid_timespan_spec.rb
timespan-0.2.7 spec/timespan/mongoid/mongoid_timespan_spec.rb