test/clockwork_test.rb in clockwork-0.3.4 vs test/clockwork_test.rb in clockwork-0.4.0
- old
+ new
@@ -167,6 +167,80 @@
event = Clockwork.every(1.minute, 'myjob')
event.stubs(:log_error)
Clockwork.tick(t = Time.now)
assert_equal t, event.last
end
+
+ test "should be configurable" do
+ Clockwork.configure do |config|
+ config[:sleep_timeout] = 200
+ config[:logger] = "A Logger"
+ end
+
+ assert_equal 200, Clockwork.config[:sleep_timeout]
+ assert_equal "A Logger", Clockwork.config[:logger]
+ end
+
+ test "configuration should have reasonable defaults" do
+ assert_equal 1, Clockwork.config[:sleep_timeout]
+ assert Clockwork.config[:logger].is_a?(Logger)
+ end
+
+ test "should be able to specify a different timezone than local" do
+ Clockwork.every(1.day, 'myjob', :at => '10:00', :tz => 'UTC')
+
+ assert_wont_run 'jan 1 2010 10:00:00 EST'
+ assert_will_run 'jan 1 2010 10:00:00 UTC'
+ end
+
+ test "should be able to specify a different timezone than local for multiple times" do
+ Clockwork.every(1.day, 'myjob', :at => ['10:00', '8:00'], :tz => 'UTC')
+
+ assert_wont_run 'jan 1 2010 08:00:00 EST'
+ assert_will_run 'jan 1 2010 08:00:00 UTC'
+ assert_wont_run 'jan 1 2010 10:00:00 EST'
+ assert_will_run 'jan 1 2010 10:00:00 UTC'
+ end
+
+ test "should be able to configure a default timezone to use for all events" do
+ Clockwork.configure { |config| config[:tz] = 'UTC' }
+ Clockwork.every(1.day, 'myjob', :at => '10:00')
+
+ assert_wont_run 'jan 1 2010 10:00:00 EST'
+ assert_will_run 'jan 1 2010 10:00:00 UTC'
+ end
+
+ test "should be able to override a default timezone in an event" do
+ Clockwork.configure { |config| config[:tz] = 'UTC' }
+ Clockwork.every(1.day, 'myjob', :at => '10:00', :tz => 'EST')
+
+ assert_will_run 'jan 1 2010 10:00:00 EST'
+ assert_wont_run 'jan 1 2010 10:00:00 UTC'
+ end
+
+ test ":if true then always run" do
+ Clockwork.every(1.second, 'myjob', :if => lambda { |_| true })
+
+ assert_will_run 'jan 1 2010 16:20:00'
+ end
+
+ test ":if false then never run" do
+ Clockwork.every(1.second, 'myjob', :if => lambda { |_| false })
+
+ assert_wont_run 'jan 1 2010 16:20:00'
+ end
+
+ test ":if the first day of month" do
+ Clockwork.every(1.second, 'myjob', :if => lambda { |t| t.day == 1 })
+
+ assert_will_run 'jan 1 2010 16:20:00'
+ assert_wont_run 'jan 2 2010 16:20:00'
+ assert_will_run 'feb 1 2010 16:20:00'
+ end
+
+ test ":if is not callable then raise ArgumentError" do
+ assert_raise(ArgumentError) do
+ Clockwork.every(1.second, 'myjob', :if => true)
+ end
+ end
+
end