Sha256: 567d76956000ac2e65a265d2d12a53c9530db4b9ee3230b88748d47ad70ea5bb

Contents?: true

Size: 1.43 KB

Versions: 7

Compression:

Stored size: 1.43 KB

Contents

require 'timespan/mongoid/spec_helper'

describe TimeSpan do
  subject { account }

  context '3 Accounts with periods serialized' do
    before do
      Account.delete_all
      @acc1 = Account.create :period => Timespan.new(:start_date => 2.days.ago)
      @acc2 = Account.create :period => Timespan.new(:start_date => 5.days.ago, :end_date => 2.days.ago)
      @acc3 = Account.create :period => Timespan.new(:start_date => 10.days.ago)

      # puts [@acc1._id, @acc2._id, @acc3._id]
    end

    describe 'find accounts within specific period' do
      it 'should find a single period less than 6 days old' do
        Account.where(:'period.from'.lt => 6.days.ago.to_i).first.should == @acc3
      end

      it 'should find a single period later than 3 days old' do
        Account.where(:'period.from'.gt => 3.days.ago.to_i).first.should == @acc1
      end

      describe 'find a single period that is within period from 6 days ago to tomorrow' do
        it 'should use Account.where' do
          Account.where(:'period.from'.gt => 6.days.ago.to_i, :'period.to'.lte => 1.day.ago.to_i).first.should == @acc2
        end

        it 'should use Account class helper #between' do
          Account.between(6.days.ago, 1.day.ago).first.should == @acc2
        end

        it 'should use Account class generated helper #period_between' do
          Account.period_between(6.days.ago, 1.day.ago).first.should == @acc2
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
timespan-0.4.4 spec/timespan/mongoid/mongoid_search_spec.rb
timespan-0.4.3 spec/timespan/mongoid/mongoid_search_spec.rb
timespan-0.4.2 spec/timespan/mongoid/mongoid_search_spec.rb
timespan-0.4.1 spec/timespan/mongoid/mongoid_search_spec.rb
timespan-0.4.0 spec/timespan/mongoid/mongoid_search_spec.rb
timespan-0.3.2 spec/timespan/mongoid/mongoid_search_spec.rb
timespan-0.3.1 spec/timespan/mongoid/mongoid_search_spec.rb