edge-state-machine 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.
@@ -1,13 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe EdgeStateMachine::State do
3
+ describe EdgeStateMachine::Transition do
4
4
  it "should set from, to, and opts attr readers" do
5
5
  opts = {:from => "foo", :to => "bar", :guard => "g"}
6
6
  st = EdgeStateMachine::Transition.new(opts)
7
7
 
8
- st.from.should == opts[:from]
9
- st.to.should == opts[:to]
10
- st.options.should == opts
8
+ st.from.should == [opts[:from]].flatten
9
+ st.to.should == [opts[:to]].flatten
11
10
  end
12
11
 
13
12
  it "should pass equality check if from and to are the same" do
@@ -30,42 +29,81 @@ describe EdgeStateMachine::State do
30
29
  obj = EdgeStateMachine::Transition.new(opts.merge({:to => "blah"}))
31
30
  obj.should_not == st
32
31
  end
33
- end
34
32
 
35
- describe "state transition guard check" do
36
- it "should return true of there is no guard" do
37
- opts = {:from => "foo", :to => "bar"}
38
- st = EdgeStateMachine::Transition.new(opts)
39
- st.perform(nil).should == true
40
- end
33
+ describe "state transition guard check" do
34
+ it "should return true of there is no guard" do
35
+ opts = {:from => "foo", :to => "bar"}
36
+ st = EdgeStateMachine::Transition.new(opts)
37
+ st.possible?(nil).should == true
38
+ end
41
39
 
42
- it "should call the method on the object if guard is a symbol" do
43
- opts = {:from => "foo", :to => "bar", :guard => :test_guard}
44
- st = EdgeStateMachine::Transition.new(opts)
40
+ it "should call the method on the object if guard is a symbol" do
41
+ opts = {:from => "foo", :to => "bar", :guard => :test_guard}
42
+ st = EdgeStateMachine::Transition.new(opts)
45
43
 
46
- obj = mock
47
- obj.should_receive(:test_guard)
44
+ obj = mock
45
+ obj.should_receive(:test_guard)
48
46
 
49
- st.perform(obj)
50
- end
47
+ st.find_next_state(obj)
48
+ end
51
49
 
52
- it "should call the method on the object if guard is a string" do
53
- opts = {:from => "foo", :to => "bar", :guard => "test_guard"}
54
- st = EdgeStateMachine::Transition.new(opts)
50
+ it "should call the method on the object if guard is a string" do
51
+ opts = {:from => "foo", :to => "bar", :guard => "test_guard"}
52
+ st = EdgeStateMachine::Transition.new(opts)
53
+
54
+ obj = mock
55
+ obj.should_receive(:test_guard)
56
+
57
+ st.find_next_state(obj)
58
+ end
55
59
 
56
- obj = mock
57
- obj.should_receive(:test_guard)
60
+ it "should call the proc passing the object if the guard is a proc" do
61
+ opts = {:from => "foo", :to => "bar", :guard => Proc.new {|o| o.test_guard}}
62
+ st = EdgeStateMachine::Transition.new(opts)
58
63
 
59
- st.perform(obj)
64
+ obj = mock
65
+ obj.should_receive(:test_guard)
66
+
67
+ st.find_next_state(obj)
68
+ end
60
69
  end
61
70
 
62
- it "should call the proc passing the object if the guard is a proc" do
63
- opts = {:from => "foo", :to => "bar", :guard => Proc.new {|o| o.test_guard}}
64
- st = EdgeStateMachine::Transition.new(opts)
71
+ describe "on transition execution" do
72
+ it "should call the method on the object if on_transition is a symbol" do
73
+ opts = {:from => "foo", :to => "bar", :on_transition => :test_on_transition}
74
+ st = EdgeStateMachine::Transition.new(opts)
75
+ obj = mock
76
+ obj.should_receive(:test_on_transition)
77
+ st.execute(obj)
78
+ end
65
79
 
