Skip to content

Commit 7ecda7f

Browse files
committed
Override global option with group option
Local options override globally set options, but option set on the `every` group do not. It makes sense for the options defined closer to the actual job to override those set further away, so we change the merge order of options to allow options passed to `every` to override those set globally with `set`. We still allow local options set on each job to override those set on the group.
1 parent e916b58 commit 7ecda7f

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/whenever/job_list.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def job_type(name, template)
6666

6767
@jobs[options.fetch(:mailto)] ||= {}
6868
@jobs[options.fetch(:mailto)][@current_time_scope] ||= []
69-
@jobs[options.fetch(:mailto)][@current_time_scope] << Whenever::Job.new(@options.merge(@set_variables).merge(options))
69+
@jobs[options.fetch(:mailto)][@current_time_scope] << Whenever::Job.new(@set_variables.merge(@options).merge(options))
7070
end
7171
end
7272
end

test/functional/output_defined_job_test.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,34 @@ class OutputDefinedJobTest < Whenever::TestCase
5555
assert_match(/^.+ .+ .+ .+ before during after local$/, output)
5656
end
5757

58+
test "defined job with a :task and an option where the option is set globally and on the group" do
59+
output = Whenever.cron \
60+
<<-file
61+
set :job_template, nil
62+
job_type :some_job, "before :task after :option1"
63+
set :option1, 'global'
64+
every 2.hours, :option1 => 'group' do
65+
some_job "during"
66+
end
67+
file
68+
69+
assert_match(/^.+ .+ .+ .+ before during after group$/, output)
70+
end
71+
72+
test "defined job with a :task and an option where the option is set globally, on the group, and locally" do
73+
output = Whenever.cron \
74+
<<-file
75+
set :job_template, nil
76+
job_type :some_job, "before :task after :option1"
77+
set :option1, 'global'
78+
every 2.hours, :option1 => 'group' do
79+
some_job "during", :option1 => 'local'
80+
end
81+
file
82+
83+
assert_match(/^.+ .+ .+ .+ before during after local$/, output)
84+
end
85+
5886
test "defined job with a :task and an option that is not set" do
5987
output = Whenever.cron \
6088
<<-file

0 commit comments

Comments
 (0)