stateflow 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,6 @@
1
+ = Version 0.4.1
2
+ * Removed the depreciation warnings - FINALLY :)
3
+
1
4
  = Version 0.4.0
2
5
  * Changed the order of the hooks, now runs in the following order:
3
6
  - Exit on previous state
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ stateflow (0.4.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ activemodel (3.0.3)
10
+ activesupport (= 3.0.3)
11
+ builder (~> 2.1.2)
12
+ i18n (~> 0.4)
13
+ activerecord (3.0.3)
14
+ activemodel (= 3.0.3)
15
+ activesupport (= 3.0.3)
16
+ arel (~> 2.0.2)
17
+ tzinfo (~> 0.3.23)
18
+ activesupport (3.0.3)
19
+ arel (2.0.6)
20
+ bson (1.1.4)
21
+ builder (2.1.2)
22
+ diff-lcs (1.1.2)
23
+ i18n (0.5.0)
24
+ mongo (1.1.4)
25
+ bson (>= 1.1.1)
26
+ mongoid (2.0.0.beta.20)
27
+ activemodel (~> 3.0)
28
+ mongo (~> 1.1)
29
+ tzinfo (~> 0.3.22)
30
+ will_paginate (~> 3.0.pre)
31
+ rspec (2.2.0)
32
+ rspec-core (~> 2.2)
33
+ rspec-expectations (~> 2.2)
34
+ rspec-mocks (~> 2.2)
35
+ rspec-core (2.2.1)
36
+ rspec-expectations (2.2.0)
37
+ diff-lcs (~> 1.1.2)
38
+ rspec-mocks (2.2.0)
39
+ sqlite3 (1.3.3)
40
+ sqlite3-ruby (1.3.3)
41
+ sqlite3 (>= 1.3.3)
42
+ tzinfo (0.3.23)
43
+ will_paginate (3.0.pre2)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ activerecord
50
+ mongoid (>= 2.0.0.beta.20)
51
+ rspec (>= 2.0.0)
52
+ sqlite3-ruby
53
+ stateflow!
data/Manifest CHANGED
@@ -1,4 +1,6 @@
1
1
  CHANGELOG.rdoc
2
+ Gemfile
3
+ Gemfile.lock
2
4
  LICENCE
3
5
  Manifest
4
6
  README.rdoc
@@ -17,6 +19,8 @@ lib/stateflow/persistence/mongoid.rb
17
19
  lib/stateflow/persistence/none.rb
18
20
  lib/stateflow/state.rb
19
21
  lib/stateflow/transition.rb
22
+ spec/orm/activerecord_spec.rb
23
+ spec/orm/mongoid_spec.rb
20
24
  spec/spec_helper.rb
21
25
  spec/stateflow_spec.rb
22
26
  stateflow.gemspec
data/Rakefile CHANGED
@@ -2,11 +2,11 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('stateflow', '0.4.0') do |p|
5
+ Echoe.new('stateflow', '0.4.1') do |p|
6
6
  p.description = "State machine that allows dynamic transitions for business workflows"
7
7
  p.url = "http://github.com/ryanza/stateflow"
8
8
  p.author = "Ryan Oberholzer"
9
9
  p.email = "ryan@platform45.com"
10
10
  p.ignore_pattern = ["tmp/*", "script/*"]
11
- p.development_dependencies = ["rspec", "activerecord", "mongoid >=2.0.0.beta.20", "sqlite3-ruby"]
11
+ p.development_dependencies = ["rspec >=2.0.0", "activerecord", "mongoid >=2.0.0.beta.20", "sqlite3-ruby"]
12
12
  end
@@ -45,7 +45,7 @@ module Stateflow
45
45
  @current_state ||= load_from_persistence.nil? ? machine.initial_state : machine.states[load_from_persistence.to_sym]
46
46
  end
47
47
 
48
- def set_current_state(new_state, options)
48
+ def set_current_state(new_state, options = {})
49
49
  save_to_persistence(new_state.name.to_s, options)
50
50
  @current_state = new_state
51
51
  end
@@ -2,8 +2,10 @@ module Stateflow
2
2
  module Persistence
3
3
  module MongoMapper
4
4
  def self.install(base)
5
- base.before_validation_on_create :ensure_initial_state
6
- base.send :include, InstanceMethods
5
+ ActiveSupport::Deprecation.silence do
6
+ base.respond_to?(:before_validation_on_create) ? base.before_validation_on_create(:ensure_initial_state) : base.before_validation(:ensure_initial_state, :on => :create)
7
+ base.send :include, InstanceMethods
8
+ end
7
9
  end
8
10
 
9
11
  module InstanceMethods
@@ -2,8 +2,10 @@ module Stateflow
2
2
  module Persistence
3
3
  module Mongoid
4
4
  def self.install(base)
5
- base.respond_to?(:before_validation_on_create) ? base.before_validation_on_create(:ensure_initial_state) : base.before_validation(:ensure_initial_state, :on => :create)
6
- base.send :include, InstanceMethods
5
+ ActiveSupport::Deprecation.silence do
6
+ base.respond_to?(:before_validation_on_create) ? base.before_validation_on_create(:ensure_initial_state) : base.before_validation(:ensure_initial_state, :on => :create)
7
+ base.send :include, InstanceMethods
8
+ end
7
9
  end
8
10
 
9
11
  module InstanceMethods
@@ -0,0 +1,182 @@
1
+ require 'spec_helper'
2
+ require 'active_record'
3
+
4
+ Stateflow.persistence = :active_record
5
+
6
+ # change this if sqlite is unavailable
7
+ dbconfig = {
8
+ :adapter => 'sqlite3',
9
+ :database => ':memory:'
10
+ }
11
+
12
+ ActiveRecord::Base.establish_connection(dbconfig)
13
+ ActiveRecord::Migration.verbose = false
14
+
15
+ class TestMigration < ActiveRecord::Migration
16
+ def self.up
17
+ create_table :active_record_robots, :force => true do |t|
18
+ t.column :state, :string
19
+ t.column :name, :string
20
+ end
21
+
22
+ create_table :active_record_protected_robots, :force => true do |t|
23
+ t.column :state, :string
24
+ t.column :name, :string
25
+ end
26
+
27
+ end
28
+
29
+ def self.down
30
+ drop_table :active_record_robots
31
+ drop_table :active_record_protected_robots
32
+ end
33
+ end
34
+
35
+ class ActiveRecordRobot < ActiveRecord::Base
36
+ include Stateflow
37
+
38
+ stateflow do
39
+ initial :red
40
+
41
+ state :red, :green
42
+
43
+ event :change do
44
+ transitions :from => :red, :to => :green
45
+ end
46
+ end
47
+ end
48
+
49
+ class ActiveRecordProtectedRobot < ActiveRecord::Base
50
+ include Stateflow
51
+
52
+ attr_protected :state
53
+
54
+ stateflow do
55
+ initial :red
56
+
57
+ state :red, :green
58
+
59
+ event :change do
60
+ transitions :from => :red, :to => :green
61
+ end
62
+ end
63
+ end
64
+
65
+ describe Stateflow::Persistence::ActiveRecord do
66
+ before(:all) { TestMigration.up }
67
+ after(:all) { TestMigration.down }
68
+ after { ActiveRecordRobot.delete_all; ActiveRecordProtectedRobot.delete_all }
69
+
70
+ let(:robot) { ActiveRecordRobot.new }
71
+ let(:protected_robot) { ActiveRecordProtectedRobot.new }
72
+
73
+ describe "includes" do
74
+ it "should include current_state" do
75
+ robot.respond_to?(:current_state).should be_true
76
+ end
77
+
78
+ it "should include current_state=" do
79
+ robot.respond_to?(:set_current_state).should be_true
80
+ end
81
+
82
+ it "should include save_to_persistence" do
83
+ robot.respond_to?(:save_to_persistence).should be_true
84
+ end
85
+
86
+ it "should include load_from_persistence" do
87
+ robot.respond_to?(:load_from_persistence).should be_true
88
+ end
89
+ end
90
+
91
+ describe "bang method" do
92
+ before do
93
+ @robot = robot
94
+ @robot.state = "red"
95
+ end
96
+
97
+ it "should call the set_current_state with save being true" do
98
+ @robot.should_receive(:set_current_state).with(@robot.machine.states[:green], {:save=>true})
99
+ @robot.change!
100
+ end
101
+
102
+ it "should call the setter method for the state column" do
103
+ @robot.should_receive(:state=).with("green")
104
+ @robot.change!
105
+ end
106
+
107
+ it "should call save after setting the state column" do
108
+ @robot.should_receive(:save)
109
+ @robot.change!
110
+ end
111
+
112
+ it "should save the record" do
113
+ @robot.new_record?.should be_true
114
+ @robot.change!
115
+ @robot.new_record?.should be_false
116
+ @robot.reload.state.should == "green"
117
+ end
118
+
119
+ it "should save the protected method" do
120
+ @protected_robot = protected_robot
121
+ @protected_robot.new_record?.should be_true
122
+ @protected_robot.change!
123
+ @protected_robot.new_record?.should be_false
124
+ @protected_robot.reload.state.should == "green"
125
+ end
126
+ end
127
+
128
+ describe "non bang method" do
129
+ before do
130
+ @robot = robot
131
+ @robot.state = "red"
132
+ end
133
+
134
+ it "should call the set_current_state with save being false" do
135
+ @robot.should_receive(:set_current_state).with(@robot.machine.states[:green], {:save=>false})
136
+ @robot.change
137
+ end
138
+
139
+ it "should call the setter method for the state column" do
140
+ @robot.should_receive(:state=).with("green")
141
+ @robot.change
142
+ end
143
+
144
+ it "should call save after setting the state column" do
145
+ @robot.should_not_receive(:save)
146
+ @robot.change
147
+ end
148
+
149
+ it "should not save the record" do
150
+ @robot.new_record?.should be_true
151
+ @robot.change
152
+ @robot.new_record?.should be_true
153
+ @robot.state.should == "green"
154
+ end
155
+ end
156
+
157
+ it "Make sure stateflow saves the initial state if no state is set" do
158
+ @robot3 = robot
159
+
160
+ @robot3.save
161
+ @robot3.reload
162
+
163
+ @robot3.state.should == "red"
164
+ end
165
+
166
+ describe "load from persistence" do
167
+ before do
168
+ @robot = robot
169
+ @robot.state = "green"
170
+ @robot.name = "Bottie"
171
+ @robot.save
172
+ end
173
+
174
+ it "should call the load_from_persistence method" do
175
+ @robot.reload
176
+ @robot.should_receive(:load_from_persistence)
177
+
178
+ @robot.current_state
179
+ end
180
+ end
181
+ end
182
+
@@ -0,0 +1,133 @@
1
+ require 'spec_helper'
2
+ require 'mongoid'
3
+
4
+ Stateflow.persistence = :mongoid
5
+
6
+ connection = Mongo::Connection.new
7
+ Mongoid.database = connection.db("stateflow_test")
8
+
9
+ class MongoRobot
10
+ include Mongoid::Document
11
+ include Stateflow
12
+
13
+ field :state
14
+ field :name
15
+
16
+ stateflow do
17
+ initial :red
18
+
19
+ state :red, :green
20
+
21
+ event :change do
22
+ transitions :from => :red, :to => :green
23
+ end
24
+ end
25
+ end
26
+
27
+ describe Stateflow::Persistence::Mongoid do
28
+ after { MongoRobot.collection.drop }
29
+
30
+ let(:robot) { MongoRobot.new }
31
+
32
+ describe "includes" do
33
+ it "should include current_state" do
34
+ robot.respond_to?(:current_state).should be_true
35
+ end
36
+
37
+ it "should include current_state=" do
38
+ robot.respond_to?(:set_current_state).should be_true
39
+ end
40
+
41
+ it "should include save_to_persistence" do
42
+ robot.respond_to?(:save_to_persistence).should be_true
43
+ end
44
+
45
+ it "should include load_from_persistence" do
46
+ robot.respond_to?(:load_from_persistence).should be_true
47
+ end
48
+ end
49
+
50
+ describe "bang method" do
51
+ before do
52
+ @robot = robot
53
+ @robot.state = "red"
54
+ end
55
+
56
+ it "should call the set_current_state with save being true" do
57
+ @robot.should_receive(:set_current_state).with(@robot.machine.states[:green], {:save=>true})
58
+ @robot.change!
59
+ end
60
+
61
+ it "should call the setter method for the state column" do
62
+ @robot.should_receive(:state=).with("green")
63
+ @robot.change!
64
+ end
65
+
66
+ it "should call save after setting the state column" do
67
+ @robot.should_receive(:save)
68
+ @robot.change!
69
+ end
70
+
71
+ it "should save the record" do
72
+ @robot.new_record?.should be_true
73
+ @robot.change!
74
+ @robot.new_record?.should be_false
75
+ @robot.reload.state.should == "green"
76
+ end
77
+ end
78
+
79
+ describe "non bang method" do
80
+ before do
81
+ @robot = robot
82
+ @robot.state = "red"
83
+ end
84
+
85
+ it "should call the set_current_state with save being false" do
86
+ @robot.should_receive(:set_current_state).with(@robot.machine.states[:green], {:save=>false})
87
+ @robot.change
88
+ end
89
+
90
+ it "should call the setter method for the state column" do
91
+ @robot.should_receive(:state=).with("green")
92
+ @robot.change
93
+ end
94
+
95
+ it "should call save after setting the state column" do
96
+ @robot.should_not_receive(:save)
97
+ @robot.change
98
+ end
99
+
100
+ it "should not save the record" do
101
+ @robot.new_record?.should be_true
102
+ @robot.change
103
+ @robot.new_record?.should be_true
104
+ @robot.state.should == "green"
105
+ end
106
+ end
107
+
108
+ it "Make sure stateflow saves the initial state if no state is set" do
109
+ @robot = robot
110
+
111
+ @robot.save
112
+ @robot.reload
113
+
114
+ @robot.state.should == "red"
115
+ end
116
+
117
+ describe "load from persistence" do
118
+ before do
119
+ @robot = robot
120
+ @robot.state = "green"
121
+ @robot.name = "Bottie"
122
+ @robot.save
123
+ end
124
+
125
+ it "should call the load_from_persistence method" do
126
+ @robot.reload
127
+ @robot.should_receive(:load_from_persistence)
128
+
129
+ @robot.current_state
130
+ end
131
+ end
132
+ end
133
+
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{stateflow}
5
- s.version = "0.4.0"
5
+ s.version = "0.4.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Ryan Oberholzer"]
9
- s.date = %q{2010-12-09}
9
+ s.date = %q{2011-02-13}
10
10
  s.description = %q{State machine that allows dynamic transitions for business workflows}
