stately 0.3.1 → 0.3.2

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: dbc5b0a7417deef30479a911f5c5d55fb8b948a0
4
- data.tar.gz: 93e48416ba00f224fc1e32624ce9735d69c3771e
3
+ metadata.gz: ad6d6e8f058bd9a7bb43c5860dcf3be61a0dc1b3
4
+ data.tar.gz: 5464d5e302cb6719f314c52c57d84cb55d86d504
5
5
  SHA512:
6
- metadata.gz: 5c324c0816ad104284c5c13f823cfe72ef449660ee67a443edfa5cd9b9cc17f2bc2343994810edc2eaf6c281529a9590ed0c3281fb32ae3d4f692a3369b90f2a
7
- data.tar.gz: 19a36ac59c5d26d0ae26d28378738e96c2144124a92b10b34bb373b5c20955e0b22397b9b7cd5f773da7f16e7a77e204803d313bda9c90bb4e27cce291f9a671
6
+ metadata.gz: 7b573a8920bbcc8de47f7a558a215c280f1c2f8f45d92d5b07ae7736a5cb0f5161790bdee90a6631b1ac91e82be83064b85e1b73d01c691eccdb4aa1b5d68db1
7
+ data.tar.gz: f8c318f5095e66d2431cc33eb407c0c278fb405afe06c5abc431476d89fae02207e2d9c0e905d89dbf290922c1cf128adfbcc7d76e97f99d56e96677e1e6e460
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stately (0.3.1)
4
+ stately (0.3.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -1,3 +1,3 @@
1
1
  module Stately
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.2'
3
3
  end
data/lib/stately.rb CHANGED
@@ -93,6 +93,10 @@ module Stately
93
93
  define_method(state.action) do
94
94
  transition_to(state)
95
95
  end
96
+
97
+ define_method(:"#{state.name}?") do
98
+ send(stately_machine.state_attr) == state.name.to_s
99
+ end
96
100
  end
97
101
  end
98
102
  end
@@ -161,16 +165,16 @@ module Stately
161
165
 
162
166
  if valid_transition_to?(state)
163
167
  run_before_transition_callbacks(state)
164
- write_attribute(stately_machine.state_attr, state.to_s)
168
+ write_model_attribute(stately_machine.state_attr, state.to_s)
165
169
  run_after_transition_callbacks(state)
166
170
  end
167
171
  end
168
172
 
169
173
  def set_initial_state
170
- write_attribute(stately_machine.state_attr, stately_machine.start.to_s)
174
+ write_model_attribute(stately_machine.state_attr, stately_machine.start.to_s)
171
175
  end
172
176
 
173
- def write_attribute(attr, val)
177
+ def write_model_attribute(attr, val)
174
178
  send("#{attr}=", val)
175
179
  end
176
180
 
@@ -136,6 +136,10 @@ describe Stately do
136
136
  it 'sets state' do
137
137
  @order.state.should == new_state
138
138
  end
139
+
140
+ it 'responds to test method' do
141
+ @order.send("#{new_state}?").should be_true
142
+ end
139
143
  end
140
144
  end
141
145
 
@@ -150,6 +154,13 @@ describe Stately do
150
154
  @order_class.method_defined?(:refund).should be_true
151
155
  end
152
156
 
157
+ it 'creates tests for each state' do
158
+ @order_class.method_defined?(:processing?).should be_true
159
+ @order_class.method_defined?(:completed?).should be_true
160
+ @order_class.method_defined?(:invalid?).should be_true
161
+ @order_class.method_defined?(:refunded?).should be_true
162
+ end
163
+
153
164
  it 'finds all states' do
154
165
  @order.states.should == [:completed, :invalid, :processing, :refunded]
155
166
  end
@@ -36,6 +36,11 @@ describe Stately::InstanceMethods do
36
36
  @test_class.method_defined?(:complete).should be_true
37
37
  @test_class.method_defined?(:process).should be_true
38
38
  end
39
+
40
+ it 'defines test methods' do
41
+ @test_class.method_defined?(:processing?).should be_true
42
+ @test_class.method_defined?(:completed?).should be_true
43
+ end
39
44
  end
40
45
 
41
46
  describe 'stately_machine' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stately
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Twomey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-06 00:00:00.000000000 Z
11
+ date: 2014-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry