simplificator-fsm 0.3.3 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/lib/fsm.rb +0 -2
- data/lib/fsm/state_attribute_interceptor.rb +9 -0
- data/test/ar_test.rb +10 -9
- data/test/test_helper_ar.rb +2 -1
- metadata +2 -2
data/VERSION.yml
CHANGED
data/lib/fsm.rb
CHANGED
@@ -6,6 +6,15 @@ module FSM
|
|
6
6
|
|
7
7
|
if hierarchy.include?("ActiveRecord::Base")
|
8
8
|
bar(klass)
|
9
|
+
|
10
|
+
klass.class_eval do
|
11
|
+
before_save :assign_default_state
|
12
|
+
define_method(:assign_default_state) do
|
13
|
+
if read_attribute(Machine[self.class].current_state_attribute_name).blank?
|
14
|
+
self.send("#{Machine[self.class].current_state_attribute_name}=", Machine[self.class].initial_state_name.to_s)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
9
18
|
else
|
10
19
|
foo(klass)
|
11
20
|
end
|
data/test/ar_test.rb
CHANGED
@@ -12,14 +12,15 @@ class ArTest < Test::Unit::TestCase
|
|
12
12
|
end
|
13
13
|
|
14
14
|
should 'make transition' do
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
15
|
+
o = Order.new
|
16
|
+
assert_equal :open, o.state
|
17
|
+
o.deliver
|
18
|
+
assert_equal :delivered, o.state
|
19
|
+
o.save!
|
20
|
+
o.reload
|
21
|
+
o = Order.find(o.id)
|
22
|
+
assert_equal :delivered, o.state
|
23
|
+
end
|
24
|
+
|
24
25
|
end
|
25
26
|
end
|
data/test/test_helper_ar.rb
CHANGED
@@ -16,8 +16,9 @@ rescue
|
|
16
16
|
end
|
17
17
|
|
18
18
|
ActiveRecord::Base.connection.create_table(:orders) do |table|
|
19
|
-
table.string(:state, :null => false, :limit => 10
|
19
|
+
table.string(:state, :null => false, :limit => 10)
|
20
20
|
end
|
21
|
+
|
21
22
|
class Order < ActiveRecord::Base
|
22
23
|
include FSM
|
23
24
|
define_fsm do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplificator-fsm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- simplificator
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-30 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|