aasm 4.0.2 → 4.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/lib/aasm/base.rb +10 -0
- data/lib/aasm/event.rb +2 -1
- data/lib/aasm/localizer.rb +1 -1
- data/lib/aasm/persistence/active_record_persistence.rb +7 -7
- data/lib/aasm/persistence/base.rb +7 -39
- data/lib/aasm/persistence/mongoid_persistence.rb +7 -7
- data/lib/aasm/persistence/sequel_persistence.rb +5 -5
- data/lib/aasm/version.rb +1 -1
- data/spec/models/callbacks/multiple_transitions_transition_guard.rb +65 -0
- data/spec/unit/callbacks_spec.rb +44 -13
- data/spec/unit/persistence/active_record_persistence_spec.rb +8 -8
- data/spec/unit/persistence/sequel_persistence_spec.rb +2 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d198d23fad17dc052b4135e5ef02470edd8e146
|
4
|
+
data.tar.gz: 85019079c1b7cfb236cf529b833561ba35030d51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1a3a8f5df97b012148fa50b79150d218f0dad130a4014e68502a2982b98ab3a6b79148832dac285321901366ab5ec976af11a5f431966ac528d60d5c62dcc5c
|
7
|
+
data.tar.gz: 9e09e2ec97235c8761fd34a4c884cb6d9579e9960acf02815f472e0068586b8c4d2ff50b6d08d71f6571f31d81aa9cf345b94784d7cde1a066b1ddf0f44c466b
|
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,13 @@
|
|
2
2
|
|
3
3
|
## 4.1.0 (not yet released)
|
4
4
|
|
5
|
-
* `
|
5
|
+
* `aasm_column` has been removed. Use `aasm.attribute_name` instead
|
6
|
+
* `aasm_human_event_name` has been removed. Use `aasm.human_event_name` instead
|
7
|
+
|
8
|
+
## 4.0.3
|
9
|
+
|
10
|
+
* bugfix: fire guards only once per transition, part 2 (see [issue #187](https://github.com/aasm/aasm/issues/187) for details)
|
11
|
+
* `aasm_column` is deprecated. Use `aasm.attribute_name` instead
|
6
12
|
|
7
13
|
## 4.0.2
|
8
14
|
|
@@ -11,6 +17,7 @@
|
|
11
17
|
## 4.0.1
|
12
18
|
|
13
19
|
* fire guards only once per transition (see [issue #184](https://github.com/aasm/aasm/issues/184) for details)
|
20
|
+
* `aasm_human_event_name` is deprecated, use `aasm.human_event_name` instead
|
14
21
|
|
15
22
|
## 4.0.0
|
16
23
|
|
data/lib/aasm/base.rb
CHANGED
@@ -34,6 +34,16 @@ module AASM
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
# This method is both a getter and a setter
|
38
|
+
def attribute_name(column_name=nil)
|
39
|
+
if column_name
|
40
|
+
@state_machine.config.column = column_name.to_sym
|
41
|
+
else
|
42
|
+
@state_machine.config.column ||= :aasm_state
|
43
|
+
end
|
44
|
+
@state_machine.config.column
|
45
|
+
end
|
46
|
+
|
37
47
|
def initial_state(new_initial_state=nil)
|
38
48
|
if new_initial_state
|
39
49
|
@state_machine.initial_state = new_initial_state
|
data/lib/aasm/event.rb
CHANGED
@@ -106,7 +106,8 @@ module AASM
|
|
106
106
|
|
107
107
|
transitions.each do |transition|
|
108
108
|
next if to_state and !Array(transition.to).include?(to_state)
|
109
|
-
if Array(transition.to).include?(options[:may_fire]) ||
|
109
|
+
if (options.key?(:may_fire) && Array(transition.to).include?(options[:may_fire])) ||
|
110
|
+
(!options.key?(:may_fire) && transition.allowed?(obj, *args))
|
110
111
|
result = to_state || Array(transition.to).first
|
111
112
|
if options[:test_only]
|
112
113
|
# result = true
|
data/lib/aasm/localizer.rb
CHANGED
@@ -21,7 +21,7 @@ module AASM
|
|
21
21
|
|
22
22
|
def item_for(klass, state, ancestor, options={})
|
23
23
|
separator = options[:old_style] ? '.' : '/'
|
24
|
-
:"#{i18n_scope(klass)}.attributes.#{i18n_klass(ancestor)}.#{klass.
|
24
|
+
:"#{i18n_scope(klass)}.attributes.#{i18n_klass(ancestor)}.#{klass.aasm.attribute_name}#{separator}#{state}"
|
25
25
|
end
|
26
26
|
|
27
27
|
def translate_queue(checklist)
|
@@ -84,17 +84,17 @@ module AASM
|
|
84
84
|
#
|
85
85
|
# NOTE: intended to be called from an event
|
86
86
|
def aasm_write_state(state)
|
87
|
-
old_value = read_attribute(self.class.
|
87
|
+
old_value = read_attribute(self.class.aasm.attribute_name)
|
88
88
|
aasm_write_attribute state
|
89
89
|
|
90
90
|
success = if aasm_skipping_validations
|
91
91
|
value = aasm_raw_attribute_value state
|
92
|
-
self.class.where(self.class.primary_key => self.id).update_all(self.class.
|
92
|
+
self.class.where(self.class.primary_key => self.id).update_all(self.class.aasm.attribute_name => value) == 1
|
93
93
|
else
|
94
94
|
self.save
|
95
95
|
end
|
96
96
|
unless success
|
97
|
-
write_attribute(self.class.
|
97
|
+
write_attribute(self.class.aasm.attribute_name, old_value)
|
98
98
|
return false
|
99
99
|
end
|
100
100
|
|
@@ -128,11 +128,11 @@ module AASM
|
|
128
128
|
end
|
129
129
|
|
130
130
|
def aasm_column_looks_like_enum
|
131
|
-
self.class.columns_hash[self.class.
|
131
|
+
self.class.columns_hash[self.class.aasm.attribute_name.to_s].type == :integer
|
132
132
|
end
|
133
133
|
|
134
134
|
def aasm_guess_enum_method
|
135
|
-
self.class.
|
135
|
+
self.class.aasm.attribute_name.to_s.pluralize.to_sym
|
136
136
|
end
|
137
137
|
|
138
138
|
def aasm_skipping_validations
|
@@ -140,7 +140,7 @@ module AASM
|
|
140
140
|
end
|
141
141
|
|
142
142
|
def aasm_write_attribute(state)
|
143
|
-
write_attribute self.class.
|
143
|
+
write_attribute self.class.aasm.attribute_name, aasm_raw_attribute_value(state)
|
144
144
|
end
|
145
145
|
|
146
146
|
def aasm_raw_attribute_value(state)
|
@@ -167,7 +167,7 @@ module AASM
|
|
167
167
|
# foo.aasm_state # => nil
|
168
168
|
#
|
169
169
|
def aasm_ensure_initial_state
|
170
|
-
aasm.enter_initial_state if send(self.class.
|
170
|
+
aasm.enter_initial_state if send(self.class.aasm.attribute_name).blank?
|
171
171
|
end
|
172
172
|
|
173
173
|
def aasm_fire_event(name, options, *args, &block)
|
@@ -6,7 +6,7 @@ module AASM
|
|
6
6
|
base.extend ClassMethods
|
7
7
|
end
|
8
8
|
|
9
|
-
# Returns the value of the
|
9
|
+
# Returns the value of the aasm.attribute_name - called from <tt>aasm.current_state</tt>
|
10
10
|
#
|
11
11
|
# If it's a new record, and the aasm state column is blank it returns the initial state
|
12
12
|
# (example provided here for ActiveRecord, but it's true for Mongoid as well):
|
@@ -33,7 +33,7 @@ module AASM
|
|
33
33
|
#
|
34
34
|
# This allows for nil aasm states - be sure to add validation to your model
|
35
35
|
def aasm_read_state
|
36
|
-
state = send(self.class.
|
36
|
+
state = send(self.class.aasm.attribute_name)
|
37
37
|
if new_record?
|
38
38
|
state.blank? ? aasm.determine_state_name(self.class.aasm.initial_state) : state.to_sym
|
39
39
|
else
|
@@ -42,41 +42,9 @@ module AASM
|
|
42
42
|
end
|
43
43
|
|
44
44
|
module ClassMethods
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
# create_table :foos do |t|
|
49
|
-
# t.string :name
|
50
|
-
# t.string :aasm_state
|
51
|
-
# end
|
52
|
-
#
|
53
|
-
# class Foo < ActiveRecord::Base
|
54
|
-
# include AASM
|
55
|
-
# end
|
56
|
-
#
|
57
|
-
# OR:
|
58
|
-
#
|
59
|
-
# create_table :foos do |t|
|
60
|
-
# t.string :name
|
61
|
-
# t.string :status
|
62
|
-
# end
|
63
|
-
#
|
64
|
-
# class Foo < ActiveRecord::Base
|
65
|
-
# include AASM
|
66
|
-
# aasm_column :status
|
67
|
-
# end
|
68
|
-
#
|
69
|
-
# This method is both a getter and a setter
|
70
|
-
def aasm_column(column_name=nil)
|
71
|
-
if column_name
|
72
|
-
AASM::StateMachine[self].config.column = column_name.to_sym
|
73
|
-
# @aasm_column = column_name.to_sym
|
74
|
-
else
|
75
|
-
AASM::StateMachine[self].config.column ||= :aasm_state
|
76
|
-
# @aasm_column ||= :aasm_state
|
77
|
-
end
|
78
|
-
# @aasm_column
|
79
|
-
AASM::StateMachine[self].config.column
|
45
|
+
def aasm_column(attribute_name=nil)
|
46
|
+
warn "[DEPRECATION] aasm_column is deprecated. Use aasm.attribute_name instead"
|
47
|
+
aasm.attribute_name(attribute_name)
|
80
48
|
end
|
81
49
|
end # ClassMethods
|
82
50
|
|
@@ -90,7 +58,7 @@ module AASM
|
|
90
58
|
if AASM::StateMachine[@klass].config.create_scopes && !@klass.respond_to?(name)
|
91
59
|
if @klass.ancestors.map {|klass| klass.to_s}.include?("ActiveRecord::Base")
|
92
60
|
|
93
|
-
conditions = {"#{@klass.table_name}.#{@klass.
|
61
|
+
conditions = {"#{@klass.table_name}.#{@klass.aasm.attribute_name}" => name.to_s}
|
94
62
|
if ActiveRecord::VERSION::MAJOR >= 3
|
95
63
|
@klass.class_eval do
|
96
64
|
scope name, lambda { where(conditions) }
|
@@ -101,7 +69,7 @@ module AASM
|
|
101
69
|
end
|
102
70
|
end
|
103
71
|
elsif @klass.ancestors.map {|klass| klass.to_s}.include?("Mongoid::Document")
|
104
|
-
scope_options = lambda { @klass.send(:where, {@klass.
|
72
|
+
scope_options = lambda { @klass.send(:where, {@klass.aasm.attribute_name.to_sym => name.to_s}) }
|
105
73
|
@klass.send(:scope, name, scope_options)
|
106
74
|
end
|
107
75
|
end
|
@@ -55,7 +55,7 @@ module AASM
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def with_state_scope(state)
|
58
|
-
with_scope where(
|
58
|
+
with_scope where(aasm.attribute_name.to_sym => state.to_s) do
|
59
59
|
yield if block_given?
|
60
60
|
end
|
61
61
|
end
|
@@ -75,11 +75,11 @@ module AASM
|
|
75
75
|
#
|
76
76
|
# NOTE: intended to be called from an event
|
77
77
|
def aasm_write_state(state)
|
78
|
-
old_value = read_attribute(self.class.
|
79
|
-
write_attribute(self.class.
|
78
|
+
old_value = read_attribute(self.class.aasm.attribute_name)
|
79
|
+
write_attribute(self.class.aasm.attribute_name, state.to_s)
|
80
80
|
|
81
81
|
unless self.save(:validate => false)
|
82
|
-
write_attribute(self.class.
|
82
|
+
write_attribute(self.class.aasm.attribute_name, old_value)
|
83
83
|
return false
|
84
84
|
end
|
85
85
|
|
@@ -99,7 +99,7 @@ module AASM
|
|
99
99
|
#
|
100
100
|
# NOTE: intended to be called from an event
|
101
101
|
def aasm_write_state_without_persistence(state)
|
102
|
-
write_attribute(self.class.
|
102
|
+
write_attribute(self.class.aasm.attribute_name, state.to_s)
|
103
103
|
end
|
104
104
|
|
105
105
|
private
|
@@ -120,14 +120,14 @@ module AASM
|
|
120
120
|
# foo.aasm_state # => nil
|
121
121
|
#
|
122
122
|
def aasm_ensure_initial_state
|
123
|
-
send("#{self.class.
|
123
|
+
send("#{self.class.aasm.attribute_name}=", aasm.enter_initial_state.to_s) if send(self.class.aasm.attribute_name).blank?
|
124
124
|
end
|
125
125
|
end # InstanceMethods
|
126
126
|
|
127
127
|
module NamedScopeMethods
|
128
128
|
def aasm_state_with_named_scope name, options = {}
|
129
129
|
aasm_state_without_named_scope name, options
|
130
|
-
self.named_scope name, :conditions => { "#{table_name}.#{self.
|
130
|
+
self.named_scope name, :conditions => { "#{table_name}.#{self.aasm.attribute_name}" => name.to_s} unless self.respond_to?(name)
|
131
131
|
end
|
132
132
|
end
|
133
133
|
end
|
@@ -17,7 +17,7 @@ module AASM
|
|
17
17
|
super
|
18
18
|
end
|
19
19
|
|
20
|
-
# Returns the value of the
|
20
|
+
# Returns the value of the aasm.attribute_name - called from <tt>aasm.current_state</tt>
|
21
21
|
#
|
22
22
|
# If it's a new record, and the aasm state column is blank it returns the initial state
|
23
23
|
#
|
@@ -43,7 +43,7 @@ module AASM
|
|
43
43
|
#
|
44
44
|
# This allows for nil aasm states - be sure to add validation to your model
|
45
45
|
def aasm_read_state
|
46
|
-
state = send(self.class.
|
46
|
+
state = send(self.class.aasm.attribute_name)
|
47
47
|
if new? && state.to_s.strip.empty?
|
48
48
|
aasm.determine_state_name(self.class.aasm.initial_state)
|
49
49
|
elsif state.nil?
|
@@ -70,7 +70,7 @@ module AASM
|
|
70
70
|
#
|
71
71
|
def aasm_ensure_initial_state
|
72
72
|
aasm.enter_initial_state if
|
73
|
-
send(self.class.
|
73
|
+
send(self.class.aasm.attribute_name).to_s.strip.empty?
|
74
74
|
end
|
75
75
|
|
76
76
|
# Writes <tt>state</tt> to the state column and persists it to the database
|
@@ -83,7 +83,7 @@ module AASM
|
|
83
83
|
#
|
84
84
|
# NOTE: intended to be called from an event
|
85
85
|
def aasm_write_state state
|
86
|
-
aasm_column = self.class.
|
86
|
+
aasm_column = self.class.aasm.attribute_name
|
87
87
|
update_only({aasm_column => state.to_s}, aasm_column)
|
88
88
|
end
|
89
89
|
|
@@ -100,7 +100,7 @@ module AASM
|
|
100
100
|
#
|
101
101
|
# NOTE: intended to be called from an event
|
102
102
|
def aasm_write_state_without_persistence state
|
103
|
-
send("#{self.class.
|
103
|
+
send("#{self.class.aasm.attribute_name}=", state.to_s)
|
104
104
|
end
|
105
105
|
end
|
106
106
|
end
|
data/lib/aasm/version.rb
CHANGED
@@ -0,0 +1,65 @@
|
|
1
|
+
module Callbacks
|
2
|
+
class MultipleTransitionsTransitionGuard
|
3
|
+
include AASM
|
4
|
+
|
5
|
+
def initialize(options={})
|
6
|
+
@fail_event_guard = options[:fail_event_guard]
|
7
|
+
@fail_transition_guard = options[:fail_transition_guard]
|
8
|
+
@log = options[:log]
|
9
|
+
end
|
10
|
+
|
11
|
+
aasm do
|
12
|
+
state :open, :initial => true,
|
13
|
+
:before_enter => :before_enter_open,
|
14
|
+
:enter => :enter_open,
|
15
|
+
:after_enter => :after_enter_open,
|
16
|
+
:before_exit => :before_exit_open,
|
17
|
+
:exit => :exit_open,
|
18
|
+
:after_exit => :after_exit_open
|
19
|
+
|
20
|
+
state :closed,
|
21
|
+
:before_enter => :before_enter_closed,
|
22
|
+
:enter => :enter_closed,
|
23
|
+
:after_enter => :after_enter_closed,
|
24
|
+
:before_exit => :before_exit_closed,
|
25
|
+
:exit => :exit_closed,
|
26
|
+
:after_exit => :after_exit_closed
|
27
|
+
|
28
|
+
state :failed
|
29
|
+
|
30
|
+
event :close, :before => :before, :after => :after, :guard => :event_guard do
|
31
|
+
transitions :to => :closed, :from => [:open], :guard => :transition_guard, :after => :transitioning
|
32
|
+
transitions :to => :failed, :from => [:open]
|
33
|
+
end
|
34
|
+
|
35
|
+
event :open, :before => :before, :after => :after do
|
36
|
+
transitions :to => :open, :from => :closed
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def log(text)
|
41
|
+
puts text if @log
|
42
|
+
end
|
43
|
+
|
44
|
+
def before_enter_open; log('before_enter_open'); end
|
45
|
+
def enter_open; log('enter_open'); end
|
46
|
+
def before_exit_open; log('before_exit_open'); end
|
47
|
+
def after_enter_open; log('after_enter_open'); end
|
48
|
+
def exit_open; log('exit_open'); end
|
49
|
+
def after_exit_open; log('after_exit_open'); end
|
50
|
+
|
51
|
+
def before_enter_closed; log('before_enter_closed'); end
|
52
|
+
def enter_closed; log('enter_closed'); end
|
53
|
+
def before_exit_closed; log('before_exit_closed'); end
|
54
|
+
def exit_closed; log('exit_closed'); end
|
55
|
+
def after_enter_closed; log('after_enter_closed'); end
|
56
|
+
def after_exit_closed; log('after_exit_closed'); end
|
57
|
+
|
58
|
+
def event_guard; log('event_guard'); !@fail_event_guard; end
|
59
|
+
def transition_guard; log('transition_guard'); !@fail_transition_guard; end
|
60
|
+
def transitioning; log('transitioning'); end
|
61
|
+
|
62
|
+
def before; log('before'); end
|
63
|
+
def after; log('after'); end
|
64
|
+
end
|
65
|
+
end
|
data/spec/unit/callbacks_spec.rb
CHANGED
@@ -49,27 +49,58 @@ describe 'callbacks for the new DSL' do
|
|
49
49
|
|
50
50
|
context "if the transition guard fails" do
|
51
51
|
it "does not run any state callback if guard is defined inline" do
|
52
|
-
|
52
|
+
show_debug_log = false
|
53
|
+
callback = CallbackNewDsl.new(:log => show_debug_log, :fail_transition_guard => true)
|
53
54
|
callback.aasm.current_state
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
56
|
+
unless show_debug_log
|
57
|
+
expect(callback).to receive(:before).once.ordered
|
58
|
+
expect(callback).to receive(:event_guard).once.ordered.and_return(true)
|
59
|
+
expect(callback).to receive(:transition_guard).once.ordered.and_return(false)
|
60
|
+
expect(callback).to_not receive(:before_exit_open)
|
61
|
+
expect(callback).to_not receive(:exit_open)
|
62
|
+
expect(callback).to_not receive(:transitioning)
|
63
|
+
expect(callback).to_not receive(:before_enter_closed)
|
64
|
+
expect(callback).to_not receive(:enter_closed)
|
65
|
+
expect(callback).to_not receive(:aasm_write_state)
|
66
|
+
expect(callback).to_not receive(:after_exit_open)
|
67
|
+
expect(callback).to_not receive(:after_enter_closed)
|
68
|
+
expect(callback).to_not receive(:after)
|
69
|
+
end
|
67
70
|
|
68
71
|
expect {
|
69
72
|
callback.close!
|
70
73
|
}.to raise_error(AASM::InvalidTransition)
|
71
74
|
end
|
72
75
|
|
76
|
+
it "does not run transition_guard twice for multiple permitted transitions" do
|
77
|
+
require 'models/callbacks/multiple_transitions_transition_guard'
|
78
|
+
|
79
|
+
show_debug_log = false
|
80
|
+
callback = Callbacks::MultipleTransitionsTransitionGuard.new(:log => show_debug_log, :fail_transition_guard => true)
|
81
|
+
callback.aasm.current_state
|
82
|
+
|
83
|
+
unless show_debug_log
|
84
|
+
expect(callback).to receive(:before).once.ordered
|
85
|
+
expect(callback).to receive(:event_guard).once.ordered.and_return(true)
|
86
|
+
expect(callback).to receive(:transition_guard).once.ordered.and_return(false)
|
87
|
+
expect(callback).to receive(:event_guard).once.ordered.and_return(true)
|
88
|
+
expect(callback).to receive(:before_exit_open).once.ordered
|
89
|
+
expect(callback).to receive(:exit_open).once.ordered
|
90
|
+
expect(callback).to receive(:aasm_write_state).once.ordered.and_return(true) # this is when the state changes
|
91
|
+
expect(callback).to receive(:after_exit_open).once.ordered
|
92
|
+
expect(callback).to receive(:after).once.ordered
|
93
|
+
|
94
|
+
expect(callback).to_not receive(:transitioning)
|
95
|
+
expect(callback).to_not receive(:before_enter_closed)
|
96
|
+
expect(callback).to_not receive(:enter_closed)
|
97
|
+
expect(callback).to_not receive(:after_enter_closed)
|
98
|
+
end
|
99
|
+
|
100
|
+
callback.close!
|
101
|
+
expect(callback.aasm.current_state).to eql :failed
|
102
|
+
end
|
103
|
+
|
73
104
|
it "does not run any state callback if guard is defined with block" do
|
74
105
|
callback = GuardWithinBlock.new #(:log => true, :fail_transition_guard => true)
|
75
106
|
callback.aasm.current_state
|
@@ -30,7 +30,7 @@ describe "instance methods" do
|
|
30
30
|
let(:columns_hash) { Hash[column_name, column] }
|
31
31
|
|
32
32
|
before :each do
|
33
|
-
gate.class.stub(:
|
33
|
+
gate.class.aasm.stub(:attribute_name).and_return(column_name.to_sym)
|
34
34
|
gate.class.stub(:columns_hash).and_return(columns_hash)
|
35
35
|
end
|
36
36
|
|
@@ -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.stub(:
|
58
|
+
gate.class.aasm.stub(:attribute_name).and_return(:value)
|
59
59
|
end
|
60
60
|
|
61
61
|
it "pluralizes AASM column name" do
|
@@ -81,7 +81,7 @@ describe "instance methods" do
|
|
81
81
|
context "when AASM enum setting is simply set to true" do
|
82
82
|
before :each do
|
83
83
|
AASM::StateMachine[Gate].config.stub(:enum).and_return(true)
|
84
|
-
Gate.stub(:
|
84
|
+
Gate.aasm.stub(:attribute_name).and_return(:value)
|
85
85
|
gate.stub(:aasm_guess_enum_method).and_return(:values)
|
86
86
|
end
|
87
87
|
|
@@ -104,7 +104,7 @@ describe "instance methods" do
|
|
104
104
|
context "when AASM enum setting is not enabled" do
|
105
105
|
before :each do
|
106
106
|
AASM::StateMachine[Gate].config.stub(:enum).and_return(nil)
|
107
|
-
Gate.stub(:
|
107
|
+
Gate.aasm.stub(:attribute_name).and_return(:value)
|
108
108
|
end
|
109
109
|
|
110
110
|
context "when AASM column looks like enum" do
|
@@ -172,7 +172,7 @@ describe "instance methods" do
|
|
172
172
|
gate.aasm_write_state state_sym
|
173
173
|
|
174
174
|
expect(obj).to have_received(:update_all)
|
175
|
-
.with(Hash[gate.class.
|
175
|
+
.with(Hash[gate.class.aasm.attribute_name, state_code])
|
176
176
|
end
|
177
177
|
end
|
178
178
|
|
@@ -253,7 +253,7 @@ describe "instance methods" do
|
|
253
253
|
expect(gate.aasm.current_state).to eq(:closed)
|
254
254
|
end
|
255
255
|
|
256
|
-
it "should return the aasm column when not new and the
|
256
|
+
it "should return the aasm column when not new and the aasm.attribute_name is not nil" do
|
257
257
|
allow(gate).to receive(:new_record?).and_return(false)
|
258
258
|
gate.aasm_state = "state"
|
259
259
|
expect(gate.aasm.current_state).to eq(:state)
|
@@ -293,8 +293,8 @@ describe 'subclasses' do
|
|
293
293
|
end
|
294
294
|
|
295
295
|
it "should have the same column as its parent even for the new dsl" do
|
296
|
-
expect(SimpleNewDsl.
|
297
|
-
expect(DerivateNewDsl.
|
296
|
+
expect(SimpleNewDsl.aasm.attribute_name).to eq(:status)
|
297
|
+
expect(DerivateNewDsl.aasm.attribute_name).to eq(:status)
|
298
298
|
end
|
299
299
|
end
|
300
300
|
|
@@ -81,8 +81,8 @@ describe 'sequel' do
|
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should have the same column as its parent even for the new dsl" do
|
84
|
-
expect(@model.
|
85
|
-
expect(Class.new(@model).
|
84
|
+
expect(@model.aasm.attribute_name).to eq(:status)
|
85
|
+
expect(Class.new(@model).aasm.attribute_name).to eq(:status)
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
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.
|
4
|
+
version: 4.0.3
|
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-11-
|
13
|
+
date: 2014-11-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
@@ -147,6 +147,7 @@ files:
|
|
147
147
|
- spec/models/auth_machine.rb
|
148
148
|
- spec/models/bar.rb
|
149
149
|
- spec/models/callback_new_dsl.rb
|
150
|
+
- spec/models/callbacks/multiple_transitions_transition_guard.rb
|
150
151
|
- spec/models/conversation.rb
|
151
152
|
- spec/models/double_definer.rb
|
152
153
|
- spec/models/father.rb
|
@@ -222,6 +223,7 @@ test_files:
|
|
222
223
|
- spec/models/auth_machine.rb
|
223
224
|
- spec/models/bar.rb
|
224
225
|
- spec/models/callback_new_dsl.rb
|
226
|
+
- spec/models/callbacks/multiple_transitions_transition_guard.rb
|
225
227
|
- spec/models/conversation.rb
|
226
228
|
- spec/models/double_definer.rb
|
227
229
|
- spec/models/father.rb
|