google_distance_matrix 0.4.0 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +5 -5
  2. data/.editorconfig +16 -0
  3. data/.rubocop.yml +6 -0
  4. data/.ruby-version +1 -1
  5. data/.travis.yml +4 -6
  6. data/CHANGELOG.md +40 -0
  7. data/Gemfile +2 -0
  8. data/README.md +0 -3
  9. data/Rakefile +9 -4
  10. data/google_distance_matrix.gemspec +21 -19
  11. data/lib/google_distance_matrix.rb +25 -23
  12. data/lib/google_distance_matrix/client.rb +32 -18
  13. data/lib/google_distance_matrix/client_cache.rb +9 -3
  14. data/lib/google_distance_matrix/configuration.rb +39 -24
  15. data/lib/google_distance_matrix/errors.rb +6 -3
  16. data/lib/google_distance_matrix/log_subscriber.rb +14 -14
  17. data/lib/google_distance_matrix/logger.rb +7 -5
  18. data/lib/google_distance_matrix/matrix.rb +45 -22
  19. data/lib/google_distance_matrix/place.rb +37 -28
  20. data/lib/google_distance_matrix/places.rb +5 -4
  21. data/lib/google_distance_matrix/polyline_encoder.rb +2 -2
  22. data/lib/google_distance_matrix/polyline_encoder/delta.rb +4 -2
  23. data/lib/google_distance_matrix/polyline_encoder/value_encoder.rb +13 -5
  24. data/lib/google_distance_matrix/railtie.rb +4 -1
  25. data/lib/google_distance_matrix/route.rb +22 -15
  26. data/lib/google_distance_matrix/routes_finder.rb +27 -29
  27. data/lib/google_distance_matrix/url_builder.rb +44 -16
  28. data/lib/google_distance_matrix/url_builder/polyline_encoder_buffer.rb +3 -0
  29. data/lib/google_distance_matrix/version.rb +3 -1
  30. data/spec/lib/google_distance_matrix/client_cache_spec.rb +27 -11
  31. data/spec/lib/google_distance_matrix/client_spec.rb +40 -30
  32. data/spec/lib/google_distance_matrix/configuration_spec.rb +36 -24
  33. data/spec/lib/google_distance_matrix/log_subscriber_spec.rb +13 -44
  34. data/spec/lib/google_distance_matrix/logger_spec.rb +16 -13
  35. data/spec/lib/google_distance_matrix/matrix_spec.rb +90 -57
  36. data/spec/lib/google_distance_matrix/place_spec.rb +38 -25
  37. data/spec/lib/google_distance_matrix/places_spec.rb +29 -28
  38. data/spec/lib/google_distance_matrix/polyline_encoder/delta_spec.rb +5 -3
  39. data/spec/lib/google_distance_matrix/polyline_encoder_spec.rb +7 -2
  40. data/spec/lib/google_distance_matrix/route_spec.rb +11 -9
  41. data/spec/lib/google_distance_matrix/routes_finder_spec.rb +124 -81
  42. data/spec/lib/google_distance_matrix/url_builder_spec.rb +97 -48
  43. data/spec/spec_helper.rb +3 -1
  44. metadata +46 -18
@@ -1,11 +1,13 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
2
4
 
3
5
  describe GoogleDistanceMatrix::Configuration do
4
6
  include Shoulda::Matchers::ActiveModel
5
7
 
6
8
  subject { described_class.new }
7
9
 
8
- describe "Validations" do
10
+ describe 'Validations' do
9
11
  describe 'departure_time' do
10
12
  it 'is valid with a timestamp' do
11
13
  subject.departure_time = Time.now.to_i
@@ -46,28 +48,32 @@ describe GoogleDistanceMatrix::Configuration do
46
48
  end
47
49
  end
48
50
 
49
- it { should validate_inclusion_of(:mode).in_array(["driving", "walking", "bicycling", "transit"]) }
51
+ it { should validate_inclusion_of(:mode).in_array(%w[driving walking bicycling transit]) }
50
52
  it { should allow_value(nil).for(:mode) }
