seam 1.1.3 → 2.0.0a2
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 +137 -0
- data/LICENSE.txt +16 -18
- data/README.md +118 -115
- data/Rakefile +23 -0
- data/lib/seam/client.rb +129 -0
- data/lib/seam/clients/access_codes.rb +95 -0
- data/lib/seam/clients/access_codes_simulate.rb +17 -0
- data/lib/seam/clients/access_codes_unmanaged.rb +57 -0
- data/lib/seam/clients/acs.rb +35 -0
- data/lib/seam/clients/acs_access_groups.rb +57 -0
- data/lib/seam/clients/acs_credential_pools.rb +17 -0
- data/lib/seam/clients/acs_credential_provisioning_automations.rb +17 -0
- data/lib/seam/clients/acs_credentials.rb +77 -0
- data/lib/seam/clients/acs_entrances.rb +47 -0
- data/lib/seam/clients/acs_systems.rb +27 -0
- data/lib/seam/clients/acs_users.rb +117 -0
- data/lib/seam/clients/action_attempts.rb +30 -0
- data/lib/seam/clients/base_client.rb +21 -0
- data/lib/seam/clients/client_sessions.rb +77 -0
- data/lib/seam/clients/connect_webviews.rb +47 -0
- data/lib/seam/clients/connected_accounts.rb +47 -0
- data/lib/seam/clients/devices.rb +65 -0
- data/lib/seam/clients/devices_simulate.rb +17 -0
- data/lib/seam/clients/devices_unmanaged.rb +37 -0
- data/lib/seam/clients/events.rb +27 -0
- data/lib/seam/clients/locks.rb +53 -0
- data/lib/seam/clients/networks.rb +27 -0
- data/lib/seam/clients/noise_sensors.rb +15 -0
- data/lib/seam/clients/noise_sensors_noise_thresholds.rb +57 -0
- data/lib/seam/clients/noise_sensors_simulate.rb +17 -0
- data/lib/seam/clients/phones.rb +31 -0
- data/lib/seam/clients/phones_simulate.rb +17 -0
- data/lib/seam/clients/thermostats.rb +106 -0
- data/lib/seam/clients/thermostats_climate_setting_schedules.rb +57 -0
- data/lib/seam/clients/user_identities.rb +131 -0
- data/lib/seam/clients/user_identities_enrollment_automations.rb +47 -0
- data/lib/seam/clients/webhooks.rb +57 -0
- data/lib/seam/clients/workspaces.rb +50 -0
- data/lib/seam/logger.rb +12 -0
- data/lib/seam/lts_version.rb +5 -0
- data/lib/seam/request.rb +73 -0
- data/lib/seam/resources/access_code.rb +12 -0
- data/lib/seam/resources/acs_access_group.rb +9 -0
- data/lib/seam/resources/acs_credential.rb +12 -0
- data/lib/seam/resources/acs_credential_pool.rb +9 -0
- data/lib/seam/resources/acs_credential_provisioning_automation.rb +9 -0
- data/lib/seam/resources/acs_entrance.rb +9 -0
- data/lib/seam/resources/acs_system.rb +9 -0
- data/lib/seam/resources/acs_user.rb +9 -0
- data/lib/seam/resources/action_attempt.rb +46 -0
- data/lib/seam/resources/base_resource.rb +58 -0
- data/lib/seam/resources/client_session.rb +9 -0
- data/lib/seam/resources/climate_setting_schedule.rb +11 -0
- data/lib/seam/resources/connect_webview.rb +9 -0
- data/lib/seam/resources/connected_account.rb +12 -0
- data/lib/seam/resources/device.rb +12 -0
- data/lib/seam/resources/device_provider.rb +7 -0
- data/lib/seam/resources/enrollment_automation.rb +9 -0
- data/lib/seam/resources/event.rb +9 -0
- data/lib/seam/resources/network.rb +9 -0
- data/lib/seam/resources/noise_threshold.rb +7 -0
- data/lib/seam/resources/phone.rb +12 -0
- data/lib/seam/resources/resource_error.rb +9 -0
- data/lib/seam/resources/resource_errors_support.rb +9 -0
- data/lib/seam/resources/resource_warning.rb +9 -0
- data/lib/seam/resources/resource_warnings_support.rb +9 -0
- data/lib/seam/resources/service_health.rb +7 -0
- data/lib/seam/resources/unmanaged_access_code.rb +12 -0
- data/lib/seam/resources/unmanaged_device.rb +12 -0
- data/lib/seam/resources/user_identity.rb +9 -0
- data/lib/seam/resources/webhook.rb +7 -0
- data/lib/seam/resources/workspace.rb +7 -0
- data/lib/seam/version.rb +3 -1
- data/lib/seam.rb +71 -13
- metadata +147 -82
- 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 -973
- data/spec/spec_helper.rb +0 -8
data/lib/seam/effort.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
module Seam
|
2
|
-
class Effort
|
3
|
-
attr_accessor :completed_steps
|
4
|
-
attr_accessor :created_at
|
5
|
-
attr_accessor :complete
|
6
|
-
attr_accessor :completed_at
|
7
|
-
attr_accessor :id
|
8
|
-
attr_accessor :next_execute_at
|
9
|
-
attr_accessor :next_step
|
10
|
-
attr_accessor :flow
|
11
|
-
attr_accessor :data
|
12
|
-
attr_accessor :history
|
13
|
-
|
14
|
-
class << self
|
15
|
-
|
16
|
-
def find effort_id
|
17
|
-
Seam::Persistence.find_by_effort_id effort_id
|
18
|
-
end
|
19
|
-
|
20
|
-
def find_all_by_step step
|
21
|
-
Seam::Persistence.find_all_pending_executions_by_step step
|
22
|
-
end
|
23
|
-
|
24
|
-
def parse document
|
25
|
-
Effort.new( {
|
26
|
-
id: document['id'],
|
27
|
-
created_at: Time.parse(document['created_at'].to_s),
|
28
|
-
next_execute_at: document['next_execute_at'],
|
29
|
-
next_step: document['next_step'],
|
30
|
-
flow: HashWithIndifferentAccess.new(document['flow']),
|
31
|
-
data: HashWithIndifferentAccess.new(document['data']),
|
32
|
-
history: document['history'].map { |x| HashWithIndifferentAccess.new x },
|
33
|
-
completed_steps: document['completed_steps'],
|
34
|
-
complete: document['complete'],
|
35
|
-
completed_at: document['completed_at']
|
36
|
-
} )
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
def initialize(args = {})
|
42
|
-
@completed_steps = []
|
43
|
-
@history = []
|
44
|
-
@complete = false
|
45
|
-
args.each { |k, v| self.send "#{k}=".to_sym, v }
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.create args
|
49
|
-
effort = Seam::Effort.new args
|
50
|
-
effort.save
|
51
|
-
effort
|
52
|
-
end
|
53
|
-
|
54
|
-
def save
|
55
|
-
existing_record = Seam::Effort.find self.id
|
56
|
-
if existing_record
|
57
|
-
Seam::Persistence.save self
|
58
|
-
else
|
59
|
-
Seam::Persistence.create self
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def complete?
|
64
|
-
complete
|
65
|
-
end
|
66
|
-
|
67
|
-
def to_hash
|
68
|
-
{
|
69
|
-
id: self.id,
|
70
|
-
created_at: self.created_at,
|
71
|
-
completed_steps: self.completed_steps,
|
72
|
-
completed_at: self.completed_at,
|
73
|
-
next_execute_at: self.next_execute_at,
|
74
|
-
next_step: self.next_step,
|
75
|
-
flow: self.flow,
|
76
|
-
data: self.data,
|
77
|
-
history: self.history,
|
78
|
-
complete: self.complete,
|
79
|
-
}
|
80
|
-
end
|
81
|
-
|
82
|
-
def clone
|
83
|
-
Seam::Effort.parse HashWithIndifferentAccess.new(self.to_hash)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
data/lib/seam/flow.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
module Seam
|
2
|
-
class Flow
|
3
|
-
|
4
|
-
attr_accessor :stamp_data_history
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
@steps = []
|
8
|
-
@stamp_data_history = false
|
9
|
-
end
|
10
|
-
|
11
|
-
def method_missing(meth, *args, &blk)
|
12
|
-
meth = meth.to_s
|
13
|
-
@steps << { name: meth, arguments: args }
|
14
|
-
true
|
15
|
-
end
|
16
|
-
|
17
|
-
def start(data = {})
|
18
|
-
Seam::Effort.create( {
|
19
|
-
id: SecureRandom.uuid.to_s,
|
20
|
-
created_at: Time.parse(Time.now.to_s),
|
21
|
-
next_execute_at: Time.parse(Time.now.to_s),
|
22
|
-
next_step: self.steps.first.name.to_s,
|
23
|
-
flow: the_flow_from,
|
24
|
-
data: ActiveSupport::HashWithIndifferentAccess.new(data)
|
25
|
-
} )
|
26
|
-
end
|
27
|
-
|
28
|
-
def the_flow_from
|
29
|
-
hash = self.to_hash
|
30
|
-
flow = ActiveSupport::HashWithIndifferentAccess.new hash
|
31
|
-
flow['steps'].each do |step|
|
32
|
-
step['id'] = SecureRandom.uuid.to_s
|
33
|
-
end
|
34
|
-
flow
|
35
|
-
end
|
36
|
-
|
37
|
-
def to_hash
|
38
|
-
{
|
39
|
-
steps: self.steps.map { |x| x.to_hash },
|
40
|
-
stamp_data_history: @stamp_data_history
|
41
|
-
}
|
42
|
-
end
|
43
|
-
|
44
|
-
def steps
|
45
|
-
@steps.each.map do |step|
|
46
|
-
Seam::Step.new( { name: step[:name],
|
47
|
-
type: 'do',
|
48
|
-
arguments: step[:arguments] } )
|
49
|
-
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
data/lib/seam/in_memory.rb
DELETED
data/lib/seam/persistence.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
module Seam
|
2
|
-
module Persistence
|
3
|
-
def self.find_by_effort_id effort_id
|
4
|
-
effort = Seam::InMemory.records.select { |x| x.id == effort_id }.first
|
5
|
-
return nil unless effort
|
6
|
-
effort.clone
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.find_all_pending_executions_by_step step
|
10
|
-
Seam::InMemory.records
|
11
|
-
.select { |x| x.next_step == step && x.next_execute_at <= Time.now }
|
12
|
-
.map { |x| x.clone }
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.find_something_to_do
|
16
|
-
Seam::InMemory.records
|
17
|
-
.select { |x| x.complete.nil? || x.complete == false }
|
18
|
-
.select { |x| x.next_execute_at <= Time.now }
|
19
|
-
.select { |x| x.next_step != nil }
|
20
|
-
.map { |x| x.clone }
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.save effort
|
24
|
-
old_record = find_by_effort_id effort.id
|
25
|
-
if old_record
|
26
|
-
Seam::InMemory.records = Seam::InMemory.records.select { |x| x.id != effort.id }.to_a
|
27
|
-
end
|
28
|
-
create effort
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.create effort
|
32
|
-
Seam::InMemory.records = [Seam::InMemory.records, effort].flatten
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.all
|
36
|
-
Seam::InMemory.records.to_a
|
37
|
-
end
|
38
|
-
|
39
|
-
def self.destroy
|
40
|
-
Seam::InMemory.records = []
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
data/lib/seam/step.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
module Seam
|
2
|
-
class Step
|
3
|
-
attr_accessor :id
|
4
|
-
attr_accessor :name
|
5
|
-
attr_accessor :type
|
6
|
-
attr_accessor :arguments
|
7
|
-
|
8
|
-
def initialize(args = {})
|
9
|
-
args.each { |k, v| self.send "#{k}=".to_sym, v }
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_hash
|
13
|
-
{
|
14
|
-
id: id,
|
15
|
-
name: name,
|
16
|
-
type: type,
|
17
|
-
arguments: get_arguments
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def get_arguments
|
24
|
-
arguments.map do |x|
|
25
|
-
if x.is_a? Hash
|
26
|
-
HashWithIndifferentAccess.new(x)
|
27
|
-
else
|
28
|
-
x
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/lib/seam/wait_worker.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
module Seam
|
2
|
-
|
3
|
-
class WaitWorker < ::Seam::Worker
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
handles :wait
|
7
|
-
end
|
8
|
-
|
9
|
-
def process
|
10
|
-
move_to_next_step( { on: the_time_to_move_on } )
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def the_time_to_move_on
|
16
|
-
time_of_last_execution + the_amount_of_time_to_wait
|
17
|
-
end
|
18
|
-
|
19
|
-
def the_amount_of_time_to_wait
|
20
|
-
current_step[:arguments][0]
|
21
|
-
end
|
22
|
-
|
23
|
-
def time_of_last_execution
|
24
|
-
return effort.created_at if effort.history.count == 0
|
25
|
-
effort.history.last[:stopped_at]
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
data/lib/seam/worker.rb
DELETED
@@ -1,166 +0,0 @@
|
|
1
|
-
module Seam
|
2
|
-
|
3
|
-
class Worker
|
4
|
-
|
5
|
-
def handles step
|
6
|
-
@step = step
|
7
|
-
end
|
8
|
-
|
9
|
-
def execute effort
|
10
|
-
set_current_effort effort
|
11
|
-
before_process
|
12
|
-
process
|
13
|
-
after_process
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.inherited handler
|
17
|
-
@handlers ||= []
|
18
|
-
@handlers << handler
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.handler_for step
|
22
|
-
@handlers.each do |handler|
|
23
|
-
instance = handler.new
|
24
|
-
return instance if instance.step == step
|
25
|
-
end
|
26
|
-
nil
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.all
|
30
|
-
(@handlers || []).map { |x| x.new }
|
31
|
-
end
|
32
|
-
|
33
|
-
def execute_all
|
34
|
-
efforts_to_execute.each { |e| execute e }
|
35
|
-
end
|
36
|
-
|
37
|
-
def eject
|
38
|
-
@operation_to_execute = :eject
|
39
|
-
end
|
40
|
-
|
41
|
-
def move_to_next_step(options = {})
|
42
|
-
@operation_to_execute = :move_to_next_step
|
43
|
-
operation_args[:next_execute_at] = (options[:on] || Time.now)
|
44
|
-
end
|
45
|
-
|
46
|
-
def try_again_in seconds
|
47
|
-
@operation_to_execute = :try_again_in
|
48
|
-
operation_args[:seconds] = seconds
|
49
|
-
end
|
50
|
-
|
51
|
-
def try_again_on time
|
52
|
-
@operation_to_execute = :try_again_on
|
53
|
-
operation_args[:time] = time
|
54
|
-
end
|
55
|
-
|
56
|
-
attr_accessor :operation_args
|
57
|
-
def operation_args
|
58
|
-
@operation_args ||= {}
|
59
|
-
end
|
60
|
-
|
61
|
-
def operations
|
62
|
-
{
|
63
|
-
try_again_in: -> do
|
64
|
-
seconds = operation_args[:seconds]
|
65
|
-
try_again_on = Time.now + seconds
|
66
|
-
|
67
|
-
history[:try_again_on] = try_again_on
|
68
|
-
|
69
|
-
effort.next_execute_at = try_again_on
|
70
|
-
end,
|
71
|
-
try_again_on: -> do
|
72
|
-
history[:try_again_on] = operation_args[:time]
|
73
|
-
effort.next_execute_at = operation_args[:time]
|
74
|
-
end,
|
75
|
-
move_to_next_step: -> do
|
76
|
-
effort.next_execute_at = operation_args[:next_execute_at] if operation_args[:next_execute_at]
|
77
|
-
|
78
|
-
effort.completed_steps << effort.next_step
|
79
|
-
|
80
|
-
steps = effort.flow['steps'].map { |x| x['name'] }
|
81
|
-
next_step = steps[effort.completed_steps.count]
|
82
|
-
|
83
|
-
effort.next_step = next_step
|
84
|
-
mark_effort_as_complete if next_step.nil?
|
85
|
-
|
86
|
-
end,
|
87
|
-
eject: -> { mark_effort_as_complete }
|
88
|
-
}
|
89
|
-
end
|
90
|
-
|
91
|
-
def effort
|
92
|
-
@current_effort
|
93
|
-
end
|
94
|
-
|
95
|
-
def history
|
96
|
-
@current_run
|
97
|
-
end
|
98
|
-
|
99
|
-
def step
|
100
|
-
s = @step || self.class.name.underscore.gsub('_worker', '').split('/')[-1]
|
101
|
-
s.to_s
|
102
|
-
end
|
103
|
-
|
104
|
-
def current_step
|
105
|
-
effort.flow["steps"][effort.completed_steps.count]
|
106
|
-
end
|
107
|
-
|
108
|
-
private
|
109
|
-
|
110
|
-
def mark_effort_as_complete
|
111
|
-
effort.next_step = nil
|
112
|
-
effort.complete = true
|
113
|
-
effort.completed_at = Time.now
|
114
|
-
end
|
115
|
-
|
116
|
-
def set_current_effort effort
|
117
|
-
@current_effort = effort
|
118
|
-
end
|
119
|
-
|
120
|
-
def before_process
|
121
|
-
run = {
|
122
|
-
started_at: Time.now,
|
123
|
-
step: step,
|
124
|
-
step_id: current_step['id'],
|
125
|
-
data_before: stamping_the_history? ? effort.data.clone : nil
|
126
|
-
}
|
127
|
-
@current_run = HashWithIndifferentAccess.new run
|
128
|
-
end
|
129
|
-
|
130
|
-
def after_process
|
131
|
-
execute_the_appropriate_operation
|
132
|
-
stamp_the_new_history_record
|
133
|
-
save_the_effort
|
134
|
-
end
|
135
|
-
|
136
|
-
def efforts_to_execute
|
137
|
-
Seam::Effort.find_all_by_step step
|
138
|
-
end
|
139
|
-
|
140
|
-
def execute_the_appropriate_operation
|
141
|
-
@operation_to_execute ||= :move_to_next_step
|
142
|
-
operations[@operation_to_execute].call
|
143
|
-
end
|
144
|
-
|
145
|
-
def stamp_the_new_history_record
|
146
|
-
history[:result] = @operation_to_execute
|
147
|
-
history[:stopped_at] = Time.now
|
148
|
-
|
149
|
-
if stamping_the_history?
|
150
|
-
history[:data_after] = effort.data.clone
|
151
|
-
end
|
152
|
-
|
153
|
-
effort.history << history
|
154
|
-
end
|
155
|
-
|
156
|
-
def stamping_the_history?
|
157
|
-
effort.flow['stamp_data_history']
|
158
|
-
end
|
159
|
-
|
160
|
-
def save_the_effort
|
161
|
-
effort.save
|
162
|
-
end
|
163
|
-
|
164
|
-
end
|
165
|
-
|
166
|
-
end
|
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
|