simple_machine 1.0.1 → 1.0.2
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.
- data/lib/simple_machine.rb +6 -3
- data/spec/spec_simple_machine.rb +11 -7
- metadata +4 -4
data/lib/simple_machine.rb
CHANGED
@@ -102,7 +102,7 @@ module SimpleMachine
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
-
SimpleMachine::ClassMethods.get_state_machine_class_for(self, state_field_name).instance_eval &block
|
105
|
+
SimpleMachine::ClassMethods.get_state_machine_class_for(self, state_field_name, true).instance_eval &block
|
106
106
|
|
107
107
|
raise "Initial state not defined." unless send default_state_field_name
|
108
108
|
end
|
@@ -111,10 +111,13 @@ module SimpleMachine
|
|
111
111
|
|
112
112
|
@state_machine_classes = {}
|
113
113
|
|
114
|
-
def self.get_state_machine_class_for(cls, state_field_name)
|
114
|
+
def self.get_state_machine_class_for(cls, state_field_name, delete_if_exists=false)
|
115
115
|
key = [cls.to_s.to_sym, state_field_name]
|
116
|
+
if @state_machine_classes.has_key? key and delete_if_exists
|
117
|
+
@state_machine_classes.delete key
|
118
|
+
end
|
116
119
|
unless @state_machine_classes.has_key? key
|
117
|
-
@state_machine_classes[key]
|
120
|
+
@state_machine_classes[key] = SimpleMachine::SimpleMachinePrototype.clone
|
118
121
|
@state_machine_classes[key].owner_class = cls
|
119
122
|
@state_machine_classes[key].parents_state_field_name = state_field_name
|
120
123
|
end
|
data/spec/spec_simple_machine.rb
CHANGED
@@ -34,7 +34,7 @@ describe SimpleMachine, "for :dispatch_state field on Job, when state machine is
|
|
34
34
|
end
|
35
35
|
|
36
36
|
context "with only initial state :waiting" do
|
37
|
-
before :
|
37
|
+
before :all do
|
38
38
|
Job.implement_state_machine_for :dispatch_state do
|
39
39
|
initial_state :waiting
|
40
40
|
end
|
@@ -200,12 +200,11 @@ describe SimpleMachine, "for :dispatch_state field on Job, when state machine is
|
|
200
200
|
end
|
201
201
|
context "when there are more job instances" do
|
202
202
|
before :all do
|
203
|
-
Job.new.dispatch_state_machine.class
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
end
|
203
|
+
@inner_state_machine_class = Job.new.dispatch_state_machine.class
|
204
|
+
@inner_state_machine_class.expects(:defined_transition?).with(:assign, :waiting).returns false
|
205
|
+
@inner_state_machine_class.expects(:defined_transition?).with(:accept, :assigned)
|
206
|
+
@inner_state_machine_class.allow_transition :assign, :from => :waiting, :to => :assigned
|
207
|
+
@inner_state_machine_class.allow_transition :accept, :from => :assigned, :to => :accepted
|
209
208
|
end
|
210
209
|
|
211
210
|
it "each instance tracks it's own flow" do
|
@@ -222,4 +221,9 @@ describe SimpleMachine, "for :dispatch_state field on Job, when state machine is
|
|
222
221
|
job3.dispatch_state.should be(:waiting)
|
223
222
|
end
|
224
223
|
end
|
224
|
+
context "when invoking implement_state_machine_for :dispatch_state on Job again" do
|
225
|
+
xit "undos meta works from previous invocation" do
|
226
|
+
|
227
|
+
end
|
228
|
+
end
|
225
229
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_machine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 2
|
10
|
+
version: 1.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Milan Burmaja
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-12-
|
18
|
+
date: 2010-12-17 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|