transitions 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ # 1.0.5
2
+
3
+ * (troessner) Fix unhelpful error message when event can not be fired.
4
+ * (simonc) Fixing set_initial_state with Mongoid
5
+
1
6
  # 1.0.4
2
7
 
3
8
  (troessner)
@@ -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.has_attribute?(:state)
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
@@ -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, to_state) if transitions.size == 0
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, to_state)
142
- "Cannot transition to #{to_state || 'default'} from #{obj.current_state} for `#{obj.class.name}` #{obj.class < ActiveRecord::Base && obj.persisted? ? "with ID #{obj.id} " : nil}"
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
@@ -1,3 +1,3 @@
1
1
  module Transitions
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
@@ -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, :event)
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 /Cannot transition to default from running for `TestEventBeingFired::AnotherDummy/, exception.message
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
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: 2012-11-21 00:00:00.000000000 Z
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: -392757581
182
+ hash: -1071042129
183
183
  required_rubygems_version: !ruby/object:Gem::Requirement
184
184
  none: false
185
185
  requirements: