@@ -8,6 +8,12 @@ class SolidQueue::JobBatchTest < ActiveSupport::TestCase
8
8
SolidQueue ::JobBatch . destroy_all
9
9
end
10
10
11
+ class BatchWithArgumentsJob < ApplicationJob
12
+ def perform ( batch , arg1 , arg2 )
13
+ Rails . logger . info "Hi #{ batch . id } , #{ arg1 } , #{ arg2 } !"
14
+ end
15
+ end
16
+
11
17
class NiceJob < ApplicationJob
12
18
retry_on Exception , wait : 1 . second
13
19
@@ -18,14 +24,14 @@ def perform(arg)
18
24
19
25
test "batch will be completed on success" do
20
26
batch = SolidQueue ::JobBatch . enqueue ( on_finish : BatchCompletionJob ) { }
21
- assert_equal "success" , batch . completion_type
22
- assert_equal BatchCompletionJob . name , batch . job_class
27
+ assert_not_nil batch . on_finish_active_job
28
+ assert_equal BatchCompletionJob . name , batch . on_finish_active_job [ " job_class" ]
23
29
end
24
30
25
31
test "batch will be completed on finish" do
26
32
batch = SolidQueue ::JobBatch . enqueue ( on_success : BatchCompletionJob ) { }
27
- assert_equal "success" , batch . completion_type
28
- assert_equal BatchCompletionJob . name , batch . job_class
33
+ assert_not_nil batch . on_success_active_job
34
+ assert_equal BatchCompletionJob . name , batch . on_success_active_job [ " job_class" ]
29
35
end
30
36
31
37
test "sets the batch_id on jobs created inside of the enqueue block" do
@@ -45,4 +51,16 @@ def perform(arg)
45
51
end
46
52
assert_nil SolidQueue ::JobBatch . current_batch_id
47
53
end
54
+
55
+ test "allow arguments and options for callbacks" do
56
+ SolidQueue ::JobBatch . enqueue (
57
+ on_finish : BatchWithArgumentsJob . new ( 1 , 2 ) . set ( queue : :batch ) ,
58
+ ) do
59
+ NiceJob . perform_later ( "world" )
60
+ end
61
+
62
+ assert_not_nil SolidQueue ::JobBatch . last . on_finish_active_job [ "arguments" ]
63
+ assert_equal SolidQueue ::JobBatch . last . on_finish_active_job [ "arguments" ] , [ 1 , 2 ]
64
+ assert_equal SolidQueue ::JobBatch . last . on_finish_active_job [ "queue_name" ] , "batch"
65
+ end
48
66
end
0 commit comments