aasm 3.0.26 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,15 +27,15 @@ describe 'mongoid', :if => Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version
27
27
 
28
28
  context "Does not already respond_to? the scope name" do
29
29
  it "should add a scope" do
30
- SimpleMongoid.should respond_to(:unknown_scope)
31
- SimpleMongoid.unknown_scope.class.should == Mongoid::Criteria
30
+ expect(SimpleMongoid).to respond_to(:unknown_scope)
31
+ expect(SimpleMongoid.unknown_scope.class).to eq(Mongoid::Criteria)
32
32
  end
33
33
  end
34
34
 
35
35
  context "Already respond_to? the scope name" do
36
36
  it "should not add a scope" do
37
- SimpleMongoid.should respond_to(:new)
38
- SimpleMongoid.new.class.should == SimpleMongoid
37
+ expect(SimpleMongoid).to respond_to(:new)
38
+ expect(SimpleMongoid.new.class).to eq(SimpleMongoid)
39
39
  end
40
40
  end
41
41
 
@@ -45,20 +45,20 @@ describe 'mongoid', :if => Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version
45
45
 
46
46
  context "Does not already respond_to? the scope name" do
47
47
  it "should add a scope" do
48
- SimpleNewDslMongoid.should respond_to(:unknown_scope)
49
- SimpleNewDslMongoid.unknown_scope.class.should == Mongoid::Criteria
48
+ expect(SimpleNewDslMongoid).to respond_to(:unknown_scope)
49
+ expect(SimpleNewDslMongoid.unknown_scope.class).to eq(Mongoid::Criteria)
50
50
  end
51
51
  end
52
52
 
53
53
  context "Already respond_to? the scope name" do
54
54
  it "should not add a scope" do
55
- SimpleNewDslMongoid.should respond_to(:new)
56
- SimpleNewDslMongoid.new.class.should == SimpleNewDslMongoid
55
+ expect(SimpleNewDslMongoid).to respond_to(:new)
56
+ expect(SimpleNewDslMongoid.new.class).to eq(SimpleNewDslMongoid)
57
57
  end
58
58
  end
59
59
 
60
60
  it "does not create scopes if requested" do
61
- NoScopeMongoid.should_not respond_to(:ignored_scope)
61
+ expect(NoScopeMongoid).not_to respond_to(:ignored_scope)
62
62
  end
63
63
 
64
64
  end
@@ -69,12 +69,12 @@ describe 'mongoid', :if => Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version
69
69
  let!(:model_id) { model._id }
70
70
 
71
71
  it "should respond to method" do
72
- SimpleNewDslMongoid.should respond_to(:find_in_state)
72
+ expect(SimpleNewDslMongoid).to respond_to(:find_in_state)
73
73
  end
74
74
 
75
75
  it "should find the model when given the correct scope and model id" do
76
- SimpleNewDslMongoid.find_in_state(model_id, 'unknown_scope').class.should == SimpleNewDslMongoid
77
- SimpleNewDslMongoid.find_in_state(model_id, 'unknown_scope').should == model
76
+ expect(SimpleNewDslMongoid.find_in_state(model_id, 'unknown_scope').class).to eq(SimpleNewDslMongoid)
77
+ expect(SimpleNewDslMongoid.find_in_state(model_id, 'unknown_scope')).to eq(model)
78
78
  end
79
79
 
80
80
  it "should raise DocumentNotFound error when given incorrect scope" do
@@ -94,17 +94,17 @@ describe 'mongoid', :if => Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version
94
94
  end
95
95
 
96
96
  it "should respond to method" do
97
- SimpleNewDslMongoid.should respond_to(:count_in_state)
97
+ expect(SimpleNewDslMongoid).to respond_to(:count_in_state)
98
98
  end
99
99
 
100
100
  it "should return n for a scope with n records persisted" do
101
- SimpleNewDslMongoid.count_in_state('unknown_scope').class.should == Fixnum
102
- SimpleNewDslMongoid.count_in_state('unknown_scope').should == 3
101
+ expect(SimpleNewDslMongoid.count_in_state('unknown_scope').class).to eq(Fixnum)
102
+ expect(SimpleNewDslMongoid.count_in_state('unknown_scope')).to eq(3)
103
103
  end
104
104
 
105
105
  it "should return zero for a scope without records persisted" do
106
- SimpleNewDslMongoid.count_in_state('new').class.should == Fixnum
107
- SimpleNewDslMongoid.count_in_state('new').should == 0
106
+ expect(SimpleNewDslMongoid.count_in_state('new').class).to eq(Fixnum)
107
+ expect(SimpleNewDslMongoid.count_in_state('new')).to eq(0)
108
108
  end
109
109
 
110
110
  end
@@ -117,16 +117,16 @@ describe 'mongoid', :if => Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version
117
117
  end
118
118
 
119
119
  it "should respond to method" do
120
- SimpleNewDslMongoid.should respond_to(:with_state_scope)
120
+ expect(SimpleNewDslMongoid).to respond_to(:with_state_scope)
121
121
  end
122
122
 
123
123
  it "should correctly process block" do
124
- SimpleNewDslMongoid.with_state_scope('unknown_scope') do
124
+ expect(SimpleNewDslMongoid.with_state_scope('unknown_scope') do
125
125
  SimpleNewDslMongoid.count
126
- end.should == 3
127
- SimpleNewDslMongoid.with_state_scope('new') do
126
+ end).to eq(3)
127
+ expect(SimpleNewDslMongoid.with_state_scope('new') do
128
128
  SimpleNewDslMongoid.count
129
- end.should == 2
129
+ end).to eq(2)
130
130
  end
131
131
 
132
132
  end
@@ -136,12 +136,12 @@ describe 'mongoid', :if => Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version
136
136
  let(:simple) {SimpleNewDslMongoid.new}
137
137
 
138
138
  it "should call aasm_ensure_initial_state on validation before create" do
139
- simple.should_receive(:aasm_ensure_initial_state).and_return(true)
139
+ expect(simple).to receive(:aasm_ensure_initial_state).and_return(true)
140
140
  simple.valid?
141
141
  end
142
142
 
143
143
  it "should call aasm_ensure_initial_state before create, even if skipping validations" do
144
- simple.should_receive(:aasm_ensure_initial_state).and_return(true)
144
+ expect(simple).to receive(:aasm_ensure_initial_state).and_return(true)
145
145
  simple.save(:validate => false)
146
146
  end
147
147
  end
@@ -20,39 +20,39 @@ describe 'state machine' do
20
20
  let(:payment) {Payment.new}
21
21
 
22
22
  it 'starts with an initial state' do
23
- payment.aasm.current_state.should == :initialised
24
- payment.should respond_to(:initialised?)
25
- payment.should be_initialised
23
+ expect(payment.aasm.current_state).to eq(:initialised)
24
+ expect(payment).to respond_to(:initialised?)
25
+ expect(payment).to be_initialised
26
26
  end
27
27
 
28
28
  it 'allows transitions to other states' do
29
- payment.should respond_to(:fill_out)
30
- payment.should respond_to(:fill_out!)
29
+ expect(payment).to respond_to(:fill_out)
30
+ expect(payment).to respond_to(:fill_out!)
31
31
  payment.fill_out!
32
- payment.should respond_to(:filled_out?)
33
- payment.should be_filled_out
32
+ expect(payment).to respond_to(:filled_out?)
33
+ expect(payment).to be_filled_out
34
34
 
35
- payment.should respond_to(:authorise)
36
- payment.should respond_to(:authorise!)
35
+ expect(payment).to respond_to(:authorise)
36
+ expect(payment).to respond_to(:authorise!)
37
37
  payment.authorise
38
- payment.should respond_to(:authorised?)
39
- payment.should be_authorised
38
+ expect(payment).to respond_to(:authorised?)
39
+ expect(payment).to be_authorised
40
40
  end
41
41
 
42
42
  it 'denies transitions to other states' do
43
- lambda {payment.authorise}.should raise_error(AASM::InvalidTransition)
44
- lambda {payment.authorise!}.should raise_error(AASM::InvalidTransition)
43
+ expect {payment.authorise}.to raise_error(AASM::InvalidTransition)
44
+ expect {payment.authorise!}.to raise_error(AASM::InvalidTransition)
45
45
  payment.fill_out
