2013-11-03 06:43:09 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
|
|
describe User do
|
|
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
X If user provides profile location data, that will be used for lat/lng lookup
|
|
|
|
|
X If the user changes their profile location, we update their lat/lng address
|
|
|
|
|
X If no profile location is provided, then we populate lat/lng from their IP address
|
|
|
|
|
X If no profile location is provided, and the user creates/joins a music session, then we update their lat/lng from the IP address
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
@geocode1 = FactoryGirl.create(:geocoder)
|
|
|
|
|
@geocode2 = FactoryGirl.create(:geocoder)
|
|
|
|
|
@user = User.new(first_name: "Example", last_name: "User", email: "user@example.com",
|
|
|
|
|
password: "foobar", password_confirmation: "foobar",
|
|
|
|
|
city: "Apex", state: "NC", country: "US",
|
|
|
|
|
terms_of_service: true, musician: true)
|
|
|
|
|
@user.save!
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "with profile location data" do
|
|
|
|
|
it "should have lat/lng values" do
|
2014-03-17 17:21:32 +00:00
|
|
|
pending 'distance search changes'
|
2013-11-03 14:08:25 +00:00
|
|
|
geo = MaxMindGeo.find_by_city(@user.city)
|
|
|
|
|
@user.lat.should == geo.lat
|
|
|
|
|
@user.lng.should == geo.lng
|
2013-11-03 06:43:09 +00:00
|
|
|
end
|
2014-03-17 17:21:32 +00:00
|
|
|
|
2013-11-03 06:43:09 +00:00
|
|
|
it "should have updated lat/lng values" do
|
2014-03-17 17:21:32 +00:00
|
|
|
pending 'distance search changes'
|
2013-11-03 06:43:09 +00:00
|
|
|
@user.update_attributes({ :city => @geocode2.city,
|
|
|
|
|
:state => @geocode2.region,
|
|
|
|
|
:country => @geocode2.country,
|
|
|
|
|
})
|
2013-11-03 14:08:25 +00:00
|
|
|
geo = MaxMindGeo.find_by_city(@user.city)
|
|
|
|
|
@user.lat.should == geo.lat
|
|
|
|
|
@user.lng.should == geo.lng
|
2013-11-03 06:43:09 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "without profile location data" do
|
|
|
|
|
it "should have lat/lng values from ip_address" do
|
2014-03-17 17:21:32 +00:00
|
|
|
pending 'distance search changes'
|
2013-11-03 06:43:09 +00:00
|
|
|
@user.update_attributes({ :city => nil,
|
|
|
|
|
:state => nil,
|
|
|
|
|
:country => nil,
|
|
|
|
|
})
|
|
|
|
|
@user.lat.should == nil
|
|
|
|
|
@user.lng.should == nil
|
|
|
|
|
geo = JamRuby::MaxMindGeo.ip_lookup('1.1.0.0')
|
|
|
|
|
geo.should_not be_nil
|
|
|
|
|
geo = JamRuby::MaxMindGeo.ip_lookup('1.1.0.255')
|
|
|
|
|
geo.should_not be_nil
|
|
|
|
|
@user.update_lat_lng('1.1.0.255')
|
2013-11-03 14:08:25 +00:00
|
|
|
@user.lat.should == geo.lat
|
|
|
|
|
@user.lng.should == geo.lng
|
2013-11-03 06:43:09 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|