51
53
 
52
- it { should validate_inclusion_of(:avoid).in_array(["tolls", "highways", "ferries", "indoor"]) }
54
+ it { should validate_inclusion_of(:avoid).in_array(%w[tolls highways ferries indoor]) }
53
55
  it { should allow_value(nil).for(:avoid) }
54
56
 
55
- it { should validate_inclusion_of(:units).in_array(["metric", "imperial"]) }
57
+ it { should validate_inclusion_of(:units).in_array(%w[metric imperial]) }
56
58
  it { should allow_value(nil).for(:units) }
57
59
 
58
-
59
- it { should validate_inclusion_of(:protocol).in_array(["http", "https"]) }
60
-
61
- it { should validate_inclusion_of(:transit_mode).in_array(["bus", "subway", "train", "tram", "rail"])}
62
- it { should validate_inclusion_of(:transit_routing_preference).in_array(["less_walking", "fewer_transfers"])}
63
- it { should validate_inclusion_of(:traffic_model).in_array(["best_guess", "pessimistic", "optimistic"])}
60
+ it { should validate_inclusion_of(:protocol).in_array(%w[http https]) }
61
+
62
+ it { should validate_inclusion_of(:transit_mode).in_array(%w[bus subway train tram rail]) }
63
+ it {
64
+ should validate_inclusion_of(
65
+ :transit_routing_preference
66
+ ).in_array(%w[less_walking fewer_transfers])
67
+ }
68
+ it {
69
+ should validate_inclusion_of(:traffic_model).in_array(%w[best_guess pessimistic optimistic])
70
+ }
64
71
  end
65
72
 
66
-
67
- describe "defaults" do
68
- it { expect(subject.mode).to eq "driving" }
73
+ describe 'defaults' do
74
+ it { expect(subject.mode).to eq 'driving' }
69
75
  it { expect(subject.avoid).to be_nil }
70
- it { expect(subject.units).to eq "metric" }
76
+ it { expect(subject.units).to eq 'metric' }
71
77
  it { expect(subject.lat_lng_scale).to eq 5 }
72
78
  it { expect(subject.use_encoded_polylines).to eq false }
73
79
  it { expect(subject.protocol).to eq 'https' }
@@ -84,13 +90,19 @@ describe GoogleDistanceMatrix::Configuration do
84
90
 
85
91
  it { expect(subject.logger).to be_nil }
86
92
  it { expect(subject.cache).to be_nil }
87
- end
88
93
 
94
+ # rubocop:disable Metrics/LineLength
95
+ it 'has a default expected cache_key_transform' do
96
+ key = subject.cache_key_transform.call('foo')
97
+ expect(key).to eq 'f7fbba6e0636f890e56fbbf3283e524c6fa3204ae298382d624741d0dc6638326e282c41be5e4254d8820772c5518a2c5a8c0c7f7eda19594a7eb539453e1ed7'
98
+ end
99
+ # rubocop:enable Metrics/LineLength
100
+ end
89
101
 
90
- describe "#to_param" do
102
+ describe '#to_param' do
91
103
  described_class::ATTRIBUTES.each do |attr|
92
104
  it "includes #{attr}" do
93
- subject[attr] = "foo"
105
+ subject[attr] = 'foo'
94
106
  expect(subject.to_param[attr]).to eq subject.public_send(attr)
95
107
  end
96
108
 
@@ -108,14 +120,14 @@ describe GoogleDistanceMatrix::Configuration do
108
120
  end
109
121
  end
110
122
 
111
- it "includes client if google_business_api_client_id has been set" do
112
- subject.google_business_api_client_id = "123"
113
- expect(subject.to_param['client']).to eq "123"
123
+ it 'includes client if google_business_api_client_id has been set' do
124
+ subject.google_business_api_client_id = '123'
125
+ expect(subject.to_param['client']).to eq '123'
114
126
  end
