1
1
require "spec_helper"
2
2
require "rspec/rails/feature_check"
3
+
3
4
if RSpec ::Rails ::FeatureCheck . has_active_job?
4
5
require "rspec/rails/matchers/active_job"
6
+
7
+ class GlobalIdModel
8
+ include GlobalID ::Identification
9
+
10
+ attr_reader :id
11
+
12
+ def self . find ( id )
13
+ new ( id )
14
+ end
15
+
16
+ def initialize ( id )
17
+ @id = id
18
+ end
19
+
20
+ def ==( comparison_object )
21
+ id == comparison_object . id
22
+ end
23
+
24
+ def to_global_id ( options = { } )
25
+ @global_id ||= GlobalID . create ( self , :app => "rspec-suite" )
26
+ end
27
+ end
5
28
end
6
29
7
30
RSpec . describe "ActiveJob matchers" , :skip => !RSpec ::Rails ::FeatureCheck . has_active_job? do
@@ -26,30 +49,6 @@ def perform; end
26
49
end
27
50
end
28
51
29
- let ( :global_id_model ) do
30
- Class . new do
31
- include GlobalID ::Identification
32
-
33
- attr_reader :id
34
-
35
- def self . find ( id )
36
- new ( id )
37
- end
38
-
39
- def self . name
40
- "AnonymousClass"
41
- end
42
-
43
- def initialize ( id )
44
- @id = id
45
- end
46
-
47
- def to_global_id ( options = { } )
48
- @global_id ||= GlobalID . create ( self , :app => "rspec-suite" )
49
- end
50
- end
51
- end
52
-
53
52
before do
54
53
ActiveJob ::Base . queue_adapter = :test
55
54
end
@@ -196,7 +195,7 @@ def to_global_id(options = {})
196
195
end
197
196
198
197
it "passes with provided arguments containing global id object" do
199
- global_id_object = global_id_model . new ( 42 )
198
+ global_id_object = GlobalIdModel . new ( "42" )
200
199
201
200
expect {
202
201
hello_job . perform_later ( global_id_object )
@@ -247,6 +246,17 @@ def to_global_id(options = {})
247
246
}
248
247
end
249
248
249
+ it "passess deserialized arguments to with block" do
250
+ global_id_object = GlobalIdModel . new ( "42" )
251
+
252
+ expect {
253
+ hello_job . perform_later ( global_id_object , :symbolized_key => "asdf" )
254
+ } . to have_enqueued_job ( hello_job ) . with { |first_arg , second_arg |
255
+ expect ( first_arg ) . to eq ( global_id_object )
256
+ expect ( second_arg ) . to eq ( { :symbolized_key => "asdf" } )
257
+ }
258
+ end
259
+
250
260
it "only calls with block if other conditions are met" do
251
261
noon = Date . tomorrow . noon
252
262
midnight = Date . tomorrow . midnight
0 commit comments