114 lines
3.1 KiB
Ruby
114 lines
3.1 KiB
Ruby
|
|
module StripeMock
|
|
class ErrorQueue
|
|
def clear
|
|
@queue = []
|
|
end
|
|
end
|
|
|
|
def self.clear_errors
|
|
instance.error_queue.clear if instance
|
|
client.error_queue.clear if client
|
|
end
|
|
end
|
|
|
|
def testdrive_lesson(user, teacher, slots = nil)
|
|
|
|
if slots.nil?
|
|
slots = []
|
|
slots << FactoryGirl.build(:lesson_booking_slot_single)
|
|
slots << FactoryGirl.build(:lesson_booking_slot_single)
|
|
end
|
|
|
|
if user.stored_credit_card == false
|
|
user.stored_credit_card = true
|
|
user.save!
|
|
end
|
|
|
|
|
|
booking = LessonBooking.book_test_drive(user, teacher, slots, "Hey I've heard of you before.")
|
|
#puts "BOOKING #{booking.errors.inspect}"
|
|
booking.errors.any?.should be_false
|
|
lesson = booking.lesson_sessions[0]
|
|
booking.card_presumed_ok.should be_true
|
|
|
|
if user.most_recent_test_drive_purchase.nil?
|
|
LessonPackagePurchase.create(user, booking, LessonPackageType.test_drive_4)
|
|
end
|
|
|
|
lesson.accept({message: 'Yeah I got this', slot: slots[0]})
|
|
lesson.errors.any?.should be_false
|
|
lesson.reload
|
|
lesson.slot.should eql slots[0]
|
|
lesson.status.should eql LessonSession::STATUS_APPROVED
|
|
|
|
lesson
|
|
end
|
|
|
|
|
|
def normal_lesson(user, teacher, slots = nil)
|
|
|
|
if slots.nil?
|
|
slots = []
|
|
slots << FactoryGirl.build(:lesson_booking_slot_single)
|
|
slots << FactoryGirl.build(:lesson_booking_slot_single)
|
|
end
|
|
|
|
if user.stored_credit_card == false
|
|
user.stored_credit_card = true
|
|
user.save!
|
|
end
|
|
|
|
booking = LessonBooking.book_normal(user, teacher, slots, "Hey I've heard of you before.", false, LessonBooking::PAYMENT_STYLE_SINGLE, 60)
|
|
# puts "NORMAL BOOKING #{booking.errors.inspect}"
|
|
booking.errors.any?.should be_false
|
|
lesson = booking.lesson_sessions[0]
|
|
booking.card_presumed_ok.should be_true
|
|
|
|
#if user.most_recent_test_drive_purchase.nil?
|
|
# LessonPackagePurchase.create(user, booking, LessonPackageType.test_drive_4)
|
|
#end
|
|
|
|
lesson.accept({message: 'Yeah I got this', slot: slots[0]})
|
|
lesson.errors.any?.should be_false
|
|
lesson.reload
|
|
lesson.slot.should eql slots[0]
|
|
lesson.status.should eql LessonSession::STATUS_APPROVED
|
|
lesson.music_session.should_not be_nil
|
|
|
|
lesson
|
|
end
|
|
|
|
|
|
def monthly_lesson(user, teacher, slots = nil)
|
|
|
|
if slots.nil?
|
|
slots = []
|
|
slots << FactoryGirl.build(:lesson_booking_slot_recurring)
|
|
slots << FactoryGirl.build(:lesson_booking_slot_recurring)
|
|
end
|
|
|
|
if user.stored_credit_card == false
|
|
user.stored_credit_card = true
|
|
user.save!
|
|
end
|
|
|
|
booking = LessonBooking.book_normal(user, teacher, slots, "Hey I've heard of you before.", true, LessonBooking::PAYMENT_STYLE_MONTHLY, 60)
|
|
# puts "NORMAL BOOKING #{booking.errors.inspect}"
|
|
booking.errors.any?.should be_false
|
|
lesson = booking.lesson_sessions[0]
|
|
booking.card_presumed_ok.should be_true
|
|
|
|
#if user.most_recent_test_drive_purchase.nil?
|
|
# LessonPackagePurchase.create(user, booking, LessonPackageType.test_drive_4)
|
|
#end
|
|
|
|
lesson.accept({message: 'Yeah I got this', slot: slots[0]})
|
|
lesson.errors.any?.should be_false
|
|
lesson.reload
|
|
lesson.slot.should eql slots[0]
|
|
lesson.status.should eql LessonSession::STATUS_APPROVED
|
|
lesson.music_session.should_not be_nil
|
|
|
|
lesson
|
|
end |