115
127
 
116
- it "includes key if google_api_key has been set" do
117
- subject.google_api_key = "12345"
118
- expect(subject.to_param['key']).to eq("12345")
128
+ it 'includes key if google_api_key has been set' do
129
+ subject.google_api_key = '12345'
130
+ expect(subject.to_param['key']).to eq('12345')
119
131
  end
120
132
  end
121
133
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module GoogleDistanceMatrix
@@ -9,22 +11,23 @@ module GoogleDistanceMatrix
9
11
  @logged = []
10
12
  end
11
13
 
12
- def info(msg, tag)
14
+ def info(msg, _tag)
13
15
  @logged << msg
14
16
  end
15
17
 
16
18
  def error(msg)
17
- fail msg
19
+ raise msg
18
20
  end
19
21
  end
20
22
 
21
23
  # Little helper to clean up examples
22
24
  def notify(instrumentation)
23
- ActiveSupport::Notifications.instrument "client_request_matrix_data.google_distance_matrix", instrumentation do
25
+ ActiveSupport::Notifications.instrument(
26
+ 'client_request_matrix_data.google_distance_matrix', instrumentation
27
+ ) do
24
28
  end
25
29
  end
26
30
 
27
-
28
31
  let(:mock_logger) { MockLogger.new }
29
32
  let(:config) { Configuration.new }
30
33
 
@@ -32,57 +35,23 @@ module GoogleDistanceMatrix
32
35
  before do
33
36
  @old_subscribers = LogSubscriber.subscribers.dup
34
37
  LogSubscriber.subscribers.clear
35
- LogSubscriber.attach_to "google_distance_matrix", LogSubscriber.new(logger: mock_logger, config: config)
38
+ LogSubscriber.attach_to 'google_distance_matrix',
39
+ LogSubscriber.new(logger: mock_logger, config: config)
36
40
  end
37
41
 
38
42
  after do
39
43
  @old_subscribers.each do |subscriber|
40
- LogSubscriber.attach_to "google_distance_matrix", subscriber
44
+ LogSubscriber.attach_to 'google_distance_matrix', subscriber
41
45
  end
42
46
  end
43
47
 
44
-
45
- it "logs the url and elements" do
48
+ it 'logs the url and elements' do
46
49
  url = 'https://example.com'
47
- instrumentation = {url: url, elements: 0}
50
+ instrumentation = { filtered_url: url, elements: 0 }
48
51
 
49
52
  expect { notify instrumentation }.to change(mock_logger.logged, :length).from(0).to 1
50
53
 
51
- expect(mock_logger.logged.first).to include "(elements: 0) GET https://example.com"
52
- end
53
-
54
- describe "filtering of logged url" do
55
- it "filters nothing if config has no keys to be filtered" do
56
- config.filter_parameters_in_logged_url.clear
57
-
58
- instrumentation = {url: 'https://example.com/?foo=bar&sensitive=secret'}
59
- notify instrumentation
60
-
61
- expect(mock_logger.logged.first).to include "https://example.com/?foo=bar&sensitive=secret"
62
- end
63
-
64
- it "filters sensitive GET param if config has it in list of params to filter" do
65
- config.filter_parameters_in_logged_url << 'sensitive'
66
-
67
- instrumentation = {url: 'https://example.com/?foo=bar&sensitive=secret'}
68
- notify instrumentation
69
-
70
- expect(mock_logger.logged.first).to include "https://example.com/?foo=bar&sensitive=[FILTERED]"
71
- end
72
-
73
- it "filters key and signature as defaul from configuration" do
74
- instrumentation = {url: 'https://example.com/?key=bar&signature=secret&other=foo'}
75
- notify instrumentation
76
-
77
- expect(mock_logger.logged.first).to include "https://example.com/?key=[FILTERED]&signature=[FILTERED]&other=foo"
78
- end
79
-
80
- it "filters all appearances of a param" do
81
- instrumentation = {url: 'https://example.com/?key=bar&key=secret&other=foo'}
82
- notify instrumentation
83
-
84
- expect(mock_logger.logged.first).to include "https://example.com/?key=[FILTERED]&key=[FILTERED]&other=foo"
85
- end
54
+ expect(mock_logger.logged.first).to include '(elements: 0) GET https://example.com'
86
55
  end
