state_manager 0.3.0 → 0.3.1

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.
@@ -28,8 +28,10 @@ module StateManager
28
28
  # reached so we wrap in a lamda.
29
29
  scope state, lambda {
30
30
  conn = ::ActiveRecord::Base.connection
31
+ table = conn.quote_table_name table_name
31
32
  column = conn.quote_column_name klass._state_property
32
- query = "#{column} = ? OR #{column} LIKE ?"
33
+ namespaced_col = "#{table}.#{column}"
34
+ query = "#{namespaced_col} = ? OR #{namespaced_col} LIKE ?"
33
35
  like_term = "#{state.to_s}.%"
34
36
  where(query, state, like_term)
35
37
  }
@@ -86,15 +88,21 @@ module StateManager
86
88
 
87
89
  def after_save
88
90
  return unless pending_transition
89
- _run_after_callbacks(*pending_transition)
91
+ transition = pending_transition
92
+
90
93
  self.uncommitted_transitions ||= []
91
94
  self.uncommitted_transitions << self.pending_transition
92
95
  self.pending_transition = nil
96
+
97
+ _run_after_callbacks(*transition)
93
98
  end
94
99
 
95
100
  def after_commit
96
- self.uncommitted_transitions.each{ |t| run_commit_callbacks(*t) }
101
+ transitions = self.uncommitted_transitions.dup
102
+
97
103
  self.uncommitted_transitions.clear
104
+
105
+ transitions.each{ |t| run_commit_callbacks(*t) }
98
106
  end
99
107
 
100
108
  def run_commit_callbacks(from_state, to_state, current_event, enter_states, exit_states)
@@ -1,3 +1,3 @@
1
1
  module StateManager
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -24,6 +24,7 @@ class ActiveRecordTest < Minitest::Test
24
24
  end
25
25
  state :active
26
26
  state :rejected
27
+ state :mutated
27
28
 
28
29
  attr_accessor :unsubmitted_entered_count
29
30
  attr_accessor :unsubmitted_enter_committed_count
@@ -82,6 +83,15 @@ class ActiveRecordTest < Minitest::Test
82
83
  end
83
84
 
84
85
  end
86
+
87
+ class Mutated
88
+
89
+ def entered
90
+ self.title = 'mutant'
91
+ save
92
+ end
93
+
94
+ end
85
95
 
86
96
  end
87
97
 
@@ -256,4 +266,10 @@ class ActiveRecordTest < Minitest::Test
256
266
  assert_equal @resource.state_manager.active_entered_count, 1
257
267
  assert_equal @resource.state_manager.active_enter_committed_count, 1
258
268
  end
269
+
270
+ def test_save_in_entered_callback
271
+ @resource = Post.new(:state => 'mutated')
272
+ @resource.save
273
+ assert_equal 'mutant', @resource.title
274
+ end
259
275
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: state_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-25 00:00:00.000000000 Z
12
+ date: 2014-06-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport