-
Notifications
You must be signed in to change notification settings - Fork 7
/
state_spec.rb
74 lines (53 loc) · 1.85 KB
/
state_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
# TODO These are specs ported from original aasm
describe AASM::SupportingClasses::State do
before(:each) do
@name = :astate
@options = { :crazy_custom_key => 'key' }
end
def new_state(options={})
AASM::SupportingClasses::State.new(@name, @options.merge(options))
end
it 'should set the name' do
state = new_state
state.name.should == :astate
end
it 'should set the options and expose them as options' do
state = new_state
state.options.should == @options
end
it 'should be equal to a symbol of the same name' do
state = new_state
state.should == :astate
end
it 'should be equal to a State of the same name' do
new_state.should == new_state
end
it 'should send a message to the record for an action if the action is present as a symbol' do
state = new_state(:entering => :foo)
record = mock('record')
record.should_receive(:foo)
state.call_action(:entering, record)
end
it 'should send a message to the record for an action if the action is present as a string' do
state = new_state(:entering => 'foo')
record = mock('record')
record.should_receive(:foo)
state.call_action(:entering, record)
end
it 'should send a message to the record for each action' do
state = new_state(:entering => [:a, :b, "c", lambda {|r| r.foobar }])
record = mock('record')
record.should_receive(:a)
record.should_receive(:b)
record.should_receive(:c)
record.should_receive(:foobar)
state.call_action(:entering, record)
end
it 'should call a proc, passing in the record for an action if the action is present' do
state = new_state(:entering => Proc.new {|r| r.foobar})
record = mock('record')
record.should_receive(:foobar)
state.call_action(:entering, record)
end
end