87
56
  end
88
57
  end
@@ -1,36 +1,39 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
2
4
 
3
5
  describe GoogleDistanceMatrix::Logger do
4
- context "without a logger backend" do
6
+ context 'without a logger backend' do
5
7
  subject { described_class.new }
6
8
 
7
9
  described_class::LEVELS.each do |level|
8
10
  it "logging #{level} does not fail" do
9
- subject.public_send level, "log msg"
11
+ subject.public_send level, 'log msg'
10
12
  end
11
13
  end
12
14
  end
13
15
 
14
- context "with a logger backend" do
16
+ context 'with a logger backend' do
15
17
  let(:backend) { double }
16
18
 
17
19
  subject { described_class.new backend }
18
20
 
19
21
  described_class::LEVELS.each do |level|
20
22
  describe level do
21
- it "sends log message to the backend" do
22
- expect(backend).to receive(level).with("[google_distance_matrix] log msg")
23
- subject.public_send level, "log msg"
23
+ it 'sends log message to the backend' do
24
+ expect(backend).to receive(level).with('[google_distance_matrix] log msg')
25
+ subject.public_send level, 'log msg'
24
26
  end
25
27
 
26
- it "supports sending in a tag" do
27
- expect(backend).to receive(level).with("[google_distance_matrix] [client] log msg")
28
- subject.public_send level, "log msg", tag: :client
28
+ it 'supports sending in a tag' do
29
+ expect(backend).to receive(level).with('[google_distance_matrix] [client] log msg')
30
+ subject.public_send level, 'log msg', tag: :client
29
31
  end
30
32
 
31
- it "supports sending in multiple tags" do
32
- expect(backend).to receive(level).with("[google_distance_matrix] [client] [request] log msg")
33
- subject.public_send level, "log msg", tag: ['client', 'request']
33
+ it 'supports sending in multiple tags' do
34
+ expect(backend).to receive(level)
35
+ .with('[google_distance_matrix] [client] [request] log msg')
36
+ subject.public_send level, 'log msg', tag: %w[client request]
34
37
  end
35
38
  end
36
39
  end
@@ -1,14 +1,16 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
2
4
 
3
5
  describe GoogleDistanceMatrix::Matrix do
4
- let(:origin_1) { GoogleDistanceMatrix::Place.new address: "Karl Johans gate, Oslo" }
5
- let(:origin_2) { GoogleDistanceMatrix::Place.new address: "Askerveien 1, Asker" }
6
+ let(:origin_1) { GoogleDistanceMatrix::Place.new address: 'Karl Johans gate, Oslo' }
7
+ let(:origin_2) { GoogleDistanceMatrix::Place.new address: 'Askerveien 1, Asker' }
6
8
 
7
- let(:destination_1) { GoogleDistanceMatrix::Place.new address: "Drammensveien 1, Oslo" }
8
- let(:destination_2) { GoogleDistanceMatrix::Place.new address: "Skjellestadhagen, Heggedal" }
9
+ let(:destination_1) { GoogleDistanceMatrix::Place.new address: 'Drammensveien 1, Oslo' }
10
+ let(:destination_2) { GoogleDistanceMatrix::Place.new address: 'Skjellestadhagen, Heggedal' }
9
11
 
10
12
  let(:url_builder) { GoogleDistanceMatrix::UrlBuilder.new subject }
11
- let(:url) { url_builder.url }
13
+ let(:url) { url_builder.sensitive_url }
12
14
 
13
15
  subject do
