transitions 0.1.4 → 0.1.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/CHANGELOG.md +5 -0
- data/lib/active_model/transitions.rb +1 -1
- data/lib/transitions/event.rb +3 -3
- data/lib/transitions/version.rb +1 -1
- data/test/event/test_event_being_fired.rb +2 -2
- metadata +3 -3
data/CHANGELOG.md
CHANGED
@@ -63,7 +63,7 @@ module ActiveModel
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def set_initial_state
|
66
|
-
self.state ||= self.class.get_state_machine.initial_state.to_s if self.
|
66
|
+
self.state ||= self.class.get_state_machine.initial_state.to_s if self.respond_to?(:state=)
|
67
67
|
end
|
68
68
|
|
69
69
|
def state_inclusion
|
data/lib/transitions/event.rb
CHANGED
@@ -44,7 +44,7 @@ module Transitions
|
|
44
44
|
|
45
45
|
def fire(obj, to_state = nil, *args)
|
46
46
|
transitions = @transitions.select { |t| t.from == obj.current_state }
|
47
|
-
raise InvalidTransition, error_message_for_invalid_transitions(obj
|
47
|
+
raise InvalidTransition, error_message_for_invalid_transitions(obj) if transitions.size == 0
|
48
48
|
|
49
49
|
next_state = nil
|
50
50
|
transitions.each do |transition|
|
@@ -138,8 +138,8 @@ module Transitions
|
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
|
-
def error_message_for_invalid_transitions(obj
|
142
|
-
"
|
141
|
+
def error_message_for_invalid_transitions(obj)
|
142
|
+
"Can't fire event `#{name}` in current state `#{obj.current_state}` for `#{obj.class.name}` #{obj.class < ActiveRecord::Base && obj.persisted? ? "with ID #{obj.id} " : nil}"
|
143
143
|
end
|
144
144
|
end
|
145
145
|
end
|
data/lib/transitions/version.rb
CHANGED
@@ -2,7 +2,7 @@ require "helper"
|
|
2
2
|
|
3
3
|
class TestEventBeingFired < Test::Unit::TestCase
|
4
4
|
test "should raise an Transitions::InvalidTransition error if the transitions are empty" do
|
5
|
-
event = Transitions::Event.new(nil, :
|
5
|
+
event = Transitions::Event.new(nil, :event_that_is_fired)
|
6
6
|
class AnotherDummy; end
|
7
7
|
obj = AnotherDummy.new
|
8
8
|
obj.stubs(:current_state).returns(:running)
|
@@ -10,7 +10,7 @@ class TestEventBeingFired < Test::Unit::TestCase
|
|
10
10
|
exception = assert_raise Transitions::InvalidTransition do
|
11
11
|
event.fire(obj)
|
12
12
|
end
|
13
|
-
assert_match /
|
13
|
+
assert_match /Can't fire event `event_that_is_fired` in current state `running` for `TestEventBeingFired::AnotherDummy`/, exception.message
|
14
14
|
end
|
15
15
|
|
16
16
|
test "should return the state of the first matching transition it finds" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transitions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2013-01-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -179,7 +179,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
179
179
|
version: '0'
|
180
180
|
segments:
|
181
181
|
- 0
|
182
|
-
hash: -
|
182
|
+
hash: -1071042129
|
183
183
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
184
|
none: false
|
185
185
|
requirements:
|