aasm 4.0.5 → 4.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0fd3025d299701a391be90b67871d0110925522e
4
- data.tar.gz: d56adcb31986d0bc257e4c4a32e79462a6715709
3
+ metadata.gz: 2d4a2455383d1017cdc688cf4f01c8d9d4ce9a03
4
+ data.tar.gz: a100390b837f02f283afebc66dc8495df2b950e9
5
5
  SHA512:
6
- metadata.gz: f2e8c7bd2e7ce8f614b8b72a48ffbf396c9194c5369a128bbe6d201443e067a48caea69b9f3f9ec4c6af30956b358deb4d8544172599fe7120bd4edbc4c9717d
7
- data.tar.gz: b6d9db8e0f1cd99e263d3cb9e16ff837adab1ce57faf918ca222f48a9bb674ebf29bbdae640d4987bd6f676d35896dec9d3060347e709229ad831160702b11a4
6
+ metadata.gz: 4d9cbefb8cfc6644923134aa679d8cbc5c672da11f428f969974777edcda43b947b2a88df6743006e384f2b5a4ecb9bc36b8c937332e144bd8af7abe5a7215d0
7
+ data.tar.gz: bc56510d4cf59437d92e1b2853e87b478709dbd2dc98841aa7e3b1a2c8405011a5cbef75f882b8e4c0ee755a7b16014359ac843e9fe43f05e396674de09413de
@@ -1,4 +1,6 @@
1
+ sudo: false
1
2
  language: ruby
3
+ cache: bundler
2
4
 
3
5
  rvm:
4
6
  # - 1.8.7
@@ -5,6 +5,11 @@
5
5
  * `aasm_column` has been removed. Use `aasm.attribute_name` instead
6
6
  * `aasm_human_event_name` has been removed. Use `aasm.human_event_name` instead
7
7
 
