stator 0.1.6 → 0.1.7
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.
- checksums.yaml +4 -4
- data/lib/stator/integration.rb +2 -0
- data/lib/stator/machine.rb +9 -0
- data/lib/stator/model.rb +6 -0
- data/lib/stator/version.rb +1 -1
- data/spec/model_spec.rb +28 -2
- data/spec/support/models.rb +8 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 180601e58af4388c32de7aa763a4bfaa863d3c95
|
4
|
+
data.tar.gz: fe619ed09b0337182e8a05674fac0c60dce52313
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56b0b46471626b08f35f0acd57cea57650c58388d7b87b98b2ffeaedb3ebae1b42dd49d5b0f747e429727613c7fe1957d1cc14adeb96fea680174e3951b82df6
|
7
|
+
data.tar.gz: 1a502b1af92d195ffcd7167f8374ec83961c9227630a508222c904026c76a3a34031077bd60779e4a518c9320e3400d5432357e2b587a319153355beb8f025fa
|
data/lib/stator/integration.rb
CHANGED
data/lib/stator/machine.rb
CHANGED
@@ -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
data/lib/stator/version.rb
CHANGED
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?)
|
data/spec/support/models.rb
CHANGED
@@ -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.
|
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:
|
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.
|
78
|
+
rubygems_version: 2.6.8
|
79
79
|
signing_key:
|
80
80
|
specification_version: 4
|
81
81
|
summary: The simplest of ActiveRecord state machines
|