|
3 | 3 | require 'test_helper' |
4 | 4 |
|
5 | 5 | class IPinfoTest < Minitest::Test |
6 | | - IP4 = '195.233.174.116' |
7 | | - IP6 = '2601:9:7680:363:75df:f491:6f85:352f' |
| 6 | + IP4 = '195.233.174.116' |
| 7 | + IP6 = '2601:9:7680:363:75df:f491:6f85:352f' |
8 | 8 |
|
9 | | - def test_that_it_has_a_version_number |
10 | | - refute_nil ::IPinfo::VERSION |
11 | | - end |
| 9 | + def test_that_it_has_a_version_number |
| 10 | + refute_nil ::IPinfo::VERSION |
| 11 | + end |
12 | 12 |
|
13 | | - def test_set_adapter |
14 | | - ipinfo = IPinfo.create(nil, { http_client: :excon }) |
15 | | - assert ipinfo.http_client = :excon |
16 | | - ipinfo.http_client = nil |
17 | | - end |
| 13 | + def test_set_adapter |
| 14 | + ipinfo = IPinfo.create(nil, { http_client: :excon }) |
| 15 | + assert ipinfo.http_client = :excon |
| 16 | + ipinfo.http_client = nil |
| 17 | + end |
18 | 18 |
|
19 | | - def test_set_access_token |
20 | | - ipinfo = IPinfo.create('test_token') |
| 19 | + def test_set_access_token |
| 20 | + ipinfo = IPinfo.create('test_token') |
21 | 21 |
|
22 | | - VCR.use_cassette('lookup_with_token') do |
23 | | - ipinfo.details |
24 | | - assert_requested :get, 'https://ipinfo.io?token=test_token' |
25 | | - end |
| 22 | + VCR.use_cassette('lookup_with_token') do |
| 23 | + ipinfo.details |
| 24 | + assert_requested :get, 'https://ipinfo.io?token=test_token' |
| 25 | + end |
26 | 26 |
|
27 | | - ipinfo.access_token = nil |
28 | | - end |
| 27 | + ipinfo.access_token = nil |
| 28 | + end |
29 | 29 |
|
30 | | - def test_rate_limit_error |
31 | | - ipinfo = IPinfo.create |
32 | | - stub_request(:get, 'https://ipinfo.io').to_return(body: '', status: 429) |
33 | | - error = assert_raises(IPinfo::RateLimitError) { ipinfo.details } |
34 | | - assert_equal |
35 | | -'To increase your limits, please review our paid plans at https://ipinfo.io/pricing', error.message |
36 | | - end |
| 30 | + def test_rate_limit_error |
| 31 | + ipinfo = IPinfo.create |
| 32 | + stub_request(:get, 'https://ipinfo.io').to_return(body: '', status: 429) |
| 33 | + error = assert_raises(IPinfo::RateLimitError) { ipinfo.details } |
| 34 | + assert_equal \ |
| 35 | + 'To increase your limits, please review our paid plans at ' \ |
| 36 | + 'https://ipinfo.io/pricing', \ |
| 37 | + error.message |
| 38 | + end |
37 | 39 |
|
38 | | - def test_lookup_without_arg |
39 | | - expected = { |
40 | | - ip: '110.171.151.183', |
41 | | - ip_address: IPAddr.new('110.171.151.183'), |
42 | | - hostname: 'cm-110-171-151-183.revip7.asianet.co.th', |
43 | | - city: 'Chiang Mai', |
44 | | - region: 'Chiang Mai Province', |
45 | | - country: 'TH', |
46 | | - country_name: 'Thailand', |
47 | | - loc: '18.7904,98.9847', |
48 | | - latitude: '18.7904', |
49 | | - longitude: '98.9847', |
50 | | - org: 'AS17552 TRUE INTERNET CO., LTD.', |
51 | | - postal: '50000' |
52 | | - } |
| 40 | + def test_lookup_without_arg |
| 41 | + expected = { |
| 42 | + ip: '110.171.151.183', |
| 43 | + ip_address: IPAddr.new('110.171.151.183'), |
| 44 | + hostname: 'cm-110-171-151-183.revip7.asianet.co.th', |
| 45 | + city: 'Chiang Mai', |
| 46 | + region: 'Chiang Mai Province', |
| 47 | + country: 'TH', |
| 48 | + country_name: 'Thailand', |
| 49 | + loc: '18.7904,98.9847', |
| 50 | + latitude: '18.7904', |
| 51 | + longitude: '98.9847', |
| 52 | + org: 'AS17552 TRUE INTERNET CO., LTD.', |
| 53 | + postal: '50000' |
| 54 | + } |
53 | 55 |
|
54 | | - VCR.use_cassette('current machine search') do |
55 | | - ipinfo = IPinfo.create |
56 | | - response = ipinfo.details |
57 | | - assert_instance_of IPinfo::Response, response |
58 | | - assert_equal expected[:ip], response.ip |
59 | | - assert_instance_of IPAddr, response.ip_address |
60 | | - assert_equal expected[:country_name], response.country_name |
61 | | - assert_equal expected, response.all |
| 56 | + VCR.use_cassette('current machine search') do |
| 57 | + ipinfo = IPinfo.create |
| 58 | + response = ipinfo.details |
| 59 | + assert_instance_of IPinfo::Response, response |
| 60 | + assert_equal expected[:ip], response.ip |
| 61 | + assert_instance_of IPAddr, response.ip_address |
| 62 | + assert_equal expected[:country_name], response.country_name |
| 63 | + assert_equal expected, response.all |
| 64 | + end |
62 | 65 | end |
63 | | - end |
64 | 66 |
|
65 | | - def test_lookup_ip6 |
66 | | - expected = { |
67 | | - ip: IP6, |
68 | | - ip_address: IPAddr.new(IP6), |
69 | | - city: '', |
70 | | - region: '', |
71 | | - country: 'US', |
72 | | - country_name: 'United States', |
73 | | - loc: '37.7510,-97.8220', |
74 | | - latitude: '37.7510', |
75 | | - longitude: '-97.8220', |
76 | | - org: 'AS7922 Comcast Cable Communications, LLC' |
77 | | - } |
| 67 | + def test_lookup_ip6 |
| 68 | + expected = { |
| 69 | + ip: IP6, |
| 70 | + ip_address: IPAddr.new(IP6), |
| 71 | + city: '', |
| 72 | + region: '', |
| 73 | + country: 'US', |
| 74 | + country_name: 'United States', |
| 75 | + loc: '37.7510,-97.8220', |
| 76 | + latitude: '37.7510', |
| 77 | + longitude: '-97.8220', |
| 78 | + org: 'AS7922 Comcast Cable Communications, LLC' |
| 79 | + } |
78 | 80 |
|
79 | | - VCR.use_cassette('search with ip6') do |
80 | | - ipinfo = IPinfo.create |
81 | | - response = ipinfo.details(IP6) |
82 | | - assert_equal expected, response.all |
| 81 | + VCR.use_cassette('search with ip6') do |
| 82 | + ipinfo = IPinfo.create |
| 83 | + response = ipinfo.details(IP6) |
| 84 | + assert_equal expected, response.all |
| 85 | + end |
83 | 86 | end |
84 | | - end |
85 | 87 |
|
86 | | - def test_lookup_ip4 |
87 | | - expected = { |
88 | | - ip: IP4, |
89 | | - ip_address: IPAddr.new(IP4), |
90 | | - city: '', |
91 | | - region: '', |
92 | | - country: 'DE', |
93 | | - country_name: 'Germany', |
94 | | - loc: '51.2993,9.4910', |
95 | | - latitude: '51.2993', |
96 | | - longitude: '9.4910', |
97 | | - org: 'AS12663 Vodafone Italia S.p.A.' |
98 | | - } |
| 88 | + def test_lookup_ip4 |
| 89 | + expected = { |
| 90 | + ip: IP4, |
| 91 | + ip_address: IPAddr.new(IP4), |
| 92 | + city: '', |
| 93 | + region: '', |
| 94 | + country: 'DE', |
| 95 | + country_name: 'Germany', |
| 96 | + loc: '51.2993,9.4910', |
| 97 | + latitude: '51.2993', |
| 98 | + longitude: '9.4910', |
| 99 | + org: 'AS12663 Vodafone Italia S.p.A.' |
| 100 | + } |
99 | 101 |
|
100 | | - VCR.use_cassette('search with random ip') do |
101 | | - ipinfo = IPinfo.create |
102 | | - response = ipinfo.details(IP4) |
103 | | - assert_equal expected, response.all |
| 102 | + VCR.use_cassette('search with random ip') do |
| 103 | + ipinfo = IPinfo.create |
| 104 | + response = ipinfo.details(IP4) |
| 105 | + assert_equal expected, response.all |
| 106 | + end |
104 | 107 | end |
105 | | - end |
106 | 108 | end |
0 commit comments