Sha256: d8d8b15ae581d5b824acaa06ee4bd786248b0255125f5fa20d75ca774a5597f4

Contents?: true

Size: 1.88 KB

Versions: 1

Compression:

Stored size: 1.88 KB

Contents

require 'spec_helper'

shared_examples_for 'by day' do

  describe '#by_day' do

    context 'point-in-time' do
      subject { Post.by_day('2014-01-01') }
      its(:count){ should eq 2 }
    end

    context 'timespan' do
      subject { Event.by_day(Time.parse '2014-01-01') }
      its(:count){ should eq 4 }
    end

    context 'timespan strict' do
      subject { Event.by_day(Date.parse('2014-01-01'), strict: true) }
      its(:count){ should eq 0 }
    end

    it 'should be able to use an alternative field' do
      Event.by_day(:field => 'end_time').count.should eq 4
    end

    it 'should support :offset option' do
      Post.by_day('2014-01-01', :offset => -16.hours).count.should eq 1
    end
  end

  describe '#today' do # 2014-01-01

    context 'point-in-time' do
      subject { Post.today }
      its(:count){ should eq 2 }
    end

    context 'timespan' do
      subject { Event.today }
      its(:count){ should eq 4 }
    end

    context 'timespan strict' do
      subject { Event.today(strict: true) }
      its(:count){ should eq 0 }
    end
  end

  describe '#yesterday' do # 2013-12-31

    context 'point-in-time' do
      subject { Post.yesterday }
      its(:count){ should eq 1 }
    end

    context 'timespan' do
      subject { Event.yesterday }
      its(:count){ should eq 4 }
    end

    context 'timespan strict' do
      subject { Event.yesterday(strict: true) }
      its(:count){ should eq 0 }
    end
  end

  describe '#tomorrow' do # 2014-01-02

    context 'point-in-time' do
      subject { Post.tomorrow }
      its(:count){ should eq 0 }
    end

    context 'timespan' do
      subject { Event.tomorrow }
      its(:count){ should eq 4 }
    end

    context 'timespan strict' do
      subject { Event.tomorrow(strict: true) }
      its(:count){ should eq 0 }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
by_star-2.2.0.rc1 spec/integration/shared/by_day.rb