46
- lambda {payment.fill_out}.should raise_error(AASM::InvalidTransition)
47
- lambda {payment.fill_out!}.should raise_error(AASM::InvalidTransition)
46
+ expect {payment.fill_out}.to raise_error(AASM::InvalidTransition)
47
+ expect {payment.fill_out!}.to raise_error(AASM::InvalidTransition)
48
48
  payment.authorise
49
- lambda {payment.fill_out}.should raise_error(AASM::InvalidTransition)
50
- lambda {payment.fill_out!}.should raise_error(AASM::InvalidTransition)
49
+ expect {payment.fill_out}.to raise_error(AASM::InvalidTransition)
50
+ expect {payment.fill_out!}.to raise_error(AASM::InvalidTransition)
51
51
  end
52
52
 
53
53
  it 'defines constants for each state name' do
54
- Payment::STATE_INITIALISED.should eq(:initialised)
55
- Payment::STATE_FILLED_OUT.should eq(:filled_out)
56
- Payment::STATE_AUTHORISED.should eq(:authorised)
54
+ expect(Payment::STATE_INITIALISED).to eq(:initialised)
55
+ expect(Payment::STATE_FILLED_OUT).to eq(:filled_out)
56
+ expect(Payment::STATE_AUTHORISED).to eq(:authorised)
57
57
  end
58
58
  end
@@ -12,34 +12,34 @@ describe AASM::State do
12
12
 
13
13
  it 'should set the name' do
14
14
  state = new_state
15
- state.name.should == :astate
15
+ expect(state.name).to eq(:astate)
16
16
  end
17
17
 
18
18
  it 'should set the display_name from name' do
19
- new_state.display_name.should == 'Astate'
19
+ expect(new_state.display_name).to eq('Astate')
20
20
  end
21
21
 
22
22
  it 'should set the display_name from options' do
23
- new_state(:display => "A State").display_name.should == 'A State'
23
+ expect(new_state(:display => "A State").display_name).to eq('A State')
24
24
  end
25
25
 
26
26
  it 'should set the options and expose them as options' do
27
- new_state.options.should == @options
27
+ expect(new_state.options).to eq(@options)
28
28
  end
29
29
 
30
30
  it 'should be equal to a symbol of the same name' do
31
- new_state.should == :astate
31
+ expect(new_state).to eq(:astate)
32
32
  end
33
33
 
34
34
  it 'should be equal to a State of the same name' do
35
- new_state.should == new_state
35
+ expect(new_state).to eq(new_state)
36
36
  end
37
37
 
38
38
  it 'should send a message to the record for an action if the action is present as a symbol' do
39
39
  state = new_state(:entering => :foo)
40
40
 
41
41
  record = double('record')
42
- record.should_receive(:foo)
42
+ expect(record).to receive(:foo)
43
43
 
44
44
  state.fire_callbacks(:entering, record)
45
45
  end
@@ -48,7 +48,7 @@ describe AASM::State do
48
48
  state = new_state(:entering => 'foo')
49
49
 
50
50
  record = double('record')
51
- record.should_receive(:foo)
51
+ expect(record).to receive(:foo)
52
52
 
53
53
  state.fire_callbacks(:entering, record)
54
54
  end
@@ -57,10 +57,10 @@ describe AASM::State do
57
57
  state = new_state(:entering => [:a, :b, "c", lambda {|r| r.foobar }])
58
58
 
59
59
  record = double('record')
60
- record.should_receive(:a)
61
- record.should_receive(:b)
62
- record.should_receive(:c)
63
- record.should_receive(:foobar)
60
+ expect(record).to receive(:a)
61
+ expect(record).to receive(:b)
62
+ expect(record).to receive(:c)
63
+ expect(record).to receive(:foobar)
64
64
 
65
65
  state.fire_callbacks(:entering, record)
66
66
  end
@@ -69,9 +69,9 @@ describe AASM::State do
69
69
  state = new_state(:entering => [:a, :b, :c])
70
70
 
71
71
  record = double('record')
72
- record.should_receive(:a)
73
- record.should_receive(:b).and_throw(:halt_aasm_chain)
74
- record.should_not_receive(:c)
72
+ expect(record).to receive(:a)
73
+ expect(record).to receive(:b).and_throw(:halt_aasm_chain)
74
+ expect(record).not_to receive(:c)
75
75
 
76
76
  state.fire_callbacks(:entering, record)
77
77
  end
@@ -80,7 +80,7 @@ describe AASM::State do
80
80
  state = new_state(:entering => Proc.new {|r| r.foobar})
81
81
 
82
82
  record = double('record')
83
- record.should_receive(:foobar)
83
+ expect(record).to receive(:foobar)
84
84
 
85
85
  state.fire_callbacks(:entering, record)
86
86
  end
@@ -5,26 +5,26 @@ describe 'subclassing' do
5
5
 
6
6
  it 'should have the parent states' do
7
7
  Foo.aasm.states.each do |state|
8
- FooTwo.aasm.states.should include(state)
8
+ expect(FooTwo.aasm.states).to include(state)
9
9
  end
10
- Baz.aasm.states.should == Bar.aasm.states
10
+ expect(Baz.aasm.states).to eq(Bar.aasm.states)
11
11
  end
12
12
 
13
13
  it 'should not add the child states to the parent machine' do
14
- Foo.aasm.states.should_not include(:foo)
14
+ expect(Foo.aasm.states).not_to include(:foo)
15
15
  end
16
16
 
17
17
  it "should have the same events as its parent" do
18
- Baz.aasm.events.should == Bar.aasm.events
18
+ expect(Baz.aasm.events).to eq(Bar.aasm.events)
19
19
  end
20
20
 
21
21
  it 'should know how to respond to `may_add_details?`' do
22
- son.may_add_details?.should be_true
22
+ expect(son.may_add_details?).to be_true
23
23
  end
24
24
 
25
25
  it 'should not break if I call Son#update_state' do
26
26
  son.update_state
27
- son.aasm.current_state.should == :pending_details_confirmation
27
+ expect(son.aasm.current_state).to eq(:pending_details_confirmation)
28
28
  end
29
29
 
30
30
  end
@@ -4,46 +4,46 @@ describe 'transitions' do
4
4
 
5
5
  it 'should raise an exception when whiny' do
6
6
  process = ProcessWithNewDsl.new
7
- lambda { process.stop! }.should raise_error(AASM::InvalidTransition)
8
- process.should be_sleeping
7
+ expect { process.stop! }.to raise_error(AASM::InvalidTransition)
8
+ expect(process).to be_sleeping
9
9
  end
10
10
 
11
11
  it 'should not raise an exception when not whiny' do
12
12
  silencer = Silencer.new
13
- silencer.smile!.should be_false
14
- silencer.should be_silent
13
+ expect(silencer.smile!).to be_false
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
- sub.smile!.should be_false
20
- sub.should be_silent
19
+ expect(sub.smile!).to be_false
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
- silencer.smile_any!.should be_true
26
- silencer.should be_smiling
25
+ expect(silencer.smile_any!).to be_true
26
+ expect(silencer).to be_smiling
27
27
  end
28
28
 
29
29
  it 'should call the block when success' do
30
30
  silencer = Silencer.new
31
31
  success = false
32
- lambda {
32
+ expect {
33
33
  silencer.smile_any! do
34
34
  success = true
35
35
  end
36
- }.should change { success }.to(true)
36
+ }.to change { success }.to(true)
37
37
  end
38
38
 
39
39
  it 'should not call the block when failure' do
40
40
  silencer = Silencer.new
41
41
  success = false
42
- lambda {
42
+ expect {
43
43
  silencer.smile! do
44
44
  success = true
45
45
  end
46
- }.should_not change { success }.to(true)
46
+ }.not_to change { success }.to(true)
47
47
  end
48
48
 
49
49
  end
@@ -56,9 +56,9 @@ describe AASM::Transition do
56
56
  opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
57
57
  st = AASM::Transition.new(opts)
58
58
 
