seam 1.1.2 → 2.0.0a1
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.
- checksums.yaml +5 -5
- data/Gemfile +4 -2
- data/Gemfile.lock +105 -0
- data/LICENSE.txt +16 -18
- data/README.md +115 -115
- data/Rakefile +23 -0
- data/lib/seam/todo.rb +9 -0
- data/lib/seam/version.rb +3 -1
- data/lib/seam.rb +5 -13
- metadata +61 -91
- data/.gitignore +0 -18
- data/lib/seam/effort.rb +0 -86
- data/lib/seam/flow.rb +0 -53
- data/lib/seam/in_memory.rb +0 -13
- data/lib/seam/persistence.rb +0 -43
- data/lib/seam/step.rb +0 -33
- data/lib/seam/wait_worker.rb +0 -30
- data/lib/seam/worker.rb +0 -166
- data/seam.gemspec +0 -30
- data/spec/seam/effort_spec.rb +0 -43
- data/spec/seam/flow_spec.rb +0 -173
- data/spec/seam/step_spec.rb +0 -34
- data/spec/seam/wait_worker_spec.rb +0 -179
- data/spec/seam/worker_spec.rb +0 -959
- data/spec/spec_helper.rb +0 -8
data/spec/seam/worker_spec.rb
DELETED
@@ -1,959 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe "worker" do
|
4
|
-
|
5
|
-
before do
|
6
|
-
Seam::Persistence.destroy
|
7
|
-
@stamp_data_history = true
|
8
|
-
end
|
9
|
-
|
10
|
-
after do
|
11
|
-
Timecop.return
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "step" do
|
15
|
-
it "should match the name" do
|
16
|
-
worker = Seam::Worker.new
|
17
|
-
worker.handles(:darren)
|
18
|
-
worker.step.must_equal "darren"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "inherited & all" do
|
23
|
-
|
24
|
-
before do
|
25
|
-
Seam::Worker.instance_eval { @handlers = nil }
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should default to an empty set" do
|
29
|
-
Seam::Worker.all.count.must_equal 0
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should return new instances of all handlers" do
|
33
|
-
instance = Object.new
|
34
|
-
klass = Struct.new(:new).new instance
|
35
|
-
Seam::Worker.inherited klass
|
36
|
-
Seam::Worker.all.count.must_equal 1
|
37
|
-
Seam::Worker.all[0].must_be_same_as instance
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "handler for" do
|
43
|
-
|
44
|
-
let(:handler_1) { Struct.new(:step).new SecureRandom.uuid }
|
45
|
-
let(:handler_2) { Struct.new(:step).new SecureRandom.uuid }
|
46
|
-
let(:handler_3) { Struct.new(:step).new SecureRandom.uuid }
|
47
|
-
|
48
|
-
before do
|
49
|
-
handler_1_class, handler_2_class, handler_3_class = Object.new, Object.new, Object.new
|
50
|
-
|
51
|
-
handler_1_class = Struct.new(:new).new handler_1
|
52
|
-
handler_2_class = Struct.new(:new).new handler_2
|
53
|
-
handler_3_class = Struct.new(:new).new handler_3
|
54
|
-
|
55
|
-
Seam::Worker.instance_eval do
|
56
|
-
@handlers = [handler_1_class, handler_2_class, handler_3_class]
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should return the handler for the type" do
|
61
|
-
Seam::Worker.handler_for(handler_2.step).must_be_same_as handler_2
|
62
|
-
Seam::Worker.handler_for(handler_1.step).must_be_same_as handler_1
|
63
|
-
Seam::Worker.handler_for(handler_3.step).must_be_same_as handler_3
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should return nil if none exist" do
|
67
|
-
Seam::Worker.handler_for('test').nil?.must_equal true
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe "move_to_next_step" do
|
72
|
-
|
73
|
-
[:date].to_objects {[
|
74
|
-
['1/1/2011'],
|
75
|
-
['3/4/2015']
|
76
|
-
]}.each do |test|
|
77
|
-
|
78
|
-
describe "move immediately" do
|
79
|
-
|
80
|
-
before { Timecop.freeze Time.parse(test.date) }
|
81
|
-
after { Timecop.return }
|
82
|
-
|
83
|
-
it "should move to the next step and set the date to now" do
|
84
|
-
flow = Seam::Flow.new
|
85
|
-
flow.apple
|
86
|
-
flow.orange
|
87
|
-
|
88
|
-
effort = flow.start( { first_name: 'John' } )
|
89
|
-
effort = Seam::Effort.find(effort.id)
|
90
|
-
|
91
|
-
effort.next_step.must_equal "apple"
|
92
|
-
|
93
|
-
apple_worker = Seam::Worker.new
|
94
|
-
apple_worker.handles(:apple)
|
95
|
-
def apple_worker.process
|
96
|
-
move_to_next_step
|
97
|
-
end
|
98
|
-
|
99
|
-
apple_worker.execute effort
|
100
|
-
|
101
|
-
effort = Seam::Effort.find(effort.id)
|
102
|
-
effort.next_step.must_equal "orange"
|
103
|
-
effort.next_execute_at.must_equal Time.parse(test.date)
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|
107
|
-
|
108
|
-
end
|
109
|
-
|
110
|
-
[:date, :next_date].to_objects {[
|
111
|
-
['1/1/2011', '2/1/2011'],
|
112
|
-
['1/1/2011', '2/2/2011'],
|
113
|
-
['3/4/2015', '4/5/2016']
|
114
|
-
]}.each do |test|
|
115
|
-
|
116
|
-
describe "move to some point in the future" do
|
117
|
-
|
118
|
-
before { Timecop.freeze Time.parse(test.date) }
|
119
|
-
after { Timecop.return }
|
120
|
-
|
121
|
-
it "should move to the next step and set the date to now" do
|
122
|
-
flow = Seam::Flow.new
|
123
|
-
flow.apple
|
124
|
-
flow.orange
|
125
|
-
|
126
|
-
effort = flow.start( { first_name: 'John' } )
|
127
|
-
effort = Seam::Effort.find(effort.id)
|
128
|
-
|
129
|
-
effort.next_step.must_equal "apple"
|
130
|
-
|
131
|
-
apple_worker = Seam::Worker.new
|
132
|
-
apple_worker.handles(:apple)
|
133
|
-
eval("
|
134
|
-
def apple_worker.process
|
135
|
-
move_to_next_step( { on: Time.parse('#{test.next_date}') } )
|
136
|
-
end
|
137
|
-
")
|
138
|
-
|
139
|
-
apple_worker.execute effort
|
140
|
-
|
141
|
-
effort = Seam::Effort.find(effort.id)
|
142
|
-
effort.next_step.must_equal "orange"
|
143
|
-
effort.next_execute_at.must_equal Time.parse(test.next_date)
|
144
|
-
end
|
145
|
-
|
146
|
-
end
|
147
|
-
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe "move_to_next_step as a default" do
|
152
|
-
it "should go to move_to_next_step by default" do
|
153
|
-
flow = Seam::Flow.new
|
154
|
-
flow.apple
|
155
|
-
flow.orange
|
156
|
-
|
157
|
-
effort = flow.start( { first_name: 'John' } )
|
158
|
-
effort = Seam::Effort.find(effort.id)
|
159
|
-
|
160
|
-
effort.next_step.must_equal "apple"
|
161
|
-
|
162
|
-
apple_worker = Seam::Worker.new
|
163
|
-
apple_worker.handles(:apple)
|
164
|
-
def apple_worker.process
|
165
|
-
end
|
166
|
-
|
167
|
-
apple_worker.execute effort
|
168
|
-
|
169
|
-
effort = Seam::Effort.find(effort.id)
|
170
|
-
effort.next_step.must_equal "orange"
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
describe "try_again_in" do
|
175
|
-
|
176
|
-
let(:effort) do
|
177
|
-
flow = Seam::Flow.new
|
178
|
-
flow.apple
|
179
|
-
flow.orange
|
180
|
-
|
181
|
-
e = flow.start( { first_name: 'John' } )
|
182
|
-
Seam::Effort.find(e.id)
|
183
|
-
end
|
184
|
-
|
185
|
-
before do
|
186
|
-
Timecop.freeze Time.parse('3/4/2013')
|
187
|
-
effort.next_step.must_equal "apple"
|
188
|
-
|
189
|
-
apple_worker = Seam::Worker.new
|
190
|
-
apple_worker.handles(:apple)
|
191
|
-
def apple_worker.process
|
192
|
-
try_again_in 1.day
|
193
|
-
end
|
194
|
-
|
195
|
-
apple_worker.execute effort
|
196
|
-
end
|
197
|
-
|
198
|
-
it "should not update the next step" do
|
199
|
-
fresh_effort = Seam::Effort.find(effort.id)
|
200
|
-
fresh_effort.next_step.must_equal "apple"
|
201
|
-
end
|
202
|
-
|
203
|
-
it "should update the next execute date" do
|
204
|
-
fresh_effort = Seam::Effort.find(effort.id)
|
205
|
-
fresh_effort.next_execute_at.must_equal Time.parse('4/4/2013')
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
describe "try_again_on" do
|
210
|
-
|
211
|
-
describe "putting it off for one day" do
|
212
|
-
let(:effort) do
|
213
|
-
flow = Seam::Flow.new
|
214
|
-
flow.apple
|
215
|
-
flow.orange
|
216
|
-
|
217
|
-
e = flow.start( { first_name: 'John' } )
|
218
|
-
Seam::Effort.find(e.id)
|
219
|
-
end
|
220
|
-
|
221
|
-
before do
|
222
|
-
Timecop.freeze Time.parse('3/4/2013')
|
223
|
-
effort.next_step.must_equal "apple"
|
224
|
-
|
225
|
-
apple_worker = Seam::Worker.new
|
226
|
-
apple_worker.handles(:apple)
|
227
|
-
def apple_worker.process
|
228
|
-
try_again_on Time.parse('4/4/2013')
|
229
|
-
end
|
230
|
-
|
231
|
-
apple_worker.execute effort
|
232
|
-
end
|
233
|
-
|
234
|
-
it "should not update the next step" do
|
235
|
-
fresh_effort = Seam::Effort.find(effort.id)
|
236
|
-
fresh_effort.next_step.must_equal "apple"
|
237
|
-
end
|
238
|
-
|
239
|
-
it "should update the next execute date" do
|
240
|
-
fresh_effort = Seam::Effort.find(effort.id)
|
241
|
-
fresh_effort.next_execute_at.must_equal Time.parse('4/4/2013')
|
242
|
-
end
|
243
|
-
|
244
|
-
it "should update the history" do
|
245
|
-
fresh_effort = Seam::Effort.find(effort.id)
|
246
|
-
fresh_effort.history[0]['try_again_on'].must_equal Time.parse('4/4/2013')
|
247
|
-
end
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
describe "more copmlex example" do
|
252
|
-
|
253
|
-
let(:effort1) do
|
254
|
-
flow = Seam::Flow.new
|
255
|
-
flow.grape
|
256
|
-
flow.mango
|
257
|
-
|
258
|
-
e = flow.start( { status: 'Good' } )
|
259
|
-
Seam::Effort.find(e.id)
|
260
|
-
end
|
261
|
-
|
262
|
-
let(:effort2) do
|
263
|
-
flow = Seam::Flow.new
|
264
|
-
flow.grape
|
265
|
-
flow.mango
|
266
|
-
|
267
|
-
e = flow.start( { status: 'Bad' } )
|
268
|
-
Seam::Effort.find(e.id)
|
269
|
-
end
|
270
|
-
|
271
|
-
before do
|
272
|
-
Timecop.freeze Time.parse('1/6/2013')
|
273
|
-
|
274
|
-
apple_worker = Seam::Worker.new
|
275
|
-
apple_worker.handles(:apple)
|
276
|
-
def apple_worker.process
|
277
|
-
if @current_effort.data[:status] == 'Good'
|
278
|
-
move_to_next_step
|
279
|
-
else
|
280
|
-
try_again_in 1.day
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
apple_worker.execute effort1
|
285
|
-
apple_worker.execute effort2
|
286
|
-
end
|
287
|
-
|
288
|
-
it "should move the first effort forward" do
|
289
|
-
fresh_effort = Seam::Effort.find(effort1.id)
|
290
|
-
fresh_effort.next_step.must_equal "mango"
|
291
|
-
end
|
292
|
-
|
293
|
-
it "should keep the second effort at the same step" do
|
294
|
-
fresh_effort = Seam::Effort.find(effort2.id)
|
295
|
-
fresh_effort.next_step.must_equal "grape"
|
296
|
-
fresh_effort.next_execute_at.must_equal Time.parse('2/6/2013')
|
297
|
-
end
|
298
|
-
end
|
299
|
-
|
300
|
-
describe "processing all pending steps for one effort" do
|
301
|
-
let(:effort1_creator) do
|
302
|
-
->() do
|
303
|
-
flow = Seam::Flow.new
|
304
|
-
flow.banana
|
305
|
-
flow.mango
|
306
|
-
|
307
|
-
e = flow.start
|
308
|
-
Seam::Effort.find(e.id)
|
309
|
-
end
|
310
|
-
end
|
311
|
-
|
312
|
-
let(:effort2_creator) do
|
313
|
-
->() do
|
314
|
-
flow = Seam::Flow.new
|
315
|
-
flow.apple
|
316
|
-
flow.orange
|
317
|
-
|
318
|
-
e = flow.start
|
319
|
-
Seam::Effort.find(e.id)
|
320
|
-
end
|
321
|
-
end
|
322
|
-
|
323
|
-
let(:apple_worker) do
|
324
|
-
apple_worker = Seam::Worker.new
|
325
|
-
apple_worker.handles(:apple)
|
326
|
-
|
327
|
-
apple_worker.class_eval do
|
328
|
-
attr_accessor :count
|
329
|
-
end
|
330
|
-
|
331
|
-
def apple_worker.process
|
332
|
-
self.count += 1
|
333
|
-
end
|
334
|
-
|
335
|
-
apple_worker.count = 0
|
336
|
-
apple_worker
|
337
|
-
end
|
338
|
-
|
339
|
-
before do
|
340
|
-
Timecop.freeze Time.parse('1/6/2013')
|
341
|
-
|
342
|
-
effort1_creator.call
|
343
|
-
effort1_creator.call
|
344
|
-
effort1_creator.call
|
345
|
-
effort2_creator.call
|
346
|
-
effort2_creator.call
|
347
|
-
|
348
|
-
apple_worker.execute_all
|
349
|
-
end
|
350
|
-
|
351
|
-
it "should call the apple worker for the record in question" do
|
352
|
-
apple_worker.count.must_equal 2
|
353
|
-
end
|
354
|
-
end
|
355
|
-
|
356
|
-
describe "a more realistic example" do
|
357
|
-
|
358
|
-
let(:flow) do
|
359
|
-
flow = Seam::Flow.new
|
360
|
-
flow.wait_for_attempting_contact_stage
|
361
|
-
flow.determine_if_postcard_should_be_sent
|
362
|
-
flow.send_postcard_if_necessary
|
363
|
-
flow
|
364
|
-
end
|
365
|
-
|
366
|
-
let(:effort_creator) do
|
367
|
-
->() do
|
368
|
-
e = flow.start
|
369
|
-
flow.stamp_data_history = @stamp_data_history
|
370
|
-
Seam::Effort.find(e.id)
|
371
|
-
end
|
372
|
-
end
|
373
|
-
|
374
|
-
let(:wait_for_attempting_contact_stage_worker) do
|
375
|
-
worker = Seam::Worker.new
|
376
|
-
worker.handles(:wait_for_attempting_contact_stage)
|
377
|
-
|
378
|
-
def worker.process
|
379
|
-
@current_effort.data['hit 1'] ||= 0
|
380
|
-
@current_effort.data['hit 1'] += 1
|
381
|
-
move_to_next_step
|
382
|
-
end
|
383
|
-
|
384
|
-
worker
|
385
|
-
end
|
386
|
-
|
387
|
-
let(:determine_if_postcard_should_be_sent_worker) do
|
388
|
-
worker = Seam::Worker.new
|
389
|
-
worker.handles(:determine_if_postcard_should_be_sent)
|
390
|
-
|
391
|
-
def worker.process
|
392
|
-
@current_effort.data['hit 2'] ||= 0
|
393
|
-
@current_effort.data['hit 2'] += 1
|
394
|
-
move_to_next_step
|
395
|
-
end
|
396
|
-
|
397
|
-
worker
|
398
|
-
end
|
399
|
-
|
400
|
-
let(:send_postcard_if_necessary_worker) do
|
401
|
-
worker = Seam::Worker.new
|
402
|
-
worker.handles(:send_postcard_if_necessary)
|
403
|
-
|
404
|
-
def worker.process
|
405
|
-
@current_effort.data['hit 3'] ||= 0
|
406
|
-
@current_effort.data['hit 3'] += 1
|
407
|
-
move_to_next_step
|
408
|
-
end
|
409
|
-
|
410
|
-
worker
|
411
|
-
end
|
412
|
-
|
413
|
-
before do
|
414
|
-
Timecop.freeze Time.parse('1/6/2013')
|
415
|
-
end
|
416
|
-
|
417
|
-
it "should progress through the story" do
|
418
|
-
|
419
|
-
# SETUP
|
420
|
-
effort = effort_creator.call
|
421
|
-
effort.next_step.must_equal "wait_for_attempting_contact_stage"
|
422
|
-
|
423
|
-
# FIRST WAVE
|
424
|
-
send_postcard_if_necessary_worker.execute_all
|
425
|
-
determine_if_postcard_should_be_sent_worker.execute_all
|
426
|
-
wait_for_attempting_contact_stage_worker.execute_all
|
427
|
-
|
428
|
-
effort = Seam::Effort.find effort.id
|
429
|
-
effort.next_step.must_equal "determine_if_postcard_should_be_sent"
|
430
|
-
|
431
|
-
effort.complete?.must_equal false
|
432
|
-
|
433
|
-
# SECOND WAVE
|
434
|
-
send_postcard_if_necessary_worker.execute_all
|
435
|
-
determine_if_postcard_should_be_sent_worker.execute_all
|
436
|
-
wait_for_attempting_contact_stage_worker.execute_all
|
437
|
-
|
438
|
-
effort = Seam::Effort.find effort.id
|
439
|
-
effort.next_step.must_equal "send_postcard_if_necessary"
|
440
|
-
|
441
|
-
# THIRD WAVE
|
442
|
-
send_postcard_if_necessary_worker.execute_all
|
443
|
-
determine_if_postcard_should_be_sent_worker.execute_all
|
444
|
-
wait_for_attempting_contact_stage_worker.execute_all
|
445
|
-
|
446
|
-
effort = Seam::Effort.find effort.id
|
447
|
-
effort.next_step.must_equal nil
|
448
|
-
|
449
|
-
effort.data['hit 1'].must_equal 1
|
450
|
-
effort.data['hit 2'].must_equal 1
|
451
|
-
effort.data['hit 3'].must_equal 1
|
452
|
-
|
453
|
-
effort.complete?.must_equal true
|
454
|
-
effort.completed_at.must_equal Time.now
|
455
|
-
|
456
|
-
# FUTURE WAVES
|
457
|
-
send_postcard_if_necessary_worker.execute_all
|
458
|
-
determine_if_postcard_should_be_sent_worker.execute_all
|
459
|
-
wait_for_attempting_contact_stage_worker.execute_all
|
460
|
-
send_postcard_if_necessary_worker.execute_all
|
461
|
-
determine_if_postcard_should_be_sent_worker.execute_all
|
462
|
-
wait_for_attempting_contact_stage_worker.execute_all
|
463
|
-
send_postcard_if_necessary_worker.execute_all
|
464
|
-
determine_if_postcard_should_be_sent_worker.execute_all
|
465
|
-
wait_for_attempting_contact_stage_worker.execute_all
|
466
|
-
|
467
|
-
effort = Seam::Effort.find effort.id
|
468
|
-
effort.next_step.must_equal nil
|
469
|
-
|
470
|
-
effort.data['hit 1'].must_equal 1
|
471
|
-
effort.data['hit 2'].must_equal 1
|
472
|
-
effort.data['hit 3'].must_equal 1
|
473
|
-
|
474
|
-
end
|
475
|
-
end
|
476
|
-
|
477
|
-
describe "a more realistic example with waiting" do
|
478
|
-
|
479
|
-
let(:flow) do
|
480
|
-
flow = Seam::Flow.new
|
481
|
-
flow.wait_for_attempting_contact_stage
|
482
|
-
flow.determine_if_postcard_should_be_sent
|
483
|
-
flow.send_postcard_if_necessary
|
484
|
-
flow
|
485
|
-
end
|
486
|
-
|
487
|
-
let(:effort_creator) do
|
488
|
-
->() do
|
489
|
-
e = flow.start
|
490
|
-
Seam::Effort.find(e.id)
|
491
|
-
end
|
492
|
-
end
|
493
|
-
|
494
|
-
let(:wait_for_attempting_contact_stage_worker) do
|
495
|
-
worker = Seam::Worker.new
|
496
|
-
worker.handles(:wait_for_attempting_contact_stage)
|
497
|
-
|
498
|
-
def worker.process
|
499
|
-
@current_effort.data['hit 1'] ||= 0
|
500
|
-
@current_effort.data['hit 1'] += 1
|
501
|
-
if Time.now >= Time.parse('28/12/2013')
|
502
|
-
move_to_next_step
|
503
|
-
else
|
504
|
-
try_again_in 1.day
|
505
|
-
end
|
506
|
-
end
|
507
|
-
|
508
|
-
worker
|
509
|
-
end
|
510
|
-
|
511
|
-
let(:determine_if_postcard_should_be_sent_worker) do
|
512
|
-
worker = Seam::Worker.new
|
513
|
-
worker.handles(:determine_if_postcard_should_be_sent)
|
514
|
-
|
515
|
-
def worker.process
|
516
|
-
@current_effort.data['hit 2'] ||= 0
|
517
|
-
@current_effort.data['hit 2'] += 1
|
518
|
-
move_to_next_step
|
519
|
-
end
|
520
|
-
|
521
|
-
worker
|
522
|
-
end
|
523
|
-
|
524
|
-
let(:send_postcard_if_necessary_worker) do
|
525
|
-
worker = Seam::Worker.new
|
526
|
-
worker.handles(:send_postcard_if_necessary)
|
527
|
-
|
528
|
-
def worker.process
|
529
|
-
@current_effort.data['hit 3'] ||= 0
|
530
|
-
@current_effort.data['hit 3'] += 1
|
531
|
-
move_to_next_step
|
532
|
-
end
|
533
|
-
|
534
|
-
worker
|
535
|
-
end
|
536
|
-
|
537
|
-
before do
|
538
|
-
Timecop.freeze Time.parse('25/12/2013')
|
539
|
-
end
|
540
|
-
|
541
|
-
it "should progress through the story" do
|
542
|
-
|
543
|
-
# SETUP
|
544
|
-
effort = effort_creator.call
|
545
|
-
effort.next_step.must_equal "wait_for_attempting_contact_stage"
|
546
|
-
|
547
|
-
# FIRST DAY
|
548
|
-
send_postcard_if_necessary_worker.execute_all
|
549
|
-
determine_if_postcard_should_be_sent_worker.execute_all
|
550
|
-
wait_for_attempting_contact_stage_worker.execute_all
|
551
|
-
|
552
|
-
effort = Seam::Effort.find effort.id
|
553
|
-
effort.next_step.must_equal "wait_for_attempting_contact_stage"
|
554
|
-
|
555
|
-
send_postcard_if_necessary_worker.execute_all
|
556
|
-
determine_if_postcard_should_be_sent_worker.execute_all
|
557
|
-
wait_for_attempting_contact_stage_worker.execute_all
|
558
|
-
send_postcard_if_necessary_worker.execute_all
|
559
|
-
determine_if_postcard_should_be_sent_worker.execute_all
|
560
|
-
wait_for_attempting_contact_stage_worker.execute_all
|
561
|
-
|
562
|
-
effort = Seam::Effort.find effort.id
|
563
|
-
effort.next_step.must_equal "wait_for_attempting_contact_stage"
|
564
|
-
|
565
|
-
Timecop.freeze Time.parse('29/12/2013')
|
566
|
-
|
567
|
-
send_postcard_if_necessary_worker.execute_all
|
568
|
-
determine_if_postcard_should_be_sent_worker.execute_all
|
569
|
-
wait_for_attempting_contact_stage_worker.execute_all
|
570
|
-
|
571
|
-
effort = Seam::Effort.find effort.id
|
572
|
-
effort.next_step.must_equal "determine_if_postcard_should_be_sent"
|
573
|
-
effort.data['hit 1'].must_equal 2
|
574
|
-
end
|
575
|
-
end
|
576
|
-
|
577
|
-
describe "tracking history" do
|
578
|
-
|
579
|
-
let(:flow) do
|
580
|
-
flow = Seam::Flow.new
|
581
|
-
flow.wait_for_attempting_contact_stage
|
582
|
-
flow.determine_if_postcard_should_be_sent
|
583
|
-
flow.send_postcard_if_necessary
|
584
|
-
flow
|
585
|
-
end
|
586
|
-
|
587
|
-
let(:effort_creator) do
|
588
|
-
->(values = {}) do
|
589
|
-
e = flow.start values
|
590
|
-
Seam::Effort.find(e.id)
|
591
|
-
end
|
592
|
-
end
|
593
|
-
|
594
|
-
let(:wait_for_attempting_contact_stage_worker) do
|
595
|
-
worker = Seam::Worker.new
|
596
|
-
worker.handles(:wait_for_attempting_contact_stage)
|
597
|
-
|
598
|
-
def worker.process
|
599
|
-
@current_effort.data['hit 1'] ||= 0
|
600
|
-
@current_effort.data['hit 1'] += 1
|
601
|
-
if Time.now >= Time.parse('28/12/2013')
|
602
|
-
move_to_next_step
|
603
|
-
else
|
604
|
-
try_again_in 1.day
|
605
|
-
end
|
606
|
-
end
|
607
|
-
|
608
|
-
worker
|
609
|
-
end
|
610
|
-
|
611
|
-
let(:determine_if_postcard_should_be_sent_worker) do
|
612
|
-
worker = Seam::Worker.new
|
613
|
-
worker.handles(:determine_if_postcard_should_be_sent)
|
614
|
-
|
615
|
-
def worker.process
|
616
|
-
@current_effort.data['hit 2'] ||= 0
|
617
|
-
@current_effort.data['hit 2'] += 1
|
618
|
-
move_to_next_step
|
619
|
-
end
|
620
|
-
|
621
|
-
worker
|
622
|
-
end
|
623
|
-
|
624
|
-
let(:send_postcard_if_necessary_worker) do
|
625
|
-
worker = Seam::Worker.new
|
626
|
-
worker.handles(:send_postcard_if_necessary)
|
627
|
-
|
628
|
-
def worker.process
|
629
|
-
@current_effort.data['hit 3'] ||= 0
|
630
|
-
@current_effort.data['hit 3'] += 1
|
631
|
-
move_to_next_step
|
632
|
-
end
|
633
|
-
|
634
|
-
worker
|
635
|
-
end
|
636
|
-
|
637
|
-
before do
|
638
|
-
Timecop.freeze Time.parse('26/12/2013')
|
639
|
-
end
|
640
|
-
|
641
|
-
it "should progress through the story" do
|
642
|
-
|
643
|
-
# SETUP
|
644
|
-
effort = effort_creator.call({ first_name: 'DARREN' })
|
645
|
-
effort.next_step.must_equal "wait_for_attempting_contact_stage"
|
646
|
-
|
647
|
-
# FIRST DAY
|
648
|
-
send_postcard_if_necessary_worker.execute_all
|
649
|
-
determine_if_postcard_should_be_sent_worker.execute_all
|
650
|
-
wait_for_attempting_contact_stage_worker.execute_all
|
651
|
-
|
652
|
-
effort = Seam::Effort.find effort.id
|
653
|
-
effort.next_step.must_equal "wait_for_attempting_contact_stage"
|
654
|
-
|
655
|
-
effort.history.count.must_equal 1
|
656
|
-
effort.history[0].contrast_with!( {
|
657
|
-
"step_id" => effort.flow['steps'][0]['id'],
|
658
|
-
"started_at"=> Time.now,
|
659
|
-
"step"=>"wait_for_attempting_contact_stage",
|
660
|
-
"stopped_at" => Time.now,
|
661
|
-
} )
|
662
|
-
|
663
|
-
send_postcard_if_necessary_worker.execute_all
|
664
|
-
determine_if_postcard_should_be_sent_worker.execute_all
|
665
|
-
wait_for_attempting_contact_stage_worker.execute_all
|
666
|
-
send_postcard_if_necessary_worker.execute_all
|
667
|
-
determine_if_postcard_should_be_sent_worker.execute_all
|
668
|
-
wait_for_attempting_contact_stage_worker.execute_all
|
669
|
-
|
670
|
-
effort = Seam::Effort.find effort.id
|
671
|
-
effort.next_step.must_equal "wait_for_attempting_contact_stage"
|
672
|
-
|
673
|
-
effort.history.count.must_equal 1
|
674
|
-
effort.history[0].contrast_with!( {
|
675
|
-
"step_id" => effort.flow['steps'][0]['id'],
|
676
|
-
"started_at"=> Time.now,
|
677
|
-
"step"=>"wait_for_attempting_contact_stage",
|
678
|
-
"stopped_at" => Time.now,
|
679
|
-
"result" => "try_again_in",
|
680
|
-
"try_again_on" => Time.now + 1.day
|
681
|
-
} )
|
682
|
-
|
683
|
-
# THE NEXT DAY
|
684
|
-
Timecop.freeze Time.parse('27/12/2013')
|
685
|
-
|
686
|
-
send_postcard_if_necessary_worker.execute_all
|
687
|
-
determine_if_postcard_should_be_sent_worker.execute_all
|
688
|
-
wait_for_attempting_contact_stage_worker.execute_all
|
689
|
-
|
690
|
-
effort = Seam::Effort.find effort.id
|
691
|
-
effort.next_step.must_equal "wait_for_attempting_contact_stage"
|
692
|
-
|
693
|
-
effort.history.count.must_equal 2
|
694
|
-
effort.history[1].contrast_with!( {
|
695
|
-
"step_id" => effort.flow['steps'][0]['id'],
|
696
|
-
"started_at"=> Time.now,
|
697
|
-
"step"=>"wait_for_attempting_contact_stage",
|
698
|
-
"stopped_at" => Time.now,
|
699
|
-
"result" => "try_again_in"
|
700
|
-
} )
|
701
|
-
|
702
|
-
# THE NEXT DAY
|
703
|
-
Timecop.freeze Time.parse('28/12/2013')
|
704
|
-
|
705
|
-
send_postcard_if_necessary_worker.execute_all
|
706
|
-
determine_if_postcard_should_be_sent_worker.execute_all
|
707
|
-
wait_for_attempting_contact_stage_worker.execute_all
|
708
|
-
|
709
|
-
effort = Seam::Effort.find effort.id
|
710
|
-
effort.next_step.must_equal "determine_if_postcard_should_be_sent"
|
711
|
-
|
712
|
-
effort.history.count.must_equal 3
|
713
|
-
effort.history[2].contrast_with!( {
|
714
|
-
"step_id" => effort.flow['steps'][0]['id'],
|
715
|
-
"started_at"=> Time.now,
|
716
|
-
"step"=>"wait_for_attempting_contact_stage",
|
717
|
-
"stopped_at" => Time.now,
|
718
|
-
"result" => "move_to_next_step"
|
719
|
-
} )
|
720
|
-
|
721
|
-
# KEEP GOING
|
722
|
-
send_postcard_if_necessary_worker.execute_all
|
723
|
-
determine_if_postcard_should_be_sent_worker.execute_all
|
724
|
-
wait_for_attempting_contact_stage_worker.execute_all
|
725
|
-
effort = Seam::Effort.find effort.id
|
726
|
-
effort.next_step.must_equal "send_postcard_if_necessary"
|
727
|
-
|
728
|
-
effort.history.count.must_equal 4
|
729
|
-
effort.history[3].contrast_with!( {
|
730
|
-
"step_id" => effort.flow['steps'][1]['id'],
|
731
|
-
"started_at"=> Time.now,
|
732
|
-
"step"=>"determine_if_postcard_should_be_sent",
|
733
|
-
"stopped_at" => Time.now,
|
734
|
-
"result" => "move_to_next_step"
|
735
|
-
} )
|
736
|
-
|
737
|
-
# KEEP GOING
|
738
|
-
send_postcard_if_necessary_worker.execute_all
|
739
|
-
determine_if_postcard_should_be_sent_worker.execute_all
|
740
|
-
wait_for_attempting_contact_stage_worker.execute_all
|
741
|
-
effort = Seam::Effort.find effort.id
|
742
|
-
effort.next_step.must_equal nil
|
743
|
-
|
744
|
-
effort.history.count.must_equal 5
|
745
|
-
effort.history[4].contrast_with!( {
|
746
|
-
"step_id" => effort.flow['steps'][2]['id'],
|
747
|
-
"started_at"=> Time.now,
|
748
|
-
"step"=>"send_postcard_if_necessary",
|
749
|
-
"stopped_at" => Time.now,
|
750
|
-
"result" => "move_to_next_step"
|
751
|
-
} )
|
752
|
-
end
|
753
|
-
end
|
754
|
-
|
755
|
-
describe "eject" do
|
756
|
-
|
757
|
-
let(:effort) do
|
758
|
-
flow = Seam::Flow.new
|
759
|
-
flow.apple
|
760
|
-
flow.orange
|
761
|
-
|
762
|
-
e = flow.start( { first_name: 'John' } )
|
763
|
-
Seam::Effort.find(e.id)
|
764
|
-
end
|
765
|
-
|
766
|
-
before do
|
767
|
-
Timecop.freeze Time.parse('5/11/2013')
|
768
|
-
effort.next_step.must_equal "apple"
|
769
|
-
|
770
|
-
apple_worker = Seam::Worker.new
|
771
|
-
apple_worker.handles(:apple)
|
772
|
-
def apple_worker.process
|
773
|
-
eject
|
774
|
-
end
|
775
|
-
|
776
|
-
apple_worker.execute effort
|
777
|
-
end
|
778
|
-
|
779
|
-
it "should mark the step as completed" do
|
780
|
-
fresh_effort = Seam::Effort.find(effort.id)
|
781
|
-
fresh_effort.complete?.must_equal true
|
782
|
-
end
|
783
|
-
|
784
|
-
it "should mark the next step to nil" do
|
785
|
-
fresh_effort = Seam::Effort.find(effort.id)
|
786
|
-
fresh_effort.next_step.nil?.must_equal true
|
787
|
-
end
|
788
|
-
|
789
|
-
it "should mark the completed_at date" do
|
790
|
-
fresh_effort = Seam::Effort.find(effort.id)
|
791
|
-
fresh_effort.completed_at.must_equal Time.now
|
792
|
-
end
|
793
|
-
|
794
|
-
it "should mark the history" do
|
795
|
-
effort.history[0].contrast_with!({"step"=>"apple", "result" => "eject" } )
|
796
|
-
end
|
797
|
-
|
798
|
-
end
|
799
|
-
|
800
|
-
describe "use the name of the worker to tie to a step" do
|
801
|
-
|
802
|
-
let(:effort) do
|
803
|
-
flow = Seam::Flow.new
|
804
|
-
flow.i_will_not_call_handles
|
805
|
-
|
806
|
-
e = flow.start
|
807
|
-
Seam::Effort.find(e.id)
|
808
|
-
end
|
809
|
-
|
810
|
-
before do
|
811
|
-
effort
|
812
|
-
worker = IWillNotCallHandlesWorker.new
|
813
|
-
IWillNotCallHandlesWorker.new.execute_all
|
814
|
-
end
|
815
|
-
|
816
|
-
it "should complete the effort" do
|
817
|
-
fresh_effort = Seam::Effort.find effort.id
|
818
|
-
fresh_effort.complete?.must_equal true
|
819
|
-
end
|
820
|
-
|
821
|
-
end
|
822
|
-
|
823
|
-
describe "making the current step available" do
|
824
|
-
it "should return the first step if on the first step" do
|
825
|
-
flow = Seam::Flow.new
|
826
|
-
flow.apple("test")
|
827
|
-
flow.orange
|
828
|
-
|
829
|
-
effort = flow.start( { first_name: 'John' } )
|
830
|
-
effort = Seam::Effort.find(effort.id)
|
831
|
-
|
832
|
-
effort.next_step.must_equal "apple"
|
833
|
-
|
834
|
-
apple_worker = Seam::Worker.new
|
835
|
-
apple_worker.handles(:apple)
|
836
|
-
def apple_worker.process
|
837
|
-
current_step.nil?.must_equal false
|
838
|
-
current_step["name"].must_equal "apple"
|
839
|
-
current_step["arguments"].must_equal ["test"]
|
840
|
-
end
|
841
|
-
|
842
|
-
apple_worker.execute effort
|
843
|
-
end
|
844
|
-
|
845
|
-
it "should return the second step if on the second step" do
|
846
|
-
flow = Seam::Flow.new
|
847
|
-
flow.apple("test")
|
848
|
-
flow.orange("another test")
|
849
|
-
|
850
|
-
effort = flow.start( { first_name: 'John' } )
|
851
|
-
effort = Seam::Effort.find(effort.id)
|
852
|
-
|
853
|
-
effort.next_step.must_equal "apple"
|
854
|
-
|
855
|
-
apple_worker = Seam::Worker.new
|
856
|
-
apple_worker.handles(:apple)
|
857
|
-
def apple_worker.process
|
858
|
-
current_step.nil?.must_equal false
|
859
|
-
current_step["name"].must_equal "apple"
|
860
|
-
current_step["arguments"].must_equal ["test"]
|
861
|
-
end
|
862
|
-
|
863
|
-
orange_worker = Seam::Worker.new
|
864
|
-
orange_worker.handles(:orange)
|
865
|
-
def orange_worker.process
|
866
|
-
current_step.nil?.must_equal false
|
867
|
-
current_step["name"].must_equal "orange"
|
868
|
-
current_step["arguments"].must_equal ["another test"]
|
869
|
-
end
|
870
|
-
|
871
|
-
apple_worker.execute_all
|
872
|
-
orange_worker.execute_all
|
873
|
-
end
|
874
|
-
end
|
875
|
-
|
876
|
-
describe "data history" do
|
877
|
-
describe "stamping the history" do
|
878
|
-
let(:effort) do
|
879
|
-
flow = Seam::Flow.new
|
880
|
-
flow.stamp_data_history = true
|
881
|
-
flow.apple
|
882
|
-
|
883
|
-
e = flow.start( { first_name: 'John' } )
|
884
|
-
Seam::Effort.find(e.id)
|
885
|
-
end
|
886
|
-
|
887
|
-
before do
|
888
|
-
Timecop.freeze Time.parse('3/4/2013')
|
889
|
-
effort.next_step.must_equal "apple"
|
890
|
-
|
891
|
-
apple_worker = Seam::Worker.new
|
892
|
-
apple_worker.handles(:apple)
|
893
|
-
def apple_worker.process
|
894
|
-
effort.data['something'] = 'else'
|
895
|
-
end
|
896
|
-
|
897
|
-
apple_worker.execute effort
|
898
|
-
end
|
899
|
-
|
900
|
-
it "should not update the next step" do
|
901
|
-
fresh_effort = Seam::Effort.find(effort.id)
|
902
|
-
fresh_effort.history.count.must_equal 1
|
903
|
-
end
|
904
|
-
|
905
|
-
it "should set the data_before history" do
|
906
|
-
fresh_effort = Seam::Effort.find(effort.id)
|
907
|
-
fresh_effort.history.first["data_before"].must_equal( { "first_name" => 'John' } )
|
908
|
-
end
|
909
|
-
|
910
|
-
it "should set the data_after history" do
|
911
|
-
fresh_effort = Seam::Effort.find(effort.id)
|
912
|
-
fresh_effort.history.first["data_after"].must_equal( { "first_name" => 'John', "something" => 'else' } )
|
913
|
-
end
|
914
|
-
end
|
915
|
-
|
916
|
-
describe "not stamping the history" do
|
917
|
-
let(:effort) do
|
918
|
-
flow = Seam::Flow.new
|
919
|
-
flow.stamp_data_history = false
|
920
|
-
flow.apple
|
921
|
-
|
922
|
-
e = flow.start( { first_name: 'John' } )
|
923
|
-
Seam::Effort.find(e.id)
|
924
|
-
end
|
925
|
-
|
926
|
-
before do
|
927
|
-
Timecop.freeze Time.parse('3/4/2013')
|
928
|
-
|
929
|
-
apple_worker = Seam::Worker.new
|
930
|
-
apple_worker.handles(:apple)
|
931
|
-
def apple_worker.process
|
932
|
-
effort.data['something'] = 'else'
|
933
|
-
end
|
934
|
-
|
935
|
-
apple_worker.execute effort
|
936
|
-
end
|
937
|
-
|
938
|
-
it "should not update the next step" do
|
939
|
-
fresh_effort = Seam::Effort.find(effort.id)
|
940
|
-
fresh_effort.history.count.must_equal 1
|
941
|
-
end
|
942
|
-
|
943
|
-
it "should set the data_before history" do
|
944
|
-
fresh_effort = Seam::Effort.find(effort.id)
|
945
|
-
fresh_effort.history.first["data_before"].nil?.must_equal true
|
946
|
-
end
|
947
|
-
|
948
|
-
it "should set the data_after history" do
|
949
|
-
fresh_effort = Seam::Effort.find(effort.id)
|
950
|
-
fresh_effort.history.first["data_after"].nil?.must_equal true
|
951
|
-
end
|
952
|
-
end
|
953
|
-
end
|
954
|
-
end
|
955
|
-
|
956
|
-
class IWillNotCallHandlesWorker < Seam::Worker
|
957
|
-
# no calling handles here
|
958
|
-
def process; end
|
959
|
-
end
|