Sha256: d1a4c31efee21d9f5b4e7b87b3631bdfea19d00cb40539b9cb8174a6c4c2a56e

Contents?: true

Size: 1.41 KB

Versions: 4

Compression:

Stored size: 1.41 KB

Contents

require 'spec_helper'
require 'ice_cube'
require 'schedule_attributes/rule_parser'
require 'schedule_attributes/input'

describe ScheduleAttributes::RuleParser::Week do
  let(:t)   { Date.current.to_time }
  let(:sun) { (Date.current - Date.current.cwday.days).to_time + 1.week }
  let(:mon) { sun + 1.day }
  let(:sat) { sun - 1.day }

  let(:weekly)        { [t, t+1.week, t+2.weeks, t+3.weeks, t+4.weeks, t+5.weeks] }
  let(:every_2_weeks) { [t, t+2.week, t+4.weeks]}
  let(:weekends)      { [sat, sun, sat+1.week, sun+1.week, sat+2.weeks, sun+2.weeks] }

  describe "#rule" do
    let(:input)  { ScheduleAttributes::Input.new(RSpec.current_example.metadata[:args]) }
    let(:parser) { described_class.new(input) }
    subject      { parser.rule }

    context 'no arguments', args: {} do
      it { is_expected.to eq(IceCube::Rule.weekly) }
      its_occurrences_until(5.weeks.from_now) { is_expected.to eq(weekly) }
    end

    context 'interval argument', args: {"interval" => "2"} do
      it { is_expected.to eq(IceCube::Rule.weekly(2)) }
      its_occurrences_until(5.weeks.from_now) { is_expected.to eq(every_2_weeks) }
    end

    context 'several day name arguments', args: {"monday" => "0", "saturday" => "1", "sunday" => "1"} do
      it { is_expected.to eq(IceCube::Rule.weekly.day(0,6)) }
      its_occurrences_until(Date.today.beginning_of_week+3.weeks) { expect(subject[-4..-1]).to eq weekends[-4..-1] }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dgp-schedule_attributes-0.5.3 spec/schedule_attributes/rule_parser/week_spec.rb
dgp-schedule_attributes-0.5.2 spec/schedule_attributes/rule_parser/week_spec.rb
dgp-schedule_attributes-0.5.1 spec/schedule_attributes/rule_parser/week_spec.rb
dgp-schedule_attributes-0.5.0 spec/schedule_attributes/rule_parser/week_spec.rb