我正在使用 aasm gem 来处理我的项目中的状态转换。我有一个看起来像这样的简单模型:
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
我正在尝试使用 rspec 匹配器中内置的 aasm 测试转换:
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
当我运行此规范时,它会返回以下错误:
AASM::UnknownStateMachineError:
There is no state machine with the name 'default' defined in TransferPostingBid!
我怎样才能解决这个问题?