Sha256: 25aa2a0d73c679338a82734f52c73c8cb45755099b2167a70e20cfd64b101fa0

Contents?: true

Size: 1.39 KB

Versions: 10

Compression:

Stored size: 1.39 KB

Contents

require 'timespan/mongoid/spec_helper'
load_models!

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)
    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

10 entries across 10 versions & 1 rubygems

Version Path
timespan-0.6.0 spec/timespan/mongoid/mongoid_search_spec.rb
timespan-0.5.9 spec/timespan/mongoid/mongoid_search_spec.rb
timespan-0.5.7 spec/timespan/mongoid/mongoid_search_spec.rb
timespan-0.5.6.1 spec/timespan/mongoid/mongoid_search_spec.rb
timespan-0.5.6 spec/timespan/mongoid/mongoid_search_spec.rb
timespan-0.5.5 spec/timespan/mongoid/mongoid_search_spec.rb
timespan-0.5.4 spec/timespan/mongoid/mongoid_search_spec.rb
timespan-0.5.3 spec/timespan/mongoid/mongoid_search_spec.rb
timespan-0.5.2 spec/timespan/mongoid/mongoid_search_spec.rb
timespan-0.5.1 spec/timespan/mongoid/mongoid_search_spec.rb