resque_unit 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  module ResqueUnit
2
-
2
+
3
3
  # ResqueUnit::Scheduler is a group of functions mocking the behavior
4
4
  # of resque-scheduler. It is included into Resque when
5
5
  # 'resque_unit_scheduler' is required.
@@ -11,13 +11,13 @@ module ResqueUnit
11
11
  def enqueue_at(timestamp, klass, *args)
12
12
  enqueue_with_timestamp(timestamp, klass, *args)
13
13
  end
14
-
14
+
15
15
  # Identical to enqueue_at but takes number_of_seconds_from_now
16
16
  # instead of a timestamp.
17
17
  def enqueue_in(number_of_seconds_from_now, klass, *args)
18
18
  enqueue_at(Time.now + number_of_seconds_from_now, klass, *args)
19
19
  end
20
-
20
+
21
21
  def enqueue_with_timestamp(timestamp, klass, *args)
22
22
  enqueue_unit(queue_for(klass), {"class" => klass.name, "args" => args, "timestamp" => timestamp})
23
23
  end
@@ -32,10 +32,9 @@ module ResqueUnit
32
32
  def remove_delayed_job_from_timestamp(timestamp, klass, *args)
33
33
  encoded_job_payloads = Resque.queue(queue_for(klass))
34
34
  args ||= []
35
- encoded_job_payloads.delete_if { |e| e = Resque.decode(e); e["class"] == klass.to_s && e["timestamp"] == timestamp.to_s && e["args"] == args }
35
+ encoded_job_payloads.delete_if { |e| e = Resque.decode(e); e["class"] == klass.to_s && Time.parse(e["timestamp"]).to_i == Time.parse(timestamp.to_s).to_i && e["args"] == args }
36
36
  end
37
37
  end
38
38
 
39
39
  Resque.send(:extend, Scheduler)
40
40
  end
41
-
@@ -129,7 +129,7 @@ class ResqueUnitSchedulerTest < Test::Unit::TestCase
129
129
  end
130
130
  end
131
131
 
132
- context "and then the job is removed with #remove_delayed_job_with_timestamp" do
132
+ context "and then the job is removed with #remove_delayed_job_from_timestamp" do
133
133
  setup do
134
134
  Resque.remove_delayed_job_from_timestamp(@time, MediumPriorityJob)
135
135
  end
@@ -144,6 +144,22 @@ class ResqueUnitSchedulerTest < Test::Unit::TestCase
144
144
  end
145
145
  end
146
146
  end
147
+
148
+ context "and then the job is removed with #remove_delayed_job_from_timestamp with timestamp specified in another timezone" do
149
+ setup do
150
+ Resque.remove_delayed_job_from_timestamp(@time.utc, MediumPriorityJob)
151
+ end
152
+
153
+ should "pass the assert_not_queued_at(@time, MediumPriorityJob) assertion" do
154
+ assert_not_queued_at(@time, MediumPriorityJob)
155
+ end
156
+
157
+ should "fail the assert_queued_at(@time, MediumPriorityJob) assertion" do
158
+ assert_raise Test::Unit::AssertionFailedError do
159
+ assert_queued_at(@time, MediumPriorityJob)
160
+ end
161
+ end
162
+ end
147
163
  end
148
164
 
149
165
  context "A task that schedules a resque job with arguments on on Sept. 6, 2016 at 6am" do
@@ -197,5 +213,21 @@ class ResqueUnitSchedulerTest < Test::Unit::TestCase
197
213
  end
198
214
  end
199
215
  end
216
+
217
+ context "and then the job is removed with #remove_delayed_job_from_timestamp with timestamp in another timezone" do
218
+ setup do
219
+ Resque.remove_delayed_job_from_timestamp(@time.utc, JobWithArguments, 1, "test")
220
+ end
221
+
222
+ should "pass the assert_not_queued_at(@time, JobWithArguments, *args) assertion" do
223
+ assert_not_queued_at(@time, JobWithArguments, [1, "test"])
224
+ end
225
+
226
+ should "fail the assert_queued_at(@time, MediumPriorityJob, *args) assertion" do
227
+ assert_raise Test::Unit::AssertionFailedError do
228
+ assert_queued_at(@time, JobWithArguments, [1, "test"])
229
+ end
230
+ end
231
+ end
200
232
  end
201
233
  end
@@ -26,9 +26,9 @@ class ResqueUnitTest < Test::Unit::TestCase
26
26
  assert_equal 1, Resque.queue(:a_non_class_determined_queue).length
27
27
  end
28
28
  end
29
-
29
+
30
30
  context "A task that spawns multiple jobs on a single queue" do
31
- setup do
31
+ setup do
32
32
  3.times {Resque.enqueue(HighPriorityJob)}
33
33
  end
34
34
 
@@ -52,7 +52,7 @@ class ResqueUnitTest < Test::Unit::TestCase
52
52
  end