14
16
  described_class.new(
@@ -17,24 +19,24 @@ describe GoogleDistanceMatrix::Matrix do
17
19
  )
18
20
  end
19
21
 
20
- describe "#initialize" do
21
- it "takes a list of origins" do
22
+ describe '#initialize' do
23
+ it 'takes a list of origins' do
22
24
  matrix = described_class.new origins: [origin_1, origin_2]
23
25
  expect(matrix.origins).to include origin_1, origin_2
24
26
  end
25
27
 
26
- it "takes a list of destinations" do
28
+ it 'takes a list of destinations' do
27
29
  matrix = described_class.new destinations: [destination_1, destination_2]
28
30
  expect(matrix.destinations).to include destination_1, destination_2
29
31
  end
30
32
 
31
- it "has a default configuration" do
33
+ it 'has a default configuration' do
32
34
  expect(subject.configuration).to be_present
33
35
  end
34
36
  end
35
37
 
36
- describe "#configuration" do
37
- it "is by default set from default_configuration" do
38
+ describe '#configuration' do
39
+ it 'is by default set from default_configuration' do
38
40
  config = double
39
41
  allow(config).to receive(:dup).and_return config
40
42
  expect(GoogleDistanceMatrix).to receive(:default_configuration).and_return config
@@ -43,47 +45,58 @@ describe GoogleDistanceMatrix::Matrix do
43
45
  end
44
46
 
45
47
  it "has it's own configuration" do
46
- expect {
48
+ expect do
47
49
  subject.configure { |c| c.mode = !GoogleDistanceMatrix.default_configuration.mode }
48
- }.to_not change(GoogleDistanceMatrix.default_configuration, :mode)
50
+ end.to_not change(GoogleDistanceMatrix.default_configuration, :mode)
49
51
  end
50
52
 
51
- it "has a configurable configuration :-)" do
52
- expect {
53
+ it 'has a configurable configuration :-)' do
54
+ expect do
53
55
  subject.configure { |c| c.mode = !GoogleDistanceMatrix.default_configuration.mode }
54
- }.to change(subject.configuration, :mode).to !GoogleDistanceMatrix.default_configuration.mode
56
+ end.to change(
57
+ subject.configuration, :mode
58
+ ).to !GoogleDistanceMatrix.default_configuration.mode
55
59
  end
56
60
  end
57
61
 
58
62
  %w[origins destinations].each do |attr|
59
- let(:place) { GoogleDistanceMatrix::Place.new address: "My street" }
63
+ let(:place) { GoogleDistanceMatrix::Place.new address: 'My street' }
64
+ let(:place_2) { GoogleDistanceMatrix::Place.new address: 'Some other street' }
60
65
 
61
66
  describe "##{attr}" do
62
- it "can receive places" do
67
+ it 'can receive places' do
63
68
  subject.public_send(attr) << place
64
69
  expect(subject.public_send(attr)).to include place
65
70
  end
66
71
 
67
- it "does not same place twice" do
68
- expect {
72
+ it 'does not same place twice' do
73
+ expect do
69
74
  2.times { subject.public_send(attr) << place }
70
- }.to change(subject.public_send(attr), :length).by 1
75
+ end.to change(subject.public_send(attr), :length).by 1
76
+ end
77
+
78
+ it 'updates the url when adding places' do
79
+ subject.public_send(attr) << place
80
+ expect(subject.sensitive_url).to include CGI.escape('My street')
81
+
82
+ subject.public_send(attr) << place_2
83
+ expect(subject.sensitive_url).to include CGI.escape('Some other street')
71
84
  end
72
85
  end
73
86
  end
74
87
 
