simple_state_machine 0.5.3 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Changelog.rdoc +23 -0
- data/README.rdoc +154 -100
- data/lib/simple_state_machine/active_record.rb +2 -62
- data/lib/simple_state_machine/decorator/active_record.rb +68 -0
- data/lib/simple_state_machine/decorator/default.rb +91 -0
- data/lib/simple_state_machine/railtie.rb +1 -1
- data/lib/simple_state_machine/simple_state_machine.rb +8 -251
- data/lib/simple_state_machine/state_machine.rb +88 -0
- data/lib/simple_state_machine/state_machine_definition.rb +72 -0
- data/lib/simple_state_machine/tools/graphviz.rb +21 -0
- data/lib/simple_state_machine/tools/inspector.rb +44 -0
- data/lib/simple_state_machine/transition.rb +40 -0
- data/lib/simple_state_machine/version.rb +1 -1
- data/lib/simple_state_machine.rb +13 -3
- data/lib/tasks/graphviz.rake +31 -0
- metadata +37 -150
- data/.gitignore +0 -1
- data/.rspec +0 -3
- data/Gemfile +0 -4
- data/Rakefile +0 -28
- data/autotest/discover.rb +0 -1
- data/examples/conversation.rb +0 -33
- data/examples/lamp.rb +0 -21
- data/examples/relationship.rb +0 -87
- data/examples/traffic_light.rb +0 -17
- data/examples/user.rb +0 -37
- data/lib/tasks/graphiz.rake +0 -13
- data/rails/graphiz.rake +0 -16
- data/simple_state_machine.gemspec +0 -31
- data/spec/active_record_spec.rb +0 -223
- data/spec/decorator_spec.rb +0 -195
- data/spec/examples_spec.rb +0 -60
- data/spec/mountable_spec.rb +0 -24
- data/spec/simple_state_machine_spec.rb +0 -129
- data/spec/spec_helper.rb +0 -7
- data/spec/state_machine_definition_spec.rb +0 -89
- data/spec/state_machine_spec.rb +0 -26
@@ -1,89 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe SimpleStateMachine::StateMachineDefinition do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@klass = Class.new do
|
7
|
-
extend SimpleStateMachine
|
8
|
-
def initialize(state = 'state1')
|
9
|
-
@state = state
|
10
|
-
end
|
11
|
-
event :event1, :state1 => :state2, :state2 => :state3
|
12
|
-
end
|
13
|
-
@smd = @klass.state_machine_definition
|
14
|
-
end
|
15
|
-
|
16
|
-
it "is inherited by subclasses" do
|
17
|
-
example = Class.new(@klass).new
|
18
|
-
example.should be_state1
|
19
|
-
example.event1
|
20
|
-
example.should be_state2
|
21
|
-
example.event1
|
22
|
-
example.should be_state3
|
23
|
-
end
|
24
|
-
|
25
|
-
describe '#state_method' do
|
26
|
-
subject do
|
27
|
-
klass = Class.new do
|
28
|
-
attr_reader :ssm_state
|
29
|
-
extend SimpleStateMachine
|
30
|
-
state_machine_definition.state_method = :ssm_state
|
31
|
-
|
32
|
-
def initialize(state = 'state1')
|
33
|
-
@ssm_state = state
|
34
|
-
end
|
35
|
-
event :event1, :state1 => :state2
|
36
|
-
event :event2, :state2 => :state3
|
37
|
-
end
|
38
|
-
klass.new
|
39
|
-
end
|
40
|
-
|
41
|
-
it "is used when changing state" do
|
42
|
-
subject.ssm_state.should == 'state1'
|
43
|
-
subject.event1
|
44
|
-
subject.ssm_state.should == 'state2'
|
45
|
-
subject.event2
|
46
|
-
subject.ssm_state.should == 'state3'
|
47
|
-
end
|
48
|
-
|
49
|
-
it "works with state helper methods" do
|
50
|
-
subject.should be_state1
|
51
|
-
subject.event1
|
52
|
-
subject.should be_state2
|
53
|
-
subject.event2
|
54
|
-
subject.should be_state3
|
55
|
-
end
|
56
|
-
|
57
|
-
it "raise an error if an invalid state_transition is called" do
|
58
|
-
lambda { subject.event2 }.should raise_error(SimpleStateMachine::IllegalStateTransitionError, "You cannot 'event2' when state is 'state1'")
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
describe "#transitions" do
|
64
|
-
it "has a list of transitions" do
|
65
|
-
@smd.transitions.should be_a(Array)
|
66
|
-
@smd.transitions.first.should be_a(SimpleStateMachine::Transition)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "#to_s" do
|
71
|
-
it "converts to readable string format" do
|
72
|
-
@smd.to_s.should =~ Regexp.new("state1.event1! => state2")
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "#to_graphiz_dot" do
|
77
|
-
it "converts to graphiz dot format" do
|
78
|
-
@smd.to_graphiz_dot.should == %("state1"->"state2"[label=event1];"state2"->"state3"[label=event1])
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe "#google_chart_url" do
|
83
|
-
it "shows the state and event dependencies as a Google chart" do
|
84
|
-
puts "http://chart.googleapis.com/chart?cht=gv&chl=digraph{#{::CGI.escape @smd.to_graphiz_dot}}"
|
85
|
-
@smd.google_chart_url.should == "http://chart.googleapis.com/chart?cht=gv&chl=digraph{#{::CGI.escape @smd.to_graphiz_dot}}"
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
data/spec/state_machine_spec.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe SimpleStateMachine::StateMachine do
|
4
|
-
|
5
|
-
describe "#next_state" do
|
6
|
-
subject do
|
7
|
-
klass = Class.new do
|
8
|
-
extend SimpleStateMachine
|
9
|
-
def initialize() @state = 'state1' end
|
10
|
-
event :event1, :state1 => :state2
|
11
|
-
event :event2, :state2 => :state3
|
12
|
-
end
|
13
|
-
klass.new.state_machine
|
14
|
-
end
|
15
|
-
|
16
|
-
it "returns the next state for the event and current state" do
|
17
|
-
subject.next_state('event1').should == 'state2'
|
18
|
-
end
|
19
|
-
|
20
|
-
it "returns nil if no next state for the event and current state exists" do
|
21
|
-
subject.next_state('event2').should be_nil
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|