59
- st.from.should == opts[:from]
60
- st.to.should == opts[:to]
61
- st.opts.should == opts
59
+ expect(st.from).to eq(opts[:from])
60
+ expect(st.to).to eq(opts[:to])
61
+ expect(st.opts).to eq(opts)
62
62
  end
63
63
 
64
64
  it 'should pass equality check if from and to are the same' do
@@ -66,10 +66,10 @@ describe AASM::Transition do
66
66
  st = AASM::Transition.new(opts)
67
67
 
68
68
  obj = double('object')
69
- obj.stub(:from).and_return(opts[:from])
70
- obj.stub(:to).and_return(opts[:to])
69
+ allow(obj).to receive(:from).and_return(opts[:from])
70
+ allow(obj).to receive(:to).and_return(opts[:to])
71
71
 
72
- st.should == obj
72
+ expect(st).to eq(obj)
73
73
  end
74
74
 
75
75
  it 'should fail equality check if from are not the same' do
@@ -77,10 +77,10 @@ describe AASM::Transition do
77
77
  st = AASM::Transition.new(opts)
78
78
 
79
79
  obj = double('object')
80
- obj.stub(:from).and_return('blah')
81
- obj.stub(:to).and_return(opts[:to])
80
+ allow(obj).to receive(:from).and_return('blah')
81
+ allow(obj).to receive(:to).and_return(opts[:to])
82
82
 
83
- st.should_not == obj
83
+ expect(st).not_to eq(obj)
84
84
  end
85
85
 
86
86
  it 'should fail equality check if to are not the same' do
@@ -88,10 +88,10 @@ describe AASM::Transition do
88
88
  st = AASM::Transition.new(opts)
89
89
 
90
90
  obj = double('object')
91
- obj.stub(:from).and_return(opts[:from])
92
- obj.stub(:to).and_return('blah')
91
+ allow(obj).to receive(:from).and_return(opts[:from])
92
+ allow(obj).to receive(:to).and_return('blah')
93
93
 
94
- st.should_not == obj
94
+ expect(st).not_to eq(obj)
95
95
  end
96
96
  end
97
97
 
@@ -100,7 +100,7 @@ describe AASM::Transition, '- when performing guard checks' do
100
100
  opts = {:from => 'foo', :to => 'bar'}
101
101
  st = AASM::Transition.new(opts)
102
102
 
103
- st.perform(nil).should be_true
103
+ expect(st.perform(nil)).to be_true
104
104
  end
105
105
 
106
106
  it 'should call the method on the object if guard is a symbol' do
@@ -108,7 +108,7 @@ describe AASM::Transition, '- when performing guard checks' do
108
108
  st = AASM::Transition.new(opts)
109
109
 
110
110
  obj = double('object')
111
- obj.should_receive(:test)
111
+ expect(obj).to receive(:test)
112
112
 
113
113
  st.perform(obj)
114
114
  end
@@ -118,7 +118,7 @@ describe AASM::Transition, '- when performing guard checks' do
118
118
  st = AASM::Transition.new(opts)
119
119
 
120
120
  obj = double('object')
121
- obj.should_receive(:test)
121
+ expect(obj).to receive(:test)
122
122
 
123
123
  st.perform(obj)
124
124
  end
@@ -128,7 +128,7 @@ describe AASM::Transition, '- when performing guard checks' do
128
128
  st = AASM::Transition.new(opts)
129
129
 
130
130
  obj = double('object')
131
- obj.should_receive(:test)
131
+ expect(obj).to receive(:test)
132
132
 
133
133
  st.perform(obj)
134
134
  end
@@ -139,9 +139,9 @@ describe AASM::Transition, '- when executing the transition with a Proc' do
139
139
  opts = {:from => 'foo', :to => 'bar', :on_transition => Proc.new {|o| o.test}}
140
140
  st = AASM::Transition.new(opts)
141
141
  args = {:arg1 => '1', :arg2 => '2'}
142
- obj = double('object')
142
+ obj = double('object', :aasm => 'aasm')
143
143
 
144
- opts[:on_transition].should_receive(:call).with(any_args)
144
+ expect(opts[:on_transition]).to receive(:call).with(any_args)
145
145
 
146
146
  st.execute(obj, args)
