state_manager 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d8f1d38c94644635476694a05bf9f5461753058
4
- data.tar.gz: b715e0342ff1faedb8cfc03c03afa5d289dd985d
3
+ metadata.gz: 0419accf4a65819e6bd75028b092a9888a36e691
4
+ data.tar.gz: a0565779df5cc5b9446a8ecca9774360050956ef
5
5
  SHA512:
6
- metadata.gz: 3d0b6c7cb6fde30f0d7a0aad17c59714dc48fa66546e274c2504baa0d16189474f9424cc6d42db15846890c869ff9bcd2b482691111bfd25e4edbf6c5d1b11aa
7
- data.tar.gz: 33fe78f700bf67b646b120d945782e75b1537b214c74945c6c00a0b94bb7b9d8eda93acdc3de22bed91d0df4abe75e13c05da968c36492aaf83b018427f077d2
6
+ metadata.gz: 23dbd0c988675d0a84913c4882632ca8fc44c529a1694a43ad3ec91892e3b1495a2aeeb49538e9e7c8a162c788d65afa0a899664cab2f635ff1f76779fec10fc
7
+ data.tar.gz: a8576af247fd9ee9401198d64573d3e867b807251887d4893dca15d7916324a44e595b214a2505c183db7519dea5deb9d5244d41afd25462d60d1b4b67227700
data/.travis.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  rvm:
2
- - 1.9.3
3
2
  - 2.0.0
4
3
  - 2.1.0
4
+ - 2.2.0
5
5
  before_install:
6
6
  - gem install bundler --version '>= 1.2.2'
7
7
  script: "bundle exec rake test"
@@ -1,5 +1,5 @@
1
1
  module StateManager
2
-
2
+
3
3
  class StateNotFound < StandardError; end;
4
4
  class InvalidEvent < StandardError; end;
5
5
  class InvalidTransition < StandardError; end;
@@ -25,7 +25,7 @@ module StateManager
25
25
  transition_to initial_path, nil
26
26
  end
27
27
  end
28
-
28
+
29
29
  # In the case of a new model, we wan't to transition into the initial state
30
30
  # and fire the appropriate callbacks. The default behavior is to just check
31
31
  # if the state field is nil.
@@ -46,7 +46,7 @@ module StateManager
46
46
  while(!new_states) do
47
47
  exit_states << state
48
48
  state = state.parent_state
49
- raise(StateNotFound, path) unless state
49
+ raise(StateNotFound, transition_error(path)) unless state
50
50
  new_states = state.find_states(path)
51
51
  end
52
52
 
@@ -55,7 +55,7 @@ module StateManager
55
55
 
56
56
  # Can only transition to leaf states
57
57
  # TODO: transition to the initial_state of the state?
58
- raise(InvalidTransition, path) unless new_states.last.leaf?
58
+ raise(InvalidTransition, transition_error(path)) unless new_states.last.leaf?
59
59
 
60
60
  enter_states = new_states - exit_states
61
61
  exit_states = exit_states - new_states
@@ -93,7 +93,8 @@ module StateManager
93
93
  def send_event(name, *args)
94
94
  self.current_event = name
95
95
  state = find_state_for_event(name)
96
- raise(InvalidEvent, name) unless state
96
+
97
+ raise(InvalidEvent, transition_error(name)) unless state
97
98
  result = state.perform_event name, *args
98
99
  self.current_event = nil
99
100
  result
@@ -130,7 +131,7 @@ module StateManager
130
131
  # state_manager.in_state? 'inner' # false
131
132
  #
132
133
  def in_state?(path)
133
- self.find_states(current_state.path).include? find_state(path)
134
+ self.find_states(current_state.path).include? find_state(path)
134
135
  end
135
136
 
136
137
  # Will not have a state if the state is invalid or nil
@@ -155,7 +156,7 @@ module StateManager
155
156
 
156
157
  def did_transition(from, to, event)
157
158
  end
158
-
159
+
159
160
  def around_event(event, *args, &block)
160
161
  yield
161
162
  end
@@ -187,6 +188,10 @@ module StateManager
187
188
  def self.added_to_resource(klass, property, options)
188
189
  end
189
190
 
191
+ def transition_error(state)
192
+ "Unable to transition from #{current_state} to #{state}"
193
+ end
194
+
190
195
  protected
191
196
 
192
197
  attr_accessor :current_event
@@ -1,3 +1,3 @@
1
1
  module StateManager
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
@@ -168,4 +168,26 @@ class TransitionsTest < Minitest::Test
168
168
  assert_equal :ban, @resource.state_manager.did_event
169
169
  end
170
170
 
171
- end
171
+ def error_message_test(klass, state)
172
+ @resource.ban!
173
+ exp = "StateManager::#{klass}".constantize
174
+ begin
175
+ @resource.state_manager.transition_to(state)
176
+ rescue exp => e
177
+ assert_equal "Unable to transition from inactive.banned to #{state}", e.message
178
+ end
179
+ end
180
+
181
+ def test_invalid_event
182
+ error_message_test("InvalidEvent", "active.default")
183
+ end
184
+
185
+ def test_state_not_found
186
+ error_message_test("StateNotFound", "brodown")
187
+ end
188
+
189
+ def test_invalid_transition
190
+ error_message_test("InvalidTransition", "active")
191
+ end
192
+
193
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: state_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gordon L. Hempton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-13 00:00:00.000000000 Z
11
+ date: 2016-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  requirements: []
110
110
  rubyforge_project:
111
- rubygems_version: 2.2.2
111
+ rubygems_version: 2.4.5.1
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: "%Q{Finite state machine implementation.}"