diff --git a/app/models/user_auth_token.rb b/app/models/user_auth_token.rb index ffe26e07cd0..0dcf75cbd30 100644 --- a/app/models/user_auth_token.rb +++ b/app/models/user_auth_token.rb @@ -36,7 +36,7 @@ class UserAuthToken < ActiveRecord::Base def self.login_location(ip) ipinfo = DiscourseIpInfo.get(ip) - ipinfo['latitude'] && ipinfo['longitude'] ? [ipinfo['latitude'], ipinfo['longitude']] : nil + ipinfo[:latitude] && ipinfo[:longitude] ? [ipinfo[:latitude], ipinfo[:longitude]] : nil end def self.distance(loc1, loc2) diff --git a/spec/jobs/suspicious_login_spec.rb b/spec/jobs/suspicious_login_spec.rb index 06b2bd76250..c1e9aa3dc18 100644 --- a/spec/jobs/suspicious_login_spec.rb +++ b/spec/jobs/suspicious_login_spec.rb @@ -4,20 +4,20 @@ describe Jobs::SuspiciousLogin do let(:user) { Fabricate(:moderator) } - let(:zurich) { [47.3686498, 8.5391825] } # Zurich, Switzerland - let(:bern) { [46.947922, 7.444608] } # Bern, Switzerland - let(:london) { [51.5073509, -0.1277583] } # London, United Kingdom + let(:zurich) { { latitude: 47.3686498, longitude: 8.5391825 } } # Zurich, Switzerland + let(:bern) { { latitude: 46.947922, longitude: 7.444608 } } # Bern, Switzerland + let(:london) { { latitude: 51.5073509, longitude: -0.1277583 } } # London, United Kingdom before do - UserAuthToken.stubs(:login_location).with("1.1.1.1").returns(zurich) - UserAuthToken.stubs(:login_location).with("1.1.1.2").returns(bern) - UserAuthToken.stubs(:login_location).with("1.1.2.1").returns(london) + DiscourseIpInfo.stubs(:get).with("1.1.1.1").returns(zurich) + DiscourseIpInfo.stubs(:get).with("1.1.1.2").returns(bern) + DiscourseIpInfo.stubs(:get).with("1.1.2.1").returns(london) end it "will correctly compute distance" do def expect_distance(from, to, distance) - expect(UserAuthToken.distance(from, to).to_i).to eq(distance) - expect(UserAuthToken.distance(to, from).to_i).to eq(distance) + expect(UserAuthToken.distance(from.values, to.values).to_i).to eq(distance) + expect(UserAuthToken.distance(to.values, from.values).to_i).to eq(distance) end expect_distance(zurich, bern, 95)