State machine transition don't work if you set state explicitly, like you do, with Adjustment#state=
method (in this case). You should use events instead, for example:
adjustment.close
题
I have spree Adjustment extension
Spree::Adjustment.class_eval do
state_machine do
after_transition :to => :closed, :do => :some_method
end
def some_method
end
end
And I have rspec test, which fails. In real application method are called and all things work as expected.
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
failed with
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
解决方案
State machine transition don't work if you set state explicitly, like you do, with Adjustment#state=
method (in this case). You should use events instead, for example:
adjustment.close