11
11
  s.email = %q{ryan@platform45.com}
12
12
  s.extra_rdoc_files = ["CHANGELOG.rdoc", "README.rdoc", "lib/stateflow.rb", "lib/stateflow/event.rb", "lib/stateflow/exception.rb", "lib/stateflow/machine.rb", "lib/stateflow/persistence.rb", "lib/stateflow/persistence/active_record.rb", "lib/stateflow/persistence/mongo_mapper.rb", "lib/stateflow/persistence/mongoid.rb", "lib/stateflow/persistence/none.rb", "lib/stateflow/state.rb", "lib/stateflow/transition.rb"]
13
- s.files = ["CHANGELOG.rdoc", "LICENCE", "Manifest", "README.rdoc", "Rakefile", "examples/robot.rb", "examples/test.rb", "init.rb", "lib/stateflow.rb", "lib/stateflow/event.rb", "lib/stateflow/exception.rb", "lib/stateflow/machine.rb", "lib/stateflow/persistence.rb", "lib/stateflow/persistence/active_record.rb", "lib/stateflow/persistence/mongo_mapper.rb", "lib/stateflow/persistence/mongoid.rb", "lib/stateflow/persistence/none.rb", "lib/stateflow/state.rb", "lib/stateflow/transition.rb", "spec/spec_helper.rb", "spec/stateflow_spec.rb", "stateflow.gemspec"]
13
+ s.files = ["CHANGELOG.rdoc", "Gemfile", "Gemfile.lock", "LICENCE", "Manifest", "README.rdoc", "Rakefile", "examples/robot.rb", "examples/test.rb", "init.rb", "lib/stateflow.rb", "lib/stateflow/event.rb", "lib/stateflow/exception.rb", "lib/stateflow/machine.rb", "lib/stateflow/persistence.rb", "lib/stateflow/persistence/active_record.rb", "lib/stateflow/persistence/mongo_mapper.rb", "lib/stateflow/persistence/mongoid.rb", "lib/stateflow/persistence/none.rb", "lib/stateflow/state.rb", "lib/stateflow/transition.rb", "spec/orm/activerecord_spec.rb", "spec/orm/mongoid_spec.rb", "spec/spec_helper.rb", "spec/stateflow_spec.rb", "stateflow.gemspec"]
14
14
  s.homepage = %q{http://github.com/ryanza/stateflow}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Stateflow", "--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
@@ -23,18 +23,18 @@ Gem::Specification.new do |s|
23
23
  s.specification_version = 3
24
24
 
25
25
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
- s.add_development_dependency(%q<rspec>, [">= 0"])
26
+ s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
27
27
  s.add_development_dependency(%q<activerecord>, [">= 0"])
28
28
  s.add_development_dependency(%q<mongoid>, [">= 2.0.0.beta.20"])
29
29
  s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
30
30
  else
31
- s.add_dependency(%q<rspec>, [">= 0"])
31
+ s.add_dependency(%q<rspec>, [">= 2.0.0"])
32
32
  s.add_dependency(%q<activerecord>, [">= 0"])
33
33
  s.add_dependency(%q<mongoid>, [">= 2.0.0.beta.20"])
34
34
  s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
35
35
  end
36
36
  else
37
- s.add_dependency(%q<rspec>, [">= 0"])
37
+ s.add_dependency(%q<rspec>, [">= 2.0.0"])
38
38
  s.add_dependency(%q<activerecord>, [">= 0"])
39
39
  s.add_dependency(%q<mongoid>, [">= 2.0.0.beta.20"])
40
40
  s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stateflow
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 4
9
- - 0
10
- version: 0.4.0
8
+ - 1
9
+ version: 0.4.1
11
10
  platform: ruby
12
11
  authors:
13
12
  - Ryan Oberholzer
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-12-09 00:00:00 +02:00
17
+ date: 2011-02-13 00:00:00 +00:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,10 +25,11 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 3
30
28
  segments:
29
+ - 2
31
30
  - 0
32
- version: "0"
31
+ - 0
32
+ version: 2.0.0
33
33
  type: :development
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
@@ -40,7 +40,6 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- hash: 3
44
43
  segments:
45
44
  - 0
46
45
  version: "0"
@@ -54,7 +53,6 @@ dependencies:
54
53
  requirements:
55
54
  - - ">="
56
55
  - !ruby/object:Gem::Version
57
- hash: 62196427
58
56
  segments:
59
57
  - 2
60
58
  - 0
@@ -72,7 +70,6 @@ dependencies:
72
70
  requirements:
73
71
  - - ">="
74
72
  - !ruby/object:Gem::Version
75
- hash: 3
76
73
  segments:
77
74
  - 0
78
75
  version: "0"
@@ -100,6 +97,8 @@ extra_rdoc_files:
100
97
  - lib/stateflow/transition.rb
101
98
  files:
102
99
  - CHANGELOG.rdoc
100
+ - Gemfile
101
+ - Gemfile.lock
103
102
  - LICENCE
104
103
  - Manifest
105
104
  - README.rdoc
@@ -118,6 +117,8 @@ files:
118
117
  - lib/stateflow/persistence/none.rb
119
118
  - lib/stateflow/state.rb
120
119
  - lib/stateflow/transition.rb
120
+ - spec/orm/activerecord_spec.rb
121
+ - spec/orm/mongoid_spec.rb
121
122
  - spec/spec_helper.rb
122
123
  - spec/stateflow_spec.rb
123
124
  - stateflow.gemspec
@@ -140,7 +141,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
141
  requirements:
141
142
  - - ">="
142
143
  - !ruby/object:Gem::Version
143
- hash: 3
144
144
  segments:
145
145
  - 0
146
146
  version: "0"
@@ -149,7 +149,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
- hash: 11
153
152
  segments:
154
153
  - 1
155
154
  - 2