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 CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 3
2
+ :patch: 5
3
3
  :major: 0
4
4
  :minor: 3
data/lib/fsm.rb CHANGED
@@ -15,8 +15,6 @@ module FSM
15
15
  # create alias for state attribute method to intercept it
16
16
  # intercept
17
17
  FSM::StateAttributeInterceptor.add_interceptor(self)
18
-
19
-
20
18
  end
21
19
 
22
20
  def draw_graph(options = {})
@@ -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
- o = Order.new
16
- o.deliver
17
- assert_equal :delivered, o.state
18
- o.save!
19
- o.reload
20
- o = Order.find(o.id)
21
- assert_equal :delivered, o.state
22
- end
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
@@ -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, :default => 'open')
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.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-24 00:00:00 -07:00
12
+ date: 2009-06-30 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15