=begin
require 'spec_helper'

# collissions with teacher's schedule?
describe LessonBookingSlot do

  let(:user) { FactoryGirl.create(:user, stored_credit_card: false, remaining_free_lessons: 1, remaining_test_drives: 1) }
  let(:lesson_booking_slot_single1) { FactoryGirl.build(:lesson_booking_slot_single, timezone: 'US/Pacific', hour: 12) }
  let(:lesson_booking_slot_recurring1) { FactoryGirl.build(:lesson_booking_slot_recurring, timezone: 'US/Pacific', hour: 12) }


  before do

  end

  after do
    Timecop.return
  end

  describe "next_day" do
    before do
      # Set Time.now to September 1, 2008 10:05:00 AM (at this instant). This is Monday
      @now = Time.local(2008, 9, 1, 10, 5, 0)
      Timecop.freeze(@now)
    end
    it "same day of week" do

      @now.wday.should eql 1
      # let's make it match
      lesson_booking_slot_recurring1.day_of_week = @now.wday

      (@now.to_date).should eql lesson_booking_slot_recurring1.next_day
    end

    it "day of week is tomorrow" do

      # make the slot be today + 1 (Tuesday in this case)
      lesson_booking_slot_recurring1.day_of_week = @now.wday + 1

      lesson_booking_slot_recurring1.next_day.should eql(@now.to_date + 1)
    end

    it "day of week is yesterday" do
      # make the slot be today + 1 (Sunday in this case)
      lesson_booking_slot_recurring1.day_of_week = @now.wday - 1

      lesson_booking_slot_recurring1.next_day.should eql(@now.to_date + 6)
    end

    it "day of week is two day ago" do
      # make the slot be today + 1 (Saturday in this case)
      lesson_booking_slot_recurring1.day_of_week = 6

      lesson_booking_slot_recurring1.next_day.should eql(@now.to_date + 5)
    end
  end

  describe "scheduled_time" do
    before do
      # Set Time.now to September 1, 2008 10:05:00 AM (at this instant). This is Monday
      @now = Time.local(2008, 9, 1, 10, 5, 0)
      Timecop.freeze(@now)
    end

    it "creates a single time OK" do
      time = lesson_booking_slot_single1.scheduled_time(0)
      time.utc_offset.should eq 0
      time.year.should eql lesson_booking_slot_single1.preferred_day.year
      time.month.should eql lesson_booking_slot_single1.preferred_day.month
      time.day.should eql lesson_booking_slot_single1.preferred_day.day
      time.hour.should be > lesson_booking_slot_single1.hour
      time.min.should eql lesson_booking_slot_single1.minute
      time.sec.should eql 0
    end

    it "creates a recurring time OK" do
      lesson_booking_slot_recurring1.day_of_week = @now.wday
      time = lesson_booking_slot_recurring1.scheduled_time(0)
      time.utc_offset.should eq 0
      time.year.should eql @now.year
      time.month.should eql @now.month
      time.day.should eql @now.day
      time.hour.should be > lesson_booking_slot_recurring1.hour
      time.min.should eql lesson_booking_slot_recurring1.minute
      time.sec.should eql 0
    end

    it "creates a recurring time OK 1 week out" do
      lesson_booking_slot_recurring1.day_of_week = @now.wday
      time = lesson_booking_slot_recurring1.scheduled_time(1)
      time.utc_offset.should eq 0
      time.year.should eql @now.year
      time.month.should eql @now.month
      time.day.should eql @now.day + 7
      time.hour.should be > lesson_booking_slot_recurring1.hour
      time.min.should eql lesson_booking_slot_recurring1.minute
      time.sec.should eql 0
    end
  end


  describe "scheduled_times" do
    before do
      # Set Time.now to September 1, 2008 10:05:00 AM (at this instant). This is Monday
      @now = Time.local(2008, 9, 1, 10, 5, 0)
      Timecop.freeze(@now)
    end

    it "creates a single time session OK" do
      times = lesson_booking_slot_single1.scheduled_times(1, @now.to_date + 2)
      times.length.should eq 1
      time = times[0]
      time.utc_offset.should eq 0
      time.year.should eql lesson_booking_slot_single1.preferred_day.year
      time.month.should eql lesson_booking_slot_single1.preferred_day.month
      time.day.should eql lesson_booking_slot_single1.preferred_day.day
      time.hour.should be > lesson_booking_slot_single1.hour
      time.min.should eql lesson_booking_slot_single1.minute
      time.sec.should eql 0
    end


    it "creates a recurring time session OK" do
      lesson_booking_slot_recurring1.day_of_week = @now.wday + 3
      times = lesson_booking_slot_recurring1.scheduled_times(1, @now.to_date + 2)
      times.length.should eq 1
      time = times[0]
      time.utc_offset.should eq 0
      time.year.should eql @now.year
      time.month.should eql @now.month
      time.day.should eql @now.day + 3
      time.hour.should be > lesson_booking_slot_recurring1.hour
      time.min.should eql lesson_booking_slot_recurring1.minute
      time.sec.should eql 0
    end

    it "creates a recurring time session OK (minimum time hit)" do
      lesson_booking_slot_recurring1.day_of_week = @now.wday
      times = lesson_booking_slot_recurring1.scheduled_times(1, @now.to_date + 2)
      times.length.should eq 1
      time = times[0]
      time.utc_offset.should eq 0
      time.year.should eql @now.year
      time.month.should eql @now.month
      time.day.should eql @now.day + 7
      time.hour.should be > lesson_booking_slot_recurring1.hour
      time.min.should eql lesson_booking_slot_recurring1.minute
      time.sec.should eql 0
    end

    it "creates 2 recurring times session OK" do
      lesson_booking_slot_recurring1.day_of_week = @now.wday
      times = lesson_booking_slot_recurring1.scheduled_times(2, @now.to_date + 2)
      times.length.should eq 2
      time = times[0]
      time.utc_offset.should eq 0
      time.year.should eql @now.year
      time.month.should eql @now.month
      time.day.should eql @now.day + 7
      time.hour.should be > lesson_booking_slot_recurring1.hour
      time.min.should eql lesson_booking_slot_recurring1.minute
      time.sec.should eql 0
      time = times[1]
      time.utc_offset.should eq 0
      time.year.should eql @now.year
      time.month.should eql @now.month
      time.day.should eql @now.day + 14
      time.hour.should be > lesson_booking_slot_recurring1.hour
      time.min.should eql lesson_booking_slot_recurring1.minute
      time.sec.should eql 0
    end
  end
end
=end