fix cancel of lessons

This commit is contained in:
Seth Call 2016-05-24 15:17:42 -05:00
parent 0528f09e27
commit 61314002b2
3 changed files with 10 additions and 0 deletions

View File

@ -35,6 +35,7 @@ module JamRuby
belongs_to :canceler, class_name: "JamRuby::User", foreign_key: :canceler_id
belongs_to :lesson_package_purchase, class_name: "JamRuby::LessonPackagePurchase"
belongs_to :lesson_booking, class_name: "JamRuby::LessonBooking"
belongs_to :user, class_name: "JamRuby::User"
belongs_to :slot, class_name: "JamRuby::LessonBookingSlot", foreign_key: :slot_id, :dependent => :destroy
belongs_to :lesson_payment_charge, class_name: "JamRuby::LessonPaymentCharge", foreign_key: :charge_id
belongs_to :counter_slot, class_name: "JamRuby::LessonBookingSlot", foreign_key: :counter_slot_id, inverse_of: :countered_lesson, :dependent => :destroy
@ -501,6 +502,7 @@ module JamRuby
lesson_session.status = booking.status
lesson_session.slot = booking.default_slot
lesson_session.assigned_student = booking.student
lesson_session.user = booking.student
if booking.is_test_drive? && booking.student.remaining_test_drives > 0
lesson_session.lesson_package_purchase = booking.student.most_recent_test_drive_purchase
end
@ -758,6 +760,7 @@ module JamRuby
response = self
LessonSession.transaction do
self.status = LessonSession::STATUS_CANCELED
canceler = params[:canceler]
canceled_by_student = canceler == student
other = canceled_by_student ? teacher : student
@ -779,6 +782,11 @@ module JamRuby
if response.errors.any?
raise ActiveRecord::Rollback
end
if !save
response = self
raise ActiveRecord::Rollback
end
else
cancel_lesson(canceler, message)
if !save

View File

@ -47,6 +47,7 @@ describe LessonSession do
it "cancel in the past is OK" do
slot = FactoryGirl.build(:lesson_booking_slot_single, preferred_day: Date.today + 1)
lesson = normal_lesson(user, teacher, {slots: [slot, slot2]})
Timecop.travel(Date.today + 2)
lesson.cancel({
message: "Cancel time!",

View File

@ -33,6 +33,7 @@ rest = new context.JK.Rest()
inThePast = false
beforeSession = false
startingSoon = false
lessonWindow = false
if untilInfo.total < 0
# we are past the start time