stator 0.1.6 → 0.1.7

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: c51bab4f9cfa7e0c8fbaac47da18143898daeb76
4
- data.tar.gz: d542029f7c61d7e4b048cca25b4b069fe9e6675d
3
+ metadata.gz: 180601e58af4388c32de7aa763a4bfaa863d3c95
4
+ data.tar.gz: fe619ed09b0337182e8a05674fac0c60dce52313
5
5
  SHA512:
6
- metadata.gz: f1c077b6c700ec18e6004145b8f6a7bbb29dcf71a548b4140faefadbd3ba846110ed30c57babc0fc7a53c1930c680d4170b6ada1f3620a3944d8ef3e683173aa
7
- data.tar.gz: 27547c0eb04dd4e3436aa743d03ab48c0fc4ea7dc41c01c9b4862c1c8d4190b718db17f8c90f14a938260bbcbcf04fa606d477e8e33b74330d16c75da0ee07e6
6
+ metadata.gz: 56b0b46471626b08f35f0acd57cea57650c58388d7b87b98b2ffeaedb3ebae1b42dd49d5b0f747e429727613c7fe1957d1cc14adeb96fea680174e3951b82df6
7
+ data.tar.gz: 1a502b1af92d195ffcd7167f8374ec83961c9227630a508222c904026c76a3a34031077bd60779e4a518c9320e3400d5432357e2b587a319153355beb8f025fa
@@ -65,6 +65,8 @@ module Stator
65
65
  end
66
66
 
67
67
  def track_transition
68
+ return if @machine.skip_transition_tracking
69
+
68
70
  self.attempt_to_track_state(self.state)
69
71
  self.attempt_to_track_state_changed_timestamp
70
72
 
@@ -8,6 +8,7 @@ module Stator
8
8
  attr_reader :states
9
9
  attr_reader :namespace
10
10
  attr_reader :skip_validations
11
+ attr_reader :skip_transition_tracking
11
12
 
12
13
 
13
14
  def initialize(klass, options = {})
@@ -93,6 +94,14 @@ module Stator
93
94
  @skip_validations = was
94
95
  end
95
96
 
97
+ def without_transition_tracking
98
+ was = @skip_transition_tracking
99
+ @skip_transition_tracking = true
100
+ yield
101
+ ensure
102
+ @skip_transition_tracking = was
103
+ end
104
+
96
105
  protected
97
106
 
98
107
  def verify_transition_validity(transition)
data/lib/stator/model.rb CHANGED
@@ -77,6 +77,12 @@ module Stator
77
77
  end
78
78
  end
79
79
 
80
+ def without_state_transition_tracking(namespace = '')
81
+ self._stator(namespace).without_transition_tracking do
82
+ yield
83
+ end
84
+ end
85
+
80
86
  protected
81
87
 
82
88
  def _stator_validate_transition
@@ -1,7 +1,7 @@
1
1
  module Stator
2
2
  MAJOR = 0
3
3
  MINOR = 1
4
- PATCH = 6
4
+ PATCH = 7
5
5
  PRERELEASE = nil
6
6
 
7
7
  VERSION = [MAJOR, MINOR, PATCH, PRERELEASE].compact.join('.')
data/spec/model_spec.rb CHANGED
@@ -141,6 +141,22 @@ describe Stator::Model do
141
141
  end
142
142
  end
143
143
 
144
+ it 'should skip tracking timestamps if opted out of' do
145
+ u = User.new
146
+ u.email = 'doug@example.com'
147
+
148
+ u.without_state_transition_tracking do
149
+ u.semiactivate!
150
+ u.state.should eql('semiactivated')
151
+ u.semiactivated_state_at.should be_nil
152
+ end
153
+
154
+ # Make sure that tracking is ensured back to
155
+ # original value
156
+ u.activate!
157
+ u.activated_state_at.should_not be_nil
158
+ end
159
+
144
160
  describe 'helper methods' do
145
161
 
146
162
  it 'should answer the question of whether the state is currently the one invoked' do
@@ -227,12 +243,22 @@ describe Stator::Model do
227
243
  User::ACTIVE_STATES.should eql(['activated', 'hyperactivated'])
228
244
  User::INACTIVE_STATES.should eql(['pending', 'deactivated', 'semiactivated'])
229
245
 
230
- u2 = User.create(:email => 'phil@example.com')
231
-
232
246
  User.active.to_sql.gsub(' ', ' ').should eq("SELECT users.* FROM users WHERE users.state IN ('activated', 'hyperactivated')")
233
247
  User.inactive.to_sql.gsub(' ', ' ').should eq("SELECT users.* FROM users WHERE users.state IN ('pending', 'deactivated', 'semiactivated')")
234
248
  end
235
249
 
250
+ it "should evaluate inverses correctly" do
251
+ f = Farm.new
252
+ f.house_state = "dirty"
253
+ f.should_not be_house_cleaned
254
+
255
+ f.house_state = "disgusting"
256
+ f.should_not be_house_cleaned
257
+
258
+ f.house_state = "clean"
259
+ f.should be_house_cleaned
260
+ end
261
+
236
262
  it 'should namespace aliases just like everything else' do
237
263
  f = Farm.new
238
264
  f.should respond_to(:house_cleaned?)
@@ -3,7 +3,7 @@ class User < ActiveRecord::Base
3
3
 
4
4
 
5
5
  # initial state = pending
6
- stator do
6
+ stator track: true do
7
7
 
8
8
  transition :activate do
9
9
  from :pending, :semiactivated
@@ -146,13 +146,19 @@ class Farm < ActiveRecord::Base
146
146
 
147
147
  # initial state = dirty
148
148
  stator :field => 'house_state', :namespace => 'house' do
149
+
149
150
  transition :cleanup do
150
151
  from :dirty
151
152
  to :clean
152
153
  end
153
154
 
155
+ transition :ruin do
156
+ from any
157
+ to :disgusting
158
+ end
159
+
154
160
  state_alias :cleaned do
155
- is_not :dirty
161
+ is_not :dirty, :disgusting
156
162
  end
157
163
  end
158
164
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Nelson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-26 00:00:00.000000000 Z
11
+ date: 2018-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  version: '0'
76
76
  requirements: []
77
77
  rubyforge_project:
78
- rubygems_version: 2.4.5.1
78
+ rubygems_version: 2.6.8
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: The simplest of ActiveRecord state machines