Skip to content

Commit 5c05794

Browse files
committed
more rubocop stuff
1 parent 7c8c0df commit 5c05794

File tree

6 files changed

+121
-95
lines changed

6 files changed

+121
-95
lines changed

.rubocop.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
AllCops:
2-
TargetRubyVersion: 2.7
2+
TargetRubyVersion: 2.5
3+
NewCops: enable
34

45
Layout/IndentationWidth:
56
Width: 4
67

78
Layout/LineLength:
89
Enabled: true
910
Max: 80
11+
12+
Metrics/MethodLength:
13+
Enabled: false
14+
15+
Metrics/AbcSize:
16+
Enabled: false
17+
18+
Lint/DuplicateMethods:
19+
Enabled: false
20+
21+
Style/MethodCallWithArgsParentheses:
22+
AllowParenthesesInMultilineCall: true
23+
AllowParenthesesInChaining: true
24+
AllowParenthesesInCamelCaseMethod: true

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ group :development do
1515
gem 'webmock'
1616

1717
platforms :mri do
18-
# to avoid problems, bring Byebug in on just versions of Ruby under which
19-
# it's known to work well
18+
# to avoid problems, bring Byebug in on just versions of Ruby under
19+
# which it's known to work well
2020
if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.0.0')
2121
gem 'byebug'
2222
gem 'pry'

lib/ipinfo.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ module IPinfo
1414
DEFAULT_CACHE_TTL = 60 * 60 * 24
1515
DEFAULT_COUNTRY_FILE = File.join(File.dirname(__FILE__),
1616
'ipinfo/countries.json')
17-
RATE_LIMIT_MESSAGE = 'To increase your limits, please review our paid plans at https://ipinfo.io/pricing'
17+
RATE_LIMIT_MESSAGE = 'To increase your limits, please review our ' \
18+
'paid plans at https://ipinfo.io/pricing'
1819

1920
class << self
2021
def create(access_token = nil, settings = {})
@@ -40,8 +41,7 @@ def details(ip_address = nil)
4041
details = request_details(ip_address)
4142
if details.key? :country
4243
details[:country_name] =
43-
@countries.fetch(details.fetch(:country),
44-
nil)
44+
@countries.fetch(details.fetch(:country), nil)
4545
end
4646

4747
if details.key? :ip

lib/ipinfo/cache/default_cache.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
module IPinfo
77
class DefaultCache < CacheInterface
88
def initialize(ttl, max_size)
9+
super
910
@cache = LruRedux::TTL::Cache.new(max_size, ttl)
1011
end
1112

test/ipinfo_test.rb

Lines changed: 87 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -3,104 +3,106 @@
33
require 'test_helper'
44

55
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'
88

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
1212

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
1818

19-
def test_set_access_token
20-
ipinfo = IPinfo.create('test_token')
19+
def test_set_access_token
20+
ipinfo = IPinfo.create('test_token')
2121

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
2626

27-
ipinfo.access_token = nil
28-
end
27+
ipinfo.access_token = nil
28+
end
2929

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
3739

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+
}
5355

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
6265
end
63-
end
6466

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+
}
7880

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
8386
end
84-
end
8587

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+
}
99101

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
104107
end
105-
end
106108
end

test/lib/adapter_test.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ module IPinfo
77
class AdapterTest < Minitest::Test
88
def test_default
99
adapter = IPinfo::Adapter.new
10-
assert(adapter.conn.builder.handlers[0] === Faraday::Adapter::NetHttp)
10+
assert_equal(
11+
adapter.conn.builder.handlers[0],
12+
Faraday::Adapter::NetHttp
13+
)
1114
end
1215

1316
SUPPORTED_ADAPTERS = {
@@ -25,14 +28,19 @@ def test_unsupported_adapter
2528
error = assert_raises(Faraday::Error) do
2629
IPinfo::Adapter.new(nil, :missing_adapter)
2730
end
28-
assert_equal error.message,
29-
':missing_adapter is not registered on Faraday::Adapter'
31+
assert_equal(
32+
error.message,
33+
':missing_adapter is not registered on Faraday::Adapter'
34+
)
3035
end
3136

3237
def test_all_possible_adapters
3338
SUPPORTED_ADAPTERS.each_key do |key|
3439
adapter = IPinfo::Adapter.new(nil, key)
35-
assert(adapter.conn.builder.handlers[0] === SUPPORTED_ADAPTERS[key])
40+
assert_equal(
41+
adapter.conn.builder.handlers[0],
42+
SUPPORTED_ADAPTERS[key]
43+
)
3644
end
3745
end
3846
end

0 commit comments

Comments
 (0)