stator 0.0.16 → 0.0.17
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.
- data/README.md +2 -0
- data/lib/stator/integration.rb +12 -0
- data/lib/stator/version.rb +1 -1
- data/spec/model_spec.rb +22 -5
- data/spec/support/schema.rb +1 -0
- metadata +2 -2
data/README.md
CHANGED
data/lib/stator/integration.rb
CHANGED
@@ -66,6 +66,7 @@ module Stator
|
|
66
66
|
def track_transition
|
67
67
|
self.attempt_to_track_state(self.state_was)
|
68
68
|
self.attempt_to_track_state(self.state)
|
69
|
+
self.attempt_to_track_state_changed_timestamp
|
69
70
|
|
70
71
|
true
|
71
72
|
end
|
@@ -86,6 +87,17 @@ module Stator
|
|
86
87
|
end
|
87
88
|
end
|
88
89
|
|
90
|
+
def attempt_to_track_state_changed_timestamp
|
91
|
+
return unless self.state_changed?
|
92
|
+
|
93
|
+
field_name = "#{@machine.field}_changed_at"
|
94
|
+
|
95
|
+
return unless @record.respond_to?(field_name)
|
96
|
+
return unless @record.respond_to?("#{field_name}=")
|
97
|
+
|
98
|
+
@record.send("#{field_name}=", (Time.zone || Time).now)
|
99
|
+
end
|
100
|
+
|
89
101
|
|
90
102
|
end
|
91
103
|
end
|
data/lib/stator/version.rb
CHANGED
data/spec/model_spec.rb
CHANGED
@@ -121,7 +121,7 @@ describe Stator::Model do
|
|
121
121
|
f = Factory.new
|
122
122
|
f.state.should be_nil
|
123
123
|
|
124
|
-
f.construct.should
|
124
|
+
f.construct.should eql(true)
|
125
125
|
|
126
126
|
f.state.should eql('constructed')
|
127
127
|
end
|
@@ -141,11 +141,11 @@ describe Stator::Model do
|
|
141
141
|
|
142
142
|
it 'should determine if it can validly execute a transition' do
|
143
143
|
a = Animal.new
|
144
|
-
a.can_birth?.should
|
144
|
+
a.can_birth?.should eql(true)
|
145
145
|
|
146
146
|
a.birth
|
147
147
|
|
148
|
-
a.can_birth?.should
|
148
|
+
a.can_birth?.should eql(false)
|
149
149
|
end
|
150
150
|
|
151
151
|
end
|
@@ -165,6 +165,23 @@ describe Stator::Model do
|
|
165
165
|
a.born_status_at.should be_within(1).of(Time.zone.now)
|
166
166
|
end
|
167
167
|
|
168
|
+
it 'should store when a record change states' do
|
169
|
+
a = Animal.new
|
170
|
+
a.status_changed_at.should be_nil
|
171
|
+
|
172
|
+
a.birth
|
173
|
+
|
174
|
+
a.status_changed_at.should be_within(1).of(Time.zone.now)
|
175
|
+
|
176
|
+
previous_status_changed_at = a.status_changed_at
|
177
|
+
|
178
|
+
a.name = "new name"
|
179
|
+
a.save
|
180
|
+
|
181
|
+
a.status_changed_at.should eql(previous_status_changed_at)
|
182
|
+
|
183
|
+
end
|
184
|
+
|
168
185
|
end
|
169
186
|
|
170
187
|
describe 'aliasing' do
|
@@ -207,7 +224,7 @@ describe Stator::Model do
|
|
207
224
|
|
208
225
|
it 'should allow for explicit constant and scope names to be provided' do
|
209
226
|
User.should respond_to(:luke_warmers)
|
210
|
-
defined?(User::LUKE_WARMERS).should
|
227
|
+
(!!defined?(User::LUKE_WARMERS)).should eql(true)
|
211
228
|
u = User.new
|
212
229
|
u.should respond_to(:luke_warm?)
|
213
230
|
end
|
@@ -215,7 +232,7 @@ describe Stator::Model do
|
|
215
232
|
it 'should not create constants or scopes by default' do
|
216
233
|
u = User.new
|
217
234
|
u.should respond_to(:iced_tea?)
|
218
|
-
defined?(User::ICED_TEA_STATES).should
|
235
|
+
(!!defined?(User::ICED_TEA_STATES)).should eql(false)
|
219
236
|
User.should_not respond_to(:iced_tea)
|
220
237
|
end
|
221
238
|
end
|
data/spec/support/schema.rb
CHANGED
@@ -16,6 +16,7 @@ ActiveRecord::Schema.define(:version => 20130628161227) do
|
|
16
16
|
t.string "status", :default => 'unborn'
|
17
17
|
t.datetime "created_at", :null => false
|
18
18
|
t.datetime "updated_at", :null => false
|
19
|
+
t.datetime "status_changed_at"
|
19
20
|
t.datetime "unborn_status_at"
|
20
21
|
t.datetime "born_status_at"
|
21
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.17
|
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-
|
12
|
+
date: 2014-08-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|