fix the login test for locidispid and add a test for reconnect
This commit is contained in:
parent
ab1143c9a8
commit
6ee68e8943
|
|
@ -58,7 +58,7 @@ describe ConnectionManager do
|
|||
end
|
||||
|
||||
it "create connection then delete it" do
|
||||
|
||||
|
||||
client_id = "client_id2"
|
||||
#user_id = create_user("test", "user2", "user2@jamkazam.com")
|
||||
user = FactoryGirl.create(:user)
|
||||
|
|
@ -89,7 +89,7 @@ describe ConnectionManager do
|
|||
cc.connected?.should be_true
|
||||
cc.ip_address.should eql("1.1.1.1")
|
||||
cc.addr.should == 0x01010101
|
||||
cc.locidispid == 0
|
||||
cc.locidispid.should == 17192000002
|
||||
cc.latitude.should == 30.2076
|
||||
cc.longitude.should == -97.8587
|
||||
cc.city.should eql('Austin')
|
||||
|
|
@ -99,7 +99,7 @@ describe ConnectionManager do
|
|||
x = User.find(user.id)
|
||||
#x.ip_address.should eql("1.1.1.1")
|
||||
x.addr.should == 0x01010101
|
||||
x.locidispid == 0
|
||||
x.locidispid.should == 17192000002
|
||||
x.lat.should == 30.2076
|
||||
x.lng.should == -97.8587
|
||||
x.city.should eql('Austin')
|
||||
|
|
@ -115,6 +115,100 @@ describe ConnectionManager do
|
|||
end
|
||||
end
|
||||
|
||||
it "create connection, reconnect, then delete it" do
|
||||
|
||||
client_id = "client_id3"
|
||||
#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).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.should == 17192000002
|
||||
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.should == 17192000002
|
||||
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
|
||||
|
||||
@connman.reconnect(cc, nil, "33.1.2.3") { |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
|
||||
}
|
||||
|
||||
cc = Connection.find_by_client_id!(client_id)
|
||||
cc.connected?.should be_true
|
||||
cc.ip_address.should eql("33.1.2.3")
|
||||
cc.addr.should == 0x21010203
|
||||
cc.locidispid.should == 30350000003
|
||||
cc.latitude.should == 29.7633
|
||||
cc.longitude.should == -95.3633
|
||||
cc.city.should eql('Houston')
|
||||
cc.region.should eql('TX')
|
||||
cc.countrycode.should eql('US')
|
||||
|
||||
x = User.find(user.id)
|
||||
#x.ip_address.should eql("33.1.2.3")
|
||||
x.addr.should == 0x21010203
|
||||
x.locidispid.should == 30350000003
|
||||
x.lat.should == 29.7633
|
||||
x.lng.should == -95.3633
|
||||
x.city.should eql('Houston')
|
||||
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).to_i.should == 0
|
||||
end
|
||||
end
|
||||
|
||||
# it "create connection creates user joined message appropriately" do
|
||||
|
||||
# client_id = "client_id3"
|
||||
|
|
|
|||
Loading…
Reference in New Issue