resque-approve 0.0.1

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.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +30 -0
  4. data/lib/resque-approve.rb +10 -0
  5. data/lib/resque/approve_server.rb +232 -0
  6. data/lib/resque/plugins/approve.rb +77 -0
  7. data/lib/resque/plugins/approve/approval_key_list.rb +100 -0
  8. data/lib/resque/plugins/approve/cleaner.rb +44 -0
  9. data/lib/resque/plugins/approve/pending_job.rb +187 -0
  10. data/lib/resque/plugins/approve/pending_job_queue.rb +128 -0
  11. data/lib/resque/plugins/approve/redis_access.rb +16 -0
  12. data/lib/resque/plugins/version.rb +9 -0
  13. data/lib/resque/server/public/approve.css +56 -0
  14. data/lib/resque/server/views/_approval_key_list_pagination.erb +67 -0
  15. data/lib/resque/server/views/_approval_key_rows.erb +18 -0
  16. data/lib/resque/server/views/_job_list_table.erb +30 -0
  17. data/lib/resque/server/views/_job_pagination.erb +67 -0
  18. data/lib/resque/server/views/approval_keys.erb +66 -0
  19. data/lib/resque/server/views/job_details.erb +82 -0
  20. data/lib/resque/server/views/job_list.erb +58 -0
  21. data/lib/tasks/resque-approve_tasks.rake +6 -0
  22. data/spec/approve/approval_key_list_spec.rb +289 -0
  23. data/spec/approve/cleaner_spec.rb +96 -0
  24. data/spec/approve/pending_job_queue_spec.rb +219 -0
  25. data/spec/approve/pending_job_spec.rb +326 -0
  26. data/spec/approve_spec.rb +188 -0
  27. data/spec/examples.txt +135 -0
  28. data/spec/rails_helper.rb +35 -0
  29. data/spec/server/public/approve.css_spec.rb +18 -0
  30. data/spec/server/views/approval_keys.erb_spec.rb +105 -0
  31. data/spec/server/views/job_details.erb_spec.rb +133 -0
  32. data/spec/server/views/job_list.erb_spec.rb +108 -0
  33. data/spec/spec_helper.rb +101 -0
  34. data/spec/support/config/redis-auth.yml +12 -0
  35. data/spec/support/jobs/01_basic_job.rb +13 -0
  36. data/spec/support/jobs/auto_delete_approval_key_job.rb +5 -0
  37. data/spec/support/purge_all.rb +15 -0
  38. metadata +292 -0
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails_helper"
4
+
5
+ RSpec.describe Resque::Plugins::Approve::Cleaner do
6
+ let!(:key_list) { Resque::Plugins::Approve::ApprovalKeyList.new }
7
+ let!(:keys) { Array.new(3) { Faker::Lorem.sentence } }
8
+ let!(:jobs) do
9
+ keys.map do |approval_key|
10
+ Array.new(3) do
11
+ job = Resque::Plugins::Approve::PendingJob.new(SecureRandom.uuid, class_name: BasicJob, args: [approval_key: approval_key])
12
+
13
+ key_list.add_job(job)
14
+
15
+ job
16
+ end
17
+ end
18
+ end
19
+
20
+ describe "purge_all" do
21
+ it "deletes all jobs" do
22
+ Resque::Plugins::Approve::Cleaner.purge_all
23
+
24
+ jobs.flatten.each do |job|
25
+ expect(Resque::Plugins::Approve::PendingJob.new(job.id).class_name).to be_blank
26
+ end
27
+ end
28
+
29
+ it "deletes all queues" do
30
+ Resque::Plugins::Approve::Cleaner.purge_all
31
+
32
+ keys.each do |approval_key|
33
+ expect(Resque::Plugins::Approve::PendingJobQueue.new(approval_key).num_jobs).to be_zero
34
+ end
35
+ end
36
+
37
+ it "deletes all queue names" do
38
+ Resque::Plugins::Approve::Cleaner.purge_all
39
+
40
+ expect(key_list.num_queues).to be_zero
41
+ end
42
+ end
43
+
44
+ describe "cleanup_jobs" do
45
+ it "re-adds the job to the queue" do
46
+ job = jobs.first.first
47
+
48
+ queue = Resque::Plugins::Approve::PendingJobQueue.new(job.approval_key)
49
+
50
+ queue.remove_job(job)
51
+ expect(queue.num_jobs).to eq 2
52
+ expect(queue.jobs).not_to be_include(job)
53
+
54
+ Resque::Plugins::Approve::Cleaner.cleanup_jobs
55
+
56
+ queue = Resque::Plugins::Approve::PendingJobQueue.new(job.approval_key)
57
+
58
+ expect(queue.num_jobs).to eq 3
59
+ expect(queue.jobs).to be_include(job)
60
+ end
61
+
62
+ it "re-adds the queue to the list" do
63
+ job = jobs.first.first
64
+
65
+ key_list.remove_key(job.approval_key)
66
+
67
+ list = Resque::Plugins::Approve::ApprovalKeyList.new
68
+ expect(list.num_queues).to eq 2
69
+ expect(list.queues.map(&:approval_key)).not_to be_include(job.approval_key)
70
+
71
+ Resque::Plugins::Approve::Cleaner.cleanup_jobs
72
+
73
+ list = Resque::Plugins::Approve::ApprovalKeyList.new
74
+ expect(list.num_queues).to eq 3
75
+ expect(list.queues.map(&:approval_key)).to be_include(job.approval_key)
76
+ end
77
+ end
78
+
79
+ describe "cleanup_queues" do
80
+ it "removes empty queues" do
81
+ job = jobs.first.first
82
+
83
+ jobs.first.each(&:delete)
84
+
85
+ list = Resque::Plugins::Approve::ApprovalKeyList.new
86
+ expect(list.num_queues).to eq 3
87
+ expect(list.queues.map(&:approval_key)).to be_include(job.approval_key)
88
+
89
+ Resque::Plugins::Approve::Cleaner.cleanup_queues
90
+
91
+ list = Resque::Plugins::Approve::ApprovalKeyList.new
92
+ expect(list.num_queues).to eq 2
93
+ expect(list.queues.map(&:approval_key)).not_to be_include(job.approval_key)
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,219 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails_helper"
4
+
5
+ RSpec.describe Resque::Plugins::Approve::PendingJobQueue do
6
+ let(:key_list) { Resque::Plugins::Approve::ApprovalKeyList.new }
7
+ let!(:key) { Faker::Lorem.sentence }
8
+ let(:job_queue) { Resque::Plugins::Approve::PendingJobQueue.new(key) }
9
+ let(:job_class) { BasicJob }
10
+ let!(:jobs) do
11
+ Array.new(4) do |index|
12
+ Timecop.freeze((5 - index).hours.ago) do
13
+ job = Resque::Plugins::Approve::PendingJob.new(SecureRandom.uuid, class_name: job_class, args: [index, approval_key: key])
14
+
15
+ key_list.add_job(job)
16
+
17
+ job
18
+ end
19
+ end
20
+ end
21
+
22
+ before(:each) do
23
+ allow(Resque).to receive(:enqueue_to).and_call_original
24
+ end
25
+
26
+ describe "delete" do
27
+ it "deletes all jobs" do
28
+ job_queue.delete
29
+
30
+ jobs.flatten.each do |job|
31
+ expect(Resque::Plugins::Approve::PendingJob.new(job.id).class_name).to be_blank
32
+ end
33
+ end
34
+
35
+ it "removes all jobs from the queue" do
36
+ job_queue.delete
37
+
38
+ expect(job_queue.num_jobs).to eq 0
39
+ end
40
+
41
+ it "does not remove the key from the key_list" do
42
+ job_queue.delete
43
+
44
+ expect(key_list.queue_keys).to be_include key
45
+ end
46
+
47
+ context("auto-delete") do
48
+ let(:job_class) { AutoDeleteApprovalKeyJob }
49
+
50
+ it "removes the key from the key_list" do
51
+ job_queue.delete
52
+
53
+ expect(key_list.queue_keys).not_to be_include key
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "verify_job" do
59
+ let(:other_key) { Faker::Lorem.sentence }
60
+
61
+ it "adds the queue to the list" do
62
+ job = Resque::Plugins::Approve::PendingJob.new(SecureRandom.uuid, class_name: job_class, args: [approval_key: other_key])
63
+
64
+ job.save!
65
+
66
+ expect(key_list.queue_keys).not_to be_include other_key
67
+
68
+ job_queue.verify_job(job)
69
+
70
+ expect(Resque::Plugins::Approve::ApprovalKeyList.new.queue_keys).to be_include other_key
71
+ end
72
+
73
+ it "adds the job to the list" do
74
+ job = Resque::Plugins::Approve::PendingJob.new(SecureRandom.uuid, class_name: job_class, args: [approval_key: other_key])
75
+
76
+ job.save!
77
+
78
+ expect(job_queue.jobs).not_to be_include job
79
+
80
+ job_queue.verify_job(job)
81
+
82
+ expect(job_queue.jobs).to be_include job
83
+
84
+ expect { job_queue.verify_job(job) }.not_to(change { job_queue.num_jobs })
85
+ end
86
+ end
87
+
88
+ describe "approve_one" do
89
+ it "enqueues the first job" do
90
+ job_queue.approve_one
91
+
92
+ expect(Resque).to have_received(:enqueue_to).with "Some_Queue", BasicJob, 0
93
+ expect(Resque).not_to have_received(:enqueue_to).with "Some_Queue", BasicJob, 1
94
+ expect(Resque).not_to have_received(:enqueue_to).with "Some_Queue", BasicJob, 2
95
+ expect(Resque).not_to have_received(:enqueue_to).with "Some_Queue", BasicJob, 3
96
+
97
+ expect(job_queue.jobs).not_to be_include jobs[0]
98
+ expect(job_queue.num_jobs).to eq 3
99
+ end
100
+ end
101
+
102
+ describe "pop_job" do
103
+ it "enqueues the last job" do
104
+ job_queue.pop_job
105
+
106
+ expect(Resque).to have_received(:enqueue_to).with "Some_Queue", BasicJob, 3
107
+ expect(Resque).not_to have_received(:enqueue_to).with "Some_Queue", BasicJob, 0
108
+ expect(Resque).not_to have_received(:enqueue_to).with "Some_Queue", BasicJob, 1
109
+ expect(Resque).not_to have_received(:enqueue_to).with "Some_Queue", BasicJob, 2
110
+
111
+ expect(job_queue.jobs).not_to be_include jobs[3]
112
+ expect(job_queue.num_jobs).to eq 3
113
+ end
114
+ end
115
+
116
+ describe "approve_all" do
117
+ it "enqueues all jobs" do
118
+ job_queue.approve_all
119
+
120
+ expect(Resque).to have_received(:enqueue_to).with "Some_Queue", BasicJob, 0
121
+ expect(Resque).to have_received(:enqueue_to).with "Some_Queue", BasicJob, 1
122
+ expect(Resque).to have_received(:enqueue_to).with "Some_Queue", BasicJob, 2
123
+ expect(Resque).to have_received(:enqueue_to).with "Some_Queue", BasicJob, 3
124
+
125
+ expect(job_queue.jobs).to be_blank
126
+ end
127
+ end
128
+
129
+ describe "remove_one" do
130
+ it "enqueues the first job" do
131
+ job_queue.remove_one
132
+
133
+ expect(Resque).not_to have_received(:enqueue_to).with "Some_Queue", BasicJob, 0
134
+ expect(Resque).not_to have_received(:enqueue_to).with "Some_Queue", BasicJob, 1
135
+ expect(Resque).not_to have_received(:enqueue_to).with "Some_Queue", BasicJob, 2
136
+ expect(Resque).not_to have_received(:enqueue_to).with "Some_Queue", BasicJob, 3
137
+
138
+ expect(job_queue.jobs).not_to be_include jobs[0]
139
+ expect(job_queue.num_jobs).to eq 3
140
+ end
141
+ end
142
+
143
+ describe "remove_job_pop" do
144
+ it "enqueues the last job" do
145
+ job_queue.remove_job_pop
146
+
147
+ expect(Resque).not_to have_received(:enqueue_to).with "Some_Queue", BasicJob, 3
148
+ expect(Resque).not_to have_received(:enqueue_to).with "Some_Queue", BasicJob, 0
149
+ expect(Resque).not_to have_received(:enqueue_to).with "Some_Queue", BasicJob, 1
150
+ expect(Resque).not_to have_received(:enqueue_to).with "Some_Queue", BasicJob, 2
151
+
152
+ expect(job_queue.jobs).not_to be_include jobs[3]
153
+ expect(job_queue.num_jobs).to eq 3
154
+ end
155
+ end
156
+
157
+ describe "remove_all" do
158
+ it "enqueues all jobs" do
159
+ job_queue.remove_all
160
+
161
+ expect(Resque).not_to have_received(:enqueue_to).with "Some_Queue", BasicJob, 0
162
+ expect(Resque).not_to have_received(:enqueue_to).with "Some_Queue", BasicJob, 1
163
+ expect(Resque).not_to have_received(:enqueue_to).with "Some_Queue", BasicJob, 2
164
+ expect(Resque).not_to have_received(:enqueue_to).with "Some_Queue", BasicJob, 3
165
+
166
+ expect(job_queue.jobs).to be_blank
167
+ end
168
+ end
169
+
170
+ describe "paged_jobs" do
171
+ let!(:jobs) do
172
+ Array.new(30) do |index|
173
+ job = Resque::Plugins::Approve::PendingJob.new(SecureRandom.uuid, class_name: job_class, args: [index, approval_key: key])
174
+
175
+ key_list.add_job(job)
176
+
177
+ job
178
+ end
179
+ end
180
+
181
+ it "defaults to the first 20 jobs" do
182
+ expect(job_queue.paged_jobs).to eq jobs[0..19]
183
+ end
184
+
185
+ it "pages jobs" do
186
+ expect(job_queue.paged_jobs(4, 3)).to eq jobs[9..11]
187
+ end
188
+
189
+ it "deals with too small a page" do
190
+ expect(job_queue.paged_jobs(-4, 3)).to eq jobs[0..2]
191
+ end
192
+
193
+ it "deals with too large a page" do
194
+ expect(job_queue.paged_jobs(400, 3)).to eq jobs[0..2]
195
+ end
196
+
197
+ it "deals with invalid page size" do
198
+ expect(job_queue.paged_jobs(4, 0)).to eq jobs[0..19]
199
+ end
200
+ end
201
+
202
+ describe "num_jobs" do
203
+ it "returns the number of jobs" do
204
+ expect(job_queue.num_jobs).to eq 4
205
+ end
206
+ end
207
+
208
+ describe "first_enqueued" do
209
+ it "returns the time of the first enqueued item" do
210
+ 4.times do |index|
211
+ expect(job_queue.first_enqueued).to be_within(1.second).of((5 - index).hours.ago)
212
+
213
+ job_queue.remove_one
214
+ end
215
+
216
+ expect(job_queue.first_enqueued).to be_nil
217
+ end
218
+ end
219
+ end
@@ -0,0 +1,326 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails_helper"
4
+
5
+ # rubocop:disable Layout/AlignHash
6
+ RSpec.describe Resque::Plugins::Approve::PendingJob do
7
+ let(:key_list) { Resque::Plugins::Approve::ApprovalKeyList.new }
8
+ let!(:key) { Faker::Lorem.sentence }
9
+ let(:job_queue) { Resque::Plugins::Approve::PendingJobQueue.new(key) }
10
+ let(:job_class) { BasicJob }
11
+ let(:no_args_job) do
12
+ job = Resque::Plugins::Approve::PendingJob.new(SecureRandom.uuid, class_name: job_class, args: nil)
13
+
14
+ key_list.add_job(job)
15
+
16
+ job
17
+ end
18
+ let(:no_hash_args_job) do
19
+ job = Resque::Plugins::Approve::PendingJob.new(SecureRandom.uuid, class_name: job_class, args: [1, "fred", "something else", 888])
20
+
21
+ key_list.add_job(job)
22
+
23
+ job
24
+ end
25
+ let(:hash_args_job) do
26
+ job = Resque::Plugins::Approve::PendingJob.new(SecureRandom.uuid,
27
+ class_name: job_class,
28
+ args: [1, "fred", "something else", 888, other_arg: 1, "something else" => "something"])
29
+
30
+ key_list.add_job(job)
31
+
32
+ job
33
+ end
34
+ let(:approval_only_args_job) do
35
+ job = Resque::Plugins::Approve::PendingJob.new(SecureRandom.uuid, class_name: job_class, args: [approval_key: key])
36
+
37
+ key_list.add_job(job)
38
+
39
+ job
40
+ end
41
+ let(:approval_no_hash_args_job) do
42
+ job = Resque::Plugins::Approve::PendingJob.new(SecureRandom.uuid,
43
+ class_name: job_class,
44
+ args: [1, "fred", "something else", 888, approval_key: key])
45
+
46
+ key_list.add_job(job)
47
+
48
+ job
49
+ end
50
+ let(:approval_hash_args_job) do
51
+ job = Resque::Plugins::Approve::PendingJob.new(SecureRandom.uuid,
52
+ class_name: job_class,
53
+ args: [1,
54
+ "fred",
55
+ "something else",
56
+ 888,
57
+ other_arg: 1,
58
+ "approval_key" => key,
59
+ "something else" => "something"])
60
+
61
+ key_list.add_job(job)
62
+
63
+ job
64
+ end
65
+ let(:approval_all_args_job) do
66
+ job = Resque::Plugins::Approve::PendingJob.new(SecureRandom.uuid,
67
+ class_name: job_class,
68
+ args: [1,
69
+ "fred",
70
+ "something else",
71
+ 888,
72
+ approval_queue: "Another Queue",
73
+ approval_at: 2.hours.from_now,
74
+ other_arg: 1,
75
+ "approval_key" => key,
76
+ "something else" => "something"])
77
+
78
+ key_list.add_job(job)
79
+
80
+ job
81
+ end
82
+
83
+ before(:each) do
84
+ allow(Resque).to receive(:enqueue_to).and_call_original
85
+ end
86
+
87
+ describe "initialize" do
88
+ it "extracts delay arguments from job with no argument" do
89
+ expect(no_args_job.args).to eq []
90
+ expect(no_args_job.approve_options).to eq({}.with_indifferent_access)
91
+ end
92
+
93
+ it "extracts delay arguments from job with no hash arguments" do
94
+ expect(no_hash_args_job.args).to eq [1, "fred", "something else", 888]
95
+ expect(no_hash_args_job.approve_options).to eq({}.with_indifferent_access)
96
+ end
97
+
98
+ it "extracts delay arguments from job with no approval arguments" do
99
+ expect(hash_args_job.args).to eq [1, "fred", "something else", 888, "other_arg" => 1, "something else" => "something"]
100
+ expect(hash_args_job.approve_options).to eq({}.with_indifferent_access)
101
+ end
102
+
103
+ it "extracts delay arguments from job with no argument and approval_args" do
104
+ expect(approval_only_args_job.args).to eq []
105
+ expect(approval_only_args_job.approve_options).to eq("approval_key" => key)
106
+ end
107
+
108
+ it "extracts delay arguments from job with no hash arguments and approval args" do
109
+ expect(approval_no_hash_args_job.args).to eq [1, "fred", "something else", 888]
110
+ expect(approval_no_hash_args_job.approve_options).to eq("approval_key" => key)
111
+ end
112
+
113
+ it "extracts delay arguments from job with no approval arguments and approval args" do
114
+ expect(approval_hash_args_job.args).to eq [1, "fred", "something else", 888, "other_arg" => 1, "something else" => "something"]
115
+ expect(approval_hash_args_job.approve_options).to eq("approval_key" => key)
116
+ end
117
+
118
+ it "extracts all delay arguments from job with no approval arguments and approval args" do
119
+ expect(approval_all_args_job.args).to eq [1, "fred", "something else", 888, "other_arg" => 1, "something else" => "something"]
120
+
121
+ expect(approval_all_args_job.approve_options[:approval_key]).to eq key
122
+ expect(approval_all_args_job.approve_options["approval_key"]).to eq key
123
+
124
+ expect(approval_all_args_job.approve_options[:approval_queue]).to eq "Another Queue"
125
+ expect(approval_all_args_job.approve_options["approval_queue"]).to eq "Another Queue"
126
+
127
+ expect(approval_all_args_job.approve_options[:approval_at]).to be_within(2.seconds).of(2.hours.from_now)
128
+ expect(approval_all_args_job.approve_options["approval_at"]).to be_within(2.seconds).of(2.hours.from_now)
129
+ end
130
+ end
131
+
132
+ describe "<=>" do
133
+ let(:a_job) { Resque::Plugins::Approve::PendingJob.new("A") }
134
+ let(:a_job_too) { Resque::Plugins::Approve::PendingJob.new("A") }
135
+ let(:b_job) { Resque::Plugins::Approve::PendingJob.new("B") }
136
+
137
+ it "compares two jobs" do
138
+ expect(no_hash_args_job).not_to eq no_args_job
139
+ expect(no_hash_args_job).to eq Resque::Plugins::Approve::PendingJob.new(no_hash_args_job.id)
140
+ end
141
+
142
+ it "compares <" do
143
+ expect(a_job).to be < b_job
144
+ end
145
+
146
+ it "compares >" do
147
+ expect(b_job).to be > a_job
148
+ end
149
+
150
+ it "compares <=" do
151
+ expect(a_job).to be <= b_job
152
+ expect(a_job).to be <= a_job_too
153
+ end
154
+
155
+ it "compares >=" do
156
+ expect(b_job).to be >= a_job
157
+ expect(a_job).to be >= a_job
158
+ end
159
+ end
160
+
161
+ RSpec.shared_examples "pending job attributes" do
162
+ it "has a class_name" do
163
+ expect(job.class_name).to eq "BasicJob"
164
+ end
165
+
166
+ it "has args" do
167
+ expect(job.args).to eq [1, "fred", "something else", 888, "other_arg" => 1, "something else" => "something"]
168
+ end
169
+
170
+ it "has the approval_key" do
171
+ expect(job.approval_key).to eq key
172
+ end
173
+
174
+ it "has the approval_queue" do
175
+ expect(job.approval_queue).to eq "Another Queue"
176
+ end
177
+
178
+ it "has the approval_at" do
179
+ expect(job.approval_at).to be_within(1.second).of(2.hours.from_now)
180
+ end
181
+
182
+ it "has the queue_time" do
183
+ expect(job.queue_time).to be_within(1.second).of(2.hours.ago)
184
+ end
185
+
186
+ it "has the queue" do
187
+ expect(job.queue.approval_key).to eq key
188
+ end
189
+ end
190
+
191
+ describe "initialized object" do
192
+ let(:job) { approval_all_args_job }
193
+
194
+ before(:each) do
195
+ job
196
+
197
+ Timecop.freeze(2.hours.ago) do
198
+ job.save!
199
+ end
200
+ end
201
+
202
+ it_behaves_like "pending job attributes"
203
+ end
204
+
205
+ describe "saved object" do
206
+ let(:job) { Resque::Plugins::Approve::PendingJob.new(approval_all_args_job.id) }
207
+
208
+ before(:each) do
209
+ approval_all_args_job
210
+
211
+ Timecop.freeze(2.hours.ago) do
212
+ approval_all_args_job.save!
213
+ end
214
+ end
215
+
216
+ it_behaves_like "pending job attributes"
217
+ end
218
+
219
+ describe "approval_queue" do
220
+ it "returns the classes default queue" do
221
+ expect(no_args_job.approval_queue).to eq "Some_Queue"
222
+ end
223
+ end
224
+
225
+ describe "requires_approval?" do
226
+ it "requires_approval only if approval_key is set" do
227
+ expect(no_args_job).not_to be_requires_approval
228
+ expect(no_hash_args_job).not_to be_requires_approval
229
+ expect(hash_args_job).not_to be_requires_approval
230
+ expect(approval_only_args_job).to be_requires_approval
231
+ expect(approval_no_hash_args_job).to be_requires_approval
232
+ expect(approval_hash_args_job).to be_requires_approval
233
+ expect(approval_all_args_job).to be_requires_approval
234
+
235
+ job = Resque::Plugins::Approve::PendingJob.new(SecureRandom.uuid,
236
+ class_name: job_class,
237
+ args: [1,
238
+ "fred",
239
+ "something else",
240
+ 888,
241
+ approval_queue: "Another Queue",
242
+ approval_at: 2.hours.from_now,
243
+ other_arg: 1,
244
+ "something else" => "something"])
245
+
246
+ expect(job).not_to be_requires_approval
247
+ end
248
+ end
249
+
250
+ describe "enqueue_job" do
251
+ it "enqueues the job without any parameters" do
252
+ no_args_job.enqueue_job
253
+
254
+ expect(Resque).to have_received(:enqueue_to).with("Some_Queue", BasicJob)
255
+ end
256
+
257
+ it "enqueues the job without any parameters" do
258
+ key_list.add_job(no_args_job)
259
+
260
+ no_args_job.enqueue_job
261
+ end
262
+
263
+ it "delay enqueues a job" do
264
+ allow(Resque).to receive(:enqueue_at_with_queue).and_call_original
265
+
266
+ Timecop.freeze do
267
+ approval_all_args_job.enqueue_job
268
+
269
+ expect(Resque).
270
+ to have_received(:enqueue_at_with_queue).
271
+ with("Another Queue",
272
+ 2.hours.from_now,
273
+ BasicJob,
274
+ 1,
275
+ "fred",
276
+ "something else",
277
+ 888,
278
+ "other_arg" => 1,
279
+ "something else" => "something")
280
+ end
281
+ end
282
+ end
283
+
284
+ describe "delete" do
285
+ it "works with an already deleted job" do
286
+ no_args_job.delete
287
+
288
+ expect { Resque::Plugins::Approve::PendingJob.new(no_args_job.id).delete }.not_to raise_exception
289
+ end
290
+
291
+ it "deletes the job" do
292
+ no_args_job.delete
293
+
294
+ expect(Resque::Plugins::Approve::PendingJob.new(no_args_job.id).class_name).not_to be
295
+ end
296
+
297
+ it "removes the job from the queue" do
298
+ no_args_job.delete
299
+
300
+ expect(Resque::Plugins::Approve::PendingJobQueue.new(key).num_jobs).to be_zero
301
+ end
302
+
303
+ it "does not remoe the queue" do
304
+ no_args_job.delete
305
+
306
+ expect(key_list.num_queues).to eq 1
307
+ end
308
+
309
+ it "does delete the queue if the class says to" do
310
+ job = Resque::Plugins::Approve::PendingJob.new SecureRandom.uuid,
311
+ class_name: AutoDeleteApprovalKeyJob,
312
+ args: [approval_key: key]
313
+
314
+ key_list.add_job(job)
315
+
316
+ expect(Resque::Plugins::Approve::ApprovalKeyList.new.num_queues).to eq 1
317
+ expect(Resque::Plugins::Approve::PendingJobQueue.new(key).num_jobs).to eq 1
318
+
319
+ job.delete
320
+
321
+ expect(Resque::Plugins::Approve::PendingJobQueue.new(key).num_jobs).to eq 0
322
+ expect(Resque::Plugins::Approve::ApprovalKeyList.new.num_queues).to eq 0
323
+ end
324
+ end
325
+ end
326
+ # rubocop:enable Layout/AlignHash