aasm 3.0.26 → 3.1.0
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/.travis.yml +1 -1
- data/CHANGELOG.md +9 -1
- data/README.md +56 -4
- data/aasm.gemspec +1 -1
- data/lib/aasm/base.rb +21 -15
- data/lib/aasm/event.rb +15 -4
- data/lib/aasm/instance_base.rb +2 -0
- data/lib/aasm/persistence/active_record_persistence.rb +17 -1
- data/lib/aasm/transition.rb +13 -6
- data/lib/aasm/version.rb +1 -1
- data/spec/models/guardian.rb +48 -0
- data/spec/unit/api_spec.rb +12 -12
- data/spec/unit/callbacks_spec.rb +25 -25
- data/spec/unit/complex_example_spec.rb +15 -15
- data/spec/unit/event_spec.rb +44 -44
- data/spec/unit/guard_spec.rb +60 -0
- data/spec/unit/initial_state_spec.rb +3 -3
- data/spec/unit/inspection_spec.rb +36 -36
- data/spec/unit/localizer_spec.rb +12 -12
- data/spec/unit/new_dsl_spec.rb +2 -2
- data/spec/unit/persistence/active_record_persistence_spec.rb +107 -67
- data/spec/unit/persistence/mongoid_persistance_spec.rb +24 -24
- data/spec/unit/simple_example_spec.rb +20 -20
- data/spec/unit/state_spec.rb +16 -16
- data/spec/unit/subclassing_spec.rb +6 -6
- data/spec/unit/transition_spec.rb +55 -40
- metadata +8 -4
@@ -17,11 +17,11 @@ describe 'initial states' do
|
|
17
17
|
let(:bar) {Bar.new}
|
18
18
|
|
19
19
|
it 'should use the first state defined if no initial state is given' do
|
20
|
-
bar.aasm.current_state.
|
20
|
+
expect(bar.aasm.current_state).to eq(:read)
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'should determine initial state from the Proc results' do
|
24
|
-
Banker.new(Banker::RICH - 1).aasm.current_state.
|
25
|
-
Banker.new(Banker::RICH + 1).aasm.current_state.
|
24
|
+
expect(Banker.new(Banker::RICH - 1).aasm.current_state).to eq(:selling_bad_mortgages)
|
25
|
+
expect(Banker.new(Banker::RICH + 1).aasm.current_state).to eq(:retired)
|
26
26
|
end
|
27
27
|
end
|
@@ -2,16 +2,16 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'inspection for common cases' do
|
4
4
|
it 'should support the new DSL' do
|
5
|
-
Foo.aasm.
|
6
|
-
Foo.aasm.states.
|
7
|
-
Foo.aasm.states.
|
5
|
+
expect(Foo.aasm).to respond_to(:states)
|
6
|
+
expect(Foo.aasm.states).to include(:open)
|
7
|
+
expect(Foo.aasm.states).to include(:closed)
|
8
8
|
|
9
|
-
Foo.aasm.
|
10
|
-
Foo.aasm.initial_state.
|
9
|
+
expect(Foo.aasm).to respond_to(:initial_state)
|
10
|
+
expect(Foo.aasm.initial_state).to eq(:open)
|
11
11
|
|
12
|
-
Foo.aasm.
|
13
|
-
Foo.aasm.events.
|
14
|
-
Foo.aasm.events.
|
12
|
+
expect(Foo.aasm).to respond_to(:events)
|
13
|
+
expect(Foo.aasm.events).to include(:close)
|
14
|
+
expect(Foo.aasm.events).to include(:null)
|
15
15
|
end
|
16
16
|
|
17
17
|
context "instance level inspection" do
|
@@ -20,77 +20,77 @@ describe 'inspection for common cases' do
|
|
20
20
|
|
21
21
|
it "delivers all states" do
|
22
22
|
states = foo.aasm.states
|
23
|
-
states.
|
24
|
-
states.
|
23
|
+
expect(states).to include(:open)
|
24
|
+
expect(states).to include(:closed)
|
25
25
|
|
26
26
|
states = foo.aasm.states(:permissible => true)
|
27
|
-
states.
|
28
|
-
states.
|
27
|
+
expect(states).to include(:closed)
|
28
|
+
expect(states).not_to include(:open)
|
29
29
|
|
30
30
|
foo.close
|
31
|
-
foo.aasm.states(:permissible => true).
|
31
|
+
expect(foo.aasm.states(:permissible => true)).to be_empty
|
32
32
|
end
|
33
33
|
|
34
34
|
it "delivers all states for subclasses" do
|
35
35
|
states = two.aasm.states
|
36
|
-
states.
|
37
|
-
states.
|
38
|
-
states.
|
36
|
+
expect(states).to include(:open)
|
37
|
+
expect(states).to include(:closed)
|
38
|
+
expect(states).to include(:foo)
|
39
39
|
|
40
40
|
states = two.aasm.states(:permissible => true)
|
41
|
-
states.
|
42
|
-
states.
|
41
|
+
expect(states).to include(:closed)
|
42
|
+
expect(states).not_to include(:open)
|
43
43
|
|
44
44
|
two.close
|
45
|
-
two.aasm.states(:permissible => true).
|
45
|
+
expect(two.aasm.states(:permissible => true)).to be_empty
|
46
46
|
end
|
47
47
|
|
48
48
|
it "delivers all events" do
|
49
49
|
events = foo.aasm.events
|
50
|
-
events.
|
51
|
-
events.
|
50
|
+
expect(events).to include(:close)
|
51
|
+
expect(events).to include(:null)
|
52
52
|
foo.close
|
53
|
-
foo.aasm.events.
|
53
|
+
expect(foo.aasm.events).to be_empty
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'should list states in the order they have been defined' do
|
58
|
-
Conversation.aasm.states.
|
58
|
+
expect(Conversation.aasm.states).to eq([:needs_attention, :read, :closed, :awaiting_response, :junk])
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
62
|
describe "special cases" do
|
63
63
|
it "should support valid a state name" do
|
64
|
-
Argument.aasm.states.
|
65
|
-
Argument.aasm.states.
|
64
|
+
expect(Argument.aasm.states).to include(:invalid)
|
65
|
+
expect(Argument.aasm.states).to include(:valid)
|
66
66
|
|
67
67
|
argument = Argument.new
|
68
|
-
argument.invalid
|
69
|
-
argument.aasm.current_state.
|
68
|
+
expect(argument.invalid?).to be_true
|
69
|
+
expect(argument.aasm.current_state).to eq(:invalid)
|
70
70
|
|
71
71
|
argument.valid!
|
72
|
-
argument.valid
|
73
|
-
argument.aasm.current_state.
|
72
|
+
expect(argument.valid?).to be_true
|
73
|
+
expect(argument.aasm.current_state).to eq(:valid)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
77
|
describe 'aasm.states_for_select' do
|
78
78
|
it "should return a select friendly array of states" do
|
79
|
-
Foo.aasm.
|
80
|
-
Foo.aasm.states_for_select.
|
79
|
+
expect(Foo.aasm).to respond_to(:states_for_select)
|
80
|
+
expect(Foo.aasm.states_for_select).to eq([['Open', 'open'], ['Closed', 'closed']])
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
84
|
describe 'aasm.from_states_for_state' do
|
85
85
|
it "should return all from states for a state" do
|
86
|
-
AuthMachine.aasm.
|
86
|
+
expect(AuthMachine.aasm).to respond_to(:from_states_for_state)
|
87
87
|
froms = AuthMachine.aasm.from_states_for_state(:active)
|
88
|
-
[:pending, :passive, :suspended].each {|from| froms.
|
88
|
+
[:pending, :passive, :suspended].each {|from| expect(froms).to include(from)}
|
89
89
|
end
|
90
90
|
|
91
91
|
it "should return from states for a state for a particular transition only" do
|
92
92
|
froms = AuthMachine.aasm.from_states_for_state(:active, :transition => :unsuspend)
|
93
|
-
[:suspended].each {|from| froms.
|
93
|
+
[:suspended].each {|from| expect(froms).to include(from)}
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
@@ -98,7 +98,7 @@ describe 'permissible events' do
|
|
98
98
|
let(:foo) {Foo.new}
|
99
99
|
|
100
100
|
it 'work' do
|
101
|
-
foo.aasm.permissible_events.
|
102
|
-
foo.aasm.permissible_events.
|
101
|
+
expect(foo.aasm.permissible_events).to include(:close)
|
102
|
+
expect(foo.aasm.permissible_events).not_to include(:null)
|
103
103
|
end
|
104
104
|
end
|
data/spec/unit/localizer_spec.rb
CHANGED
@@ -31,14 +31,14 @@ describe 'localized state names' do
|
|
31
31
|
|
32
32
|
it 'should localize' do
|
33
33
|
state = LocalizerTestModel.aasm.states.detect {|s| s == :opened}
|
34
|
-
state.localized_name.
|
35
|
-
state.human_name.
|
34
|
+
expect(state.localized_name).to eq("It's open now!")
|
35
|
+
expect(state.human_name).to eq("It's open now!")
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'should use fallback' do
|
39
39
|
state = LocalizerTestModel.aasm.states.detect {|s| s == :closed}
|
40
|
-
state.localized_name.
|
41
|
-
state.human_name.
|
40
|
+
expect(state.localized_name).to eq('Closed')
|
41
|
+
expect(state.human_name).to eq('Closed')
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -58,21 +58,21 @@ describe AASM::Localizer, "new style" do
|
|
58
58
|
|
59
59
|
context 'aasm.human_state' do
|
60
60
|
it 'should return translated state value' do
|
61
|
-
foo_opened.aasm.human_state.
|
61
|
+
expect(foo_opened.aasm.human_state).to eq("It's open now!")
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'should return humanized value if not localized' do
|
65
|
-
foo_closed.aasm.human_state.
|
65
|
+
expect(foo_closed.aasm.human_state).to eq("Closed")
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
69
|
context 'aasm_human_event_name' do
|
70
70
|
it 'should return translated event name' do
|
71
|
-
LocalizerTestModel.aasm_human_event_name(:close).
|
71
|
+
expect(LocalizerTestModel.aasm_human_event_name(:close)).to eq("Let's close it!")
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'should return humanized event name' do
|
75
|
-
LocalizerTestModel.aasm_human_event_name(:open).
|
75
|
+
expect(LocalizerTestModel.aasm_human_event_name(:open)).to eq("Open")
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
@@ -93,21 +93,21 @@ describe AASM::Localizer, "deprecated style" do
|
|
93
93
|
|
94
94
|
context 'aasm.human_state' do
|
95
95
|
it 'should return translated state value' do
|
96
|
-
foo_opened.aasm.human_state.
|
96
|
+
expect(foo_opened.aasm.human_state).to eq("It's open now!")
|
97
97
|
end
|
98
98
|
|
99
99
|
it 'should return humanized value if not localized' do
|
100
|
-
foo_closed.aasm.human_state.
|
100
|
+
expect(foo_closed.aasm.human_state).to eq("Closed")
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
104
|
context 'aasm_human_event_name' do
|
105
105
|
it 'should return translated event name' do
|
106
|
-
LocalizerTestModel.aasm_human_event_name(:close).
|
106
|
+
expect(LocalizerTestModel.aasm_human_event_name(:close)).to eq("Let's close it!")
|
107
107
|
end
|
108
108
|
|
109
109
|
it 'should return humanized event name' do
|
110
|
-
LocalizerTestModel.aasm_human_event_name(:open).
|
110
|
+
expect(LocalizerTestModel.aasm_human_event_name(:open)).to eq("Open")
|
111
111
|
end
|
112
112
|
end
|
113
113
|
end
|
data/spec/unit/new_dsl_spec.rb
CHANGED
@@ -5,8 +5,8 @@ describe "the new dsl" do
|
|
5
5
|
let(:process) {ProcessWithNewDsl.new}
|
6
6
|
|
7
7
|
it 'should not conflict with other event or state methods' do
|
8
|
-
|
9
|
-
|
8
|
+
expect {ProcessWithNewDsl.state}.to raise_error(RuntimeError, "wrong state method")
|
9
|
+
expect {ProcessWithNewDsl.event}.to raise_error(RuntimeError, "wrong event method")
|
10
10
|
end
|
11
11
|
|
12
12
|
end
|
@@ -9,8 +9,8 @@ load_schema
|
|
9
9
|
|
10
10
|
shared_examples_for "aasm model" do
|
11
11
|
it "should include persistence mixins" do
|
12
|
-
klass.included_modules.
|
13
|
-
klass.included_modules.
|
12
|
+
expect(klass.included_modules).to be_include(AASM::Persistence::ActiveRecordPersistence)
|
13
|
+
expect(klass.included_modules).to be_include(AASM::Persistence::ActiveRecordPersistence::InstanceMethods)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -18,45 +18,45 @@ describe "instance methods" do
|
|
18
18
|
let(:gate) {Gate.new}
|
19
19
|
|
20
20
|
it "should respond to aasm persistence methods" do
|
21
|
-
gate.
|
22
|
-
gate.
|
23
|
-
gate.
|
21
|
+
expect(gate).to respond_to(:aasm_read_state)
|
22
|
+
expect(gate).to respond_to(:aasm_write_state)
|
23
|
+
expect(gate).to respond_to(:aasm_write_state_without_persistence)
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should return the initial state when new and the aasm field is nil" do
|
27
|
-
gate.aasm.current_state.
|
27
|
+
expect(gate.aasm.current_state).to eq(:opened)
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should return the aasm column when new and the aasm field is not nil" do
|
31
31
|
gate.aasm_state = "closed"
|
32
|
-
gate.aasm.current_state.
|
32
|
+
expect(gate.aasm.current_state).to eq(:closed)
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should return the aasm column when not new and the aasm_column is not nil" do
|
36
|
-
gate.
|
36
|
+
allow(gate).to receive(:new_record?).and_return(false)
|
37
37
|
gate.aasm_state = "state"
|
38
|
-
gate.aasm.current_state.
|
38
|
+
expect(gate.aasm.current_state).to eq(:state)
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should allow a nil state" do
|
42
|
-
gate.
|
42
|
+
allow(gate).to receive(:new_record?).and_return(false)
|
43
43
|
gate.aasm_state = nil
|
44
|
-
gate.aasm.current_state.
|
44
|
+
expect(gate.aasm.current_state).to be_nil
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should call aasm_ensure_initial_state on validation before create" do
|
48
|
-
gate.
|
48
|
+
expect(gate).to receive(:aasm_ensure_initial_state).and_return(true)
|
49
49
|
gate.valid?
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should call aasm_ensure_initial_state before create, even if skipping validations" do
|
53
|
-
gate.
|
53
|
+
expect(gate).to receive(:aasm_ensure_initial_state).and_return(true)
|
54
54
|
gate.save(:validate => false)
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should not call aasm_ensure_initial_state on validation before update" do
|
58
|
-
gate.
|
59
|
-
gate.
|
58
|
+
allow(gate).to receive(:new_record?).and_return(false)
|
59
|
+
expect(gate).not_to receive(:aasm_ensure_initial_state)
|
60
60
|
gate.valid?
|
61
61
|
end
|
62
62
|
|
@@ -64,36 +64,36 @@ end
|
|
64
64
|
|
65
65
|
describe 'subclasses' do
|
66
66
|
it "should have the same states as its parent class" do
|
67
|
-
DerivateNewDsl.aasm.states.
|
67
|
+
expect(DerivateNewDsl.aasm.states).to eq(SimpleNewDsl.aasm.states)
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should have the same events as its parent class" do
|
71
|
-
DerivateNewDsl.aasm.events.
|
71
|
+
expect(DerivateNewDsl.aasm.events).to eq(SimpleNewDsl.aasm.events)
|
72
72
|
end
|
73
73
|
|
74
74
|
it "should have the same column as its parent even for the new dsl" do
|
75
|
-
SimpleNewDsl.aasm_column.
|
76
|
-
DerivateNewDsl.aasm_column.
|
75
|
+
expect(SimpleNewDsl.aasm_column).to eq(:status)
|
76
|
+
expect(DerivateNewDsl.aasm_column).to eq(:status)
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
80
|
describe "named scopes with the new DSL" do
|
81
81
|
context "Does not already respond_to? the scope name" do
|
82
82
|
it "should add a scope" do
|
83
|
-
SimpleNewDsl.
|
84
|
-
SimpleNewDsl.unknown_scope.is_a?(ActiveRecord::Relation).
|
83
|
+
expect(SimpleNewDsl).to respond_to(:unknown_scope)
|
84
|
+
expect(SimpleNewDsl.unknown_scope.is_a?(ActiveRecord::Relation)).to be_true
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
88
|
context "Already respond_to? the scope name" do
|
89
89
|
it "should not add a scope" do
|
90
|
-
SimpleNewDsl.
|
91
|
-
SimpleNewDsl.new.class.
|
90
|
+
expect(SimpleNewDsl).to respond_to(:new)
|
91
|
+
expect(SimpleNewDsl.new.class).to eq(SimpleNewDsl)
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
95
|
it "does not create scopes if requested" do
|
96
|
-
NoScope.
|
96
|
+
expect(NoScope).not_to respond_to(:ignored_scope)
|
97
97
|
end
|
98
98
|
|
99
99
|
end
|
@@ -101,8 +101,8 @@ end
|
|
101
101
|
describe 'initial states' do
|
102
102
|
|
103
103
|
it 'should support conditions' do
|
104
|
-
Thief.new(:skilled => true).aasm.current_state.
|
105
|
-
Thief.new(:skilled => false).aasm.current_state.
|
104
|
+
expect(Thief.new(:skilled => true).aasm.current_state).to eq(:rich)
|
105
|
+
expect(Thief.new(:skilled => false).aasm.current_state).to eq(:jailed)
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
@@ -110,54 +110,54 @@ describe 'transitions with persistence' do
|
|
110
110
|
|
111
111
|
it "should work for valid models" do
|
112
112
|
valid_object = Validator.create(:name => 'name')
|
113
|
-
valid_object.
|
113
|
+
expect(valid_object).to be_sleeping
|
114
114
|
valid_object.status = :running
|
115
|
-
valid_object.
|
115
|
+
expect(valid_object).to be_running
|
116
116
|
end
|
117
117
|
|
118
118
|
it 'should not store states for invalid models' do
|
119
119
|
validator = Validator.create(:name => 'name')
|
120
|
-
validator.
|
121
|
-
validator.
|
120
|
+
expect(validator).to be_valid
|
121
|
+
expect(validator).to be_sleeping
|
122
122
|
|
123
123
|
validator.name = nil
|
124
|
-
validator.
|
125
|
-
validator.run
|
126
|
-
validator.
|
124
|
+
expect(validator).not_to be_valid
|
125
|
+
expect(validator.run!).to be_false
|
126
|
+
expect(validator).to be_sleeping
|
127
127
|
|
128
128
|
validator.reload
|
129
|
-
validator.
|
130
|
-
validator.
|
129
|
+
expect(validator).not_to be_running
|
130
|
+
expect(validator).to be_sleeping
|
131
131
|
|
132
132
|
validator.name = 'another name'
|
133
|
-
validator.
|
134
|
-
validator.run
|
135
|
-
validator.
|
133
|
+
expect(validator).to be_valid
|
134
|
+
expect(validator.run!).to be_true
|
135
|
+
expect(validator).to be_running
|
136
136
|
|
137
137
|
validator.reload
|
138
|
-
validator.
|
139
|
-
validator.
|
138
|
+
expect(validator).to be_running
|
139
|
+
expect(validator).not_to be_sleeping
|
140
140
|
end
|
141
141
|
|
142
142
|
it 'should store states for invalid models if configured' do
|
143
143
|
persistor = InvalidPersistor.create(:name => 'name')
|
144
|
-
persistor.
|
145
|
-
persistor.
|
144
|
+
expect(persistor).to be_valid
|
145
|
+
expect(persistor).to be_sleeping
|
146
146
|
|
147
147
|
persistor.name = nil
|
148
|
-
persistor.
|
149
|
-
persistor.run
|
150
|
-
persistor.
|
148
|
+
expect(persistor).not_to be_valid
|
149
|
+
expect(persistor.run!).to be_true
|
150
|
+
expect(persistor).to be_running
|
151
151
|
|
152
152
|
persistor = InvalidPersistor.find(persistor.id)
|
153
153
|
persistor.valid?
|
154
|
-
persistor.
|
155
|
-
persistor.
|
156
|
-
persistor.
|
154
|
+
expect(persistor).to be_valid
|
155
|
+
expect(persistor).to be_running
|
156
|
+
expect(persistor).not_to be_sleeping
|
157
157
|
|
158
158
|
persistor.reload
|
159
|
-
persistor.
|
160
|
-
persistor.
|
159
|
+
expect(persistor).to be_running
|
160
|
+
expect(persistor).not_to be_sleeping
|
161
161
|
end
|
162
162
|
|
163
163
|
describe 'transactions' do
|
@@ -165,41 +165,81 @@ describe 'transitions with persistence' do
|
|
165
165
|
let(:transactor) { Transactor.create!(:name => 'transactor', :worker => worker) }
|
166
166
|
|
167
167
|
it 'should rollback all changes' do
|
168
|
-
transactor.
|
169
|
-
worker.status.
|
168
|
+
expect(transactor).to be_sleeping
|
169
|
+
expect(worker.status).to eq('sleeping')
|
170
170
|
|
171
|
-
|
172
|
-
transactor.
|
173
|
-
worker.reload.status.
|
171
|
+
expect {transactor.run!}.to raise_error(StandardError, 'failed on purpose')
|
172
|
+
expect(transactor).to be_running
|
173
|
+
expect(worker.reload.status).to eq('sleeping')
|
174
174
|
end
|
175
175
|
|
176
|
-
|
177
|
-
|
178
|
-
|
176
|
+
context "nested transactions" do
|
177
|
+
it "should rollback all changes in nested transaction" do
|
178
|
+
expect(transactor).to be_sleeping
|
179
|
+
expect(worker.status).to eq('sleeping')
|
179
180
|
|
180
|
-
|
181
|
-
|
181
|
+
Worker.transaction do
|
182
|
+
expect { transactor.run! }.to raise_error(StandardError, 'failed on purpose')
|
183
|
+
end
|
184
|
+
|
185
|
+
expect(transactor).to be_running
|
186
|
+
expect(worker.reload.status).to eq('sleeping')
|
182
187
|
end
|
183
188
|
|
184
|
-
|
185
|
-
|
189
|
+
it "should only rollback changes in the main transaction not the nested one" do
|
190
|
+
# change configuration to not require new transaction
|
191
|
+
AASM::StateMachine[Transactor].config.requires_new_transaction = false
|
192
|
+
|
193
|
+
expect(transactor).to be_sleeping
|
194
|
+
expect(worker.status).to eq('sleeping')
|
195
|
+
|
196
|
+
Worker.transaction do
|
197
|
+
expect { transactor.run! }.to raise_error(StandardError, 'failed on purpose')
|
198
|
+
end
|
199
|
+
|
200
|
+
expect(transactor).to be_running
|
201
|
+
expect(worker.reload.status).to eq('running')
|
202
|
+
end
|
186
203
|
end
|
187
204
|
|
188
205
|
describe "after_commit callback" do
|
189
206
|
it "should fire :after_commit if transaction was successful" do
|
190
207
|
validator = Validator.create(:name => 'name')
|
191
|
-
validator.
|
208
|
+
expect(validator).to be_sleeping
|
192
209
|
validator.run!
|
193
|
-
validator.
|
194
|
-
validator.name.
|
210
|
+
expect(validator).to be_running
|
211
|
+
expect(validator.name).not_to eq("name")
|
195
212
|
end
|
196
213
|
|
197
214
|
it "should not fire :after_commit if transaction failed" do
|
198
215
|
validator = Validator.create(:name => 'name')
|
199
|
-
|
200
|
-
validator.name.
|
216
|
+
expect { validator.fail! }.to raise_error(StandardError, 'failed on purpose')
|
217
|
+
expect(validator.name).to eq("name")
|
201
218
|
end
|
202
219
|
|
203
220
|
end
|
204
221
|
end
|
205
222
|
end
|
223
|
+
|
224
|
+
describe "invalid states with persistence" do
|
225
|
+
|
226
|
+
it "should not store states" do
|
227
|
+
validator = Validator.create(:name => 'name')
|
228
|
+
validator.status = 'invalid_state'
|
229
|
+
expect(validator.save).to be_false
|
230
|
+
expect {validator.save!}.to raise_error(ActiveRecord::RecordInvalid)
|
231
|
+
|
232
|
+
validator.reload
|
233
|
+
expect(validator).to be_sleeping
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should store invalid states if configured" do
|
237
|
+
persistor = InvalidPersistor.create(:name => 'name')
|
238
|
+
persistor.status = 'invalid_state'
|
239
|
+
expect(persistor.save).to be_true
|
240
|
+
|
241
|
+
persistor.reload
|
242
|
+
expect(persistor.status).to eq('invalid_state')
|
243
|
+
end
|
244
|
+
|
245
|
+
end
|