45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/call_center/test/dsl.rb', line 45
def should_flow(options, &block)
event = options.delete(:on)
setup_block = options.delete(:when)
setup_block_line = setup_block.to_s.match(/.*@(.*):([0-9]+)>/)[2] if setup_block
state_field = self.call_center_state_field || options.delete(:state) || :state
from, to = options.to_a.first
description = ":#{from} => :#{to} via #{event}!#{setup_block_line.present? ? " when:#{setup_block_line}" : nil}"
context "" do
should "transition #{description}" do
self.instance_eval(&setup_block) if setup_block
@call.send(:"#{state_field}=", from.to_s)
@call.send(:"#{event}")
assert_equal to, @call.send(:"#{state_field}_name"), "status should be :#{to}, not :#{@call.send(state_field)}"
if @call.respond_to?(:call_flow_run_deferred)
@call.call_flow_run_deferred(:before_transition)
@call.call_flow_run_deferred(:after_transition)
@call.call_flow_run_deferred(:after_failure)
end
end
if block.present?
context "#{description} and :#{to}" do
setup do
self.instance_eval(&setup_block) if setup_block
@call.send(:"#{state_field}=", from.to_s)
@call.send(:"#{event}")
body(@call.render) if @call.respond_to?(:render)
if @call.respond_to?(:call_flow_run_deferred)
@call.call_flow_run_deferred(:before_transition)
@call.call_flow_run_deferred(:after_transition)
@call.call_flow_run_deferred(:after_failure)
end
end
self.instance_eval(&block)
end
end
end
end
|