seam 1.1.2 → 2.0.0a1
Sign up to get free protection for your applications and to get access to all the features.
- 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/seam.gemspec
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'seam/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "seam"
|
8
|
-
spec.version = Seam::VERSION
|
9
|
-
spec.authors = ["Darren Cauthon"]
|
10
|
-
spec.email = ["darren@cauthon.com"]
|
11
|
-
spec.description = %q{Simple workflows}
|
12
|
-
spec.summary = %q{Simple workflows}
|
13
|
-
spec.homepage = ""
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = `git ls-files`.split($/)
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_runtime_dependency "activesupport"
|
22
|
-
spec.add_runtime_dependency "i18n"
|
23
|
-
spec.add_runtime_dependency "json"
|
24
|
-
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
-
spec.add_development_dependency "rake"
|
26
|
-
spec.add_development_dependency "subtle"
|
27
|
-
spec.add_development_dependency "mocha"
|
28
|
-
spec.add_development_dependency "contrast"
|
29
|
-
spec.add_development_dependency "timecop"
|
30
|
-
end
|
data/spec/seam/effort_spec.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe Seam::Effort do
|
4
|
-
before do
|
5
|
-
Seam::Persistence.destroy
|
6
|
-
end
|
7
|
-
|
8
|
-
let(:flow) do
|
9
|
-
f = Seam::Flow.new
|
10
|
-
f.step1
|
11
|
-
f.step2
|
12
|
-
f
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "updating an effort" do
|
16
|
-
it "should not create another document in the collection" do
|
17
|
-
first_effort = flow.start
|
18
|
-
Seam::Persistence.all.count.must_equal 1
|
19
|
-
first_effort.save
|
20
|
-
Seam::Persistence.all.count.must_equal 1
|
21
|
-
|
22
|
-
second_effort = flow.start
|
23
|
-
Seam::Persistence.all.count.must_equal 2
|
24
|
-
second_effort.save
|
25
|
-
Seam::Persistence.all.count.must_equal 2
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should update the information" do
|
29
|
-
first_effort = flow.start
|
30
|
-
second_effort = flow.start
|
31
|
-
|
32
|
-
first_effort.next_step = 'i_changed_the_first_one'
|
33
|
-
first_effort.save
|
34
|
-
first_effort.to_hash.contrast_with! Seam::Effort.find(first_effort.id).to_hash, [:id, :created_at]
|
35
|
-
second_effort.to_hash.contrast_with! Seam::Effort.find(second_effort.id).to_hash, [:id, :created_at]
|
36
|
-
|
37
|
-
second_effort.next_step = 'i_changed_the_second_one'
|
38
|
-
second_effort.save
|
39
|
-
first_effort.to_hash.contrast_with! Seam::Effort.find(first_effort.id).to_hash, [:id, :created_at]
|
40
|
-
second_effort.to_hash.contrast_with! Seam::Effort.find(second_effort.id).to_hash, [:id, :created_at]
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
data/spec/seam/flow_spec.rb
DELETED
@@ -1,173 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe "flow" do
|
4
|
-
before do
|
5
|
-
Seam::Persistence.destroy
|
6
|
-
end
|
7
|
-
|
8
|
-
after do
|
9
|
-
Timecop.return
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "a useful example" do
|
13
|
-
let(:flow) do
|
14
|
-
f = Seam::Flow.new
|
15
|
-
f.wait_for_attempting_contact_stage limit: 2.weeks
|
16
|
-
f.determine_if_postcard_should_be_sent
|
17
|
-
f.send_postcard_if_necessary
|
18
|
-
f
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "steps that must be taken" do
|
22
|
-
before do
|
23
|
-
flow
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should not throw an error" do
|
27
|
-
flow.steps.count.must_equal 3
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should set the name of the three steps" do
|
31
|
-
flow.steps[0].name.must_equal "wait_for_attempting_contact_stage"
|
32
|
-
flow.steps[1].name.must_equal "determine_if_postcard_should_be_sent"
|
33
|
-
flow.steps[2].name.must_equal "send_postcard_if_necessary"
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should set the step types of the three steps" do
|
37
|
-
flow.steps[0].type.must_equal "do"
|
38
|
-
flow.steps[1].type.must_equal "do"
|
39
|
-
flow.steps[2].type.must_equal "do"
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should set the arguments as well" do
|
43
|
-
flow.steps[0].arguments.must_equal [{ limit: 14.days.to_i }]
|
44
|
-
flow.steps[1].arguments.must_equal []
|
45
|
-
flow.steps[2].arguments.must_equal []
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "a more useful example" do
|
51
|
-
|
52
|
-
describe "starting an effort" do
|
53
|
-
let(:flow) do
|
54
|
-
flow = Seam::Flow.new
|
55
|
-
flow.do_something
|
56
|
-
flow.do_something_else
|
57
|
-
flow
|
58
|
-
end
|
59
|
-
|
60
|
-
let(:now) { Time.parse('1/1/2011') }
|
61
|
-
|
62
|
-
before do
|
63
|
-
Timecop.freeze now
|
64
|
-
|
65
|
-
@expected_uuid = SecureRandom.uuid.to_s
|
66
|
-
SecureRandom.stubs(:uuid).returns(@expected_uuid)
|
67
|
-
.then.returns(1)
|
68
|
-
.then.returns(2)
|
69
|
-
|
70
|
-
@effort = flow.start( { first_name: 'John' } )
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should mark no steps as completed" do
|
74
|
-
@effort.completed_steps.count.must_equal 0
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should stamp the effort with a uuid" do
|
78
|
-
@effort.id.must_equal @expected_uuid
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should stamp the create date" do
|
82
|
-
@effort.created_at.must_equal now
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should stamp the next execute date" do
|
86
|
-
@effort.next_execute_at.must_equal now
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should stamp the next step name" do
|
90
|
-
@effort.next_step.must_equal "do_something"
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should save an effort in the db" do
|
94
|
-
effort = Seam::Effort.find @effort.id
|
95
|
-
effort.to_hash.contrast_with! @effort.to_hash, [:id, :created_at]
|
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
|
-
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
describe "adding steps" do
|
108
|
-
describe "new steps" do
|
109
|
-
it "should return true" do
|
110
|
-
flow = Seam::Flow.new
|
111
|
-
flow.do_something.must_equal true
|
112
|
-
flow.do_something_else.must_equal true
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
describe "repeating steps" do
|
117
|
-
it "should only add the step once" do
|
118
|
-
flow = Seam::Flow.new
|
119
|
-
flow.do_something.must_equal true
|
120
|
-
flow.steps.count.must_equal 1
|
121
|
-
flow.do_something.must_equal true
|
122
|
-
flow.steps.count.must_equal 2
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe "repeating steps with different data" do
|
127
|
-
it "should only add the step once" do
|
128
|
-
flow = Seam::Flow.new
|
129
|
-
flow.do_something(special_id: 'one').must_equal true
|
130
|
-
flow.do_something( { special_id: 'two' }, 4).must_equal true
|
131
|
-
flow.steps.count.must_equal 2
|
132
|
-
|
133
|
-
flow.steps[0].arguments.count.must_equal 1
|
134
|
-
flow.steps[0].arguments[0].contrast_with!( { special_id: 'one' } )
|
135
|
-
flow.steps[1].arguments.count.must_equal 2
|
136
|
-
flow.steps[1].arguments[0].contrast_with!( { special_id: 'two' } )
|
137
|
-
flow.steps[1].arguments[1].must_equal 4
|
138
|
-
end
|
139
|
-
end
|
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
|
173
|
-
end
|
data/spec/seam/step_spec.rb
DELETED
@@ -1,34 +0,0 @@
|
|
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( { id: 'an id',
|
7
|
-
name: 'a name',
|
8
|
-
type: 'a type',
|
9
|
-
arguments: ['1234', 2] } )
|
10
|
-
step.id.must_equal 'an id'
|
11
|
-
step.name.must_equal 'a name'
|
12
|
-
step.type.must_equal 'a type'
|
13
|
-
step.arguments.count.must_equal 2
|
14
|
-
step.arguments[0].must_equal '1234'
|
15
|
-
step.arguments[1].must_equal 2
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "to hash" do
|
20
|
-
it "should allow values to be set with the constructor" do
|
21
|
-
step = Seam::Step.new( { id: 'an id',
|
22
|
-
name: 'a name',
|
23
|
-
type: 'a type',
|
24
|
-
arguments: ['1234', 2] } )
|
25
|
-
step = Seam::Step.new step.to_hash
|
26
|
-
step.id.must_equal 'an id'
|
27
|
-
step.name.must_equal 'a name'
|
28
|
-
step.type.must_equal 'a type'
|
29
|
-
step.arguments.count.must_equal 2
|
30
|
-
step.arguments[0].must_equal '1234'
|
31
|
-
step.arguments[1].must_equal 2
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,179 +0,0 @@
|
|
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
|