75
88
  %w[
76
- route_for
77
- route_for!
78
- routes_for
79
- routes_for!
80
- shortest_route_by_duration_to
81
- shortest_route_by_duration_to!
82
- shortest_route_by_distance_to
83
- shortest_route_by_distance_to!
84
- shortest_route_by_duration_in_traffic_to
85
- shortest_route_by_duration_in_traffic_to!
86
- ].each do |method|
89
+ route_for
90
+ route_for!
91
+ routes_for
92
+ routes_for!
93
+ shortest_route_by_duration_to
94
+ shortest_route_by_duration_to!
95
+ shortest_route_by_distance_to
96
+ shortest_route_by_distance_to!
97
+ shortest_route_by_duration_in_traffic_to
98
+ shortest_route_by_duration_in_traffic_to!
99
+ ].each do |method|
87
100
  it "delegates #{method} to routes_finder" do
88
101
  finder = double
89
102
  result = double
@@ -95,8 +108,8 @@ describe GoogleDistanceMatrix::Matrix do
95
108
  end
96
109
  end
97
110
 
98
- describe "making API requests", :request_recordings do
99
- it "loads correctly API response data in to route objects" do
111
+ describe 'making API requests', :request_recordings do
112
+ it 'loads correctly API response data in to route objects' do
100
113
  stub_request(:get, url).to_return body: recorded_request_for(:success)
101
114
  expect(subject.data[0][0].distance_text).to eq '2.0 km'
102
115
  expect(subject.data[0][0].distance_in_meters).to eq 2032
@@ -104,7 +117,7 @@ describe GoogleDistanceMatrix::Matrix do
104
117
  expect(subject.data[0][0].duration_in_seconds).to eq 367
105
118
  end
106
119
 
107
- it "loads correctly API response data in to route objects when it includes in traffic data" do
120
+ it 'loads correctly API response data in to route objects when it includes in traffic data' do
108
121
  stub_request(:get, url).to_return body: recorded_request_for(:success_with_in_traffic)
109
122
  expect(subject.data[0][0].distance_text).to eq '1.8 km'
110
123
  expect(subject.data[0][0].distance_in_meters).to eq 1752
@@ -114,8 +127,8 @@ describe GoogleDistanceMatrix::Matrix do
114
127
  expect(subject.data[0][0].duration_in_traffic_in_seconds).to eq 405
115
128
  end
116
129
 
117
- context "no cache" do
118
- it "makes multiple requests to same url" do
130
+ context 'no cache' do
131
+ it 'makes multiple requests to same url' do
119
132
  stub = stub_request(:get, url).to_return body: recorded_request_for(:success)
120
133
  subject.data
121
134
  subject.reset!
@@ -125,15 +138,16 @@ describe GoogleDistanceMatrix::Matrix do
125
138
  end
126
139
  end
127
140
 
128
- context "with cache" do
141
+ context 'with cache' do
129
142
  before do
130
143
  subject.configure do |config|
131
144
  config.cache = ActiveSupport::Cache.lookup_store :memory_store
132
145
  end
133
146
  end
134
147
 
135
- it "makes one requests to same url" do
148
+ it 'makes one requests to same url' do
136
149
  stub = stub_request(:get, url).to_return body: recorded_request_for(:success)
150
+
137
151
  subject.data
138
152
  subject.reset!
139
153
  subject.data
@@ -141,7 +155,22 @@ describe GoogleDistanceMatrix::Matrix do
141
155
  expect(stub).to have_been_requested.once
142
156
  end
143
157
 
144
- it "clears the cache key on reload" do
158
+ it 'makes one request when filtered params to same url' do
159
+ was = GoogleDistanceMatrix.default_configuration.filter_parameters_in_logged_url
160
+ GoogleDistanceMatrix.default_configuration.filter_parameters_in_logged_url = ['origins']
161
+
162
+ stub = stub_request(:get, url).to_return body: recorded_request_for(:success)
163
+
164
+ subject.data
165
+ subject.reset!
166
+ subject.data
167
+
168
+ expect(stub).to have_been_requested.once
169
+
170
+ GoogleDistanceMatrix.default_configuration.filter_parameters_in_logged_url = was
171
+ end
172
+
173
+ it 'clears the cache key on reload' do
145
174
  stub = stub_request(:get, url).to_return body: recorded_request_for(:success)
