2010-09-12 13:16:44 +00:00
|
|
|
require 'test_helper'
|
|
|
|
require 'minicomic-backend/scheduler'
|
2010-01-04 04:43:58 +00:00
|
|
|
|
|
|
|
class TestScheduler < Test::Unit::TestCase
|
|
|
|
def setup
|
|
|
|
@scheduler = Scheduler.instance
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_schedule
|
|
|
|
[
|
|
|
|
[
|
|
|
|
{
|
2010-01-05 00:44:39 +00:00
|
|
|
'start' => DateTime.parse('2010-01-01'),
|
|
|
|
'interval' => Scheduler::WEEKLY
|
2010-01-04 04:43:58 +00:00
|
|
|
},
|
|
|
|
2,
|
|
|
|
[ DateTime.parse('2010-01-01'), DateTime.parse('2010-01-08') ]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
2010-01-05 00:44:39 +00:00
|
|
|
'start' => DateTime.parse('2010-01-01'),
|
|
|
|
'interval' => [ 'monday' ]
|
2010-01-04 04:43:58 +00:00
|
|
|
},
|
|
|
|
2,
|
|
|
|
[ DateTime.parse('2010-01-04'), DateTime.parse('2010-01-11') ]
|
|
|
|
],
|
2010-01-05 00:43:15 +00:00
|
|
|
[
|
|
|
|
{
|
2010-01-05 00:44:39 +00:00
|
|
|
'start' => DateTime.parse('2010-01-01'),
|
|
|
|
'interval' => Scheduler::DAILY,
|
|
|
|
'breaks' => [
|
|
|
|
{ 'from' => DateTime.parse('2010-01-03'), 'to' => DateTime.parse('2010-01-05') }
|
2010-01-05 00:43:15 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
4,
|
|
|
|
[ DateTime.parse('2010-01-01'), DateTime.parse('2010-01-02'), DateTime.parse('2010-01-06'), DateTime.parse('2010-01-07') ]
|
|
|
|
],
|
2010-01-05 02:34:57 +00:00
|
|
|
[
|
|
|
|
{
|
2010-01-11 02:54:20 +00:00
|
|
|
'start' => DateTime.parse('2010-01-02'),
|
2010-01-05 02:34:57 +00:00
|
|
|
'interval' => [ 'monday', 'wednesday', 'friday' ],
|
|
|
|
'breaks' => [
|
|
|
|
{ 'at_index' => 3, 'for_days' => 7 }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
6,
|
|
|
|
[
|
|
|
|
DateTime.parse('2010-01-04'), DateTime.parse('2010-01-06'), DateTime.parse('2010-01-08'),
|
|
|
|
DateTime.parse('2010-01-18'), DateTime.parse('2010-01-20'), DateTime.parse('2010-01-22')
|
|
|
|
]
|
|
|
|
],
|
2010-01-11 02:54:20 +00:00
|
|
|
[
|
|
|
|
{
|
|
|
|
'start' => DateTime.parse('2010-01-06'),
|
|
|
|
'interval' => [ 'monday', 'wednesday', 'friday' ],
|
|
|
|
},
|
|
|
|
3,
|
|
|
|
[
|
|
|
|
DateTime.parse('2010-01-06'), DateTime.parse('2010-01-08'), DateTime.parse('2010-01-11'),
|
|
|
|
]
|
|
|
|
],
|
2010-01-04 04:43:58 +00:00
|
|
|
].each do |parameters, to_produce, expected_results|
|
|
|
|
assert_equal expected_results, @scheduler.schedule(parameters, to_produce)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-01-05 00:33:58 +00:00
|
|
|
def test_skip_to_dow
|
|
|
|
assert_equal DateTime.parse('2010-01-02'), @scheduler.skip_to_dow(DateTime.parse('2010-01-01'), 6)
|
|
|
|
assert_equal DateTime.parse('2010-01-02'), @scheduler.skip_to_dow(DateTime.parse('2010-01-01'), 'saturday')
|
|
|
|
end
|
2010-01-04 04:43:58 +00:00
|
|
|
end
|