File: validated_rule_spec.rb

package info (click to toggle)
ruby-ice-cube 0.16.4-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 800 kB
  • sloc: ruby: 7,823; makefile: 6
file content (50 lines) | stat: -rw-r--r-- 1,656 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require 'active_support/time'
require File.dirname(__FILE__) + '/../spec_helper'

describe IceCube, "::ValidatedRule" do
  describe "#next_time" do

    context "monthly" do
      let(:rule) { IceCube::Rule.monthly }

      it "Should return current day when starting on same day" do
        t0 = Time.new(2013, 2, 25, 0, 0, 0)
        expect(rule.next_time(t0, t0, nil)).to eq(t0)
      end

      it "Should return the next month when starting one second in the future" do
        t0 = Time.new(2013, 2, 25, 0, 0, 0)
        t1 = Time.new(2013, 3, 25, 0, 0, 0)
        expect(rule.next_time(t0 + 1, t0, nil)).to eq t1
      end

      it 'should return the next month near end of longer month [#171]' do
        t0 = Time.new(2013, 1, 1)
        t1 = Time.new(2013, 2, 1)
        [27, 28, 29, 30, 31].each do |day|
          expect(rule.next_time(Time.new(2013, 1, day), t0, nil)).to eq t1
        end
      end

      context "DST edge", system_time_zone: "Europe/London" do
        let(:t0) { Time.local(2013, 3, 31) }

        it "should not return the same time on a DST edge when starting one second in the future (results in infinite loop [#98])" do
          expect(rule.next_time(t0 + 1, t0, nil)).to eq Time.local(2013, 4, 30)
        end

        it "previous failing test with DST edge taken into account" do
          expect(rule.next_time(t0 + ONE_HOUR + 1, t0, nil)).to eq Time.local(2013, 4, 30)
        end
      end

    end

    it 'should match times with usec' do
      t0 = Time.new(2012, 12, 21, 12, 21, 12.12121212)
      rule = IceCube::Rule.secondly

      expect(rule.next_time(t0 + 1, t0, nil)).to eq(t0 + 1)
    end
  end
end