transitions 0.0.4 → 0.0.5
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/README.rdoc +3 -5
- data/VERSION +1 -1
- data/lib/active_record/{state_machine.rb → transitions.rb} +2 -2
- data/lib/{state_machine → transitions}/event.rb +1 -1
- data/lib/{state_machine → transitions}/machine.rb +1 -1
- data/lib/{state_machine → transitions}/state.rb +1 -1
- data/lib/{state_machine → transitions}/state_transition.rb +1 -1
- data/lib/{state_machine.rb → transitions.rb} +5 -5
- data/test/helper.rb +2 -2
- data/test/test_active_record.rb +2 -2
- data/test/test_event.rb +3 -3
- data/test/test_event_arguments.rb +1 -1
- data/test/test_event_being_fired.rb +4 -4
- data/test/test_machine.rb +3 -3
- data/test/test_state.rb +2 -2
- data/test/test_state_transition.rb +4 -4
- data/test/test_state_transition_guard_check.rb +4 -4
- data/transitions.gemspec +7 -7
- metadata +8 -8
data/README.rdoc
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
=
|
1
|
+
= transitions
|
2
2
|
|
3
3
|
The gem is based on Rick Olson's code of ActiveModel::StateMachine,
|
4
4
|
axed from ActiveModel in {this
|
@@ -6,11 +6,9 @@ commit}[http://github.com/rails/rails/commit/db49c706b62e7ea2ab93f05399dbfddf508
|
|
6
6
|
|
7
7
|
== Installation
|
8
8
|
|
9
|
-
|
10
|
-
name). However it's fully usable in bundler, you can just paste the
|
11
|
-
following line into the Gemfile:
|
9
|
+
Just paste the following line into the Gemfile:
|
12
10
|
|
13
|
-
gem "
|
11
|
+
gem "transitions"
|
14
12
|
|
15
13
|
== Note on Patches/Pull Requests
|
16
14
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
@@ -21,11 +21,11 @@
|
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
23
|
module ActiveRecord
|
24
|
-
module
|
24
|
+
module Transitions
|
25
25
|
extend ActiveSupport::Concern
|
26
26
|
|
27
27
|
included do
|
28
|
-
include ::
|
28
|
+
include ::Transitions
|
29
29
|
before_validation :set_initial_state
|
30
30
|
validates_presence_of :state
|
31
31
|
end
|
@@ -20,12 +20,12 @@
|
|
20
20
|
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
|
-
require "
|
24
|
-
require "
|
25
|
-
require "
|
26
|
-
require "
|
23
|
+
require "transitions/event"
|
24
|
+
require "transitions/machine"
|
25
|
+
require "transitions/state"
|
26
|
+
require "transitions/state_transition"
|
27
27
|
|
28
|
-
module
|
28
|
+
module Transitions
|
29
29
|
class InvalidTransition < Exception
|
30
30
|
|
31
31
|
end
|
data/test/helper.rb
CHANGED
@@ -6,8 +6,8 @@ require "mocha"
|
|
6
6
|
|
7
7
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
8
8
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
9
|
-
require "
|
10
|
-
require "active_record/
|
9
|
+
require "transitions"
|
10
|
+
require "active_record/transitions"
|
11
11
|
|
12
12
|
class Test::Unit::TestCase
|
13
13
|
|
data/test/test_active_record.rb
CHANGED
@@ -7,7 +7,7 @@ class CreateTrafficLights < ActiveRecord::Migration
|
|
7
7
|
end
|
8
8
|
|
9
9
|
class TrafficLight < ActiveRecord::Base
|
10
|
-
include ActiveRecord::
|
10
|
+
include ActiveRecord::Transitions
|
11
11
|
|
12
12
|
state_machine do
|
13
13
|
state :off
|
@@ -73,7 +73,7 @@ class TestActiveRecord < Test::Unit::TestCase
|
|
73
73
|
end
|
74
74
|
|
75
75
|
test "transition to an invalid state" do
|
76
|
-
assert_raise(
|
76
|
+
assert_raise(Transitions::InvalidTransition) { @light.yellow_on }
|
77
77
|
assert_equal :off, @light.current_state
|
78
78
|
end
|
79
79
|
end
|
data/test/test_event.rb
CHANGED
@@ -7,7 +7,7 @@ class TestEvent < Test::Unit::TestCase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def new_event
|
10
|
-
@event =
|
10
|
+
@event = Transitions::Event.new(nil, @state_name, {:success => @success}) do
|
11
11
|
transitions :to => :closed, :from => [:open, :received]
|
12
12
|
end
|
13
13
|
end
|
@@ -21,8 +21,8 @@ class TestEvent < Test::Unit::TestCase
|
|
21
21
|
end
|
22
22
|
|
23
23
|
test "should create StateTransitions" do
|
24
|
-
|
25
|
-
|
24
|
+
Transitions::StateTransition.expects(:new).with(:to => :closed, :from => :open)
|
25
|
+
Transitions::StateTransition.expects(:new).with(:to => :closed, :from => :received)
|
26
26
|
new_event
|
27
27
|
end
|
28
28
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
require "helper"
|
2
2
|
|
3
3
|
class TestEventBeingFired < Test::Unit::TestCase
|
4
|
-
test "should raise an
|
5
|
-
event =
|
4
|
+
test "should raise an Transitions::InvalidTransition error if the transitions are empty" do
|
5
|
+
event = Transitions::Event.new(nil, :event)
|
6
6
|
|
7
|
-
assert_raise
|
7
|
+
assert_raise Transitions::InvalidTransition do
|
8
8
|
event.fire(nil)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
test "should return the state of the first matching transition it finds" do
|
13
|
-
event =
|
13
|
+
event = Transitions::Event.new(nil, :event) do
|
14
14
|
transitions :to => :closed, :from => [:open, :received]
|
15
15
|
end
|
16
16
|
|
data/test/test_machine.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "helper"
|
2
2
|
|
3
3
|
class MachineTestSubject
|
4
|
-
include
|
4
|
+
include Transitions
|
5
5
|
|
6
6
|
state_machine do
|
7
7
|
state :open
|
@@ -22,7 +22,7 @@ class MachineTestSubject
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
class
|
25
|
+
class TransitionsMachineTest < Test::Unit::TestCase
|
26
26
|
test "allows reuse of existing machines" do
|
27
27
|
assert_equal 2, MachineTestSubject.state_machines.size
|
28
28
|
end
|
@@ -32,7 +32,7 @@ class StateMachineMachineTest < Test::Unit::TestCase
|
|
32
32
|
end
|
33
33
|
|
34
34
|
test "accesses non-default state machine" do
|
35
|
-
assert_kind_of
|
35
|
+
assert_kind_of Transitions::Machine, MachineTestSubject.state_machine(:extra)
|
36
36
|
end
|
37
37
|
|
38
38
|
test "finds events for given state" do
|
data/test/test_state.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "helper"
|
2
2
|
|
3
3
|
class StateTestSubject
|
4
|
-
include
|
4
|
+
include Transitions
|
5
5
|
|
6
6
|
state_machine do
|
7
7
|
end
|
@@ -15,7 +15,7 @@ class TestState < Test::Unit::TestCase
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def new_state(options={})
|
18
|
-
|
18
|
+
Transitions::State.new(@state_name, @options.merge(options))
|
19
19
|
end
|
20
20
|
|
21
21
|
test "sets the name" do
|
@@ -3,7 +3,7 @@ require "helper"
|
|
3
3
|
class TestStateTransition < Test::Unit::TestCase
|
4
4
|
test "should set from, to, and opts attr readers" do
|
5
5
|
opts = {:from => "foo", :to => "bar", :guard => "g"}
|
6
|
-
st =
|
6
|
+
st = Transitions::StateTransition.new(opts)
|
7
7
|
|
8
8
|
assert_equal opts[:from], st.from
|
9
9
|
assert_equal opts[:to], st.to
|
@@ -12,7 +12,7 @@ class TestStateTransition < Test::Unit::TestCase
|
|
12
12
|
|
13
13
|
test "should pass equality check if from and to are the same" do
|
14
14
|
opts = {:from => "foo", :to => "bar", :guard => "g"}
|
15
|
-
st =
|
15
|
+
st = Transitions::StateTransition.new(opts)
|
16
16
|
|
17
17
|
obj = stub
|
18
18
|
obj.stubs(:from).returns(opts[:from])
|
@@ -23,7 +23,7 @@ class TestStateTransition < Test::Unit::TestCase
|
|
23
23
|
|
24
24
|
test "should fail equality check if from are not the same" do
|
25
25
|
opts = {:from => "foo", :to => "bar", :guard => "g"}
|
26
|
-
st =
|
26
|
+
st = Transitions::StateTransition.new(opts)
|
27
27
|
|
28
28
|
obj = stub
|
29
29
|
obj.stubs(:from).returns("blah")
|
@@ -34,7 +34,7 @@ class TestStateTransition < Test::Unit::TestCase
|
|
34
34
|
|
35
35
|
test "should fail equality check if to are not the same" do
|
36
36
|
opts = {:from => "foo", :to => "bar", :guard => "g"}
|
37
|
-
st =
|
37
|
+
st = Transitions::StateTransition.new(opts)
|
38
38
|
|
39
39
|
obj = stub
|
40
40
|
obj.stubs(:from).returns(opts[:from])
|
@@ -3,14 +3,14 @@ require "helper"
|
|
3
3
|
class TestStateTransitionGuardCheck < Test::Unit::TestCase
|
4
4
|
test "should return true of there is no guard" do
|
5
5
|
opts = {:from => "foo", :to => "bar"}
|
6
|
-
st =
|
6
|
+
st = Transitions::StateTransition.new(opts)
|
7
7
|
|
8
8
|
assert st.perform(nil)
|
9
9
|
end
|
10
10
|
|
11
11
|
test "should call the method on the object if guard is a symbol" do
|
12
12
|
opts = {:from => "foo", :to => "bar", :guard => :test_guard}
|
13
|
-
st =
|
13
|
+
st = Transitions::StateTransition.new(opts)
|
14
14
|
|
15
15
|
obj = stub
|
16
16
|
obj.expects(:test_guard)
|
@@ -20,7 +20,7 @@ class TestStateTransitionGuardCheck < Test::Unit::TestCase
|
|
20
20
|
|
21
21
|
test "should call the method on the object if guard is a string" do
|
22
22
|
opts = {:from => "foo", :to => "bar", :guard => "test_guard"}
|
23
|
-
st =
|
23
|
+
st = Transitions::StateTransition.new(opts)
|
24
24
|
|
25
25
|
obj = stub
|
26
26
|
obj.expects(:test_guard)
|
@@ -30,7 +30,7 @@ class TestStateTransitionGuardCheck < Test::Unit::TestCase
|
|
30
30
|
|
31
31
|
test "should call the proc passing the object if the guard is a proc" do
|
32
32
|
opts = {:from => "foo", :to => "bar", :guard => Proc.new {|o| o.test_guard}}
|
33
|
-
st =
|
33
|
+
st = Transitions::StateTransition.new(opts)
|
34
34
|
|
35
35
|
obj = stub
|
36
36
|
obj.expects(:test_guard)
|
data/transitions.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{transitions}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jakub Kuźma"]
|
@@ -22,12 +22,12 @@ Gem::Specification.new do |s|
|
|
22
22
|
"README.rdoc",
|
23
23
|
"Rakefile",
|
24
24
|
"VERSION",
|
25
|
-
"lib/active_record/
|
26
|
-
"lib/
|
27
|
-
"lib/
|
28
|
-
"lib/
|
29
|
-
"lib/
|
30
|
-
"lib/
|
25
|
+
"lib/active_record/transitions.rb",
|
26
|
+
"lib/transitions.rb",
|
27
|
+
"lib/transitions/event.rb",
|
28
|
+
"lib/transitions/machine.rb",
|
29
|
+
"lib/transitions/state.rb",
|
30
|
+
"lib/transitions/state_transition.rb",
|
31
31
|
"test/helper.rb",
|
32
32
|
"test/test_active_record.rb",
|
33
33
|
"test/test_event.rb",
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 5
|
9
|
+
version: 0.0.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "Jakub Ku\xC5\xBAma"
|
@@ -81,12 +81,12 @@ files:
|
|
81
81
|
- README.rdoc
|
82
82
|
- Rakefile
|
83
83
|
- VERSION
|
84
|
-
- lib/active_record/
|
85
|
-
- lib/
|
86
|
-
- lib/
|
87
|
-
- lib/
|
88
|
-
- lib/
|
89
|
-
- lib/
|
84
|
+
- lib/active_record/transitions.rb
|
85
|
+
- lib/transitions.rb
|
86
|
+
- lib/transitions/event.rb
|
87
|
+
- lib/transitions/machine.rb
|
88
|
+
- lib/transitions/state.rb
|
89
|
+
- lib/transitions/state_transition.rb
|
90
90
|
- test/helper.rb
|
91
91
|
- test/test_active_record.rb
|
92
92
|
- test/test_event.rb
|