146
175
  subject.data
147
176
  subject.reload
@@ -152,30 +181,32 @@ describe GoogleDistanceMatrix::Matrix do
152
181
  end
153
182
  end
154
183
 
155
- describe "#data", :request_recordings do
156
- context "success" do
157
- let!(:api_request_stub) { stub_request(:get, url).to_return body: recorded_request_for(:success) }
184
+ describe '#data', :request_recordings do
185
+ context 'success' do
186
+ let!(:api_request_stub) do
187
+ stub_request(:get, url).to_return body: recorded_request_for(:success)
188
+ end
158
189
 
159
190
  it "loads from Google's API" do
160
191
  subject.data
161
192
  expect(api_request_stub).to have_been_requested
162
193
  end
163
194
 
164
- it "does not load twice" do
195
+ it 'does not load twice' do
165
196
  2.times { subject.data }
166
197
  expect(api_request_stub).to have_been_requested
167
198
  end
168
199
 
169
- it "contains one row" do
200
+ it 'contains one row' do
170
201
  expect(subject.data.length).to eq 2
171
202
  end
172
203
 
173
- it "contains two columns each row" do
204
+ it 'contains two columns each row' do
174
205
  expect(subject.data[0].length).to eq 2
175
206
  expect(subject.data[1].length).to eq 2
176
207
  end
177
208
 
178
- it "assigns correct origin on routes in the data" do
209
+ it 'assigns correct origin on routes in the data' do
179
210
  expect(subject.data[0][0].origin).to eq origin_1
180
211
  expect(subject.data[0][1].origin).to eq origin_1
181
212
 
@@ -183,7 +214,7 @@ describe GoogleDistanceMatrix::Matrix do
183
214
  expect(subject.data[1][1].origin).to eq origin_2
184
215
  end
185
216
 
186
- it "assigns correct destination on routes in the data" do
217
+ it 'assigns correct destination on routes in the data' do
187
218
  expect(subject.data[0][0].destination).to eq destination_1
188
219
  expect(subject.data[0][1].destination).to eq destination_2
189
220
 
@@ -192,36 +223,38 @@ describe GoogleDistanceMatrix::Matrix do
192
223
  end
193
224
  end
194
225
 
195
- context "some elements is not OK" do
196
- let!(:api_request_stub) { stub_request(:get, url).to_return body: recorded_request_for(:zero_results) }
226
+ context 'some elements is not OK' do
227
+ let!(:api_request_stub) do
228
+ stub_request(:get, url).to_return body: recorded_request_for(:zero_results)
229
+ end
197
230
 
198
231
  it "loads from Google's API" do
199
232
  subject.data
200
233
  expect(api_request_stub).to have_been_requested
201
234
  end
202
235
 
203
- it "adds loaded route with errors correctly" do
236
+ it 'adds loaded route with errors correctly' do
204
237
  route = subject.data[0][1]
205
238
 
206
- expect(route.status).to eq "zero_results"
239
+ expect(route.status).to eq 'zero_results'
207
240
  expect(route.duration_in_seconds).to be_nil
208
241
  end
209
242
  end
210
243
  end
211
244
 
212
- describe "#reload" do
245
+ describe '#reload' do
213
246
  before do
214
247
  allow(subject).to receive(:load_matrix) { ['loaded'] }
215
248
  subject.data.clear
216
249
  end
217
250
 
218
251
  it "reloads matrix' data from the API" do
219
- expect {
252
+ expect do
220
253
  subject.reload
221
- }.to change(subject, :data).from([]).to ['loaded']
254
+ end.to change(subject, :data).from([]).to ['loaded']
222
255
  end
223
256
 
224
- it "is chainable" do
257
+ it 'is chainable' do
225
258
  expect(subject.reload.data).to eq ['loaded']
226
259
  end
227
260
  end