66
- obj = mock
67
- obj.should_receive(:test_guard)
80
+ it "should call the method on the object if on_transition is a string" do
81
+ opts = {:from => 'foo', :to => 'bar', :on_transition => 'test_on_transition'}
82
+ st = EdgeStateMachine::Transition.new(opts)
83
+ obj = mock
84
+ obj.should_receive(:test_on_transition)
85
+ st.execute(obj)
86
+ end
68
87
 
69
- st.perform(obj)
88
+ it "should call the method on the object if on_transition is a proc" do
89
+ opts = {:from => 'foo', :to => 'bar', :on_transition => Proc.new {|o| o.test_on_transition}}
90
+ st = EdgeStateMachine::Transition.new(opts)
91
+ obj = mock
92
+ obj.should_receive(:test_on_transition)
93
+ st.execute(obj)
94
+ end
95
+
96
+ it "should call all the methods/procs if on_transition is an array" do
97
+ opts = { :from => 'foo',
98
+ :to => 'bar',
99
+ :on_transition => [Proc.new {|o| o.test_on_transition}, :test_on_transition, 'test_on_transition']}
100
+ st = EdgeStateMachine::Transition.new(opts)
101
+ obj = mock
102
+ obj.should_receive(:test_on_transition).exactly(3).times
103
+ st.execute(obj)
104
+ end
70
105
  end
71
- end
106
+ end
107
+
108
+
109
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edge-state-machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-24 00:00:00.000000000Z
12
+ date: 2011-12-05 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &20230980 !ruby/object:Gem::Requirement
16
+ requirement: &11532900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.6'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *20230980
24
+ version_requirements: *11532900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &20230400 !ruby/object:Gem::Requirement
27
+ requirement: &11532280 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *20230400
35
+ version_requirements: *11532280
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mongoid
38
- requirement: &20229600 !ruby/object:Gem::Requirement
38
+ requirement: &11531180 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *20229600
46
+ version_requirements: *11531180
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bson_ext
49
- requirement: &20228540 !ruby/object:Gem::Requirement
49
+ requirement: &11530460 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *20228540
57
+ version_requirements: *11530460
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: sqlite3-ruby
60
- requirement: &20227760 !ruby/object:Gem::Requirement
60
+ requirement: &11529120 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *20227760
68
+ version_requirements: *11529120
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activerecord
71
- requirement: &20226340 !ruby/object:Gem::Requirement
71
+ requirement: &11527760 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *20226340
79
+ version_requirements: *11527760
80
80
  description: Lightweight state machine extracted from ActiveModel
81
81
  email:
82
82
  - dan.persa@gmail.com
@@ -94,6 +94,7 @@ files:
94
94
  - lib/active_record/edge-state-machine.rb
95
95
  - lib/edge-state-machine.rb
96
96
  - lib/edge-state-machine/event.rb
97
+ - lib/edge-state-machine/exception.rb
97
98
  - lib/edge-state-machine/machine.rb
98
99
  - lib/edge-state-machine/state.rb
99
100
  - lib/edge-state-machine/transition.rb
@@ -103,10 +104,19 @@ files:
103
104
  - spec/active_record/active_record_spec.rb
104
105
  - spec/active_record/migrations/create_orders.rb
105
106
  - spec/active_record/migrations/create_traffic_lights.rb
107
+ - spec/active_record/samples/order.rb
108
+ - spec/active_record/samples/traffic_light.rb
106
109
  - spec/event_spec.rb
107
110
  - spec/machine_spec.rb
108
111
  - spec/mongoid/mongoid_helper.rb
109
112
  - spec/mongoid/mongoid_spec.rb
113
+ - spec/mongoid/samples/order.rb
114
+ - spec/mongoid/samples/traffic_light.rb
115
+ - spec/non_persistent/non_persistent_helper.rb
116
+ - spec/non_persistent/non_persistent_spec.rb
117
+ - spec/non_persistent/samples/dice.rb
118
+ - spec/non_persistent/samples/microwave.rb
119
+ - spec/non_persistent/samples/user.rb
110
120
  - spec/spec_helper.rb
111
121
  - spec/state_spec.rb
112
122
  - spec/transition_spec.rb