我正在使用Rail 4.2.3和aasm gem version 4.1 是否可以在一个模型中为枚举字段添加两个状态机?
我有枚举状态:[:active,:suspended,:deleted] 和枚举活动:[:工作,:停止]
我不会有这样的2台状态机:
INTENT
和其他状态机:
aasm(:connection_state, column: :state, enum: true do
state :active, initial: true
state :suspended
state :deleted
event :activate do
transitions from: :suspended, to: :active
transitions from: :deleted, to: :active
end
event :suspend do
transitions from: :active, to: :suspended
end
event :mark_as_deleted do
transitions from: [:active, :suspended], to: :deleted
end
end
但规格失败并出现错误:
aasm(:activity_state, column: :activity, enum: true do
state :working, initial: true
state :stopped
event :start_working do
transitions from: :stopped, to: :working
end
event :stop_working do
transitions from: :working, to: :stopped
end
end
AASM :: UnknownStateMachineError: 没有状态机名称'默认'在ModelName中定义
我缺少什么?
答案 0 :(得分:0)
我的规范中存在问题,只是没有仔细阅读文档:
expect(subject).to transition_from(:active).to(:suspended).on_event(:suspend).on(:connection_state)
修复了问题