56 lines
2.0 KiB
Ruby
56 lines
2.0 KiB
Ruby
|
|
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
|
||
|
|
@user.lat.should == @geocode1.lat
|
||
|
|
@user.lng.should == @geocode1.lng
|
||
|
|
end
|
||
|
|
it "should have updated lat/lng values" do
|
||
|
|
@user.update_attributes({ :city => @geocode2.city,
|
||
|
|
:state => @geocode2.region,
|
||
|
|
:country => @geocode2.country,
|
||
|
|
})
|
||
|
|
@user.lat.should == @geocode2.lat
|
||
|
|
@user.lng.should == @geocode2.lng
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
describe "without profile location data" do
|
||
|
|
it "should have lat/lng values from ip_address" do
|
||
|
|
@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')
|
||
|
|
@user.lat.should == @geocode1.lat
|
||
|
|
@user.lng.should == @geocode1.lng
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
end
|