seam-mongodb 0.0.4 → 0.0.5
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 +15 -0
- data/lib/seam/mongodb/version.rb +1 -1
- data/lib/seam/mongodb.rb +17 -0
- data/spec/seam/flow_spec.rb +42 -1
- data/spec/seam/persistence_spec.rb +0 -0
- data/spec/seam/step_spec.rb +6 -2
- data/spec/seam/wait_worker_spec.rb +179 -0
- data/spec/seam/worker_spec.rb +188 -21
- data/spec/seam_spec.rb +47 -0
- metadata +11 -39
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NGEyOGMzMjdmMWQxMTE4MGRiOTkzNmRjMjAzZDhlMGQxYTM2OGUxZQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NGRmNzVhYjZjZjYzNGFlZWE4ODg0NThjODMyZTJlOWExNDQ4MGM4MA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OGQwZmVlNTkxMWI2NjkyMDVmNDYxMWYyYjMwODczMThlYTNiN2RjMWVlYTMz
|
10
|
+
OThmMzRhZWZlMGMwM2QxYWUwY2Y5NTNmMGEzOTdhYmUyOTRhNGU3OTc3OTJh
|
11
|
+
ZGRkZTlkMWVhZTNjMzEzZTIyNTNiMDA5YWRmNjkwYmNiMGQxMzc=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZGE4YTIyNjA1MjAxZmE5OGQzMWZkZjRlNWFhMzdiOWY3YWJmZDQ2NzNjYThi
|
14
|
+
MzBjMDYxYTVjM2YwNDhhOGQ0NzM4ZGQ0NWM5NmU1MzVkOTNmZWZmNTBiYmI2
|
15
|
+
ODVjYzU1ZDU2Zjk5ZjgzMzVmZjUwZjU4ZTM0M2I1NDJiOWJjMGQ=
|
data/lib/seam/mongodb/version.rb
CHANGED
data/lib/seam/mongodb.rb
CHANGED
@@ -35,6 +35,23 @@ module Seam
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
def self.find_something_to_do
|
39
|
+
record = Seam::Mongodb.collection
|
40
|
+
.find( {
|
41
|
+
next_execute_at: { '$lte' => Time.now },
|
42
|
+
next_step: { '$ne' => nil },
|
43
|
+
complete: { '$in' => [nil, false] },
|
44
|
+
} )
|
45
|
+
.first
|
46
|
+
return [] unless record
|
47
|
+
[record].map do |x|
|
48
|
+
-> do
|
49
|
+
record = Seam::Mongodb.collection.find( { '_id' => x['_id'] } ).first
|
50
|
+
Seam::Effort.parse record
|
51
|
+
end.to_object
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
38
55
|
def self.save effort
|
39
56
|
Seam::Mongodb.collection
|
40
57
|
.find( { id: effort.id } )
|
data/spec/seam/flow_spec.rb
CHANGED
@@ -63,7 +63,9 @@ describe "flow" do
|
|
63
63
|
Timecop.freeze now
|
64
64
|
|
65
65
|
@expected_uuid = SecureRandom.uuid.to_s
|
66
|
-
SecureRandom.
|
66
|
+
SecureRandom.stubs(:uuid).returns(@expected_uuid)
|
67
|
+
.then.returns(1)
|
68
|
+
.then.returns(2)
|
67
69
|
|
68
70
|
@effort = flow.start( { first_name: 'John' } )
|
69
71
|
end
|
@@ -92,6 +94,13 @@ describe "flow" do
|
|
92
94
|
effort = Seam::Effort.find @effort.id
|
93
95
|
effort.to_hash.contrast_with! @effort.to_hash, [:id, :created_at]
|
94
96
|
end
|
97
|
+
|
98
|
+
it "should set unique identifiers on the flow ids" do
|
99
|
+
effort = Seam::Effort.find @effort.id
|
100
|
+
effort.flow['steps'][0]['id'].must_equal '1'
|
101
|
+
effort.flow['steps'][1]['id'].must_equal '2'
|
102
|
+
end
|
103
|
+
|
95
104
|
end
|
96
105
|
end
|
97
106
|
|
@@ -129,4 +138,36 @@ describe "flow" do
|
|
129
138
|
end
|
130
139
|
end
|
131
140
|
end
|
141
|
+
|
142
|
+
describe "stamping history" do
|
143
|
+
describe "default" do
|
144
|
+
it "should should be false" do
|
145
|
+
flow = Seam::Flow.new
|
146
|
+
flow.stamp_data_history.must_equal false
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe "setting it to true" do
|
151
|
+
it "allow to be set to true" do
|
152
|
+
flow = Seam::Flow.new
|
153
|
+
flow.stamp_data_history = true
|
154
|
+
flow.stamp_data_history.must_equal true
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "carrying the value through the serialization" do
|
159
|
+
|
160
|
+
it "should be able to persist false" do
|
161
|
+
flow = Seam::Flow.new
|
162
|
+
flow.stamp_data_history = false
|
163
|
+
flow.to_hash[:stamp_data_history].must_equal false
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should be able to persist true" do
|
167
|
+
flow = Seam::Flow.new
|
168
|
+
flow.stamp_data_history = true
|
169
|
+
flow.to_hash[:stamp_data_history].must_equal true
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
132
173
|
end
|
File without changes
|
data/spec/seam/step_spec.rb
CHANGED
@@ -3,9 +3,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
3
3
|
describe Seam::Step do
|
4
4
|
describe "initialize" do
|
5
5
|
it "should allow values to be set with the constructor" do
|
6
|
-
step = Seam::Step.new( {
|
6
|
+
step = Seam::Step.new( { id: 'an id',
|
7
|
+
name: 'a name',
|
7
8
|
type: 'a type',
|
8
9
|
arguments: ['1234', 2] } )
|
10
|
+
step.id.must_equal 'an id'
|
9
11
|
step.name.must_equal 'a name'
|
10
12
|
step.type.must_equal 'a type'
|
11
13
|
step.arguments.count.must_equal 2
|
@@ -16,10 +18,12 @@ describe Seam::Step do
|
|
16
18
|
|
17
19
|
describe "to hash" do
|
18
20
|
it "should allow values to be set with the constructor" do
|
19
|
-
step = Seam::Step.new( {
|
21
|
+
step = Seam::Step.new( { id: 'an id',
|
22
|
+
name: 'a name',
|
20
23
|
type: 'a type',
|
21
24
|
arguments: ['1234', 2] } )
|
22
25
|
step = Seam::Step.new step.to_hash
|
26
|
+
step.id.must_equal 'an id'
|
23
27
|
step.name.must_equal 'a name'
|
24
28
|
step.type.must_equal 'a type'
|
25
29
|
step.arguments.count.must_equal 2
|
@@ -0,0 +1,179 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
class DoSomething < Seam::Worker
|
4
|
+
def process
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
describe Seam::WaitWorker do
|
9
|
+
|
10
|
+
it "should be a worker" do
|
11
|
+
Seam::WaitWorker.new.is_a? Seam::Worker
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should handle the wait step" do
|
15
|
+
Seam::WaitWorker.new.step.must_equal 'wait'
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:today) do
|
19
|
+
Time.parse '1/1/2011'
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:effort_id) do
|
23
|
+
effort = flow.start
|
24
|
+
effort.id
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "using it in a flow" do
|
28
|
+
|
29
|
+
[:length_of_time].to_objects { [
|
30
|
+
[3.days],
|
31
|
+
[1.day],
|
32
|
+
[30.minutes]
|
33
|
+
] }.each do |test|
|
34
|
+
|
35
|
+
describe "a simple situation" do
|
36
|
+
|
37
|
+
let(:flow) do
|
38
|
+
f = Seam::Flow.new
|
39
|
+
f.wait test.length_of_time
|
40
|
+
f.do_something
|
41
|
+
f
|
42
|
+
end
|
43
|
+
|
44
|
+
before do
|
45
|
+
Timecop.freeze today
|
46
|
+
effort_id
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should move to the next step" do
|
50
|
+
Seam::WaitWorker.new.execute_all
|
51
|
+
Seam::Effort.find(effort_id).next_step.must_equal "do_something"
|
52
|
+
end
|
53
|
+
j
|
54
|
+
it "should set the next execute date" do
|
55
|
+
Seam::WaitWorker.new.execute_all
|
56
|
+
Seam::Effort.find(effort_id).next_execute_at.must_equal (today + test.length_of_time)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "time has passed since the flow was started and the wait worker was called" do
|
64
|
+
|
65
|
+
let(:today) { Time.parse('1/1/2011') }
|
66
|
+
let(:time_to_wait) { 3.days }
|
67
|
+
let(:time_before_wait_worker_was_called) { 1.day }
|
68
|
+
let(:expected_start) { today + time_to_wait }
|
69
|
+
|
70
|
+
let(:flow) do
|
71
|
+
f = Seam::Flow.new
|
72
|
+
f.wait time_to_wait
|
73
|
+
f.do_something
|
74
|
+
f
|
75
|
+
end
|
76
|
+
|
77
|
+
before do
|
78
|
+
Timecop.freeze today
|
79
|
+
effort_id
|
80
|
+
|
81
|
+
Timecop.freeze today + time_before_wait_worker_was_called
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should move to the next step" do
|
85
|
+
Seam::WaitWorker.new.execute_all
|
86
|
+
Seam::Effort.find(effort_id).next_step.must_equal "do_something"
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should set the next execute date" do
|
90
|
+
Seam::WaitWorker.new.execute_all
|
91
|
+
Seam::Effort.find(effort_id).next_execute_at.must_equal expected_start
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "time has passed since the last step was started and the wait worker was called" do
|
97
|
+
|
98
|
+
let(:today) { Time.parse('1/1/2011') }
|
99
|
+
let(:time_to_wait) { 8.days }
|
100
|
+
let(:time_it_took_for_previous_step) { 1.days }
|
101
|
+
let(:time_before_wait_worker_was_called) { 3.day }
|
102
|
+
let(:expected_start) { today + time_to_wait + time_it_took_for_previous_step }
|
103
|
+
|
104
|
+
let(:flow) do
|
105
|
+
f = Seam::Flow.new
|
106
|
+
f.do_something
|
107
|
+
f.wait time_to_wait
|
108
|
+
f.do_something
|
109
|
+
f
|
110
|
+
end
|
111
|
+
|
112
|
+
before do
|
113
|
+
Timecop.freeze today
|
114
|
+
effort_id
|
115
|
+
|
116
|
+
Timecop.freeze Time.now + time_it_took_for_previous_step
|
117
|
+
DoSomething.new.execute_all
|
118
|
+
Timecop.freeze Time.now + time_before_wait_worker_was_called
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should move to the next step" do
|
122
|
+
Seam::WaitWorker.new.execute_all
|
123
|
+
Seam::Effort.find(effort_id).next_step.must_equal "do_something"
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should set the next execute date" do
|
127
|
+
Seam::WaitWorker.new.execute_all
|
128
|
+
Seam::Effort.find(effort_id).next_execute_at.must_equal expected_start
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
j
|
133
|
+
describe "a more complex example of waiting" do
|
134
|
+
|
135
|
+
let(:today) { Time.parse('1/1/2011') }
|
136
|
+
let(:time_to_wait) { 8.days }
|
137
|
+
let(:time_it_took_for_first_step) { 1.days }
|
138
|
+
let(:time_it_took_for_second_step) { 4.days }
|
139
|
+
let(:time_before_wait_worker_was_called) { 3.day }
|
140
|
+
let(:expected_start) { today +
|
141
|
+
time_to_wait +
|
142
|
+
time_it_took_for_first_step +
|
143
|
+
time_it_took_for_second_step }
|
144
|
+
|
145
|
+
let(:flow) do
|
146
|
+
f = Seam::Flow.new
|
147
|
+
f.do_something
|
148
|
+
f.do_something
|
149
|
+
f.wait time_to_wait
|
150
|
+
f.do_something
|
151
|
+
f
|
152
|
+
end
|
153
|
+
|
154
|
+
before do
|
155
|
+
Timecop.freeze today
|
156
|
+
effort_id
|
157
|
+
|
158
|
+
Timecop.freeze Time.now + time_it_took_for_first_step
|
159
|
+
DoSomething.new.execute_all
|
160
|
+
Timecop.freeze Time.now + time_it_took_for_second_step
|
161
|
+
DoSomething.new.execute_all
|
162
|
+
Timecop.freeze Time.now + time_before_wait_worker_was_called
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should move to the next step" do
|
166
|
+
Seam::WaitWorker.new.execute_all
|
167
|
+
Seam::Effort.find(effort_id).next_step.must_equal "do_something"
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should set the next execute date" do
|
171
|
+
Seam::WaitWorker.new.execute_all
|
172
|
+
Seam::Effort.find(effort_id).next_execute_at.must_equal expected_start
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
data/spec/seam/worker_spec.rb
CHANGED
@@ -4,6 +4,7 @@ describe "worker" do
|
|
4
4
|
|
5
5
|
before do
|
6
6
|
Seam::Persistence.destroy
|
7
|
+
@stamp_data_history = true
|
7
8
|
end
|
8
9
|
|
9
10
|
after do
|
@@ -19,26 +20,82 @@ describe "worker" do
|
|
19
20
|
end
|
20
21
|
|
21
22
|
describe "move_to_next_step" do
|
22
|
-
it "should work" do
|
23
|
-
flow = Seam::Flow.new
|
24
|
-
flow.apple
|
25
|
-
flow.orange
|
26
23
|
|
27
|
-
|
28
|
-
|
24
|
+
[:date].to_objects {[
|
25
|
+
['1/1/2011'],
|
26
|
+
['3/4/2015']
|
27
|
+
]}.each do |test|
|
28
|
+
|
29
|
+
describe "move immediately" do
|
29
30
|
|
30
|
-
|
31
|
+
before { Timecop.freeze Time.parse(test.date) }
|
32
|
+
after { Timecop.return }
|
33
|
+
|
34
|
+
it "should move to the next step and set the date to now" do
|
35
|
+
flow = Seam::Flow.new
|
36
|
+
flow.apple
|
37
|
+
flow.orange
|
38
|
+
|
39
|
+
effort = flow.start( { first_name: 'John' } )
|
40
|
+
effort = Seam::Effort.find(effort.id)
|
41
|
+
|
42
|
+
effort.next_step.must_equal "apple"
|
43
|
+
|
44
|
+
apple_worker = Seam::Worker.new
|
45
|
+
apple_worker.handles(:apple)
|
46
|
+
def apple_worker.process
|
47
|
+
move_to_next_step
|
48
|
+
end
|
49
|
+
|
50
|
+
apple_worker.execute effort
|
51
|
+
|
52
|
+
effort = Seam::Effort.find(effort.id)
|
53
|
+
effort.next_step.must_equal "orange"
|
54
|
+
effort.next_execute_at.must_equal Time.parse(test.date)
|
55
|
+
end
|
31
56
|
|
32
|
-
apple_worker = Seam::Worker.new
|
33
|
-
apple_worker.handles(:apple)
|
34
|
-
def apple_worker.process
|
35
|
-
move_to_next_step
|
36
57
|
end
|
37
58
|
|
38
|
-
|
59
|
+
end
|
60
|
+
|
61
|
+
[:date, :next_date].to_objects {[
|
62
|
+
['1/1/2011', '2/1/2011'],
|
63
|
+
['1/1/2011', '2/2/2011'],
|
64
|
+
['3/4/2015', '4/5/2016']
|
65
|
+
]}.each do |test|
|
66
|
+
|
67
|
+
describe "move to some point in the future" do
|
68
|
+
|
69
|
+
before { Timecop.freeze Time.parse(test.date) }
|
70
|
+
after { Timecop.return }
|
71
|
+
|
72
|
+
it "should move to the next step and set the date to now" do
|
73
|
+
flow = Seam::Flow.new
|
74
|
+
flow.apple
|
75
|
+
flow.orange
|
76
|
+
|
77
|
+
effort = flow.start( { first_name: 'John' } )
|
78
|
+
effort = Seam::Effort.find(effort.id)
|
79
|
+
|
80
|
+
effort.next_step.must_equal "apple"
|
81
|
+
|
82
|
+
apple_worker = Seam::Worker.new
|
83
|
+
apple_worker.handles(:apple)
|
84
|
+
eval("
|
85
|
+
def apple_worker.process
|
86
|
+
move_to_next_step( { on: Time.parse('#{test.next_date}') } )
|
87
|
+
end
|
88
|
+
")
|
89
|
+
|
90
|
+
apple_worker.execute effort
|
91
|
+
|
92
|
+
effort = Seam::Effort.find(effort.id)
|
93
|
+
effort.next_step.must_equal "orange"
|
94
|
+
effort.next_execute_at.must_equal Time.parse(test.next_date)
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
39
98
|
|
40
|
-
effort = Seam::Effort.find(effort.id)
|
41
|
-
effort.next_step.must_equal "orange"
|
42
99
|
end
|
43
100
|
end
|
44
101
|
|
@@ -260,6 +317,7 @@ describe "worker" do
|
|
260
317
|
let(:effort_creator) do
|
261
318
|
->() do
|
262
319
|
e = flow.start
|
320
|
+
flow.stamp_data_history = @stamp_data_history
|
263
321
|
Seam::Effort.find(e.id)
|
264
322
|
end
|
265
323
|
end
|
@@ -547,11 +605,10 @@ describe "worker" do
|
|
547
605
|
|
548
606
|
effort.history.count.must_equal 1
|
549
607
|
effort.history[0].contrast_with!( {
|
608
|
+
"step_id" => effort.flow['steps'][0]['id'],
|
550
609
|
"started_at"=> Time.now,
|
551
610
|
"step"=>"wait_for_attempting_contact_stage",
|
552
611
|
"stopped_at" => Time.now,
|
553
|
-
"data_before" => { "first_name" => "DARREN" } ,
|
554
|
-
"data_after" => { "first_name" => "DARREN", "hit 1" => 1 }
|
555
612
|
} )
|
556
613
|
|
557
614
|
send_postcard_if_necessary_worker.execute_all
|
@@ -565,7 +622,14 @@ describe "worker" do
|
|
565
622
|
effort.next_step.must_equal "wait_for_attempting_contact_stage"
|
566
623
|
|
567
624
|
effort.history.count.must_equal 1
|
568
|
-
effort.history[0].contrast_with!({
|
625
|
+
effort.history[0].contrast_with!( {
|
626
|
+
"step_id" => effort.flow['steps'][0]['id'],
|
627
|
+
"started_at"=> Time.now,
|
628
|
+
"step"=>"wait_for_attempting_contact_stage",
|
629
|
+
"stopped_at" => Time.now,
|
630
|
+
"result" => "try_again_in",
|
631
|
+
"try_again_on" => Time.now + 1.day
|
632
|
+
} )
|
569
633
|
|
570
634
|
# THE NEXT DAY
|
571
635
|
Timecop.freeze Time.parse('27/12/2013')
|
@@ -578,7 +642,13 @@ describe "worker" do
|
|
578
642
|
effort.next_step.must_equal "wait_for_attempting_contact_stage"
|
579
643
|
|
580
644
|
effort.history.count.must_equal 2
|
581
|
-
effort.history[1].contrast_with!({
|
645
|
+
effort.history[1].contrast_with!( {
|
646
|
+
"step_id" => effort.flow['steps'][0]['id'],
|
647
|
+
"started_at"=> Time.now,
|
648
|
+
"step"=>"wait_for_attempting_contact_stage",
|
649
|
+
"stopped_at" => Time.now,
|
650
|
+
"result" => "try_again_in"
|
651
|
+
} )
|
582
652
|
|
583
653
|
# THE NEXT DAY
|
584
654
|
Timecop.freeze Time.parse('28/12/2013')
|
@@ -591,7 +661,13 @@ describe "worker" do
|
|
591
661
|
effort.next_step.must_equal "determine_if_postcard_should_be_sent"
|
592
662
|
|
593
663
|
effort.history.count.must_equal 3
|
594
|
-
effort.history[2].contrast_with!({
|
664
|
+
effort.history[2].contrast_with!( {
|
665
|
+
"step_id" => effort.flow['steps'][0]['id'],
|
666
|
+
"started_at"=> Time.now,
|
667
|
+
"step"=>"wait_for_attempting_contact_stage",
|
668
|
+
"stopped_at" => Time.now,
|
669
|
+
"result" => "move_to_next_step"
|
670
|
+
} )
|
595
671
|
|
596
672
|
# KEEP GOING
|
597
673
|
send_postcard_if_necessary_worker.execute_all
|
@@ -601,7 +677,13 @@ describe "worker" do
|
|
601
677
|
effort.next_step.must_equal "send_postcard_if_necessary"
|
602
678
|
|
603
679
|
effort.history.count.must_equal 4
|
604
|
-
effort.history[3].contrast_with!({
|
680
|
+
effort.history[3].contrast_with!( {
|
681
|
+
"step_id" => effort.flow['steps'][1]['id'],
|
682
|
+
"started_at"=> Time.now,
|
683
|
+
"step"=>"determine_if_postcard_should_be_sent",
|
684
|
+
"stopped_at" => Time.now,
|
685
|
+
"result" => "move_to_next_step"
|
686
|
+
} )
|
605
687
|
|
606
688
|
# KEEP GOING
|
607
689
|
send_postcard_if_necessary_worker.execute_all
|
@@ -611,7 +693,13 @@ describe "worker" do
|
|
611
693
|
effort.next_step.must_equal nil
|
612
694
|
|
613
695
|
effort.history.count.must_equal 5
|
614
|
-
effort.history[4].contrast_with!({
|
696
|
+
effort.history[4].contrast_with!( {
|
697
|
+
"step_id" => effort.flow['steps'][2]['id'],
|
698
|
+
"started_at"=> Time.now,
|
699
|
+
"step"=>"send_postcard_if_necessary",
|
700
|
+
"stopped_at" => Time.now,
|
701
|
+
"result" => "move_to_next_step"
|
702
|
+
} )
|
615
703
|
end
|
616
704
|
end
|
617
705
|
|
@@ -735,6 +823,85 @@ describe "worker" do
|
|
735
823
|
orange_worker.execute_all
|
736
824
|
end
|
737
825
|
end
|
826
|
+
|
827
|
+
describe "data history" do
|
828
|
+
describe "stamping the history" do
|
829
|
+
let(:effort) do
|
830
|
+
flow = Seam::Flow.new
|
831
|
+
flow.stamp_data_history = true
|
832
|
+
flow.apple
|
833
|
+
|
834
|
+
e = flow.start( { first_name: 'John' } )
|
835
|
+
Seam::Effort.find(e.id)
|
836
|
+
end
|
837
|
+
|
838
|
+
before do
|
839
|
+
Timecop.freeze Time.parse('3/4/2013')
|
840
|
+
effort.next_step.must_equal "apple"
|
841
|
+
|
842
|
+
apple_worker = Seam::Worker.new
|
843
|
+
apple_worker.handles(:apple)
|
844
|
+
def apple_worker.process
|
845
|
+
effort.data['something'] = 'else'
|
846
|
+
end
|
847
|
+
|
848
|
+
apple_worker.execute effort
|
849
|
+
end
|
850
|
+
|
851
|
+
it "should not update the next step" do
|
852
|
+
fresh_effort = Seam::Effort.find(effort.id)
|
853
|
+
fresh_effort.history.count.must_equal 1
|
854
|
+
end
|
855
|
+
|
856
|
+
it "should set the data_before history" do
|
857
|
+
fresh_effort = Seam::Effort.find(effort.id)
|
858
|
+
fresh_effort.history.first["data_before"].must_equal( { "first_name" => 'John' } )
|
859
|
+
end
|
860
|
+
|
861
|
+
it "should set the data_after history" do
|
862
|
+
fresh_effort = Seam::Effort.find(effort.id)
|
863
|
+
fresh_effort.history.first["data_after"].must_equal( { "first_name" => 'John', "something" => 'else' } )
|
864
|
+
end
|
865
|
+
end
|
866
|
+
|
867
|
+
describe "not stamping the history" do
|
868
|
+
let(:effort) do
|
869
|
+
flow = Seam::Flow.new
|
870
|
+
flow.stamp_data_history = false
|
871
|
+
flow.apple
|
872
|
+
|
873
|
+
e = flow.start( { first_name: 'John' } )
|
874
|
+
Seam::Effort.find(e.id)
|
875
|
+
end
|
876
|
+
|
877
|
+
before do
|
878
|
+
Timecop.freeze Time.parse('3/4/2013')
|
879
|
+
|
880
|
+
apple_worker = Seam::Worker.new
|
881
|
+
apple_worker.handles(:apple)
|
882
|
+
def apple_worker.process
|
883
|
+
effort.data['something'] = 'else'
|
884
|
+
end
|
885
|
+
|
886
|
+
apple_worker.execute effort
|
887
|
+
end
|
888
|
+
|
889
|
+
it "should not update the next step" do
|
890
|
+
fresh_effort = Seam::Effort.find(effort.id)
|
891
|
+
fresh_effort.history.count.must_equal 1
|
892
|
+
end
|
893
|
+
|
894
|
+
it "should set the data_before history" do
|
895
|
+
fresh_effort = Seam::Effort.find(effort.id)
|
896
|
+
fresh_effort.history.first["data_before"].nil?.must_equal true
|
897
|
+
end
|
898
|
+
|
899
|
+
it "should set the data_after history" do
|
900
|
+
fresh_effort = Seam::Effort.find(effort.id)
|
901
|
+
fresh_effort.history.first["data_after"].nil?.must_equal true
|
902
|
+
end
|
903
|
+
end
|
904
|
+
end
|
738
905
|
end
|
739
906
|
|
740
907
|
class IWillNotCallHandlesWorker < Seam::Worker
|
data/spec/seam_spec.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Seam do
|
4
|
+
|
5
|
+
before do
|
6
|
+
Seam::Persistence.destroy
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "steps to run" do
|
10
|
+
|
11
|
+
it "should return an empty array if nothing has happened" do
|
12
|
+
Seam.steps_to_run.count.must_equal 0
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return step x if step x is next" do
|
16
|
+
flow = Seam::Flow.new
|
17
|
+
flow.x
|
18
|
+
flow.y
|
19
|
+
flow.start
|
20
|
+
|
21
|
+
Seam.steps_to_run.include?('x').must_equal true
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return step y if step y is next" do
|
25
|
+
flow = Seam::Flow.new
|
26
|
+
flow.y
|
27
|
+
flow.x
|
28
|
+
flow.start
|
29
|
+
|
30
|
+
Seam.steps_to_run.include?('y').must_equal true
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return step x or y if step x and y are next" do
|
34
|
+
flow = Seam::Flow.new
|
35
|
+
flow.y
|
36
|
+
flow.start
|
37
|
+
|
38
|
+
flow = Seam::Flow.new
|
39
|
+
flow.x
|
40
|
+
flow.start
|
41
|
+
|
42
|
+
(['x', 'y'].select { |x| Seam.steps_to_run.include?(x) }.count > 0).must_equal true
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seam-mongodb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.5
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Darren Cauthon
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-12-11 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: json
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ! '>='
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: activesupport
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ~>
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ~>
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,7 +41,6 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: i18n
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ! '>='
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ! '>='
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -62,7 +55,6 @@ dependencies:
|
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: moped
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
59
|
- - ! '>='
|
68
60
|
- !ruby/object:Gem::Version
|
@@ -70,7 +62,6 @@ dependencies:
|
|
70
62
|
type: :runtime
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
66
|
- - ! '>='
|
76
67
|
- !ruby/object:Gem::Version
|
@@ -78,7 +69,6 @@ dependencies:
|
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: json
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
73
|
- - ! '>='
|
84
74
|
- !ruby/object:Gem::Version
|
@@ -86,7 +76,6 @@ dependencies:
|
|
86
76
|
type: :runtime
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
80
|
- - ! '>='
|
92
81
|
- !ruby/object:Gem::Version
|
@@ -94,7 +83,6 @@ dependencies:
|
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: seam
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
87
|
- - ! '>='
|
100
88
|
- !ruby/object:Gem::Version
|
@@ -102,7 +90,6 @@ dependencies:
|
|
102
90
|
type: :runtime
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
94
|
- - ! '>='
|
108
95
|
- !ruby/object:Gem::Version
|
@@ -110,7 +97,6 @@ dependencies:
|
|
110
97
|
- !ruby/object:Gem::Dependency
|
111
98
|
name: subtle
|
112
99
|
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
100
|
requirements:
|
115
101
|
- - ! '>='
|
116
102
|
- !ruby/object:Gem::Version
|
@@ -118,7 +104,6 @@ dependencies:
|
|
118
104
|
type: :runtime
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
107
|
requirements:
|
123
108
|
- - ! '>='
|
124
109
|
- !ruby/object:Gem::Version
|
@@ -126,7 +111,6 @@ dependencies:
|
|
126
111
|
- !ruby/object:Gem::Dependency
|
127
112
|
name: bundler
|
128
113
|
requirement: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
114
|
requirements:
|
131
115
|
- - ~>
|
132
116
|
- !ruby/object:Gem::Version
|
@@ -134,7 +118,6 @@ dependencies:
|
|
134
118
|
type: :development
|
135
119
|
prerelease: false
|
136
120
|
version_requirements: !ruby/object:Gem::Requirement
|
137
|
-
none: false
|
138
121
|
requirements:
|
139
122
|
- - ~>
|
140
123
|
- !ruby/object:Gem::Version
|
@@ -142,7 +125,6 @@ dependencies:
|
|
142
125
|
- !ruby/object:Gem::Dependency
|
143
126
|
name: rake
|
144
127
|
requirement: !ruby/object:Gem::Requirement
|
145
|
-
none: false
|
146
128
|
requirements:
|
147
129
|
- - ! '>='
|
148
130
|
- !ruby/object:Gem::Version
|
@@ -150,7 +132,6 @@ dependencies:
|
|
150
132
|
type: :development
|
151
133
|
prerelease: false
|
152
134
|
version_requirements: !ruby/object:Gem::Requirement
|
153
|
-
none: false
|
154
135
|
requirements:
|
155
136
|
- - ! '>='
|
156
137
|
- !ruby/object:Gem::Version
|
@@ -158,7 +139,6 @@ dependencies:
|
|
158
139
|
- !ruby/object:Gem::Dependency
|
159
140
|
name: contrast
|
160
141
|
requirement: !ruby/object:Gem::Requirement
|
161
|
-
none: false
|
162
142
|
requirements:
|
163
143
|
- - ! '>='
|
164
144
|
- !ruby/object:Gem::Version
|
@@ -166,7 +146,6 @@ dependencies:
|
|
166
146
|
type: :development
|
167
147
|
prerelease: false
|
168
148
|
version_requirements: !ruby/object:Gem::Requirement
|
169
|
-
none: false
|
170
149
|
requirements:
|
171
150
|
- - ! '>='
|
172
151
|
- !ruby/object:Gem::Version
|
@@ -174,7 +153,6 @@ dependencies:
|
|
174
153
|
- !ruby/object:Gem::Dependency
|
175
154
|
name: mocha
|
176
155
|
requirement: !ruby/object:Gem::Requirement
|
177
|
-
none: false
|
178
156
|
requirements:
|
179
157
|
- - ! '>='
|
180
158
|
- !ruby/object:Gem::Version
|
@@ -182,7 +160,6 @@ dependencies:
|
|
182
160
|
type: :development
|
183
161
|
prerelease: false
|
184
162
|
version_requirements: !ruby/object:Gem::Requirement
|
185
|
-
none: false
|
186
163
|
requirements:
|
187
164
|
- - ! '>='
|
188
165
|
- !ruby/object:Gem::Version
|
@@ -190,7 +167,6 @@ dependencies:
|
|
190
167
|
- !ruby/object:Gem::Dependency
|
191
168
|
name: contrast
|
192
169
|
requirement: !ruby/object:Gem::Requirement
|
193
|
-
none: false
|
194
170
|
requirements:
|
195
171
|
- - ! '>='
|
196
172
|
- !ruby/object:Gem::Version
|
@@ -198,7 +174,6 @@ dependencies:
|
|
198
174
|
type: :development
|
199
175
|
prerelease: false
|
200
176
|
version_requirements: !ruby/object:Gem::Requirement
|
201
|
-
none: false
|
202
177
|
requirements:
|
203
178
|
- - ! '>='
|
204
179
|
- !ruby/object:Gem::Version
|
@@ -206,7 +181,6 @@ dependencies:
|
|
206
181
|
- !ruby/object:Gem::Dependency
|
207
182
|
name: timecop
|
208
183
|
requirement: !ruby/object:Gem::Requirement
|
209
|
-
none: false
|
210
184
|
requirements:
|
211
185
|
- - ! '>='
|
212
186
|
- !ruby/object:Gem::Version
|
@@ -214,7 +188,6 @@ dependencies:
|
|
214
188
|
type: :development
|
215
189
|
prerelease: false
|
216
190
|
version_requirements: !ruby/object:Gem::Requirement
|
217
|
-
none: false
|
218
191
|
requirements:
|
219
192
|
- - ! '>='
|
220
193
|
- !ruby/object:Gem::Version
|
@@ -236,43 +209,42 @@ files:
|
|
236
209
|
- seam-mongodb.gemspec
|
237
210
|
- spec/seam/effort_spec.rb
|
238
211
|
- spec/seam/flow_spec.rb
|
212
|
+
- spec/seam/persistence_spec.rb
|
239
213
|
- spec/seam/step_spec.rb
|
214
|
+
- spec/seam/wait_worker_spec.rb
|
240
215
|
- spec/seam/worker_spec.rb
|
216
|
+
- spec/seam_spec.rb
|
241
217
|
- spec/spec_helper.rb
|
242
218
|
homepage: ''
|
243
219
|
licenses:
|
244
220
|
- MIT
|
221
|
+
metadata: {}
|
245
222
|
post_install_message:
|
246
223
|
rdoc_options: []
|
247
224
|
require_paths:
|
248
225
|
- lib
|
249
226
|
required_ruby_version: !ruby/object:Gem::Requirement
|
250
|
-
none: false
|
251
227
|
requirements:
|
252
228
|
- - ! '>='
|
253
229
|
- !ruby/object:Gem::Version
|
254
230
|
version: '0'
|
255
|
-
segments:
|
256
|
-
- 0
|
257
|
-
hash: -1560466269320564369
|
258
231
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
259
|
-
none: false
|
260
232
|
requirements:
|
261
233
|
- - ! '>='
|
262
234
|
- !ruby/object:Gem::Version
|
263
235
|
version: '0'
|
264
|
-
segments:
|
265
|
-
- 0
|
266
|
-
hash: -1560466269320564369
|
267
236
|
requirements: []
|
268
237
|
rubyforge_project:
|
269
|
-
rubygems_version: 1.
|
238
|
+
rubygems_version: 2.1.11
|
270
239
|
signing_key:
|
271
|
-
specification_version:
|
240
|
+
specification_version: 4
|
272
241
|
summary: MongoDB support for seam
|
273
242
|
test_files:
|
274
243
|
- spec/seam/effort_spec.rb
|
275
244
|
- spec/seam/flow_spec.rb
|
245
|
+
- spec/seam/persistence_spec.rb
|
276
246
|
- spec/seam/step_spec.rb
|
247
|
+
- spec/seam/wait_worker_spec.rb
|
277
248
|
- spec/seam/worker_spec.rb
|
249
|
+
- spec/seam_spec.rb
|
278
250
|
- spec/spec_helper.rb
|