147
147
  end
@@ -150,9 +150,9 @@ describe AASM::Transition, '- when executing the transition with a Proc' do
150
150
  opts = {:from => 'foo', :to => 'bar', :on_transition => Proc.new {||}}
151
151
  st = AASM::Transition.new(opts)
152
152
  args = {:arg1 => '1', :arg2 => '2'}
153
- obj = double('object')
153
+ obj = double('object', :aasm => 'aasm')
154
154
 
155
- opts[:on_transition].should_receive(:call).with(no_args)
155
+ expect(opts[:on_transition]).to receive(:call).with(no_args)
156
156
 
157
157
  st.execute(obj, args)
158
158
  end
@@ -163,9 +163,9 @@ describe AASM::Transition, '- when executing the transition with an :on_transtio
163
163
  opts = {:from => 'foo', :to => 'bar', :on_transition => 'test'}
164
164
  st = AASM::Transition.new(opts)
165
165
  args = {:arg1 => '1', :arg2 => '2'}
166
- obj = double('object')
166
+ obj = double('object', :aasm => 'aasm')
167
167
 
168
- obj.should_receive(:test)
168
+ expect(obj).to receive(:test)
169
169
 
170
170
  st.execute(obj, args)
171
171
  end
@@ -174,9 +174,9 @@ describe AASM::Transition, '- when executing the transition with an :on_transtio
174
174
  opts = {:from => 'foo', :to => 'bar', :on_transition => :test}
175
175
  st = AASM::Transition.new(opts)
176
176
  args = {:arg1 => '1', :arg2 => '2'}
177
- obj = double('object')
177
+ obj = double('object', :aasm => 'aasm')
178
178
 
179
- obj.should_receive(:test)
179
+ expect(obj).to receive(:test)
180
180
 
181
181
  st.execute(obj, args)
182
182
  end
@@ -185,7 +185,7 @@ describe AASM::Transition, '- when executing the transition with an :on_transtio
185
185
  opts = {:from => 'foo', :to => 'bar', :on_transition => :test}
186
186
  st = AASM::Transition.new(opts)
187
187
  args = {:arg1 => '1', :arg2 => '2'}
188
- obj = double('object')
188
+ obj = double('object', :aasm => 'aasm')
189
189
 
190
190
  def obj.test(args)
191
191
  "arg1: #{args[:arg1]} arg2: #{args[:arg2]}"
@@ -193,14 +193,14 @@ describe AASM::Transition, '- when executing the transition with an :on_transtio
193
193
 
194
194
  return_value = st.execute(obj, args)
195
195
 
196
- return_value.should == 'arg1: 1 arg2: 2'
196
+ expect(return_value).to eq('arg1: 1 arg2: 2')
197
197
  end
198
198
 
199
199
  it 'should NOT pass args if the target method does NOT accept them' do
200
200
  opts = {:from => 'foo', :to => 'bar', :on_transition => :test}
201
201
  st = AASM::Transition.new(opts)
202
202
  args = {:arg1 => '1', :arg2 => '2'}
203
- obj = double('object')
203
+ obj = double('object', :aasm => 'aasm')
204
204
 
205
205
  def obj.test
206
206
  'success'
@@ -208,7 +208,22 @@ describe AASM::Transition, '- when executing the transition with an :on_transtio
208
208
 
209
209
  return_value = st.execute(obj, args)
210
210
 
211
- return_value.should == 'success'
211
+ expect(return_value).to eq('success')
212
+ end
213
+
214
+ it 'should allow accessing the from_state and the to_state' do
215
+ opts = {:from => 'foo', :to => 'bar', :on_transition => :test}
216
+ st = AASM::Transition.new(opts)
217
+ args = {:arg1 => '1', :arg2 => '2'}
218
+ obj = double('object', :aasm => AASM::InstanceBase.new('object'))
219
+
220
+ def obj.test(args)
221
+ "from: #{aasm.from_state} to: #{aasm.to_state}"
222
+ end
223
+
224
+ return_value = st.execute(obj, args)
225
+
226
+ expect(return_value).to eq('from: foo to: bar')
212
227
  end
213
228
 
214
229
  end