fix and test user updates upon login

This commit is contained in:
Scott Comer 2014-03-03 14:31:25 -06:00
parent 8c65c272ec
commit ab1143c9a8
3 changed files with 50 additions and 16 deletions

View File

@ -48,6 +48,10 @@ describe ConnectionManager do
it "can't create two client_ids of same value" do
client_id = "client_id1"
user_id = create_user("test", "user1", "user1@jamkazam.com")
user = User.find(user_id)
user.musician_instruments << FactoryGirl.build(:musician_instrument, user: user)
user.save!
user = nil
@connman.create_connection(user_id, client_id, "1.1.1.1")
expect { @connman.create_connection(user_id, client_id, "1.1.1.1") }.to raise_error(PG::Error)
@ -56,23 +60,58 @@ describe ConnectionManager do
it "create connection then delete it" do
client_id = "client_id2"
user_id = create_user("test", "user2", "user2@jamkazam.com")
count = @connman.create_connection(user_id, client_id, "1.1.1.1")
#user_id = create_user("test", "user2", "user2@jamkazam.com")
user = FactoryGirl.create(:user)
count = @connman.create_connection(user.id, client_id, "1.1.1.1") { |conn, count, addr, locidispid, latitude, longitude, countrycode, region, city|
# first update the user record with the current location
u = User.find(user.id)
u.addr = addr
u.locidispid = locidispid
u.lat = latitude
u.lng = longitude
u.country = countrycode
u.state = region
u.city = city;
u.save!
u = nil
}
count.should == 1
# make sure the connection is seen
@conn.exec("SELECT count(*) FROM connections where user_id = $1", [user_id]) do |result|
result.getvalue(0, 0).should == "1"
@conn.exec("SELECT count(*) FROM connections where user_id = $1", [user.id]) do |result|
result.getvalue(0, 0).to_i.should == 1
end
cc = Connection.find_by_client_id!(client_id)
cc.connected?.should be_true
cc.ip_address.should eql("1.1.1.1")
cc.addr.should == 0x01010101
cc.locidispid == 0
cc.latitude.should == 30.2076
cc.longitude.should == -97.8587
cc.city.should eql('Austin')
cc.region.should eql('TX')
cc.countrycode.should eql('US')
x = User.find(user.id)
#x.ip_address.should eql("1.1.1.1")
x.addr.should == 0x01010101
x.locidispid == 0
x.lat.should == 30.2076
x.lng.should == -97.8587
x.city.should eql('Austin')
x.state.should eql('TX')
x.country.should eql('US')
x = nil
count = @connman.delete_connection(client_id)
count.should == 0
@conn.exec("SELECT count(*) FROM connections where user_id = $1", [user_id]) do |result|
result.getvalue(0, 0).should == "0"
@conn.exec("SELECT count(*) FROM connections where user_id = $1", [user.id]) do |result|
result.getvalue(0, 0).to_i.should == 0
end
end

View File

@ -2,19 +2,14 @@ require 'spec_helper'
describe GetWork do
before(:each) do
end
it "get_work_1" do
x = GetWork.get_work(1)
puts x.inspect
x = GetWork.get_work(0)
x.should be_nil
end
it "get_work_list_1" do
x = GetWork.get_work_list(1)
puts x.inspect
x = GetWork.get_work_list(0)
x.should eql([])
end
end

View File

@ -487,7 +487,7 @@ module JamWebsockets
ConnectionManager.active_record_transaction do |connection_manager|
music_session_id, reconnected = connection_manager.reconnect(connection, reconnect_music_session_id, remote_ip) do |addr, locidispid, latitude, longitude, countrycode, region, city|
# update user
user.ip_address = remote_ip
#user.ip_address = remote_ip
user.addr = addr
user.locidispid = locidispid
user.lat = latitude
@ -543,7 +543,7 @@ module JamWebsockets
user.country = countrycode
user.state = region
user.city = city;
user.save!
user.save!(validation: false)
if count == 1
Notification.send_friend_update(user.id, true, conn)