require 'spec_helper'

describe 'ScheduledMusicSessionCleaner' do

  before(:all) {
    MusicSession.delete_all
  }

  it "purges old music sessions" do
    [MusicSession::UNSTARTED_INTERVAL_DAYS_PURGE, 
     MusicSession::UNSTARTED_INTERVAL_DAYS_PURGE_RECUR].each do |interval|
      dd = Time.now - (interval.to_i + 1).days
      Timecop.travel(dd)
      FactoryGirl.create(:music_session, scheduled_start: dd)
      Timecop.return
    end
    msess2 = FactoryGirl.create(:music_session, scheduled_start: Time.now)
    expect(MusicSession.count).to be(3)

    JamRuby::ScheduledMusicSessionCleaner.perform
    expect(MusicSession.count).to be(1)
    expect(MusicSession.first.id).to eq(msess2.id)
  end

end
