Sha256: 336574fc340d5bf6365cea25cc3f86b8c5c5441355457ef6441ce6cb6b505fa0

Contents?: true

Size: 1.52 KB

Versions: 4

Compression:

Stored size: 1.52 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

4 entries across 4 versions & 2 rubygems

Version Path
ta_by_star-4.1.0 spec/integration/shared/by_cweek.rb
ta_by_star-4.0.0 spec/integration/shared/by_cweek.rb
by_star-4.0.0 spec/integration/shared/by_cweek.rb
by_star-3.0.0 spec/integration/shared/by_cweek.rb