Reputation: 7862
I'm using aasm gem to handle state transitions in my project. I have a simple model that looks like this:
class TransferPostingBid < ActiveRecord::Base
include AASM
aasm :status do
state :offered, initial: true
state :wait_for_pap_confirmation
state :confirmed_by_pap
state :retracted_by_pap
event :pap_choosed do
transitions from: :offered, to: :wait_for_pap_confirmation
end
event :confirmed_by_pap do
transitions from: :wait_for_pap_confirmation, to: :confirmed_by_pap
end
event :retracted_by_pap do
transitions from: :wait_for_pap_confirmation, to: :retracted_by_pap
end
end
end
And I'm trying to test transitions with aasm built in rspec matchers:
require 'rails_helper'
describe TransferPostingBid, type: :model do
describe 'state transitions' do
let(:transfer_posting_bid) { TransferPostingBid.new }
it 'has default state' do
expect(transfer_posting_bid).to transition_from(:offered).to(:wait_for_pap_confirmation).on_event(:pap_choosed)
end
end
end
When I run this spec it returns me following error:
AASM::UnknownStateMachineError:
There is no state machine with the name 'default' defined in TransferPostingBid!
How can I fix this?
Upvotes: 2
Views: 5375
Reputation: 8777
You can try using the the #on
method to specify which state machine you're testing:
transition_from(:offered).to(:wait_for_pap_confirmation).on_event(:pap_choosed).on(:status)
Upvotes: 7