require 'spec_helper'

describe Connection do
  let(:user) { FactoryGirl.create(:user) }
  let (:music_session) { FactoryGirl.create(:music_session, :creator => user) }

  it 'starts in the correct state' do
    connection = FactoryGirl.create(:connection, 
                                    :user => user, 
                                    :music_session => music_session, 
                                    :ip_address => "1.1.1.1", 
                                    :client_id => "1")

    connection.idle?.should be_true
  end

  it 'transitions properly' do
    connection = FactoryGirl.create(:connection, 
                                    :user => user, 
                                    :music_session => music_session, 
                                    :ip_address => "1.1.1.1", 
                                    :client_id => "1")

    connection.connect!
    connection.connected?.should be_true
    connection.state_message.should == 'Connected'

    connection.stale!
    connection.stale?.should be_true
    connection.state_message.should == 'Stale'

    connection.expire!
    connection.destroyed?.should be_true
  end

end
