resque-approve 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,188 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails_helper"
4
+
5
+ RSpec.describe Resque::Plugins::Approve do
6
+ let(:job) { BasicJob }
7
+ let(:approval_key) { "approval key #{Faker::Lorem.sentence}" }
8
+ let(:test_args_without_hash) do
9
+ rand_args = []
10
+ rand_args << Faker::Lorem.sentence
11
+ rand_args << Faker::Lorem.paragraph
12
+ rand_args << SecureRandom.uuid.to_s
13
+ rand_args << rand(0..1_000_000_000_000_000_000_000_000).to_s
14
+ rand_args << rand(0..1_000_000_000_000).seconds.ago.to_s
15
+ rand_args << rand(0..1_000_000_000_000).seconds.from_now.to_s
16
+ rand_args << Array.new(rand(1..5)) { Faker::Lorem.word }
17
+
18
+ rand_args.sample(rand(3..rand_args.length))
19
+ end
20
+ let(:test_args_with_hash) do
21
+ rand_args = []
22
+ rand_args << Faker::Lorem.sentence
23
+ rand_args << Faker::Lorem.paragraph
24
+ rand_args << SecureRandom.uuid.to_s
25
+ rand_args << rand(0..1_000_000_000_000_000_000_000_000).to_s
26
+ rand_args << rand(0..1_000_000_000_000).seconds.ago.to_s
27
+ rand_args << rand(0..1_000_000_000_000).seconds.from_now.to_s
28
+ rand_args << Array.new(rand(1..5)) { Faker::Lorem.word }
29
+ rand_args << Array.new(rand(1..5)).each_with_object({}) do |_nil_value, sub_hash|
30
+ sub_hash[Faker::Lorem.word] = Faker::Lorem.word
31
+ end
32
+
33
+ rand_args = rand_args.sample(rand(3..rand_args.length))
34
+
35
+ options_hash = {}
36
+ options_hash[Faker::Lorem.word] = Faker::Lorem.sentence
37
+ options_hash[Faker::Lorem.word] = Faker::Lorem.paragraph
38
+ options_hash[Faker::Lorem.word] = SecureRandom.uuid.to_s
39
+ options_hash[Faker::Lorem.word] = rand(0..1_000_000_000_000_000_000_000_000).to_s
40
+ options_hash[Faker::Lorem.word] = rand(0..1_000_000_000_000).seconds.ago.to_s
41
+ options_hash[Faker::Lorem.word] = rand(0..1_000_000_000_000).seconds.from_now.to_s
42
+ options_hash[Faker::Lorem.word] = Array.new(rand(1..5)) { Faker::Lorem.word }
43
+ options_hash[Faker::Lorem.word] = Array.new(rand(1..5)).
44
+ each_with_object({}) do |_nil_value, sub_hash|
45
+ sub_hash[Faker::Lorem.word] = Faker::Lorem.word
46
+ end
47
+
48
+ rand_args << options_hash.slice(*options_hash.keys.sample(rand(5..options_hash.keys.length)))
49
+
50
+ rand_args
51
+ end
52
+ let(:test_args_without_hash_approve) do
53
+ [*test_args_without_hash, approval_key: approval_key]
54
+ end
55
+ let(:test_args_with_hash_approve) do
56
+ test_args = test_args_with_hash.dup
57
+ test_args << test_args.pop.merge(approval_key: approval_key)
58
+
59
+ test_args
60
+ end
61
+
62
+ before(:each) do
63
+ allow(BasicJob).to receive(:perform)
64
+ end
65
+
66
+ it "has auto_delete_approval_key" do
67
+ expect(BasicJob.auto_delete_approval_key).to be_falsey
68
+ end
69
+
70
+ it "does not delay jobs that are enqueued without delay args" do
71
+ Resque.enqueue BasicJob, *test_args_with_hash
72
+
73
+ expect(BasicJob).to have_received(:perform).with(*test_args_with_hash)
74
+ end
75
+
76
+ it "does not delay jobs that are enqueued without delay args no options" do
77
+ Resque.enqueue BasicJob, *test_args_without_hash
78
+
79
+ expect(BasicJob).to have_received(:perform).with(*test_args_without_hash)
80
+ end
81
+
82
+ it "delays jobs that are enqueued with the delay args" do
83
+ Resque.enqueue BasicJob, *test_args_with_hash_approve
84
+
85
+ expect(BasicJob).not_to have_received(:perform)
86
+ end
87
+
88
+ it "delays jobs that are enqueued with the delay args that did not have other options" do
89
+ Resque.enqueue BasicJob, *test_args_without_hash_approve
90
+
91
+ expect(BasicJob).not_to have_received(:perform)
92
+ end
93
+
94
+ context "end-to-end testing" do
95
+ let(:job_order) { [0, 1].sample(100) }
96
+ let(:approve_jobs) { [test_args_without_hash_approve, test_args_with_hash_approve] }
97
+ let(:param_jobs) { [test_args_without_hash, test_args_with_hash] }
98
+ let(:jobs) { [approve_jobs[job_order.first], approve_jobs[job_order.last]] }
99
+
100
+ it "does not release a job for the wrong key" do
101
+ jobs.each { |job_args| Resque.enqueue BasicJob, *job_args }
102
+
103
+ expect(BasicJob).not_to have_received(:perform)
104
+
105
+ Resque::Plugins::Approve.approve "any key"
106
+
107
+ expect(BasicJob).not_to have_received(:perform)
108
+ end
109
+
110
+ it "releases one job" do
111
+ jobs.each do |job_args|
112
+ Resque.enqueue BasicJob, *job_args
113
+ end
114
+
115
+ expect(BasicJob).not_to have_received(:perform)
116
+
117
+ Resque::Plugins::Approve.approve_one approval_key
118
+
119
+ expect(BasicJob).to have_received(:perform).with(*param_jobs[job_order.first])
120
+ expect(BasicJob).not_to have_received(:perform).with(*param_jobs[job_order.last])
121
+ end
122
+
123
+ it "releases all jobs" do
124
+ jobs.each { |job_args| Resque.enqueue BasicJob, *job_args }
125
+
126
+ expect(BasicJob).not_to have_received(:perform)
127
+
128
+ Resque::Plugins::Approve.approve approval_key
129
+
130
+ expect(BasicJob).to have_received(:perform).with(*param_jobs[job_order.first])
131
+ expect(BasicJob).to have_received(:perform).with(*param_jobs[job_order.last])
132
+ end
133
+
134
+ it "deletes all jobs" do
135
+ jobs.each { |job_args| Resque.enqueue BasicJob, *job_args }
136
+
137
+ expect(BasicJob).not_to have_received(:perform)
138
+ expect(Resque::Plugins::Approve::PendingJobQueue.new(approval_key).num_jobs).to eq 2
139
+
140
+ Resque::Plugins::Approve.remove approval_key
141
+
142
+ expect(BasicJob).not_to have_received(:perform)
143
+ expect(Resque::Plugins::Approve::PendingJobQueue.new(approval_key).num_jobs).to be_zero
144
+ end
145
+
146
+ it "deletes one job" do
147
+ jobs.each { |job_args| Resque.enqueue BasicJob, *job_args }
148
+
149
+ expect(BasicJob).not_to have_received(:perform)
150
+ expect(Resque::Plugins::Approve::PendingJobQueue.new(approval_key).num_jobs).to eq 2
151
+
152
+ Resque::Plugins::Approve.remove_one approval_key
153
+
154
+ expect(BasicJob).not_to have_received(:perform)
155
+ expect(Resque::Plugins::Approve::PendingJobQueue.new(approval_key).num_jobs).to eq 1
156
+ end
157
+ end
158
+
159
+ describe "before_perform_approve" do
160
+ it "returns true if the job is not to be approved" do
161
+ expect(BasicJob.before_perform_approve(*test_args_without_hash)).to be_truthy
162
+ expect { BasicJob.before_perform_approve(*test_args_without_hash) }.not_to(change { test_args_without_hash })
163
+ expect(BasicJob.before_perform_approve(*test_args_with_hash)).to be_truthy
164
+ expect { BasicJob.before_perform_approve(*test_args_with_hash) }.not_to(change { test_args_with_hash })
165
+ end
166
+
167
+ it "raises Resque::Job::DontPerform if it is to be approved" do
168
+ expect { BasicJob.before_perform_approve(*test_args_without_hash_approve) }.to raise_exception(Resque::Job::DontPerform)
169
+ expect { BasicJob.before_perform_approve(*test_args_with_hash_approve) }.to raise_exception(Resque::Job::DontPerform)
170
+ end
171
+ end
172
+
173
+ describe "before_enqueue_approve" do
174
+ it "returns true if the job is not to be approved" do
175
+ expect(BasicJob.before_enqueue_approve(*test_args_without_hash)).to be_truthy
176
+ expect { BasicJob.before_enqueue_approve(*test_args_without_hash) }.not_to(change { test_args_without_hash })
177
+ expect(BasicJob.before_enqueue_approve(*test_args_with_hash)).to be_truthy
178
+ expect { BasicJob.before_enqueue_approve(*test_args_with_hash) }.not_to(change { test_args_with_hash })
179
+ end
180
+
181
+ it "raises Resque::Job::DontPerform if it is to be approved" do
182
+ expect(BasicJob.before_enqueue_approve(*test_args_without_hash_approve)).to be_falsey
183
+ expect { BasicJob.before_enqueue_approve(*test_args_without_hash_approve) }.not_to(change { test_args_without_hash })
184
+ expect(BasicJob.before_enqueue_approve(*test_args_with_hash_approve)).to be_falsey
185
+ expect { BasicJob.before_enqueue_approve(*test_args_with_hash_approve) }.not_to(change { test_args_with_hash })
186
+ end
187
+ end
188
+ end
@@ -0,0 +1,135 @@
1
+ example_id | status | run_time |
2
+ ---------------------------------------------------- | ------ | --------------- |
3
+ ./spec/approve/approval_key_list_spec.rb[1:1:1] | passed | 0.00255 seconds |
4
+ ./spec/approve/approval_key_list_spec.rb[1:1:2] | passed | 0.00225 seconds |
5
+ ./spec/approve/approval_key_list_spec.rb[1:1:3] | passed | 0.00245 seconds |
6
+ ./spec/approve/approval_key_list_spec.rb[1:2:1] | passed | 0.00511 seconds |
7
+ ./spec/approve/approval_key_list_spec.rb[1:2:2] | passed | 0.01015 seconds |
8
+ ./spec/approve/approval_key_list_spec.rb[1:3:1] | passed | 0.00557 seconds |
9
+ ./spec/approve/approval_key_list_spec.rb[1:3:2] | passed | 0.00402 seconds |
10
+ ./spec/approve/approval_key_list_spec.rb[1:4:1] | passed | 0.01031 seconds |
11
+ ./spec/approve/approval_key_list_spec.rb[1:4:2] | passed | 0.01061 seconds |
12
+ ./spec/approve/approval_key_list_spec.rb[1:4:3] | passed | 0.00683 seconds |
13
+ ./spec/approve/approval_key_list_spec.rb[1:5:1] | passed | 0.03674 seconds |
14
+ ./spec/approve/approval_key_list_spec.rb[1:5:2] | passed | 0.04074 seconds |
15
+ ./spec/approve/approval_key_list_spec.rb[1:5:3] | passed | 0.03426 seconds |
16
+ ./spec/approve/approval_key_list_spec.rb[1:6:1] | passed | 0.04122 seconds |
17
+ ./spec/approve/approval_key_list_spec.rb[1:6:2] | passed | 0.03381 seconds |
18
+ ./spec/approve/approval_key_list_spec.rb[1:6:3] | passed | 0.02892 seconds |
19
+ ./spec/approve/approval_key_list_spec.rb[1:7:1:1:1] | passed | 0.40579 seconds |
20
+ ./spec/approve/approval_key_list_spec.rb[1:7:1:1:2] | passed | 0.36629 seconds |
21
+ ./spec/approve/approval_key_list_spec.rb[1:7:1:1:3] | passed | 0.39571 seconds |
22
+ ./spec/approve/approval_key_list_spec.rb[1:7:1:1:4] | passed | 0.35925 seconds |
23
+ ./spec/approve/approval_key_list_spec.rb[1:7:1:1:5] | passed | 0.36585 seconds |
24
+ ./spec/approve/approval_key_list_spec.rb[1:7:1:1:6] | passed | 0.37009 seconds |
25
+ ./spec/approve/approval_key_list_spec.rb[1:7:1:1:7] | passed | 0.39149 seconds |
26
+ ./spec/approve/approval_key_list_spec.rb[1:7:2:1:1] | passed | 0.37861 seconds |
27
+ ./spec/approve/approval_key_list_spec.rb[1:7:2:1:2] | passed | 0.35771 seconds |
28
+ ./spec/approve/approval_key_list_spec.rb[1:7:2:1:3] | passed | 0.37499 seconds |
29
+ ./spec/approve/approval_key_list_spec.rb[1:7:2:1:4] | passed | 0.39712 seconds |
30
+ ./spec/approve/approval_key_list_spec.rb[1:7:2:1:5] | passed | 0.36924 seconds |
31
+ ./spec/approve/approval_key_list_spec.rb[1:7:2:1:6] | passed | 0.37372 seconds |
32
+ ./spec/approve/approval_key_list_spec.rb[1:7:2:1:7] | passed | 0.38063 seconds |
33
+ ./spec/approve/approval_key_list_spec.rb[1:7:3:1:1] | passed | 0.43381 seconds |
34
+ ./spec/approve/approval_key_list_spec.rb[1:7:3:1:2] | passed | 0.37502 seconds |
35
+ ./spec/approve/approval_key_list_spec.rb[1:7:3:1:3] | passed | 0.39405 seconds |
36
+ ./spec/approve/approval_key_list_spec.rb[1:7:3:1:4] | passed | 0.51229 seconds |
37
+ ./spec/approve/approval_key_list_spec.rb[1:7:3:1:5] | passed | 0.37889 seconds |
38
+ ./spec/approve/approval_key_list_spec.rb[1:7:3:1:6] | passed | 0.37424 seconds |
39
+ ./spec/approve/approval_key_list_spec.rb[1:7:3:1:7] | passed | 0.37768 seconds |
40
+ ./spec/approve/approval_key_list_spec.rb[1:8:1] | passed | 0.05366 seconds |
41
+ ./spec/approve/approval_key_list_spec.rb[1:9:1] | passed | 0.04847 seconds |
42
+ ./spec/approve/cleaner_spec.rb[1:1:1] | passed | 0.02613 seconds |
43
+ ./spec/approve/cleaner_spec.rb[1:1:2] | passed | 0.01501 seconds |
44
+ ./spec/approve/cleaner_spec.rb[1:1:3] | passed | 0.0197 seconds |
45
+ ./spec/approve/cleaner_spec.rb[1:2:1] | passed | 0.02788 seconds |
46
+ ./spec/approve/cleaner_spec.rb[1:2:2] | passed | 0.03141 seconds |
47
+ ./spec/approve/cleaner_spec.rb[1:3:1] | passed | 0.02216 seconds |
48
+ ./spec/approve/pending_job_queue_spec.rb[1:1:1] | passed | 0.01294 seconds |
49
+ ./spec/approve/pending_job_queue_spec.rb[1:1:2] | passed | 0.0205 seconds |
50
+ ./spec/approve/pending_job_queue_spec.rb[1:1:3] | passed | 0.02482 seconds |
51
+ ./spec/approve/pending_job_queue_spec.rb[1:1:4:1] | passed | 0.02537 seconds |
52
+ ./spec/approve/pending_job_queue_spec.rb[1:2:1] | passed | 0.0162 seconds |
53
+ ./spec/approve/pending_job_queue_spec.rb[1:2:2] | passed | 0.01656 seconds |
54
+ ./spec/approve/pending_job_queue_spec.rb[1:3:1] | passed | 0.01922 seconds |
55
+ ./spec/approve/pending_job_queue_spec.rb[1:4:1] | passed | 0.01837 seconds |
56
+ ./spec/approve/pending_job_queue_spec.rb[1:5:1] | passed | 0.01748 seconds |
57
+ ./spec/approve/pending_job_queue_spec.rb[1:6:1] | passed | 0.01392 seconds |
58
+ ./spec/approve/pending_job_queue_spec.rb[1:7:1] | passed | 0.01642 seconds |
59
+ ./spec/approve/pending_job_queue_spec.rb[1:8:1] | passed | 0.0129 seconds |
60
+ ./spec/approve/pending_job_queue_spec.rb[1:9:1] | passed | 0.05695 seconds |
61
+ ./spec/approve/pending_job_queue_spec.rb[1:9:2] | passed | 0.04944 seconds |
62
+ ./spec/approve/pending_job_queue_spec.rb[1:9:3] | passed | 0.06517 seconds |
63
+ ./spec/approve/pending_job_queue_spec.rb[1:9:4] | passed | 0.0584 seconds |
64
+ ./spec/approve/pending_job_queue_spec.rb[1:9:5] | passed | 0.06542 seconds |
65
+ ./spec/approve/pending_job_queue_spec.rb[1:10:1] | passed | 0.01361 seconds |
66
+ ./spec/approve/pending_job_queue_spec.rb[1:11:1] | passed | 0.02146 seconds |
67
+ ./spec/approve/pending_job_spec.rb[1:1:1] | passed | 0.00433 seconds |
68
+ ./spec/approve/pending_job_spec.rb[1:1:2] | passed | 0.00373 seconds |
69
+ ./spec/approve/pending_job_spec.rb[1:1:3] | passed | 0.0051 seconds |
70
+ ./spec/approve/pending_job_spec.rb[1:1:4] | passed | 0.00605 seconds |
71
+ ./spec/approve/pending_job_spec.rb[1:1:5] | passed | 0.00347 seconds |
72
+ ./spec/approve/pending_job_spec.rb[1:1:6] | passed | 0.00661 seconds |
73
+ ./spec/approve/pending_job_spec.rb[1:1:7] | passed | 0.00352 seconds |
74
+ ./spec/approve/pending_job_spec.rb[1:2:1] | passed | 0.00653 seconds |
75
+ ./spec/approve/pending_job_spec.rb[1:2:2] | passed | 0.00442 seconds |
76
+ ./spec/approve/pending_job_spec.rb[1:2:3] | passed | 0.00445 seconds |
77
+ ./spec/approve/pending_job_spec.rb[1:2:4] | passed | 0.00272 seconds |
78
+ ./spec/approve/pending_job_spec.rb[1:2:5] | passed | 0.004 seconds |
79
+ ./spec/approve/pending_job_spec.rb[1:3:1:1] | passed | 0.00519 seconds |
80
+ ./spec/approve/pending_job_spec.rb[1:3:1:2] | passed | 0.00627 seconds |
81
+ ./spec/approve/pending_job_spec.rb[1:3:1:3] | passed | 0.00455 seconds |
82
+ ./spec/approve/pending_job_spec.rb[1:3:1:4] | passed | 0.00915 seconds |
83
+ ./spec/approve/pending_job_spec.rb[1:3:1:5] | passed | 0.00655 seconds |
84
+ ./spec/approve/pending_job_spec.rb[1:3:1:6] | passed | 0.0164 seconds |
85
+ ./spec/approve/pending_job_spec.rb[1:3:1:7] | passed | 0.0036 seconds |
86
+ ./spec/approve/pending_job_spec.rb[1:4:1:1] | passed | 0.0096 seconds |
87
+ ./spec/approve/pending_job_spec.rb[1:4:1:2] | passed | 0.00483 seconds |
88
+ ./spec/approve/pending_job_spec.rb[1:4:1:3] | passed | 0.00662 seconds |
89
+ ./spec/approve/pending_job_spec.rb[1:4:1:4] | passed | 0.00928 seconds |
90
+ ./spec/approve/pending_job_spec.rb[1:4:1:5] | passed | 0.00709 seconds |
91
+ ./spec/approve/pending_job_spec.rb[1:4:1:6] | passed | 0.00762 seconds |
92
+ ./spec/approve/pending_job_spec.rb[1:4:1:7] | passed | 0.00811 seconds |
93
+ ./spec/approve/pending_job_spec.rb[1:5:1] | passed | 0.00464 seconds |
94
+ ./spec/approve/pending_job_spec.rb[1:6:1] | passed | 0.0119 seconds |
95
+ ./spec/approve/pending_job_spec.rb[1:7:1] | passed | 0.00542 seconds |
96
+ ./spec/approve/pending_job_spec.rb[1:7:2] | passed | 0.00556 seconds |
97
+ ./spec/approve/pending_job_spec.rb[1:7:3] | passed | 0.00494 seconds |
98
+ ./spec/approve/pending_job_spec.rb[1:8:1] | passed | 0.0057 seconds |
99
+ ./spec/approve/pending_job_spec.rb[1:8:2] | passed | 0.00698 seconds |
100
+ ./spec/approve/pending_job_spec.rb[1:8:3] | passed | 0.00619 seconds |
101
+ ./spec/approve/pending_job_spec.rb[1:8:4] | passed | 0.00412 seconds |
102
+ ./spec/approve/pending_job_spec.rb[1:8:5] | passed | 0.00897 seconds |
103
+ ./spec/approve_spec.rb[1:1] | passed | 0.01388 seconds |
104
+ ./spec/approve_spec.rb[1:2] | passed | 0.00621 seconds |
105
+ ./spec/approve_spec.rb[1:3] | passed | 0.00746 seconds |
106
+ ./spec/approve_spec.rb[1:4] | passed | 0.48466 seconds |
107
+ ./spec/approve_spec.rb[1:5] | passed | 0.00489 seconds |
108
+ ./spec/approve_spec.rb[1:6:1] | passed | 0.01283 seconds |
109
+ ./spec/approve_spec.rb[1:6:2] | passed | 0.01226 seconds |
110
+ ./spec/approve_spec.rb[1:6:3] | passed | 0.00968 seconds |
111
+ ./spec/approve_spec.rb[1:6:4] | passed | 0.01214 seconds |
112
+ ./spec/approve_spec.rb[1:6:5] | passed | 0.01086 seconds |
113
+ ./spec/approve_spec.rb[1:7:1] | passed | 0.00619 seconds |
114
+ ./spec/approve_spec.rb[1:7:2] | passed | 0.01295 seconds |
115
+ ./spec/approve_spec.rb[1:8:1] | passed | 0.00699 seconds |
116
+ ./spec/approve_spec.rb[1:8:2] | passed | 0.0144 seconds |
117
+ ./spec/server/public/approve.css_spec.rb[1:1] | passed | 0.04261 seconds |
118
+ ./spec/server/views/approval_keys.erb_spec.rb[1:1:1] | passed | 0.02506 seconds |
119
+ ./spec/server/views/approval_keys.erb_spec.rb[1:1:2] | passed | 0.02492 seconds |
120
+ ./spec/server/views/approval_keys.erb_spec.rb[1:1:3] | passed | 0.03236 seconds |
121
+ ./spec/server/views/approval_keys.erb_spec.rb[1:1:4] | passed | 0.02806 seconds |
122
+ ./spec/server/views/approval_keys.erb_spec.rb[1:2] | passed | 0.04456 seconds |
123
+ ./spec/server/views/approval_keys.erb_spec.rb[1:3] | passed | 0.0421 seconds |
124
+ ./spec/server/views/job_details.erb_spec.rb[1:1] | passed | 0.01158 seconds |
125
+ ./spec/server/views/job_details.erb_spec.rb[1:2] | passed | 0.01316 seconds |
126
+ ./spec/server/views/job_details.erb_spec.rb[1:3] | passed | 0.02037 seconds |
127
+ ./spec/server/views/job_details.erb_spec.rb[1:4] | passed | 0.01779 seconds |
128
+ ./spec/server/views/job_details.erb_spec.rb[1:5] | passed | 0.02131 seconds |
129
+ ./spec/server/views/job_details.erb_spec.rb[1:6] | passed | 0.02355 seconds |
130
+ ./spec/server/views/job_list.erb_spec.rb[1:1:1] | passed | 0.02346 seconds |
131
+ ./spec/server/views/job_list.erb_spec.rb[1:1:2] | passed | 0.02557 seconds |
132
+ ./spec/server/views/job_list.erb_spec.rb[1:1:3] | passed | 0.03454 seconds |
133
+ ./spec/server/views/job_list.erb_spec.rb[1:1:4] | passed | 0.03607 seconds |
134
+ ./spec/server/views/job_list.erb_spec.rb[1:2] | passed | 0.04666 seconds |
135
+ ./spec/server/views/job_list.erb_spec.rb[1:3] | passed | 0.03115 seconds |
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "simplecov"
4
+ SimpleCov.start
5
+
6
+ require "spec_helper"
7
+ require "cornucopia/rspec_hooks"
8
+ require "resque-approve"
9
+ require "yaml"
10
+ require "timecop"
11
+ require "faker"
12
+ require "rack/test"
13
+ require "resque/server"
14
+ require "resque/approve_server"
15
+ require "resque-scheduler"
16
+
17
+ Dir[File.expand_path("spec/support/**/*.rb"), File.dirname(__FILE__)].sort.each do |f|
18
+ require f unless File.directory?(f)
19
+ end
20
+
21
+ FileUtils.mkdir_p(File.expand_path("../log", File.dirname(__FILE__)))
22
+
23
+ redis_logger = Logger.new(File.expand_path("../log/redis.log", File.dirname(__FILE__)))
24
+ redis_logger.level = Logger::DEBUG
25
+ redis_logger.formatter = Logger::Formatter.new
26
+
27
+ redis_options = YAML.load_file(File.expand_path("support/config/redis-auth.yml", File.dirname(__FILE__)))
28
+ Redis.current = Redis.new(redis_options.merge(logger: redis_logger))
29
+
30
+ Resque.redis = Redis.new(redis_options)
31
+ Resque.inline = true
32
+
33
+ # Cornucopia::Util::Configuration.context_seed = 1
34
+ # Cornucopia::Util::Configuration.seed = 1
35
+ # Cornucopia::Util::Configuration.order_seed = 1
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails_helper"
4
+
5
+ RSpec.describe "approve.css" do
6
+ include Rack::Test::Methods
7
+
8
+ def app
9
+ @app ||= Resque::Server.new
10
+ end
11
+
12
+ it "fetches the CSS file" do
13
+ get "/approve/public/approve.css"
14
+
15
+ expect(last_response).to be_ok
16
+ expect(last_response.body).to be_include(".approve_pagination_block {")
17
+ end
18
+ end
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails_helper"
4
+
5
+ RSpec.describe "approval_keys.erb" do
6
+ let(:key_list) { Resque::Plugins::Approve::ApprovalKeyList.new }
7
+ let(:keys) { Array.new(5) { Faker::Lorem.sentence } }
8
+ let!(:jobs) do
9
+ keys.map do |approval_key|
10
+ job = Resque::Plugins::Approve::PendingJob.new(SecureRandom.uuid, class_name: BasicJob, args: [approval_key: approval_key])
11
+
12
+ key_list.add_job(job)
13
+
14
+ job
15
+ end
16
+ end
17
+
18
+ include Rack::Test::Methods
19
+
20
+ def app
21
+ @app ||= Resque::Server.new
22
+ end
23
+
24
+ before(:each) do
25
+ allow(Resque).to receive(:enqueue_to).and_call_original
26
+ end
27
+
28
+ context "actions" do
29
+ let(:cleaner) { Resque::Plugins::Approve::Cleaner }
30
+
31
+ before(:each) do
32
+ allow(Resque::Plugins::Approve::ApprovalKeyList).to receive(:new).and_return key_list
33
+ end
34
+
35
+ it "should respond to /approve/audit_jobs" do
36
+ expect(cleaner).to receive(:cleanup_jobs).and_call_original
37
+
38
+ post "/approve/audit_jobs"
39
+
40
+ expect(last_response).to be_redirect
41
+ expect(last_response.header["Location"]).to match(/approve$/)
42
+ expect(Resque).not_to have_received(:enqueue_to)
43
+ end
44
+
45
+ it "should respond to /approve/audit_queues" do
46
+ expect(cleaner).to receive(:cleanup_queues).and_call_original
47
+
48
+ post "/approve/audit_queues"
49
+
50
+ expect(last_response).to be_redirect
51
+ expect(last_response.header["Location"]).to match(/approve$/)
52
+ expect(Resque).not_to have_received(:enqueue_to)
53
+ end
54
+
55
+ it "should respond to /approve/approve_all_queues" do
56
+ expect(key_list).to receive(:approve_all).and_call_original
57
+
58
+ post "/approve/approve_all_queues"
59
+
60
+ expect(last_response).to be_redirect
61
+ expect(last_response.header["Location"]).to match(/approve$/)
62
+ expect(Resque).to have_received(:enqueue_to).exactly(jobs.flatten.count).times
63
+ end
64
+
65
+ it "should respond to /approve/delete_all_queues" do
66
+ expect(key_list).to receive(:delete_all).and_call_original
67
+
68
+ post "/approve/delete_all_queues"
69
+
70
+ expect(last_response).to be_redirect
71
+ expect(last_response.header["Location"]).to match(/approve$/)
72
+ expect(Resque).not_to have_received(:enqueue_to)
73
+ end
74
+ end
75
+
76
+ it "should respond to /approve" do
77
+ get "/approve"
78
+
79
+ expect(last_response).to be_ok
80
+
81
+ expect(last_response.body).to match %r{action="/approve/audit_jobs"}
82
+ expect(last_response.body).to match %r{action="/approve/audit_queues"}
83
+ expect(last_response.body).to match %r{action="/approve/approve_all_queues"}
84
+ expect(last_response.body).to match %r{action="/approve/delete_all_queues"}
85
+
86
+ expect(last_response.body).to match %r{&sort=approval_key">(\n *)?Approval Key\n +</a>}
87
+ expect(last_response.body).to match %r{&sort=num_jobs">(\n *)?Pending Jobs\n +</a>}
88
+ expect(last_response.body).to match %r{&sort=first_enqueued">(\n *)?First Enqueued\n +</a>}
89
+
90
+ keys.each do |approval_key|
91
+ expect(last_response.body).to match %r{#{approval_key}\n +</a>}
92
+ expect(last_response.body).to match %r{/job_list\?#{{ approval_key: approval_key }.to_param.gsub("+", "\\\\+")}}
93
+ end
94
+ end
95
+
96
+ it "pages queues" do
97
+ get "/approve?page_size=2"
98
+
99
+ expect(last_response).to be_ok
100
+
101
+ expect(last_response.body).to match(%r{href="/approve?.*page_num=2})
102
+ expect(last_response.body).to match(%r{href="/approve?.*page_num=3})
103
+ expect(last_response.body).not_to match(%r{href="/approve?.*page_num=4})
104
+ end
105
+ end