53
53
 
54
54
  context "A task that schedules a resque job" do
55
- setup do
55
+ setup do
56
56
  @returned = Resque.enqueue(LowPriorityJob)
57
57
  end
58
58
 
@@ -60,12 +60,12 @@ class ResqueUnitTest < Test::Unit::TestCase
60
60
  assert @returned
61
61
  end
62
62
 
63
- should "pass the assert_queued(job) assertion" do
63
+ should "pass the assert_queued(job) assertion" do
64
64
  assert_queued(LowPriorityJob)
65
65
  end
66
66
 
67
- should "fail the assert_not_queued(job) assertion" do
68
- assert_raise Test::Unit::AssertionFailedError do
67
+ should "fail the assert_not_queued(job) assertion" do
68
+ assert_raise Test::Unit::AssertionFailedError do
69
69
  assert_not_queued(LowPriorityJob)
70
70
  end
71
71
  end
@@ -74,17 +74,17 @@ class ResqueUnitTest < Test::Unit::TestCase
74
74
  assert_equal 1, Resque.size(:low)
75
75
  end
76
76
 
77
- context ", when Resque.run! is called," do
78
- setup do
77
+ context ", when Resque.run! is called," do
78
+ setup do
79
79
  assert !LowPriorityJob.run?, "The job should not have been run yet"
80
80
  Resque.run!
81
81
  end
82
-
83
- teardown do
82
+
83
+ teardown do
84
84
  LowPriorityJob.run = false
85
85
  end
86
86
 
87
- should "run the job" do
87
+ should "run the job" do
88
88
  assert LowPriorityJob.run?, "The job should have run"
89
89
  end
90
90
 
@@ -97,7 +97,7 @@ class ResqueUnitTest < Test::Unit::TestCase
97
97
  end
98
98
 
99
99
  context "A task that schedules a resque job with hooks" do
100
- setup do
100
+ setup do
101
101
  Resque.enable_hooks!
102
102
  end
103
103
 
@@ -106,22 +106,22 @@ class ResqueUnitTest < Test::Unit::TestCase
106
106
  end
107
107
 
108
108
  context "before, around, after, failure, after_enqueue" do
109
- setup do
109
+ setup do
110
110
  JobWithHooks.clear_markers
111
111
  Resque.enqueue(JobWithHooks)
112
112
  end
113
113
 
114
- should "have run the after_enqueue hook" do
114
+ should "have run the after_enqueue hook" do
115
115
  assert_queued(JobWithHooks)
116
116
  assert(JobWithHooks.markers[:after_enqueue], 'no after_queue marker set')
117
117
  end
118
118
 
119
- should "have run the before_enqueue hook" do
119
+ should "have run the before_enqueue hook" do
120
120
  assert(JobWithHooks.markers[:before_enqueue], 'no before_queue marker set')
121
121
  assert_queued(JobWithHooks)
122
122
  end
123
123
 
124
- should "run the before and after hooks during a run" do
124
+ should "run the before and after hooks during a run" do
125
125
  Resque.run!
126
126
  assert(JobWithHooks.markers[:before], 'no before marker set')
127
127
  assert(JobWithHooks.markers[:around], 'no around marker set')
@@ -253,12 +253,12 @@ class ResqueUnitTest < Test::Unit::TestCase
253
253
  end
254
254
 
255
255
  context "An empty queue" do
256
- should "pass the assert_not_queued(job) assertion" do
256
+ should "pass the assert_not_queued(job) assertion" do
257
257
  assert_not_queued(LowPriorityJob)
258
258
  end
259
259
 
260
260
  should "fail the assert_queued(job) assertion" do
261
- assert_raise Test::Unit::AssertionFailedError do
261
+ assert_raise Test::Unit::AssertionFailedError do
262
262
  assert_queued(LowPriorityJob)
263
263
  end
264
264
  end
@@ -267,16 +267,16 @@ class ResqueUnitTest < Test::Unit::TestCase
267
267
  assert_equal 0, Resque.size(:low)
268
268
  end
269
269
  end
270
-
271
- context "A task that schedules a resque job with arguments" do
272
- setup do
270
+
271
+ context "A task that schedules a resque job with arguments" do
272
+ setup do
273
273
  Resque.enqueue(JobWithArguments, 1, :test, {:symbol => :symbol})
274
274
  end
275
-
275
+
276
276
  should "pass the assert_queued(job, *args) assertion if the args match and sees enqueued symbols as strings" do
277
277
  assert_queued(JobWithArguments, [1, "test", {"symbol"=>"symbol"}])
278
278
  end
279
-
279
+
280
280
  should "pass the assert_queued(job, *args) assertion if the args match using symbols" do
281
281
  assert_queued(JobWithArguments, [1, :test, {:symbol => :symbol}])
282
282
  end
@@ -285,8 +285,8 @@ class ResqueUnitTest < Test::Unit::TestCase
285
285
  assert_queued(JobWithArguments)
