Sha256: 89169ea48dc8d3828ef6601d5280b2688bd003c5f85f08105979819dc9924e47

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 KB

Contents

require 'spec_helper'

shared_examples_for 'by cweek' do

  describe '#by_cweek' do

    context 'point-in-time' do
      subject { Post.by_cweek('2014-01-02') }
      it { expect(subject.count).to eql(4) }
    end

    context 'timespan' do
      subject { Event.by_cweek(1) }
      it { expect(subject.count).to eql(7) }
    end

    context 'timespan strict' do
      subject { Event.by_cweek(Date.parse('2014-01-01'), strict: true) }
      it { expect(subject.count).to eql(0) }
    end

    context 'with :year option' do

      context 'point-in-time' do
        subject { Post.by_cweek(53, year: 2013) }
        it { expect(subject.count).to eql(4) }
      end

      context 'timespan' do
        subject { Event.by_cweek(53, year: 2013) }
        it { expect(subject.count).to eql(7) }
      end

      context 'timespan strict' do
        subject { Event.by_cweek(53, year: 2013, strict: true) }
        it { expect(subject.count).to eql(0) }
      end
    end

    it 'should raise an error when given an invalid argument' do
      expect { Post.by_cweek(0) }.to raise_error(ByStar::ParseError, 'cweek number must be between 1 and 53')
      expect { Post.by_cweek(54) }.to raise_error(ByStar::ParseError, 'cweek number must be between 1 and 53')
    end

    it 'should be able to use an alternative field' do
      expect(Event.by_cweek(field: 'end_time').count).to eq 3
    end

    context ':start_day option' do
      subject { Post.by_cweek('2014-01-02', start_day: :thursday) }
      it { expect(subject.count).to eql(1) }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
by_star-4.0.1 spec/integration/shared/by_cweek.rb