geo_ip_test.rb 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. require 'integration_test_helper'
  2. class GeoIpTest < ActiveSupport::TestCase
  3. # check
  4. test 'check some results' do
  5. result = Service::GeoIp.location('127.0.0.0.1')
  6. assert(result)
  7. assert_nil(result['country_name'])
  8. assert_nil(result['city_name'])
  9. assert_nil(result['country_code'])
  10. assert_nil(result['continent_code'])
  11. assert_nil(result['latitude'])
  12. assert_nil(result['longitude'])
  13. result = Service::GeoIp.location('127.0.0.1')
  14. assert(result)
  15. assert_nil(result['country_name'])
  16. assert_nil(result['city_name'])
  17. assert_nil(result['country_code'])
  18. assert_nil(result['continent_code'])
  19. assert_nil(result['latitude'])
  20. assert_nil(result['longitude'])
  21. result = Service::GeoIp.location('195.65.29.254')
  22. assert(result)
  23. assert_equal('Switzerland', result['country_name'])
  24. assert_equal('Regensdorf', result['city_name'])
  25. assert_equal('CH', result['country_code'])
  26. assert_equal('EU', result['continent_code'])
  27. assert_equal(47.4341, result['latitude'])
  28. assert_equal(8.4687, result['longitude'])
  29. result = Service::GeoIp.location('134.109.140.74')
  30. assert(result)
  31. assert_equal('Germany', result['country_name'])
  32. assert_equal('Chemnitz', result['city_name'])
  33. assert_equal('DE', result['country_code'])
  34. assert_equal('EU', result['continent_code'])
  35. assert_equal(50.8197, result['latitude'])
  36. assert_equal(12.9403, result['longitude'])
  37. result = Service::GeoIp.location('46.253.55.170')
  38. assert(result)
  39. assert_equal('Germany', result['country_name'])
  40. assert_equal('Halle', result['city_name'])
  41. assert_equal('DE', result['country_code'])
  42. assert_equal('EU', result['continent_code'])
  43. assert_equal(51.5036, result['latitude'])
  44. assert_equal(11.9594, result['longitude'])
  45. result = Service::GeoIp.location('169.229.216.200')
  46. assert(result)
  47. assert_equal('United States', result['country_name'])
  48. assert_equal('Alameda', result['city_name'])
  49. assert_equal('US', result['country_code'])
  50. assert_equal('NA', result['continent_code'])
  51. assert_equal(37.7688, result['latitude'])
  52. assert_equal(-122.262, result['longitude'])
  53. end
  54. end