-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Removes sporadically failing tests relying on possibly outdated info. * Renames GeoIPCountry to GeoLocation because we're not using geo_ip gem anymore.
- Loading branch information
Showing
6 changed files
with
45 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'maxminddb' | ||
|
||
class GeoLocation | ||
MMDB_PATH = Rails.root + 'config/GeoLite2-Country.mmdb' | ||
CACHE_KEY = 'maxmind_db' | ||
|
||
class << self | ||
# Looks up an IP address to find out what country it's coming from. | ||
# @return [String] capitalized, two-character ISO country code of the IP's | ||
# origin according to our current copy of MaxMindDB's GeoLite2 Country db. | ||
def country_code(id) | ||
mmdb.lookup(ip).country.iso_code | ||
end | ||
|
||
# Caches a new instance of MaxMindDB::Client at CACHE_KEY loaded with data | ||
# from MMDB_PATH and returns it. | ||
# @return [MaxMindDB::Client] client instance used to look up country of | ||
# origin for IP address. | ||
def mmdb | ||
Rails.cache.fetch(CACHE_KEY) { MaxMindDB.new(MMDB_PATH) } | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'geo_location' | ||
require 'resolv' | ||
|
||
describe GeoLocation do | ||
describe '.country_code' do | ||
let(:subject) { GeoLocation.country_code(ip) } | ||
|
||
context 'when IP is invalid' do | ||
let(:ip) { '0.0.0.0' } | ||
it { is_expected.to be_nil } | ||
end | ||
|
||
context 'when IP is valid' do | ||
let(:ip) { Resolv.getaddress('americanarchive.org') } | ||
it { is_expected.to be_nil } | ||
end | ||
end | ||
end |