require File.dirname(__FILE__) + '/abstract_unit' class DateFinderBaseTest < Test::Unit::TestCase def test_instantiation_with_method_missing assert_nothing_raised { assert Dater.weekly } assert_nothing_raised { assert Dater.monthly } end def test_method_missing_with_invalid_pattern assert_raises NoMethodError do Dater.moooonthly end end def test_initialize d = Dater::Monthly.new(:start_date => Date.today, :max => 20) assert_equal Date.today, d.start_date assert_equal 20, d.max end def test_daily_every_day actual = Dater.daily(:start_date => d(7, 7), :end_date => d(7, 12), :type => :everyday).find expected = [7, 8, 9, 10, 11, 12].map { |i| d(7, i) } assert_equal expected, actual end def test_daily_weekdays actual = Dater.daily(:start_date => d(8, 1), :end_date => d(8, 13), :type => :weekdays).find expected = [1, 2, 3, 4, 7, 8, 9, 10, 11].map { |i| d(8, i) } assert_equal expected, actual end def test_weekly_with_day actual = Dater.weekly(:start_date => d(9, 1), :end_date => d(9, 30), :tuesday => true, :type => :days).find expected = [5, 12, 19, 26].map{ |i| d(9, i) } assert_equal expected, actual end def test_weekly_with_interval_and_day actual = Dater.weekly(:start_date => d(9, 1), :end_date => d(10, 31), :interval => 2, :wednesday => true, :type => :days).find expected = [d(9, 13), d(9, 27), d(10, 11), d(10, 25)] assert_equal expected, actual end def test_weekly_with_interval_and_two_days actual = Dater.weekly(:start_date => d(9, 1), :max => 5, :interval => 3, :monday => true, :friday => true, :type => :days).find expected = [d(9, 1), d(9, 18), d(9, 22), d(10, 9), d(10, 13)] assert_equal expected, actual end def test_weekly_with_week_beginning actual = Dater.weekly(:start_date => d(4, 6), :max => 3, :interval => 2, :type => :week_beginning).find expected = [d(4, 3), d(4, 17), d(5, 1)] assert_equal expected, actual end def test_end_date_before_start_date actual = Dater.weekly(:start_date => Date.new(2007, 02, 13), :end_date => Date.new(2006, 7, 6), :interval => 1, :tuesday => 1, :sunday => 1, :max => 4, :type => :days).find assert_equal [], actual end def test_monthly_with_day_number actual = Dater.monthly(:start_date => d(9, 11), :max => 5, :day_number => 10, :type => :specific).find expected = [d(10, 10), d(11, 10), d(12, 10), d(2007, 1, 10), d(2007, 2, 10)] assert_equal expected, actual end def test_monthly_with_day_number_and_interval actual = Dater.monthly(:start_date => d(9, 11), :max => 5, :interval => 2, :day_number => 13, :type => :specific).find expected = [d(9, 13), d(11, 13), d(2007, 1, 13), d(2007, 3, 13), d(2007, 5, 13)] assert_equal expected, actual end def test_monthly_with_day_and_occurrence actual = Dater.monthly(:start_date => d(9, 1), :max => 3, :day => 2, :day_occurrence => :first, :type => :generic).find expected = [d(9, 5), d(10, 3), d(11, 7)] assert_equal expected, actual end def test_monthly_with_occurrence_and_day_and_interval actual = Dater.monthly(:start_date => d(1, 1), :max => 4, :day => 5, :interval => 4, :day_occurrence => :last, :type => :generic).find expected = [d(1, 27), d(5, 26), d(9, 29), d(2007, 1, 26)] assert_equal expected, actual end def test_monthly_with_invalid_occurrences actual = Dater.monthly(:start_date => d(1, 1), :max => 5, :day_number => 31, :type => :specific).find expected = [d(1, 31), d(3, 31), d(5, 31), d(7, 31), d(8, 31)] assert_equal expected, actual end def test_yearly_with_month_and_day actual = Dater.yearly(:start_date => d(1, 1), :end_date => d(2009, 1, 1), :day_number => 5, :month => 3, :type => :specific).find expected = [d(3, 5), d(2007, 3, 5), d(2008, 3, 5)] assert_equal expected, actual end def test_yearly_with_day_and_occurrence_and_month actual = Dater.yearly(:start_date => d(1, 1), :end_date => d(2010, 1, 1), :month => 9, :day => 1, :day_occurrence => :second, :type => :generic).find expected = [d(9, 11), d(2007, 9, 10), d(2008, 9, 8), d(2009, 9, 14)] assert_equal expected, actual end def test_yearly_with_invalid_occurrences assert_equal [], Dater.yearly(:start_date => d(1, 1), :end_date => d(2010, 12, 31), :month => 2, :day_number => 31, :type => :specific).find end end