state_machine 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +10 -0
- data/README.rdoc +8 -0
- data/Rakefile +1 -1
- data/examples/merb-rest/view_edit.html.erb +2 -2
- data/examples/merb-rest/view_index.html.erb +2 -2
- data/examples/merb-rest/view_show.html.erb +2 -2
- data/examples/rails-rest/view_edit.html.erb +2 -2
- data/examples/rails-rest/view_index.html.erb +2 -2
- data/examples/rails-rest/view_show.html.erb +2 -2
- data/lib/state_machine.rb +34 -0
- data/lib/state_machine/event.rb +17 -2
- data/lib/state_machine/event_collection.rb +1 -1
- data/lib/state_machine/integrations/active_model.rb +39 -15
- data/lib/state_machine/integrations/active_model/locale.rb +2 -2
- data/lib/state_machine/integrations/active_record.rb +15 -3
- data/lib/state_machine/integrations/active_record/locale.rb +16 -0
- data/lib/state_machine/integrations/mongo_mapper.rb +16 -2
- data/lib/state_machine/machine.rb +53 -10
- data/lib/state_machine/machine_collection.rb +1 -1
- data/lib/state_machine/state.rb +12 -1
- data/lib/state_machine/transition.rb +50 -34
- data/test/files/en.yml +9 -0
- data/test/{classes → files}/switch.rb +0 -0
- data/test/functional/state_machine_test.rb +9 -0
- data/test/unit/event_collection_test.rb +5 -7
- data/test/unit/event_test.rb +51 -0
- data/test/unit/integrations/active_model_test.rb +80 -33
- data/test/unit/integrations/active_record_test.rb +89 -30
- data/test/unit/integrations/data_mapper_test.rb +25 -1
- data/test/unit/integrations/mongo_mapper_test.rb +40 -7
- data/test/unit/integrations/sequel_test.rb +25 -1
- data/test/unit/machine_collection_test.rb +1 -1
- data/test/unit/machine_test.rb +123 -4
- data/test/unit/state_test.rb +53 -0
- data/test/unit/transition_test.rb +20 -0
- metadata +4 -3
data/test/unit/state_test.rb
CHANGED
@@ -18,6 +18,10 @@ class StateByDefaultTest < Test::Unit::TestCase
|
|
18
18
|
assert_equal :parked, @state.name
|
19
19
|
end
|
20
20
|
|
21
|
+
def test_should_have_a_human_name
|
22
|
+
assert_equal 'parked', @state.human_name
|
23
|
+
end
|
24
|
+
|
21
25
|
def test_should_use_stringify_the_name_as_the_value
|
22
26
|
assert_equal 'parked', @state.value
|
23
27
|
end
|
@@ -69,6 +73,11 @@ class StateTest < Test::Unit::TestCase
|
|
69
73
|
assert_equal matcher, @state.matcher
|
70
74
|
end
|
71
75
|
|
76
|
+
def test_should_allow_changing_human_name
|
77
|
+
@state.human_name = 'stopped'
|
78
|
+
assert_equal 'stopped', @state.human_name
|
79
|
+
end
|
80
|
+
|
72
81
|
def test_should_use_pretty_inspect
|
73
82
|
assert_equal '#<StateMachine::State name=:parked value="parked" initial=false context=[]>', @state.inspect
|
74
83
|
end
|
@@ -89,6 +98,10 @@ class StateWithoutNameTest < Test::Unit::TestCase
|
|
89
98
|
assert_nil @state.qualified_name
|
90
99
|
end
|
91
100
|
|
101
|
+
def test_should_have_an_empty_human_name
|
102
|
+
assert_equal 'nil', @state.human_name
|
103
|
+
end
|
104
|
+
|
92
105
|
def test_should_have_a_nil_value
|
93
106
|
assert_nil @state.value
|
94
107
|
end
|
@@ -119,6 +132,10 @@ class StateWithNameTest < Test::Unit::TestCase
|
|
119
132
|
assert_equal :parked, @state.name
|
120
133
|
end
|
121
134
|
|
135
|
+
def test_should_have_a_human_name
|
136
|
+
assert_equal 'parked', @state.human_name
|
137
|
+
end
|
138
|
+
|
122
139
|
def test_should_use_stringify_the_name_as_the_value
|
123
140
|
assert_equal 'parked', @state.value
|
124
141
|
end
|
@@ -323,6 +340,42 @@ class StateWithMatcherTest < Test::Unit::TestCase
|
|
323
340
|
end
|
324
341
|
end
|
325
342
|
|
343
|
+
class StateWithHumanNameTest < Test::Unit::TestCase
|
344
|
+
def setup
|
345
|
+
@klass = Class.new
|
346
|
+
@machine = StateMachine::Machine.new(@klass)
|
347
|
+
@state = StateMachine::State.new(@machine, :parked, :human_name => 'stopped')
|
348
|
+
end
|
349
|
+
|
350
|
+
def test_should_use_custom_human_name
|
351
|
+
assert_equal 'stopped', @state.human_name
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
class StateWithDynamicHumanNameTest < Test::Unit::TestCase
|
356
|
+
def setup
|
357
|
+
@klass = Class.new
|
358
|
+
@machine = StateMachine::Machine.new(@klass)
|
359
|
+
@state = StateMachine::State.new(@machine, :parked, :human_name => lambda {|state, object| ['stopped', object]})
|
360
|
+
end
|
361
|
+
|
362
|
+
def test_should_use_custom_human_name
|
363
|
+
human_name, klass = @state.human_name
|
364
|
+
assert_equal 'stopped', human_name
|
365
|
+
assert_equal @klass, klass
|
366
|
+
end
|
367
|
+
|
368
|
+
def test_should_allow_custom_class_to_be_passed_through
|
369
|
+
human_name, klass = @state.human_name(1)
|
370
|
+
assert_equal 'stopped', human_name
|
371
|
+
assert_equal 1, klass
|
372
|
+
end
|
373
|
+
|
374
|
+
def test_should_not_cache_value
|
375
|
+
assert_not_same @state.human_name, @state.human_name
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
326
379
|
class StateInitialTest < Test::Unit::TestCase
|
327
380
|
def setup
|
328
381
|
@machine = StateMachine::Machine.new(Class.new)
|
@@ -29,6 +29,10 @@ class TransitionTest < Test::Unit::TestCase
|
|
29
29
|
assert_equal :ignite, @transition.qualified_event
|
30
30
|
end
|
31
31
|
|
32
|
+
def test_should_have_a_human_event
|
33
|
+
assert_equal 'ignite', @transition.human_event
|
34
|
+
end
|
35
|
+
|
32
36
|
def test_should_have_a_from_value
|
33
37
|
assert_equal 'parked', @transition.from
|
34
38
|
end
|
@@ -41,6 +45,10 @@ class TransitionTest < Test::Unit::TestCase
|
|
41
45
|
assert_equal :parked, @transition.qualified_from_name
|
42
46
|
end
|
43
47
|
|
48
|
+
def test_should_have_a_human_from_name
|
49
|
+
assert_equal 'parked', @transition.human_from_name
|
50
|
+
end
|
51
|
+
|
44
52
|
def test_should_have_a_to_value
|
45
53
|
assert_equal 'idling', @transition.to
|
46
54
|
end
|
@@ -53,6 +61,10 @@ class TransitionTest < Test::Unit::TestCase
|
|
53
61
|
assert_equal :idling, @transition.qualified_to_name
|
54
62
|
end
|
55
63
|
|
64
|
+
def test_should_have_a_human_to_name
|
65
|
+
assert_equal 'idling', @transition.human_to_name
|
66
|
+
end
|
67
|
+
|
56
68
|
def test_should_have_an_attribute
|
57
69
|
assert_equal :state, @transition.attribute
|
58
70
|
end
|
@@ -192,6 +204,10 @@ class TransitionWithNamespaceTest < Test::Unit::TestCase
|
|
192
204
|
assert_equal :alarm_off, @transition.qualified_from_name
|
193
205
|
end
|
194
206
|
|
207
|
+
def test_should_have_a_human_from_name
|
208
|
+
assert_equal 'off', @transition.human_from_name
|
209
|
+
end
|
210
|
+
|
195
211
|
def test_should_have_a_to_name
|
196
212
|
assert_equal :active, @transition.to_name
|
197
213
|
end
|
@@ -199,6 +215,10 @@ class TransitionWithNamespaceTest < Test::Unit::TestCase
|
|
199
215
|
def test_should_have_a_qualified_to_name
|
200
216
|
assert_equal :alarm_active, @transition.qualified_to_name
|
201
217
|
end
|
218
|
+
|
219
|
+
def test_should_have_a_human_to_name
|
220
|
+
assert_equal 'active', @transition.human_to_name
|
221
|
+
end
|
202
222
|
end
|
203
223
|
|
204
224
|
class TransitionWithCustomMachineAttributeTest < Test::Unit::TestCase
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: state_machine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Pfeifer
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-06-27 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -76,7 +76,8 @@ files:
|
|
76
76
|
- lib/state_machine/node_collection.rb
|
77
77
|
- lib/state_machine/extensions.rb
|
78
78
|
- lib/state_machine/initializers.rb
|
79
|
-
- test/
|
79
|
+
- test/files/en.yml
|
80
|
+
- test/files/switch.rb
|
80
81
|
- test/unit/callback_test.rb
|
81
82
|
- test/unit/transition_test.rb
|
82
83
|
- test/unit/machine_test.rb
|