286
286
  end
287
287
 
288
- should "fail the assert_queued(job) assertion if the args don't match" do
289
- assert_raise Test::Unit::AssertionFailedError do
288
+ should "fail the assert_queued(job) assertion if the args don't match" do
289
+ assert_raise Test::Unit::AssertionFailedError do
290
290
  assert_queued(JobWithArguments, [2, "test"])
291
291
  end
292
292
  end
@@ -296,23 +296,23 @@ class ResqueUnitTest < Test::Unit::TestCase
296
296
  end
297
297
 
298
298
  should "fail the assert_not_queued(job) assertion if the args match" do
299
- assert_raise Test::Unit::AssertionFailedError do
299
+ assert_raise Test::Unit::AssertionFailedError do
300
300
  assert_not_queued(JobWithArguments, [1, "test", {"symbol"=>"symbol"}])
301
301
  end
302
302
  end
303
303
  end
304
304
 
305
305
  context "A job that schedules a new resque job" do
306
- setup do
306
+ setup do
307
307
  Resque.enqueue(JobThatCreatesANewJob)
308
308
  end
309
309
 
310
- should "pass the assert_queued(job) assertion" do
310
+ should "pass the assert_queued(job) assertion" do
311
311
  assert_queued(JobThatCreatesANewJob)
312
312
  end
313
313
 
314
- should "fail the assert_not_queued(job) assertion" do
315
- assert_raise Test::Unit::AssertionFailedError do
314
+ should "fail the assert_not_queued(job) assertion" do
315
+ assert_raise Test::Unit::AssertionFailedError do
316
316
  assert_not_queued(JobThatCreatesANewJob)
317
317
  end
318
318
  end
@@ -321,8 +321,8 @@ class ResqueUnitTest < Test::Unit::TestCase
321
321
  assert_not_queued(LowPriorityJob)
322
322
  end
323
323
 
324
- context ", when Resque.run! is called," do
325
- setup do
324
+ context ", when Resque.run! is called," do
325
+ setup do
326
326
  Resque.run!
327
327
  end
328
328
 
@@ -341,7 +341,7 @@ class ResqueUnitTest < Test::Unit::TestCase
341
341
  Resque.full_run!
342
342
  end
343
343
 
344
- teardown do
344
+ teardown do
345
345
  LowPriorityJob.run = false
346
346
  end
347
347
 
@@ -370,10 +370,10 @@ class ResqueUnitTest < Test::Unit::TestCase
370
370
  assert_queued(HighPriorityJob)
371
371
  end
372
372
 
373
- context ", when Resque.run_for! is called," do
373
+ context ", when Resque.run_for! is called," do
374
374
  should "run only tasks in the high priority queue" do
375
375
  Resque.run_for!(Resque.queue_for(HighPriorityJob))
376
-
376
+
377
377
  assert_queued(LowPriorityJob)
378
378
  assert_not_queued(HighPriorityJob)
379
379
  end
@@ -389,7 +389,7 @@ class ResqueUnitTest < Test::Unit::TestCase
389
389
  assert_equal "LowPriorityJob should have been queued in low: [].", error.message
390
390
  end
391
391
  end
392
-
392
+
393
393
  should "include job arguments if provided" do
394
394
  begin
395
395
  assert_not_queued(JobWithArguments, [1, "test"])
@@ -408,7 +408,7 @@ class ResqueUnitTest < Test::Unit::TestCase
408
408
  assert_equal "LowPriorityJob should not have been queued in low.", error.message
409
409
  end
410
410
  end
411
-
411
+
412
412
  should "include job arguments if provided" do
413
413
  begin
414
414
  Resque.enqueue(JobWithArguments, 1, "test")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque_unit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-08 00:00:00.000000000Z
12
+ date: 2012-04-12 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &70334013235640 !ruby/object:Gem::Requirement
16
+ requirement: &70357498000140 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.4.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70334013235640
24
+ version_requirements: *70357498000140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &70334013235240 !ruby/object:Gem::Requirement
27
+ requirement: &70357497999740 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70334013235240
35
+ version_requirements: *70357497999740
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: shoulda
38
- requirement: &70334013234780 !ruby/object:Gem::Requirement
38
+ requirement: &70357497999280 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70334013234780
46
+ version_requirements: *70357497999280
47
47
  description:
48
48
  email: justin@uberweiss.org
49
49
  executables: []
@@ -80,7 +80,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
80
  version: '0'
81
81
  segments:
82
82
  - 0
83
- hash: 504436930256171136
83
+ hash: 2837385060471172776
84
84
  required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  none: false
86
86
  requirements:
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  version: '0'
90
90
  segments:
91
91
  - 0
92
- hash: 504436930256171136
92
+ hash: 2837385060471172776
93
93
  requirements: []
94
94
  rubyforge_project:
95
95
  rubygems_version: 1.8.10