8
+ ## 4.0.6
9
+
10
+ * bugfix: `false` is treated as uninitialised state (same as `nil`) (see [issue #195](https://github.com/aasm/aasm/issues/195) for details)
11
+ * bugfix: an event's `:error` callback now retrieves all arguments passed to the event (see [issue #196](https://github.com/aasm/aasm/issues/196) for details)
12
+
8
13
  ## 4.0.5
9
14
 
10
15
  * bugfix: initialize the aasm state column after initialization of the _ActiveRecord_ instance only if the attribute has been loaded (see [issue #193](https://github.com/aasm/aasm/issues/193) for details)
@@ -139,7 +139,7 @@ to
139
139
  ```ruby
140
140
  job = Job.new
141
141
 
142
- job.aasm.events(:permitted => true)
142
+ job.aasm.events(:permitted => true).map(&:name)
143
143
  # => [:run]
144
144
  ```
145
145
 
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.add_development_dependency 'rake'
17
17
  s.add_development_dependency 'sdoc'
18
- s.add_development_dependency 'rspec', '>= 2.14', '< 2.99'
18
+ s.add_development_dependency 'rspec'
19
19
 
20
20
  # debugging
21
21
  # s.add_development_dependency 'debugger'
@@ -81,7 +81,7 @@ private
81
81
  aasm_failed(event_name, old_state)
82
82
  end
83
83
  rescue StandardError => e
84
- event.fire_callbacks(:error, self, e) || raise(e)
84
+ event.fire_callbacks(:error, self, e, *process_args(event, aasm.current_state, *args)) || raise(e)
85
85
  end
86
86
  end
87
87
 
@@ -124,14 +124,22 @@ module AASM::Core
124
124
  def invoke_callbacks(code, record, args)
125
125
  case code
126
126
  when Symbol, String
127
- record.send(code, *args)
127
+ unless record.respond_to?(code)
128
+ raise NoMethodError.new("NoMethodError: undefined method `#{code}' for #{self.inspect}:#{self.class}")
129
+ end
130
+ arity = record.send(:method, code.to_sym).arity
131
+ record.send(code, *(arity < 0 ? args : args[0...arity]))
128
132
  true
133
+
129
134
  when Proc
130
- record.instance_exec(*args, &code)
135
+ arity = code.arity
136
+ record.instance_exec(*(arity < 0 ? args : args[0...arity]), &code)
131
137
  true
138
+
132
139
  when Array
133
140
  code.each {|a| invoke_callbacks(a, record, args)}
134
141
  true
142
+
135
143
  else
136
144
  false
137
145
  end
@@ -50,11 +50,9 @@ module AASM::Core
50
50
 
51
51
  case code
52
52
  when Symbol, String
53
- # QUESTION : record.send(code, *args) ?
54
53
  arity = record.send(:method, code.to_sym).arity
55
54
  arity == 0 ? record.send(code) : record.send(code, *args)
56
55
  when Proc
57
- # QUESTION : record.instance_exec(*args, &code) ?
58
56
  code.arity == 0 ? record.instance_exec(&code) : record.instance_exec(*args, &code)
59
57
  when Array
60
58
  if options[:guard]
@@ -37,7 +37,7 @@ module AASM
37
37
  if new_record?
38
38
  state.blank? ? aasm.determine_state_name(self.class.aasm.initial_state) : state.to_sym
39
39
  else
40
- state.nil? ? nil : state.to_sym
40
+ state.blank? ? nil : state.to_sym
41
41
  end
42
42
  end
43
43
 
@@ -1,3 +1,3 @@
1
1
  module AASM
2
- VERSION = "4.0.5"
2
+ VERSION = "4.0.6"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  ActiveRecord::Migration.suppress_messages do
2
- %w{gates readers writers transients simples no_scopes no_direct_assignments thieves localizer_test_models persisted_states provided_and_persisted_states with_enums with_true_enums with_false_enums}.each do |table_name|
2
+ %w{gates readers writers transients simples no_scopes no_direct_assignments thieves localizer_test_models persisted_states provided_and_persisted_states with_enums with_true_enums with_false_enums false_states}.each do |table_name|
3
3
  ActiveRecord::Migration.create_table table_name, :force => true do |t|
4
4
  t.string "aasm_state"
5
5
  end
@@ -6,6 +6,15 @@ module Callbacks
6
6
  @fail_event_guard = options[:fail_event_guard]
7
7
  @fail_transition_guard = options[:fail_transition_guard]
8
8
  @log = options[:log]
9
+ reset_data
10
+ end
11
+
12
+ def reset_data
13
+ @data = []
14
+ end
15
+
16
+ def data
17
+ @data.join(' ')
9
18
  end
10
19
 
11
20
  aasm do
@@ -35,28 +44,32 @@ module Callbacks
35
44
  end
36
45
 
37
46
  def log(text)
47
+ @data << text
38
48
  puts text if @log
39
49
  end
40
50
 
41
- def before_enter_open; log('before_enter_open'); end
42
- def enter_open; log('enter_open'); end
43
- def before_exit_open; log('before_exit_open'); end
44
- def after_enter_open; log('after_enter_open'); end
45
- def exit_open; log('exit_open'); end
46
- def after_exit_open; log('after_exit_open'); end
47
-
48
- def before_enter_closed; log('before_enter_closed'); end
49
- def enter_closed; log('enter_closed'); end
50
- def before_exit_closed; log('before_exit_closed'); end
51
- def exit_closed; log('exit_closed'); end
52
- def after_enter_closed; log('after_enter_closed'); end
53
- def after_exit_closed; log('after_exit_closed'); end
54
-
55
- def event_guard; log('event_guard'); !@fail_event_guard; end
56
- def transition_guard; log('transition_guard'); !@fail_transition_guard; end
57
- def after_transition; log('after_transition'); end
58
-
59
- def before_event; log('before_event'); end
60
- def after_event; log('after_event'); end
51
+ def aasm_write_state(*args); log('aasm_write_state'); true; end
52
+
53
+ def before_enter_open; log('before_enter_open'); end
54
+ def enter_open; log('enter_open'); end
55
+ def before_exit_open; log('before_exit_open'); end
56
+ def after_enter_open; log('after_enter_open'); end
57
+ def exit_open; log('exit_open'); end
58
+ def after_exit_open; log('after_exit_open'); end
59
+
60
+ def before_enter_closed; log('before_enter_closed'); end
61
+ def enter_closed; log('enter_closed'); end
62
+ def before_exit_closed; log('before_exit_closed'); end
63
+ def exit_closed; log('exit_closed'); end
64
+ def after_enter_closed; log('after_enter_closed'); end
65
+ def after_exit_closed; log('after_exit_closed'); end
66
+
67
+ def event_guard; log('event_guard'); !@fail_event_guard; end
68
+ def transition_guard; log('transition_guard'); !@fail_transition_guard; end
69
+
70
+ def after_transition; log('after_transition'); end
71
+
72
+ def before_event; log('before_event'); end
73
+ def after_event; log('after_event'); end
61
74
  end
62
75
  end
@@ -2,6 +2,19 @@ module Callbacks
2
2
  class WithArgs
3
3
  include AASM
4
4
 
5
+ def initialize(options={})
6
+ @log = options[:log]
7
+ reset_data
8
+ end
9
+
10
+ def reset_data
11
+ @data = []
12
+ end
13
+
14
+ def data
15
+ @data.join(' ')
16
+ end
17
+
5
18
  aasm do
6
19
  state :open, :initial => true,
7
20
  :before_enter => :before_enter_open,
@@ -25,9 +38,12 @@ module Callbacks
25
38
  end
26
39
 
27
40
  def log(text)
28
- # puts text
41
+ @data << text
42
+ puts text if @log
29
43
  end
30
44
 
45
+ def aasm_write_state(*args); log('aasm_write_state'); true; end
46
+
31
47
  def before_enter_open; log('before_enter_open'); end
32
48
  def before_exit_open; log('before_exit_open'); end
33
49
  def after_enter_open; log('after_enter_open'); end
@@ -38,8 +54,8 @@ module Callbacks
38
54
  def after_enter_closed; log('after_enter_closed'); end
39
55
  def after_exit_closed; log('after_exit_closed'); end
40
56
 
41
- def before(*args); log('before'); end
42
- def transition_proc(arg1, arg2); log('transition_proc'); end
43
- def after(*args); log('after'); end
57
+ def before(arg1, *args); log("before(#{arg1.inspect},#{args.map(&:inspect).join(',')})"); end
58
+ def transition_proc(arg1, arg2); log("transition_proc(#{arg1.inspect},#{arg2.inspect})"); end
59
+ def after(*args); log("after(#{args.map(&:inspect).join(',')})"); end
44
60
  end
45
61
  end
@@ -18,6 +18,24 @@ class Gate < ActiveRecord::Base
18
18
  end
19
19
  end
20
20
 
21
+ class FalseState < ActiveRecord::Base
22
+ include AASM
23
+
24
+ def initialize(*args)
25
+ super
26
+ self.aasm_state = false
27
+ end
28
+
29
+ aasm do
30
+ state :opened
31
+ state :closed
32
+
33
+ event :view do
34
+ transitions :to => :read, :from => [:needs_attention]
35
+ end
36
+ end
37
+ end
38
+
21
39
  class WithEnum < ActiveRecord::Base
22
40
  include AASM
23
41
 
@@ -3,7 +3,6 @@ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib
3
3
  require 'aasm'
4
4
 
5
5
  require 'rspec'
6
- require 'rspec/autorun'
7
6
 
8
7
  require 'coveralls'
9
8
  Coveralls.wear!
@@ -128,51 +128,44 @@ describe 'callbacks for the new DSL' do
128
128
  end
129
129
 
130
130
  it "should properly pass arguments" do
131
- cb = Callbacks::WithArgs.new
132
-
133
- # TODO: use expect syntax here
134
- cb.should_receive(:before).with(:arg1, :arg2).once.ordered
135
- cb.should_receive(:before_exit_open).once.ordered # these should be before the state changes
136
- cb.should_receive(:transition_proc).with(:arg1, :arg2).once.ordered
137
- cb.should_receive(:before_enter_closed).once.ordered
138
- cb.should_receive(:aasm_write_state).once.ordered.and_return(true) # this is when the state changes
139
- cb.should_receive(:after_exit_open).once.ordered # these should be after the state changes
140
- cb.should_receive(:after_enter_closed).once.ordered
141
- cb.should_receive(:after).with(:arg1, :arg2).once.ordered
131
+ cb = Callbacks::WithArgs.new(:log => false)
132
+ cb.aasm.current_state
142
133
 
134
+ cb.reset_data
143
135
  cb.close!(:arg1, :arg2)
136
+ expect(cb.data).to eql 'before(:arg1,:arg2) before_exit_open transition_proc(:arg1,:arg2) before_enter_closed aasm_write_state after_exit_open after_enter_closed after(:arg1,:arg2)'
144
137
  end
145
138
 
146
139
  it "should call the callbacks given the to-state as argument" do
147
140
  cb = Callbacks::WithStateArg.new
148
- cb.should_receive(:before_method).with(:arg1).once.ordered
149
- cb.should_receive(:transition_method).never
150
- cb.should_receive(:transition_method2).with(:arg1).once.ordered
151
- cb.should_receive(:after_method).with(:arg1).once.ordered
141
+ expect(cb).to receive(:before_method).with(:arg1).once.ordered
142
+ expect(cb).to receive(:transition_method).never
143
+ expect(cb).to receive(:transition_method2).with(:arg1).once.ordered
144
+ expect(cb).to receive(:after_method).with(:arg1).once.ordered
152
145
  cb.close!(:out_to_lunch, :arg1)
153
146
 
154
147
  cb = Callbacks::WithStateArg.new
155
148
  some_object = double('some object')
156
- cb.should_receive(:before_method).with(some_object).once.ordered
157
- cb.should_receive(:transition_method2).with(some_object).once.ordered
158
- cb.should_receive(:after_method).with(some_object).once.ordered
149
+ expect(cb).to receive(:before_method).with(some_object).once.ordered
150
+ expect(cb).to receive(:transition_method2).with(some_object).once.ordered
151
+ expect(cb).to receive(:after_method).with(some_object).once.ordered
159
152
  cb.close!(:out_to_lunch, some_object)
160
153
  end
161
154
 
162
155
  it "should call the proper methods just with arguments" do
163
156
  cb = Callbacks::WithStateArg.new
164
- cb.should_receive(:before_method).with(:arg1).once.ordered
165
- cb.should_receive(:transition_method).with(:arg1).once.ordered
166
- cb.should_receive(:transition_method).never
167
- cb.should_receive(:after_method).with(:arg1).once.ordered
157
+ expect(cb).to receive(:before_method).with(:arg1).once.ordered
158
+ expect(cb).to receive(:transition_method).with(:arg1).once.ordered
159
+ expect(cb).to receive(:transition_method).never
160
+ expect(cb).to receive(:after_method).with(:arg1).once.ordered
168
161
  cb.close!(:arg1)
169
162
 
170
163
  cb = Callbacks::WithStateArg.new
171
164
  some_object = double('some object')
172
- cb.should_receive(:before_method).with(some_object).once.ordered
173
- cb.should_receive(:transition_method).with(some_object).once.ordered
174
- cb.should_receive(:transition_method).never
175
- cb.should_receive(:after_method).with(some_object).once.ordered
165
+ expect(cb).to receive(:before_method).with(some_object).once.ordered
166
+ expect(cb).to receive(:transition_method).with(some_object).once.ordered
167
+ expect(cb).to receive(:transition_method).never
168
+ expect(cb).to receive(:after_method).with(some_object).once.ordered
176
169
  cb.close!(some_object)
177
170
  end
178
171
  end
@@ -181,6 +174,10 @@ describe 'event callbacks' do
181
174
  describe "with an error callback defined" do
182
175
  before do
183
176
  class Foo
177
+ # this hack is needed to allow testing of parameters, since RSpec
178
+ # destroys a method's arity when mocked
179
+ attr_accessor :data
180
+
184
181
  aasm do
185
182
  event :safe_close, :success => :success_callback, :error => :error_callback do
186
183
  transitions :to => :closed, :from => [:open]
@@ -191,16 +188,42 @@ describe 'event callbacks' do
191
188
  @foo = Foo.new
192
189
  end
193
190
 
194
- it "should run error_callback if an exception is raised and error_callback defined" do
195
- def @foo.error_callback(e); end
191
+ context "error_callback defined" do
192
+ it "should run error_callback if an exception is raised" do
193
+ def @foo.error_callback(e)
194
+ @data = [e]
195
+ end
196
+
197
+ allow(@foo).to receive(:before_enter).and_raise(e = StandardError.new)
198
+
199
+ @foo.safe_close!
200
+ expect(@foo.data).to eql [e]
201
+ end
202
+
203
+ it "should run error_callback without parameters if callback does not support any" do
204
+ def @foo.error_callback(e)
205
+ @data = []
206
+ end
196
207
 
197
- allow(@foo).to receive(:before_enter).and_raise(e = StandardError.new)
198
- expect(@foo).to receive(:error_callback).with(e)
208
+ allow(@foo).to receive(:before_enter).and_raise(e = StandardError.new)
199
209
 
200
- @foo.safe_close!
210
+ @foo.safe_close!('arg1', 'arg2')
211
+ expect(@foo.data).to eql []
212
+ end
213
+
214
+ it "should run error_callback with parameters if callback supports them" do
215
+ def @foo.error_callback(e, arg1, arg2)
216
+ @data = [arg1, arg2]
217
+ end
218
+
219
+ allow(@foo).to receive(:before_enter).and_raise(e = StandardError.new)
220
+
221
+ @foo.safe_close!('arg1', 'arg2')
222
+ expect(@foo.data).to eql ['arg1', 'arg2']
223
+ end
201
224
  end
202
225
 
203
- it "should raise NoMethodError if exceptionis raised and error_callback is declared but not defined" do
226
+ it "should raise NoMethodError if exception is raised and error_callback is declared but not defined" do
204
227
  allow(@foo).to receive(:before_enter).and_raise(StandardError)
205
228
  expect{@foo.safe_close!}.to raise_error(NoMethodError)
206
229
  end
@@ -8,7 +8,7 @@ describe 'on initialization' do
8
8
  end
9
9
 
10
10
  it 'should have an activation code' do
11
- expect(auth.has_activation_code?).to be_true
11
+ expect(auth.has_activation_code?).to be_truthy
12
12
  expect(auth.activation_code).not_to be_nil
13
13
  end
14
14
  end
@@ -19,24 +19,24 @@ describe 'when being unsuspended' do
19
19
  it 'should be able to be unsuspended' do
20
20
  auth.activate!
21
21
  auth.suspend!
22
- expect(auth.may_unsuspend?).to be_true
22
+ expect(auth.may_unsuspend?).to be_truthy
23
23
  end
24
24
 
25
25
  it 'should not be able to be unsuspended into active' do
26
26
  auth.suspend!
27
- expect(auth.may_unsuspend?(:active)).not_to be_true
27
+ expect(auth.may_unsuspend?(:active)).not_to be_truthy
28
28
  end
29
29
 
30
30
  it 'should be able to be unsuspended into active if polite' do
31
31
  auth.suspend!
32
- expect(auth.may_wait?(:waiting, :please)).to be_true
32
+ expect(auth.may_wait?(:waiting, :please)).to be_truthy
33
33
  auth.wait!(nil, :please)
34
34
  end
35
35
 
36
36
  it 'should not be able to be unsuspended into active if not polite' do
37
37
  auth.suspend!
38
- expect(auth.may_wait?(:waiting)).not_to be_true
39
- expect(auth.may_wait?(:waiting, :rude)).not_to be_true
38
+ expect(auth.may_wait?(:waiting)).not_to be_truthy
39
+ expect(auth.may_wait?(:waiting, :rude)).not_to be_truthy
40
40
  expect {auth.wait!(nil, :rude)}.to raise_error(AASM::InvalidTransition)
41
41
  expect {auth.wait!}.to raise_error(AASM::InvalidTransition)
42
42
  end
@@ -46,7 +46,7 @@ describe 'when being unsuspended' do
46
46
  auth.suspend!
47
47
  auth.unsuspend!
48
48
 
49
- expect(auth.may_unpassify?).not_to be_true
49
+ expect(auth.may_unpassify?).not_to be_truthy
50
50
  expect {auth.unpassify!}.to raise_error(AASM::InvalidTransition)
51
51
  end
52
52
 
@@ -74,11 +74,11 @@ describe 'when being unsuspended' do
74
74
  end
75
75
 
76
76
  it "should be able to fire known events" do
77
- expect(auth.aasm.may_fire_event?(:activate)).to be_true
77
+ expect(auth.aasm.may_fire_event?(:activate)).to be_truthy
78
78
  end
79
79
 
80
80
  it "should not be able to fire unknown events" do
81
- expect(auth.aasm.may_fire_event?(:unknown)).to be_false
81
+ expect(auth.aasm.may_fire_event?(:unknown)).to be_falsey
82
82
  end
83
83
 
84
84
  end
@@ -43,18 +43,18 @@ describe 'transition inspection' do
43
43
 
44
44
  it 'should support inspecting transitions from other states' do
45
45
  expect(event.transitions_from_state(:sleeping).map(&:to)).to eq([:running])
46
- expect(event.transitions_from_state?(:sleeping)).to be_true
46
+ expect(event.transitions_from_state?(:sleeping)).to be_truthy
47
47
 
48
48
  expect(event.transitions_from_state(:cleaning).map(&:to)).to eq([])
49
- expect(event.transitions_from_state?(:cleaning)).to be_false
49
+ expect(event.transitions_from_state?(:cleaning)).to be_falsey
50
50
  end
51
51
 
52
52
  it 'should support inspecting transitions to other states' do
53
53
  expect(event.transitions_to_state(:running).map(&:from)).to eq([:sleeping])
54
- expect(event.transitions_to_state?(:running)).to be_true
54
+ expect(event.transitions_to_state?(:running)).to be_truthy
55
55
 
56
56
  expect(event.transitions_to_state(:cleaning).map(&:to)).to eq([])
57
- expect(event.transitions_to_state?(:cleaning)).to be_false
57
+ expect(event.transitions_to_state?(:cleaning)).to be_falsey
58
58
  end
59
59
  end
60
60
 
@@ -67,10 +67,10 @@ describe 'transition inspection without from' do
67
67
 
68
68
  it 'should support inspecting transitions from other states' do
69
69
  expect(event.transitions_from_state(:sleeping).map(&:to)).to eq([:running])
70
- expect(event.transitions_from_state?(:sleeping)).to be_true
70
+ expect(event.transitions_from_state?(:sleeping)).to be_truthy
71
71
 
72
72
  expect(event.transitions_from_state(:cleaning).map(&:to)).to eq([:running])
73
- expect(event.transitions_from_state?(:cleaning)).to be_true
73
+ expect(event.transitions_from_state?(:cleaning)).to be_truthy
74
74
  end
75
75
 
76
76
  end
@@ -67,11 +67,11 @@ describe "special cases" do
67
67
  expect(Argument.aasm.states).to include(:valid)
68
68
 
69
69
  argument = Argument.new
70
- expect(argument.invalid?).to be_true
70
+ expect(argument.invalid?).to be_truthy
71
71
  expect(argument.aasm.current_state).to eq(:invalid)
72
72
 
73
73
  argument.valid!
74
- expect(argument.valid?).to be_true
74
+ expect(argument.valid?).to be_truthy
75
75
  expect(argument.aasm.current_state).to eq(:valid)
76
76
  end
77
77
  end
@@ -30,15 +30,15 @@ describe "instance methods" do
30
30
  let(:columns_hash) { Hash[column_name, column] }
31
31
 
32
32
  before :each do
33
- gate.class.aasm.stub(:attribute_name).and_return(column_name.to_sym)
34
- gate.class.stub(:columns_hash).and_return(columns_hash)
33
+ allow(gate.class.aasm).to receive(:attribute_name).and_return(column_name.to_sym)
34
+ allow(gate.class).to receive(:columns_hash).and_return(columns_hash)
35
35
  end
36
36
 
37
37
  context "when AASM column has integer type" do
38
38
  let(:column) { double(Object, type: :integer) }
39
39
 
40
40
  it "returns true" do
41
- expect(subject.call).to be_true
41
+ expect(subject.call).to be_truthy
42
42
  end
43
43
  end
44
44
 
@@ -46,7 +46,7 @@ describe "instance methods" do
46
46
  let(:column) { double(Object, type: :string) }
47
47
 
48
48
  it "returns false" do
49
- expect(subject.call).to be_false
49
+ expect(subject.call).to be_falsey
50
50
  end
51
51
  end
52
52
  end
@@ -55,7 +55,7 @@ describe "instance methods" do
55
55
  subject { lambda{ gate.send(:aasm_guess_enum_method) } }
56
56
 
57
57
  before :each do
58
- gate.class.aasm.stub(:attribute_name).and_return(:value)
58
+ allow(gate.class.aasm).to receive(:attribute_name).and_return(:value)
59
59
  end
60
60
 
61
61
  it "pluralizes AASM column name" do
@@ -75,7 +75,7 @@ describe "instance methods" do
75
75
  context "when AASM enum setting is simply set to true" do
76
76
  let(:with_true_enum) { WithTrueEnum.new }
77
77
  before :each do
78
- WithTrueEnum.aasm.stub(:attribute_name).and_return(:value)
78
+ allow(WithTrueEnum.aasm).to receive(:attribute_name).and_return(:value)
79
79
  end
80
80
 
81
81
  it "infers enum method name from pluralized column name" do
@@ -93,12 +93,12 @@ describe "instance methods" do
93
93
 
94
94
  context "when AASM enum setting is not enabled" do
95
95
  before :each do
96
- Gate.aasm.stub(:attribute_name).and_return(:value)
96
+ allow(Gate.aasm).to receive(:attribute_name).and_return(:value)
97
97
  end
98
98
 
99
99
  context "when AASM column looks like enum" do
100
100
  before :each do
101
- gate.stub(:aasm_column_looks_like_enum).and_return(true)
101
+ allow(gate).to receive(:aasm_column_looks_like_enum).and_return(true)
102
102
  end
103
103
 
104
104
  it "infers enum method name from pluralized column name" do
@@ -108,7 +108,7 @@ describe "instance methods" do
108
108
 
109
109
  context "when AASM column doesn't look like enum'" do
110
110
  before :each do
111
- gate.stub(:aasm_column_looks_like_enum)
111
+ allow(gate).to receive(:aasm_column_looks_like_enum)
112
112
  .and_return(false)
113
113
  end
114
114
 
@@ -126,24 +126,17 @@ describe "instance methods" do
126
126
  let(:enum) { Hash[state_sym, state_code] }
127
127
 
128
128
  before :each do
129
- gate
130
- .stub(:aasm_enum)
131
- .and_return(enum_name)
132
- gate.stub(:aasm_write_attribute)
133
- gate.stub(:write_attribute)
134
-
135
- gate
136
- .class
137
- .stub(enum_name)
138
- .and_return(enum)
129
+ allow(gate).to receive(:aasm_enum).and_return(enum_name)
130
+ allow(gate).to receive(:aasm_write_attribute)
131
+ allow(gate).to receive(:write_attribute)
132
+
133
+ allow(Gate).to receive(enum_name).and_return(enum)
139
134
  end
140
135
 
141
136
  describe "aasm_write_state" do
142
137
  context "when AASM is configured to skip validations on save" do
143
138
  before :each do
144
- gate
145
- .stub(:aasm_skipping_validations)
146
- .and_return(true)
139
+ allow(gate).to receive(:aasm_skipping_validations).and_return(true)
147
140
  end
148
141
 
149
142
  it "passes state code instead of state symbol to update_all" do
@@ -151,10 +144,7 @@ describe "instance methods" do
151
144
  # parameters in the middle of the chain, so we need to use
152
145
  # intermediate object instead.
153
146
  obj = double(Object, update_all: 1)
154
- gate
155
- .class
156
- .stub(:where)
157
- .and_return(obj)
147
+ allow(Gate).to receive(:where).and_return(obj)
158
148
 
159
149
  gate.aasm_write_state state_sym
160
150
 
@@ -166,7 +156,7 @@ describe "instance methods" do
166
156
  context "when AASM is not skipping validations" do
167
157
  it "delegates state update to the helper method" do
168
158
  # Let's pretend that validation is passed
169
- gate.stub(:save).and_return(true)
159
+ allow(gate).to receive(:save).and_return(true)
170
160
 
171
161
  gate.aasm_write_state state_sym
172
162
 
@@ -197,9 +187,7 @@ describe "instance methods" do
197
187
  let(:state_sym) { :running }
198
188
 
199
189
  before :each do
200
- gate
201
- .stub(:aasm_enum)
202
- .and_return(nil)
190
+ allow(gate).to receive(:aasm_enum).and_return(nil)
203
191
  end
204
192
 
205
193
  describe "aasm_raw_attribute_value" do
@@ -215,9 +203,8 @@ describe "instance methods" do
215
203
  let(:value) { 42 }
216
204
 
217
205
  before :each do
218
- gate.stub(:write_attribute)
219
- gate.stub(:aasm_raw_attribute_value)
220
- .and_return(value)
206
+ allow(gate).to receive(:write_attribute)
207
+ allow(gate).to receive(:aasm_raw_attribute_value).and_return(value)
221
208
 
222
209
  gate.send(:aasm_write_attribute, sym)
223
210
  end
@@ -270,6 +257,16 @@ describe "instance methods" do
270
257
 
271
258
  end
272
259
 
260
+ describe "direct state column access" do
261
+ it "accepts false states" do
262
+ f = FalseState.create!
263
+ expect(f.aasm_state).to eql false
264
+ expect {
265
+ f.aasm.events.map(&:name)
266
+ }.to_not raise_error
267
+ end
268
+ end
269
+
273
270
  describe 'subclasses' do
274
271
  it "should have the same states as its parent class" do
275
272
  expect(DerivateNewDsl.aasm.states).to eq(SimpleNewDsl.aasm.states)
@@ -289,7 +286,7 @@ describe "named scopes with the new DSL" do
289
286
  context "Does not already respond_to? the scope name" do
290
287
  it "should add a scope" do
291
288
  expect(SimpleNewDsl).to respond_to(:unknown_scope)
292
- expect(SimpleNewDsl.unknown_scope.is_a?(ActiveRecord::Relation)).to be_true
289
+ expect(SimpleNewDsl.unknown_scope.is_a?(ActiveRecord::Relation)).to be_truthy
293
290
  end
294
291
  end
295
292
 
@@ -348,7 +345,7 @@ describe 'transitions with persistence' do
348
345
 
349
346
  validator.name = nil
350
347
  expect(validator).not_to be_valid
351
- expect(validator.run!).to be_false
348
+ expect(validator.run!).to be_falsey
352
349
  expect(validator).to be_sleeping
353
350
 
354
351
  validator.reload
@@ -357,7 +354,7 @@ describe 'transitions with persistence' do
357
354
 
358
355
  validator.name = 'another name'
359
356
  expect(validator).to be_valid
360
- expect(validator.run!).to be_true
357
+ expect(validator.run!).to be_truthy
361
358
  expect(validator).to be_running
362
359
 
363
360
  validator.reload
@@ -372,7 +369,7 @@ describe 'transitions with persistence' do
372
369
 
373
370
  persistor.name = nil
374
371
  expect(persistor).not_to be_valid
375
- expect(persistor.run!).to be_true
372
+ expect(persistor.run!).to be_truthy
376
373
  expect(persistor).to be_running
377
374
 
378
375
  persistor = InvalidPersistor.find(persistor.id)
@@ -477,7 +474,7 @@ describe "invalid states with persistence" do
477
474
  it "should not store states" do
478
475
  validator = Validator.create(:name => 'name')
479
476
  validator.status = 'invalid_state'
480
- expect(validator.save).to be_false
477
+ expect(validator.save).to be_falsey
481
478
  expect {validator.save!}.to raise_error(ActiveRecord::RecordInvalid)
482
479
 
483
480
  validator.reload
@@ -487,7 +484,7 @@ describe "invalid states with persistence" do
487
484
  it "should store invalid states if configured" do
488
485
  persistor = InvalidPersistor.create(:name => 'name')
489
486
  persistor.status = 'invalid_state'
490
- expect(persistor.save).to be_true
487
+ expect(persistor.save).to be_truthy
491
488
 
492
489
  persistor.reload
493
490
  expect(persistor.status).to eq('invalid_state')
@@ -19,7 +19,7 @@ describe 'subclassing' do
19
19
  end
20
20
 
21
21
  it 'should know how to respond to `may_add_details?`' do
22
- expect(son.may_add_details?).to be_true
22
+ expect(son.may_add_details?).to be_truthy
23
23
  end
24
24
 
25
25
  it 'should not break if I call Son#update_state' do
@@ -10,19 +10,19 @@ describe 'transitions' do
10
10
 
11
11
  it 'should not raise an exception when not whiny' do
12
12
  silencer = Silencer.new
13
- expect(silencer.smile!).to be_false
13
+ expect(silencer.smile!).to be_falsey
14
14
  expect(silencer).to be_silent
15
15
  end
16
16
 
17
17
  it 'should not raise an exception when superclass not whiny' do
18
18
  sub = SubClassing.new
19
- expect(sub.smile!).to be_false
19
+ expect(sub.smile!).to be_falsey
20
20
  expect(sub).to be_silent
21
21
  end
22
22
 
23
23
  it 'should not raise an exception when from is nil even if whiny' do
24
24
  silencer = Silencer.new
25
- expect(silencer.smile_any!).to be_true
25
+ expect(silencer.smile_any!).to be_truthy
26
26
  expect(silencer).to be_smiling
27
27
  end
28
28
 
@@ -43,7 +43,7 @@ describe 'transitions' do
43
43
  silencer.smile! do
44
44
  success = true
45
45
  end
46
- }.not_to change { success }.to(true)
46
+ }.not_to change { success }
47
47
  end
48
48
 
49
49
  end
@@ -64,14 +64,14 @@ describe AASM::Core::Transition do
64
64
  it 'should set on_transition with deprecation warning' do
65
65
  opts = {:from => 'foo', :to => 'bar'}
66
66
  st = AASM::Core::Transition.allocate
67
- st.should_receive(:warn).with('[DEPRECATION] :on_transition is deprecated, use :after instead')
67
+ expect(st).to receive(:warn).with('[DEPRECATION] :on_transition is deprecated, use :after instead')
68
68
 
69
69
  st.send :initialize, opts do
70
70
  guard :gg
71
71
  on_transition :after_callback
72
72
  end
73
73
 
74
- st.opts[:after].should == [:after_callback]
74
+ expect(st.opts[:after]).to eql [:after_callback]
75
75
  end
76
76
 
77
77
  it 'should set after and guard from dsl' do
@@ -81,8 +81,8 @@ describe AASM::Core::Transition do
81
81
  after :after_callback
82
82
  end
83
83
 
84
- st.opts[:guard].should == ['g', :gg]
85
- st.opts[:after].should == [:after_callback] # TODO fix this bad code coupling
84
+ expect(st.opts[:guard]).to eql ['g', :gg]
85
+ expect(st.opts[:after]).to eql [:after_callback] # TODO fix this bad code coupling
86
86
  end
87
87
 
88
88
  it 'should pass equality check if from and to are the same' do
@@ -124,7 +124,7 @@ describe AASM::Core::Transition, '- when performing guard checks' do
124
124
  opts = {:from => 'foo', :to => 'bar'}
125
125
  st = AASM::Core::Transition.new(opts)
126
126
 
127
- expect(st.allowed?(nil)).to be_true
127
+ expect(st.allowed?(nil)).to be_truthy
128
128
  end
129
129
 
130
130
  it 'should call the method on the object if guard is a symbol' do
@@ -185,7 +185,7 @@ describe AASM::Core::Transition, '- when executing the transition with a Proc' d
185
185
  args = {:arg1 => '1', :arg2 => '2'}
186
186
  obj = double('object', :aasm => 'aasm')
187
187
 
188
- obj.should_receive(:test).with(args)
188
+ expect(obj).to receive(:test).with(args)
189
189
 
190
190
  st.execute(obj, args)
191
191
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aasm
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.5
4
+ version: 4.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Barron
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-12-06 00:00:00.000000000 Z
13
+ date: 2014-12-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -46,20 +46,14 @@ dependencies:
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: '2.14'
50
- - - "<"
51
- - !ruby/object:Gem::Version
52
- version: '2.99'
49
+ version: '0'
53
50
  type: :development
54
51
  prerelease: false
55
52
  version_requirements: !ruby/object:Gem::Requirement
56
53
  requirements:
57
54
  - - ">="
58
55
  - !ruby/object:Gem::Version
59
- version: '2.14'
60
- - - "<"
61
- - !ruby/object:Gem::Version
62
- version: '2.99'
56
+ version: '0'
63
57
  - !ruby/object:Gem::Dependency
64
58
  name: pry
65
59
  requirement: !ruby/object:Gem::Requirement