-
Notifications
You must be signed in to change notification settings - Fork 629
/
api_spec.rb
97 lines (79 loc) · 2.37 KB
/
api_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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
require 'spec_helper'
require 'models/default_state.rb'
require 'models/provided_state.rb'
require 'models/active_record/persisted_state.rb'
require 'models/active_record/provided_and_persisted_state.rb'
load_schema
describe "reading the current state" do
it "uses the AASM default" do
expect(DefaultState.new.aasm.current_state).to eql :alpha
end
it "uses the provided method" do
expect(ProvidedState.new.aasm.current_state).to eql :beta
end
it "uses the persistence storage" do
expect(PersistedState.new.aasm.current_state).to eql :alpha
end
it "uses the provided method even if persisted" do
expect(ProvidedAndPersistedState.new.aasm.current_state).to eql :gamma
end
context "after dup" do
it "uses the persistence storage" do
source = PersistedState.create!
copy = source.dup
copy.save!
copy.release!
expect(source.aasm_state).to eql 'alpha'
expect(source.aasm.current_state).to eql :alpha
source2 = PersistedState.find(source.id)
expect(source2.reload.aasm_state).to eql 'alpha'
expect(source2.aasm.current_state).to eql :alpha
expect(copy.aasm_state).to eql 'beta'
expect(copy.aasm.current_state).to eql :beta
end
end
end
describe "writing and persisting the current state" do
it "uses the AASM default" do
o = DefaultState.new
o.release!
expect(o.persisted_store).to be_nil
end
it "uses the provided method" do
o = ProvidedState.new
o.release!
expect(o.persisted_store).to eql :beta
end
it "uses the persistence storage" do
o = PersistedState.new
o.release!
expect(o.persisted_store).to be_nil
end
it "uses the provided method even if persisted" do
o = ProvidedAndPersistedState.new
o.release!
expect(o.persisted_store).to eql :beta
end
end
describe "writing the current state without persisting it" do
it "uses the AASM default" do
o = DefaultState.new
o.release
expect(o.transient_store).to be_nil
end
it "uses the provided method" do
o = ProvidedState.new
o.release
expect(o.transient_store).to eql :beta
end
it "uses the persistence storage" do
o = PersistedState.new
o.release
expect(o.transient_store).to be_nil
end
it "uses the provided method even if persisted" do
o = ProvidedAndPersistedState.new
o.release
expect(o.transient_store).to eql :beta
end
end