2012-10-07 04:53:54 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
2014-04-29 03:38:30 +00:00
|
|
|
describe JamRuby::Connection do
|
2013-02-06 13:14:00 +00:00
|
|
|
let(:user) { FactoryGirl.create(:user) }
|
2014-05-06 13:34:38 +00:00
|
|
|
let (:music_session) { FactoryGirl.create(:active_music_session, :creator => user) }
|
2014-06-09 20:43:16 +00:00
|
|
|
let (:conn) { FactoryGirl.create(:connection,
|
|
|
|
|
:user => user,
|
|
|
|
|
:music_session => music_session,
|
|
|
|
|
:ip_address => "1.1.1.1",
|
|
|
|
|
:client_id => "1") }
|
2012-10-07 04:53:54 +00:00
|
|
|
|
2014-10-06 22:02:33 +00:00
|
|
|
let(:tracks) { [{'sound' => 'mono', 'client_track_id' => 'abc', 'instrument_id' => 'piano'}] }
|
|
|
|
|
|
2013-02-06 13:14:00 +00:00
|
|
|
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'
|
|
|
|
|
|
2013-02-11 06:02:25 +00:00
|
|
|
connection.stale!
|
|
|
|
|
connection.stale?.should be_true
|
|
|
|
|
connection.state_message.should == 'Stale'
|
2013-02-06 13:14:00 +00:00
|
|
|
|
|
|
|
|
connection.expire!
|
|
|
|
|
connection.destroyed?.should be_true
|
|
|
|
|
end
|
|
|
|
|
|
2013-11-03 13:10:21 +00:00
|
|
|
it 'updates user lat/lng' do
|
2014-03-17 17:21:32 +00:00
|
|
|
pending 'distance search changes'
|
2013-11-03 13:10:21 +00:00
|
|
|
uu = FactoryGirl.create(:user)
|
|
|
|
|
uu.lat.should == nil
|
2014-05-06 13:34:38 +00:00
|
|
|
msess = FactoryGirl.create(:active_music_session, :creator => uu)
|
2013-11-03 13:10:21 +00:00
|
|
|
geocode = FactoryGirl.create(:geocoder)
|
|
|
|
|
connection = FactoryGirl.create(:connection,
|
|
|
|
|
:user => uu,
|
|
|
|
|
:music_session => msess,
|
|
|
|
|
:ip_address => "1.1.1.1",
|
|
|
|
|
:client_id => "1")
|
|
|
|
|
user.lat.should == geocode.lat
|
|
|
|
|
user.lng.should == geocode.lng
|
|
|
|
|
end
|
|
|
|
|
|
2014-06-09 20:43:16 +00:00
|
|
|
describe "audio latency" do
|
|
|
|
|
it "allow update" do
|
|
|
|
|
conn.last_jam_audio_latency = 1
|
|
|
|
|
conn.save!
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "prevent negative or 0" do
|
|
|
|
|
conn.last_jam_audio_latency = 0
|
|
|
|
|
conn.save.should be_false
|
|
|
|
|
conn.errors[:last_jam_audio_latency].should == ['must be greater than 0']
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "prevent non numerical" do
|
|
|
|
|
conn.last_jam_audio_latency = 'a'
|
|
|
|
|
conn.save.should be_false
|
|
|
|
|
conn.errors[:last_jam_audio_latency].should == ['is not a number']
|
|
|
|
|
end
|
|
|
|
|
end
|
2014-07-20 02:11:16 +00:00
|
|
|
|
|
|
|
|
describe "update_locidispids" do
|
|
|
|
|
|
|
|
|
|
before(:each) do
|
|
|
|
|
create_phony_database
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
after(:all) do
|
|
|
|
|
create_phony_database
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "updates locidispid with valid maxmind data" do
|
|
|
|
|
conn.locidispid.should == 0 # default in factory girl
|
|
|
|
|
Connection.update_locidispids(false)
|
|
|
|
|
conn.reload
|
|
|
|
|
conn.locidispid.should == 17192 * 1000000 + JamIsp.lookup(conn.addr).coid
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "updates locidispid to 0 with no maxmind data" do
|
|
|
|
|
# delete the ATX location info, and update. should be 0
|
|
|
|
|
conn.locidispid = 5 # make it not zero to start
|
|
|
|
|
conn.save!
|
|
|
|
|
GeoIpLocations.connection.execute("DELETE from geoiplocations where city = 'Austin'").check
|
|
|
|
|
Connection.update_locidispids(false)
|
|
|
|
|
conn.reload
|
|
|
|
|
conn.locidispid.should == 0
|
|
|
|
|
end
|
|
|
|
|
end
|
2014-10-06 21:17:46 +00:00
|
|
|
|
2014-12-07 22:04:10 +00:00
|
|
|
describe "triggers" do
|
|
|
|
|
describe "manage_user_online" do
|
|
|
|
|
it "offline for new user" do
|
|
|
|
|
user.online.should be_false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "online/offline based on connection up/down" do
|
|
|
|
|
conn.touch # make a connection
|
|
|
|
|
user.reload
|
|
|
|
|
user.online.should be_true
|
|
|
|
|
|
|
|
|
|
conn.delete
|
|
|
|
|
user.reload
|
|
|
|
|
user.online.should be_false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "verify that online up/down is only for affected user (no spillover)" do
|
|
|
|
|
user2 = FactoryGirl.create(:user)
|
|
|
|
|
user2.online.should be_false
|
|
|
|
|
|
|
|
|
|
conn.touch
|
|
|
|
|
user.reload
|
|
|
|
|
user2.reload
|
|
|
|
|
|
|
|
|
|
user.online.should be_true
|
|
|
|
|
user2.online.should be_false # make sure there is no spillover to unrelated users
|
|
|
|
|
|
|
|
|
|
conn2 = FactoryGirl.create(:connection,
|
|
|
|
|
:user => user2,
|
|
|
|
|
:music_session => music_session,
|
|
|
|
|
:ip_address => "1.1.1.1",
|
|
|
|
|
:client_id => "2")
|
|
|
|
|
|
|
|
|
|
user.reload
|
|
|
|
|
user2.reload
|
|
|
|
|
|
|
|
|
|
user.online.should be_true
|
|
|
|
|
user2.online.should be_true
|
|
|
|
|
|
|
|
|
|
# whack one of the connections
|
|
|
|
|
conn.delete
|
|
|
|
|
user.reload
|
|
|
|
|
user2.reload
|
|
|
|
|
user.online.should be_false
|
|
|
|
|
user2.online.should be_true
|
|
|
|
|
|
|
|
|
|
conn2.delete
|
|
|
|
|
user.reload
|
|
|
|
|
user2.reload
|
|
|
|
|
user.online.should be_false
|
|
|
|
|
user2.online.should be_false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "n connections" do
|
|
|
|
|
conn.touch
|
|
|
|
|
conn2 = FactoryGirl.create(:connection,
|
|
|
|
|
:user => user,
|
|
|
|
|
:music_session => music_session,
|
|
|
|
|
:ip_address => "1.1.1.1",
|
|
|
|
|
:client_id => "2")
|
|
|
|
|
|
|
|
|
|
user.reload
|
|
|
|
|
user.online.should be_true
|
|
|
|
|
|
|
|
|
|
conn.delete
|
|
|
|
|
user.reload
|
|
|
|
|
user.online.should be_true
|
|
|
|
|
|
|
|
|
|
conn2.delete
|
|
|
|
|
user.reload
|
|
|
|
|
user.online.should be_false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
end
|
2014-12-30 23:10:16 +00:00
|
|
|
|
|
|
|
|
describe "stats" do
|
|
|
|
|
|
|
|
|
|
it "no connections" do
|
|
|
|
|
stats = Connection.stats
|
|
|
|
|
stats[Connection::TYPE_CLIENT].should eq(0)
|
|
|
|
|
stats[Connection::TYPE_BROWSER].should eq(0)
|
|
|
|
|
stats[Connection::TYPE_LATENCY_TESTER].should eq(0)
|
|
|
|
|
stats['count'].should eq(0)
|
|
|
|
|
stats['scoring_timeout'].should eq(0)
|
|
|
|
|
stats['in_session'].should eq(0)
|
|
|
|
|
stats['musicians'].should eq(0)
|
|
|
|
|
stats['udp_reachable'].should eq(0)
|
|
|
|
|
stats['networking_testing'].should eq(0)
|
|
|
|
|
end
|
|
|
|
|
end
|
2013-02-06 13:14:00 +00:00
|
|
|
end
|