我有任意调整扩展
Spree::Adjustment.class_eval do
state_machine do
after_transition :to => :closed, :do => :some_method
end
def some_method
end
end我有rspec测试失败了。在实际应用程序中,方法被调用,所有事情都按预期工作。
describe Spree:Adjustment do
let(:adjustment) { create(:adjustment, state: 'open') }
it "call some_method after close" do
adjustment.should_receive(:some_method)
adjustment.state = "closed"
end
end 失败了
1) Spree::Adjustment call some_method after close
Failure/Error: adjustment.should_receive(:some_method)
(#<Spree::Adjustment:0x0000000751a340>).some_method(any args)
expected: 1 time with any arguments
received: 0 times with any arguments发布于 2014-02-13 10:15:55
如果像使用Adjustment#state=方法一样显式地设置状态,状态机转换就不能工作(在本例中)。您应该使用事件,例如:
adjustment.closehttps://stackoverflow.com/questions/21749928
复制相似问题