Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that from_state is set after successfully firing an event. #826

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/aasm/aasm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def aasm_fired(state_machine_name, event, old_state, new_state_name, options, *a
*process_args(event, old_state.name, *args)
)

aasm(state_machine_name).from_state = old_state
self.aasm_event_fired(event.name, old_state.name, aasm(state_machine_name).current_state) if self.respond_to?(:aasm_event_fired)
else
self.aasm_event_failed(event.name, old_state.name) if self.respond_to?(:aasm_event_failed)
Expand Down
2 changes: 1 addition & 1 deletion lib/aasm/core/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _fire(obj, options={}, to_state=::AASM::NO_VALUE, *args)
args.unshift(to_state)
to_state = nil
end

# nop, to_state is a valid to-state

transitions.each do |transition|
Expand Down
17 changes: 17 additions & 0 deletions spec/unit/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,23 @@
expect(model).to receive(:do_something_after).once.ordered
model.in_right_order!
end

context 'with a transition from any state' do
it 'sets from_state' do
ThisNameBetterNotBeInUse.instance_eval do
aasm do
event :some_event do
transitions :to => :proc
end
end
end

model = ThisNameBetterNotBeInUse.new
model.some_event
expect(model.aasm.from_state).to eq(:initial)
end
end

end

describe 'current event' do
Expand Down