Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/clockwork/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ def run_if?(t)
end

def validate_if_option(if_option)
if if_option && !if_option.respond_to?(:call)
raise ArgumentError.new(':if expects a callable object, but #{if_option} does not respond to call')
return unless if_option
unless if_option.respond_to?(:call) && if_option.respond_to?(:arity) && if_option.arity == 1
raise ArgumentError.new(':if expects a callable object that accepts a single argument, but #{if_option} is not')
end
end
end
Expand Down
16 changes: 16 additions & 0 deletions test/manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,22 @@ def assert_wont_run(t)
@manager.every(1.second, 'myjob', :if => true)
end
end

it ":if does not respond to arity then raise ArgumentError" do
assert_raises(ArgumentError) do
callable = Class.new do
def call; end
end

@manager.every(1.second, 'myjob', :if => callable.new)
end
end

it ":if does not have an arity of 1 then raise ArgumentError" do
assert_raises(ArgumentError) do
@manager.every(1.second, 'myjob', :if => lambda {})
end
end
end

describe "max_threads" do
Expand Down