i have 2 models: lessonbooking , customerrequests
once lessonbooking paid, associated customerrequests marked booked. note: lessonbooking not directly associated via id customers enter email when pay , email used check existing customer requests marked "booked" if found. here relevant code in lesson_booking.rb:
event :payment_received transition :form_started => :paid end after_transition :form_started => :paid |booking| email = booking.teaching_relationship.student.account.email customer_request = customerrequest.find_by_email(email) unless customer_request.nil? customer_request.book end end
the customerrequest model has state machine has event "book" shown here:
event :book transition [:new, :opened, :awaiting_response] => :booked end
now incapable of getting spec passed tests transition of lessonbooking "form_started" "paid" , following transition of customerrequest "new" "booked".
here spec wrote:
context 'when there associated customer request' before :each @student = create(:student) relationship = create(:teaching_relationship, student: @student) @new_booking = create(:lesson_booking, teaching_relationship: relationship) @customer_request = create(:customer_request, student: @student, email: @student.account.email ) end "it changes state of customer request" @new_booking.payment_received expect(@customer_request.state).to eq 'booked' end end
end
my test fails following note:
expected: "booked" got: "new"
i knew testing in general , appreciate help.
Comments
Post a Comment