seam-mongodb 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/lib/seam/mongodb/version.rb +1 -1
- data/lib/seam/mongodb.rb +6 -1
- data/seam-mongodb.gemspec +1 -1
- data/spec/seam/flow_spec.rb +35 -0
- data/spec/seam/step_spec.rb +30 -0
- data/spec/seam/worker_spec.rb +161 -2
- metadata +18 -16
data/.gitignore
CHANGED
data/lib/seam/mongodb/version.rb
CHANGED
data/lib/seam/mongodb.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'seam'
|
2
2
|
require "seam/mongodb/version"
|
3
3
|
require 'moped'
|
4
|
+
require 'subtle'
|
4
5
|
|
5
6
|
module Seam
|
6
7
|
module Mongodb
|
@@ -25,7 +26,11 @@ module Seam
|
|
25
26
|
def self.find_all_pending_executions_by_step step
|
26
27
|
Seam::Mongodb.collection
|
27
28
|
.find( { next_step: step, next_execute_at: { '$lte' => Time.now } } )
|
28
|
-
.map
|
29
|
+
.map do |x|
|
30
|
+
-> do
|
31
|
+
Seam::Effort.parse x
|
32
|
+
end.to_object
|
33
|
+
end
|
29
34
|
end
|
30
35
|
|
31
36
|
def self.save effort
|
data/seam-mongodb.gemspec
CHANGED
@@ -24,9 +24,9 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_runtime_dependency "moped"
|
25
25
|
spec.add_runtime_dependency "json"
|
26
26
|
spec.add_runtime_dependency "seam"
|
27
|
+
spec.add_runtime_dependency 'subtle'
|
27
28
|
spec.add_development_dependency "bundler", "~> 1.3"
|
28
29
|
spec.add_development_dependency "rake"
|
29
|
-
spec.add_development_dependency "subtle"
|
30
30
|
spec.add_development_dependency "contrast"
|
31
31
|
spec.add_development_dependency "mocha"
|
32
32
|
spec.add_development_dependency "contrast"
|
data/spec/seam/flow_spec.rb
CHANGED
@@ -94,4 +94,39 @@ describe "flow" do
|
|
94
94
|
end
|
95
95
|
end
|
96
96
|
end
|
97
|
+
|
98
|
+
describe "adding steps" do
|
99
|
+
describe "new steps" do
|
100
|
+
it "should return true" do
|
101
|
+
flow = Seam::Flow.new
|
102
|
+
flow.do_something.must_equal true
|
103
|
+
flow.do_something_else.must_equal true
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "repeating steps" do
|
108
|
+
it "should only add the step once" do
|
109
|
+
flow = Seam::Flow.new
|
110
|
+
flow.do_something.must_equal true
|
111
|
+
flow.steps.count.must_equal 1
|
112
|
+
flow.do_something.must_equal true
|
113
|
+
flow.steps.count.must_equal 2
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "repeating steps with different data" do
|
118
|
+
it "should only add the step once" do
|
119
|
+
flow = Seam::Flow.new
|
120
|
+
flow.do_something(special_id: 'one').must_equal true
|
121
|
+
flow.do_something( { special_id: 'two' }, 4).must_equal true
|
122
|
+
flow.steps.count.must_equal 2
|
123
|
+
|
124
|
+
flow.steps[0].arguments.count.must_equal 1
|
125
|
+
flow.steps[0].arguments[0].contrast_with!( { special_id: 'one' } )
|
126
|
+
flow.steps[1].arguments.count.must_equal 2
|
127
|
+
flow.steps[1].arguments[0].contrast_with!( { special_id: 'two' } )
|
128
|
+
flow.steps[1].arguments[1].must_equal 4
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
97
132
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Seam::Step do
|
4
|
+
describe "initialize" do
|
5
|
+
it "should allow values to be set with the constructor" do
|
6
|
+
step = Seam::Step.new( { name: 'a name',
|
7
|
+
type: 'a type',
|
8
|
+
arguments: ['1234', 2] } )
|
9
|
+
step.name.must_equal 'a name'
|
10
|
+
step.type.must_equal 'a type'
|
11
|
+
step.arguments.count.must_equal 2
|
12
|
+
step.arguments[0].must_equal '1234'
|
13
|
+
step.arguments[1].must_equal 2
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "to hash" do
|
18
|
+
it "should allow values to be set with the constructor" do
|
19
|
+
step = Seam::Step.new( { name: 'a name',
|
20
|
+
type: 'a type',
|
21
|
+
arguments: ['1234', 2] } )
|
22
|
+
step = Seam::Step.new step.to_hash
|
23
|
+
step.name.must_equal 'a name'
|
24
|
+
step.type.must_equal 'a type'
|
25
|
+
step.arguments.count.must_equal 2
|
26
|
+
step.arguments[0].must_equal '1234'
|
27
|
+
step.arguments[1].must_equal 2
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/spec/seam/worker_spec.rb
CHANGED
@@ -10,6 +10,14 @@ describe "worker" do
|
|
10
10
|
Timecop.return
|
11
11
|
end
|
12
12
|
|
13
|
+
describe "step" do
|
14
|
+
it "should match the name" do
|
15
|
+
worker = Seam::Worker.new
|
16
|
+
worker.handles(:darren)
|
17
|
+
worker.step.must_equal "darren"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
13
21
|
describe "move_to_next_step" do
|
14
22
|
it "should work" do
|
15
23
|
flow = Seam::Flow.new
|
@@ -34,6 +42,29 @@ describe "worker" do
|
|
34
42
|
end
|
35
43
|
end
|
36
44
|
|
45
|
+
describe "move_to_next_step as a default" do
|
46
|
+
it "should go to move_to_next_step by default" do
|
47
|
+
flow = Seam::Flow.new
|
48
|
+
flow.apple
|
49
|
+
flow.orange
|
50
|
+
|
51
|
+
effort = flow.start( { first_name: 'John' } )
|
52
|
+
effort = Seam::Effort.find(effort.id)
|
53
|
+
|
54
|
+
effort.next_step.must_equal "apple"
|
55
|
+
|
56
|
+
apple_worker = Seam::Worker.new
|
57
|
+
apple_worker.handles(:apple)
|
58
|
+
def apple_worker.process
|
59
|
+
end
|
60
|
+
|
61
|
+
apple_worker.execute effort
|
62
|
+
|
63
|
+
effort = Seam::Effort.find(effort.id)
|
64
|
+
effort.next_step.must_equal "orange"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
37
68
|
describe "try_again_in" do
|
38
69
|
|
39
70
|
let(:effort) do
|
@@ -63,12 +94,54 @@ describe "worker" do
|
|
63
94
|
fresh_effort.next_step.must_equal "apple"
|
64
95
|
end
|
65
96
|
|
66
|
-
it "should
|
97
|
+
it "should update the next execute date" do
|
67
98
|
fresh_effort = Seam::Effort.find(effort.id)
|
68
99
|
fresh_effort.next_execute_at.must_equal Time.parse('4/4/2013')
|
69
100
|
end
|
70
101
|
end
|
71
102
|
|
103
|
+
describe "try_again_on" do
|
104
|
+
|
105
|
+
describe "putting it off for one day" do
|
106
|
+
let(:effort) do
|
107
|
+
flow = Seam::Flow.new
|
108
|
+
flow.apple
|
109
|
+
flow.orange
|
110
|
+
|
111
|
+
e = flow.start( { first_name: 'John' } )
|
112
|
+
Seam::Effort.find(e.id)
|
113
|
+
end
|
114
|
+
|
115
|
+
before do
|
116
|
+
Timecop.freeze Time.parse('3/4/2013')
|
117
|
+
effort.next_step.must_equal "apple"
|
118
|
+
|
119
|
+
apple_worker = Seam::Worker.new
|
120
|
+
apple_worker.handles(:apple)
|
121
|
+
def apple_worker.process
|
122
|
+
try_again_on Time.parse('4/4/2013')
|
123
|
+
end
|
124
|
+
|
125
|
+
apple_worker.execute effort
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should not update the next step" do
|
129
|
+
fresh_effort = Seam::Effort.find(effort.id)
|
130
|
+
fresh_effort.next_step.must_equal "apple"
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should update the next execute date" do
|
134
|
+
fresh_effort = Seam::Effort.find(effort.id)
|
135
|
+
fresh_effort.next_execute_at.must_equal Time.parse('4/4/2013')
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should update the history" do
|
139
|
+
fresh_effort = Seam::Effort.find(effort.id)
|
140
|
+
fresh_effort.history[0]['try_again_on'].must_equal Time.parse('4/4/2013')
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
72
145
|
describe "more copmlex example" do
|
73
146
|
|
74
147
|
let(:effort1) do
|
@@ -271,7 +344,7 @@ describe "worker" do
|
|
271
344
|
effort.data['hit 3'].must_equal 1
|
272
345
|
|
273
346
|
effort.complete?.must_equal true
|
274
|
-
|
347
|
+
effort.completed_at.must_equal Time.now
|
275
348
|
|
276
349
|
# FUTURE WAVES
|
277
350
|
send_postcard_if_necessary_worker.execute_all
|
@@ -575,10 +648,96 @@ describe "worker" do
|
|
575
648
|
fresh_effort = Seam::Effort.find(effort.id)
|
576
649
|
fresh_effort.next_step.nil?.must_equal true
|
577
650
|
end
|
651
|
+
|
652
|
+
it "should mark the completed_at date" do
|
653
|
+
fresh_effort = Seam::Effort.find(effort.id)
|
654
|
+
fresh_effort.completed_at.must_equal Time.now
|
655
|
+
end
|
578
656
|
|
579
657
|
it "should mark the history" do
|
580
658
|
effort.history[0].contrast_with!({"step"=>"apple", "result" => "eject" } )
|
581
659
|
end
|
582
660
|
|
583
661
|
end
|
662
|
+
|
663
|
+
describe "use the name of the worker to tie to a step" do
|
664
|
+
|
665
|
+
let(:effort) do
|
666
|
+
flow = Seam::Flow.new
|
667
|
+
flow.i_will_not_call_handles
|
668
|
+
|
669
|
+
e = flow.start
|
670
|
+
Seam::Effort.find(e.id)
|
671
|
+
end
|
672
|
+
|
673
|
+
before do
|
674
|
+
effort
|
675
|
+
worker = IWillNotCallHandlesWorker.new
|
676
|
+
IWillNotCallHandlesWorker.new.execute_all
|
677
|
+
end
|
678
|
+
|
679
|
+
it "should complete the effort" do
|
680
|
+
fresh_effort = Seam::Effort.find effort.id
|
681
|
+
fresh_effort.complete?.must_equal true
|
682
|
+
end
|
683
|
+
|
684
|
+
end
|
685
|
+
|
686
|
+
describe "making the current step available" do
|
687
|
+
it "should return the first step if on the first step" do
|
688
|
+
flow = Seam::Flow.new
|
689
|
+
flow.apple("test")
|
690
|
+
flow.orange
|
691
|
+
|
692
|
+
effort = flow.start( { first_name: 'John' } )
|
693
|
+
effort = Seam::Effort.find(effort.id)
|
694
|
+
|
695
|
+
effort.next_step.must_equal "apple"
|
696
|
+
|
697
|
+
apple_worker = Seam::Worker.new
|
698
|
+
apple_worker.handles(:apple)
|
699
|
+
def apple_worker.process
|
700
|
+
current_step.nil?.must_equal false
|
701
|
+
current_step["name"].must_equal "apple"
|
702
|
+
current_step["arguments"].must_equal ["test"]
|
703
|
+
end
|
704
|
+
|
705
|
+
apple_worker.execute effort
|
706
|
+
end
|
707
|
+
|
708
|
+
it "should return the second step if on the second step" do
|
709
|
+
flow = Seam::Flow.new
|
710
|
+
flow.apple("test")
|
711
|
+
flow.orange("another test")
|
712
|
+
|
713
|
+
effort = flow.start( { first_name: 'John' } )
|
714
|
+
effort = Seam::Effort.find(effort.id)
|
715
|
+
|
716
|
+
effort.next_step.must_equal "apple"
|
717
|
+
|
718
|
+
apple_worker = Seam::Worker.new
|
719
|
+
apple_worker.handles(:apple)
|
720
|
+
def apple_worker.process
|
721
|
+
current_step.nil?.must_equal false
|
722
|
+
current_step["name"].must_equal "apple"
|
723
|
+
current_step["arguments"].must_equal ["test"]
|
724
|
+
end
|
725
|
+
|
726
|
+
orange_worker = Seam::Worker.new
|
727
|
+
orange_worker.handles(:orange)
|
728
|
+
def orange_worker.process
|
729
|
+
current_step.nil?.must_equal false
|
730
|
+
current_step["name"].must_equal "orange"
|
731
|
+
current_step["arguments"].must_equal ["another test"]
|
732
|
+
end
|
733
|
+
|
734
|
+
apple_worker.execute_all
|
735
|
+
orange_worker.execute_all
|
736
|
+
end
|
737
|
+
end
|
738
|
+
end
|
739
|
+
|
740
|
+
class IWillNotCallHandlesWorker < Seam::Worker
|
741
|
+
# no calling handles here
|
742
|
+
def process; end
|
584
743
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seam-mongodb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-09-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -108,39 +108,39 @@ dependencies:
|
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
110
|
- !ruby/object:Gem::Dependency
|
111
|
-
name:
|
111
|
+
name: subtle
|
112
112
|
requirement: !ruby/object:Gem::Requirement
|
113
113
|
none: false
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ! '>='
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
118
|
-
type: :
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
none: false
|
122
122
|
requirements:
|
123
|
-
- -
|
123
|
+
- - ! '>='
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version: '
|
125
|
+
version: '0'
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
|
-
name:
|
127
|
+
name: bundler
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
129
129
|
none: false
|
130
130
|
requirements:
|
131
|
-
- -
|
131
|
+
- - ~>
|
132
132
|
- !ruby/object:Gem::Version
|
133
|
-
version: '
|
133
|
+
version: '1.3'
|
134
134
|
type: :development
|
135
135
|
prerelease: false
|
136
136
|
version_requirements: !ruby/object:Gem::Requirement
|
137
137
|
none: false
|
138
138
|
requirements:
|
139
|
-
- -
|
139
|
+
- - ~>
|
140
140
|
- !ruby/object:Gem::Version
|
141
|
-
version: '
|
141
|
+
version: '1.3'
|
142
142
|
- !ruby/object:Gem::Dependency
|
143
|
-
name:
|
143
|
+
name: rake
|
144
144
|
requirement: !ruby/object:Gem::Requirement
|
145
145
|
none: false
|
146
146
|
requirements:
|
@@ -236,6 +236,7 @@ files:
|
|
236
236
|
- seam-mongodb.gemspec
|
237
237
|
- spec/seam/effort_spec.rb
|
238
238
|
- spec/seam/flow_spec.rb
|
239
|
+
- spec/seam/step_spec.rb
|
239
240
|
- spec/seam/worker_spec.rb
|
240
241
|
- spec/spec_helper.rb
|
241
242
|
homepage: ''
|
@@ -253,7 +254,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
253
254
|
version: '0'
|
254
255
|
segments:
|
255
256
|
- 0
|
256
|
-
hash:
|
257
|
+
hash: -2871184592722645062
|
257
258
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
258
259
|
none: false
|
259
260
|
requirements:
|
@@ -262,7 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
262
263
|
version: '0'
|
263
264
|
segments:
|
264
265
|
- 0
|
265
|
-
hash:
|
266
|
+
hash: -2871184592722645062
|
266
267
|
requirements: []
|
267
268
|
rubyforge_project:
|
268
269
|
rubygems_version: 1.8.25
|
@@ -272,5 +273,6 @@ summary: MongoDB support for seam
|
|
272
273
|
test_files:
|
273
274
|
- spec/seam/effort_spec.rb
|
274
275
|
- spec/seam/flow_spec.rb
|
276
|
+
- spec/seam/step_spec.rb
|
275
277
|
- spec/seam/worker_spec.rb
|
276
278
|
- spec/spec_helper.rb
|