Sha256: eeb25aa41c574de48a2a8a2c3cf073ea4f74d03c96f602865d073e1dee1ed8d2

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

require 'spec_helper'

shared_examples_for 'by fortnight' do

  describe '#by_fortnight' do

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

    context 'timespan' do
      subject { Event.by_fortnight(0) }
      its(:count){ should eq 7 }
    end

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

    context 'with :year option' do

      context 'point-in-time' do
        subject { Post.by_fortnight(26, year: 2013) }
        its(:count){ should eq 6 }
      end

      context 'timespan' do
        subject { Event.by_fortnight(26, year: 2013) }
        its(:count){ should eq 7 }
      end

      context 'timespan strict' do
        subject { Event.by_fortnight(26, year: 2013, strict: true) }
        its(:count){ should eq 1 }
      end
    end

    it 'should raise an error when given an invalid argument' do
      lambda { Post.by_fortnight(27) }.should raise_error(ByStar::ParseError, 'Fortnight number must be between 0 and 26')
    end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
by_star-2.2.1 spec/integration/shared/by_fortnight.rb
by_star-2.2.0 spec/integration/shared/by_fortnight.rb