fix and test user updates upon login
This commit is contained in:
parent
8c65c272ec
commit
ab1143c9a8
|
|
@ -48,6 +48,10 @@ describe ConnectionManager do
|
||||||
it "can't create two client_ids of same value" do
|
it "can't create two client_ids of same value" do
|
||||||
client_id = "client_id1"
|
client_id = "client_id1"
|
||||||
user_id = create_user("test", "user1", "user1@jamkazam.com")
|
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")
|
@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)
|
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
|
it "create connection then delete it" do
|
||||||
|
|
||||||
client_id = "client_id2"
|
client_id = "client_id2"
|
||||||
user_id = create_user("test", "user2", "user2@jamkazam.com")
|
#user_id = create_user("test", "user2", "user2@jamkazam.com")
|
||||||
count = @connman.create_connection(user_id, client_id, "1.1.1.1")
|
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
|
count.should == 1
|
||||||
|
|
||||||
# make sure the connection is seen
|
# make sure the connection is seen
|
||||||
|
|
||||||
@conn.exec("SELECT count(*) FROM connections where user_id = $1", [user_id]) do |result|
|
@conn.exec("SELECT count(*) FROM connections where user_id = $1", [user.id]) do |result|
|
||||||
result.getvalue(0, 0).should == "1"
|
result.getvalue(0, 0).to_i.should == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
cc = Connection.find_by_client_id!(client_id)
|
cc = Connection.find_by_client_id!(client_id)
|
||||||
cc.connected?.should be_true
|
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 = @connman.delete_connection(client_id)
|
||||||
count.should == 0
|
count.should == 0
|
||||||
|
|
||||||
@conn.exec("SELECT count(*) FROM connections where user_id = $1", [user_id]) do |result|
|
@conn.exec("SELECT count(*) FROM connections where user_id = $1", [user.id]) do |result|
|
||||||
result.getvalue(0, 0).should == "0"
|
result.getvalue(0, 0).to_i.should == 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,19 +2,14 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe GetWork do
|
describe GetWork do
|
||||||
|
|
||||||
before(:each) do
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
it "get_work_1" do
|
it "get_work_1" do
|
||||||
x = GetWork.get_work(1)
|
x = GetWork.get_work(0)
|
||||||
puts x.inspect
|
|
||||||
x.should be_nil
|
x.should be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "get_work_list_1" do
|
it "get_work_list_1" do
|
||||||
x = GetWork.get_work_list(1)
|
x = GetWork.get_work_list(0)
|
||||||
puts x.inspect
|
|
||||||
x.should eql([])
|
x.should eql([])
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
@ -487,7 +487,7 @@ module JamWebsockets
|
||||||
ConnectionManager.active_record_transaction do |connection_manager|
|
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|
|
music_session_id, reconnected = connection_manager.reconnect(connection, reconnect_music_session_id, remote_ip) do |addr, locidispid, latitude, longitude, countrycode, region, city|
|
||||||
# update user
|
# update user
|
||||||
user.ip_address = remote_ip
|
#user.ip_address = remote_ip
|
||||||
user.addr = addr
|
user.addr = addr
|
||||||
user.locidispid = locidispid
|
user.locidispid = locidispid
|
||||||
user.lat = latitude
|
user.lat = latitude
|
||||||
|
|
@ -543,7 +543,7 @@ module JamWebsockets
|
||||||
user.country = countrycode
|
user.country = countrycode
|
||||||
user.state = region
|
user.state = region
|
||||||
user.city = city;
|
user.city = city;
|
||||||
user.save!
|
user.save!(validation: false)
|
||||||
|
|
||||||
if count == 1
|
if count == 1
|
||||||
Notification.send_friend_update(user.id, true, conn)
|
Notification.send_friend_update(user.id, true, conn)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue