Skip to content

Commit 905739f

Browse files
committed
Update syntax of aasm config
The latest version mentions that the old syntax will soon be deprecated.
1 parent abc3de7 commit 905739f

3 files changed

Lines changed: 56 additions & 56 deletions

File tree

app/models/open_conference_ware/proposal.rb

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -60,65 +60,64 @@ class Proposal < OpenConferenceWare::Base
6060
# Acts As State Machine
6161
include AASM
6262

63-
aasm_column :status
64-
65-
aasm_initial_state :proposed
66-
67-
aasm_state :proposed
68-
aasm_state :accepted
69-
aasm_state :waitlisted
70-
aasm_state :rejected
71-
aasm_state :confirmed
72-
aasm_state :declined
73-
aasm_state :junk
74-
aasm_state :cancelled
75-
76-
aasm_event :accept do
77-
transitions from: :proposed, to: :accepted
78-
transitions from: :rejected, to: :accepted
79-
transitions from: :waitlisted, to: :accepted
80-
end
63+
aasm(column: :status) do
64+
65+
state :proposed, initial: true
66+
state :accepted
67+
state :waitlisted
68+
state :rejected
69+
state :confirmed
70+
state :declined
71+
state :junk
72+
state :cancelled
73+
74+
event :accept do
75+
transitions from: :proposed, to: :accepted
76+
transitions from: :rejected, to: :accepted
77+
transitions from: :waitlisted, to: :accepted
78+
end
8179

82-
aasm_event :reject do
83-
transitions from: :proposed, to: :rejected
84-
transitions from: :accepted, to: :rejected
85-
transitions from: :waitlisted, to: :rejected
86-
end
80+
event :reject do
81+
transitions from: :proposed, to: :rejected
82+
transitions from: :accepted, to: :rejected
83+
transitions from: :waitlisted, to: :rejected
84+
end
8785

88-
aasm_event :waitlist do
89-
transitions from: :proposed, to: :waitlisted
90-
transitions from: :accepted, to: :waitlisted
91-
transitions from: :rejected, to: :waitlisted
92-
end
86+
event :waitlist do
87+
transitions from: :proposed, to: :waitlisted
88+
transitions from: :accepted, to: :waitlisted
89+
transitions from: :rejected, to: :waitlisted
90+
end
9391

94-
aasm_event :confirm do
95-
transitions from: :accepted, to: :confirmed
96-
end
92+
event :confirm do
93+
transitions from: :accepted, to: :confirmed
94+
end
9795

98-
aasm_event :decline do
99-
transitions from: :accepted, to: :declined
100-
end
96+
event :decline do
97+
transitions from: :accepted, to: :declined
98+
end
10199

102-
aasm_event :accept_and_confirm do
103-
transitions from: :proposed, to: :confirmed
104-
transitions from: :waitlisted, to: :confirmed
105-
end
100+
event :accept_and_confirm do
101+
transitions from: :proposed, to: :confirmed
102+
transitions from: :waitlisted, to: :confirmed
103+
end
106104

107-
aasm_event :accept_and_decline do
108-
transitions from: :proposed, to: :declined
109-
transitions from: :waitlisted, to: :declined
110-
end
105+
event :accept_and_decline do
106+
transitions from: :proposed, to: :declined
107+
transitions from: :waitlisted, to: :declined
108+
end
111109

112-
aasm_event :mark_as_junk do
113-
transitions from: :proposed, to: :junk
114-
end
110+
event :mark_as_junk do
111+
transitions from: :proposed, to: :junk
112+
end
115113

116-
aasm_event :reset_status do
117-
transitions from: %w(accepted rejected waitlisted confirmed declined junk cancelled), to: :proposed
118-
end
114+
event :reset_status do
115+
transitions from: %w(accepted rejected waitlisted confirmed declined junk cancelled), to: :proposed
116+
end
119117

120-
aasm_event :cancel do
121-
transitions from: :confirmed, to: :cancelled
118+
event :cancel do
119+
transitions from: :confirmed, to: :cancelled
120+
end
122121
end
123122

124123
# Associations
@@ -262,15 +261,15 @@ def end_time
262261
# representing optional states. Of each pair, the first element is the title,
263262
# the second is the status.
264263
def titles_and_statuses
265-
result = [["(currently '#{self.aasm_current_state.to_s.titleize}')", nil]]
266-
result += self.aasm_events_for_current_state.map{|s|[s.to_s.titleize, s.to_s]}.sort_by{|title, state| title}
264+
result = [["(currently '#{self.aasm.current_state.to_s.titleize}')", nil]]
265+
result += self.aasm.events(aasm.current_state).map{|s|[s.to_s.titleize, s.to_s]}.sort_by{|title, state| title}
267266
return result
268267
end
269268

270269
# allows an interface to state machine through update_attributes transition key
271270
attr_accessor :transition
272271
def transition=(event)
273-
send("#{event}!") if !event.blank? && aasm_events_for_current_state.include?(event.to_sym)
272+
send("#{event}!") if !event.blank? && aasm.events(aasm.current_state).include?(event.to_sym)
274273
end
275274

276275
# Is this +user+ allowed to alter this proposal?

app/views/open_conference_ware/proposals/_transition_control.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ proposal ||= @proposal
88
%>
99

1010
<div id="proposal_transition_control_container_<%= proposal.id %>" class="proposal_transition_control_container proposal_control_container">
11-
<% if proposal.aasm_events_for_current_state.empty? %>
12-
No valid transitions available from status <%= proposal.aasm_current_state %>
11+
<% if proposal.aasm.events(proposal.aasm.current_state).empty? %>
12+
No valid transitions available from status <%= proposal.aasm.current_state %>
1313
<% else %>
1414
<%= select('proposal', 'transition', proposal.titles_and_statuses[1 .. proposal.titles_and_statuses.length], {:include_blank => proposal.titles_and_statuses[0][0]}, {:class => 'proposal_transition_control proposal_control', :x_proposal_id => proposal.id}) %>
1515
<% end %>

spec/views/open_conference_ware/proposals/_transition_control.html.erb_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
describe "open_conference_ware/proposals/_transition_control.html.erb" do
44
it "should render a state changing select menu with valid events and destination label" do
5-
proposal = stub_model(Proposal, aasm_events_for_current_state: [:accept, :reject])
5+
aasm = double("aasm", events: [:accept, :reject], current_state: :proposed)
6+
proposal = stub_model(Proposal, aasm: aasm)
67
assign(:proposal, proposal)
78
render
89
rendered.should have_selector("select[name='proposal[transition]']") do |node|

0 commit comments

Comments
 (0)