google_distance_matrix 0.4.0 → 0.5.0

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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +16 -0
  3. data/.rubocop.yml +6 -0
  4. data/.ruby-version +1 -1
  5. data/.travis.yml +1 -0
  6. data/CHANGELOG.md +20 -0
  7. data/Gemfile +2 -0
  8. data/Rakefile +9 -4
  9. data/google_distance_matrix.gemspec +20 -18
  10. data/lib/google_distance_matrix/client.rb +32 -18
  11. data/lib/google_distance_matrix/client_cache.rb +9 -3
  12. data/lib/google_distance_matrix/configuration.rb +37 -19
  13. data/lib/google_distance_matrix/errors.rb +6 -3
  14. data/lib/google_distance_matrix/log_subscriber.rb +14 -14
  15. data/lib/google_distance_matrix/logger.rb +6 -4
  16. data/lib/google_distance_matrix/matrix.rb +45 -22
  17. data/lib/google_distance_matrix/place.rb +32 -25
  18. data/lib/google_distance_matrix/places.rb +5 -4
  19. data/lib/google_distance_matrix/polyline_encoder/delta.rb +4 -2
  20. data/lib/google_distance_matrix/polyline_encoder/value_encoder.rb +11 -4
  21. data/lib/google_distance_matrix/polyline_encoder.rb +2 -2
  22. data/lib/google_distance_matrix/railtie.rb +4 -1
  23. data/lib/google_distance_matrix/route.rb +22 -15
  24. data/lib/google_distance_matrix/routes_finder.rb +25 -29
  25. data/lib/google_distance_matrix/url_builder/polyline_encoder_buffer.rb +3 -0
  26. data/lib/google_distance_matrix/url_builder.rb +44 -16
  27. data/lib/google_distance_matrix/version.rb +3 -1
  28. data/lib/google_distance_matrix.rb +25 -23
  29. data/spec/lib/google_distance_matrix/client_cache_spec.rb +26 -11
  30. data/spec/lib/google_distance_matrix/client_spec.rb +40 -30
  31. data/spec/lib/google_distance_matrix/configuration_spec.rb +36 -24
  32. data/spec/lib/google_distance_matrix/log_subscriber_spec.rb +13 -44
  33. data/spec/lib/google_distance_matrix/logger_spec.rb +16 -13
  34. data/spec/lib/google_distance_matrix/matrix_spec.rb +90 -57
  35. data/spec/lib/google_distance_matrix/place_spec.rb +30 -25
  36. data/spec/lib/google_distance_matrix/places_spec.rb +29 -28
  37. data/spec/lib/google_distance_matrix/polyline_encoder/delta_spec.rb +5 -3
  38. data/spec/lib/google_distance_matrix/polyline_encoder_spec.rb +7 -2
  39. data/spec/lib/google_distance_matrix/route_spec.rb +11 -9
  40. data/spec/lib/google_distance_matrix/routes_finder_spec.rb +95 -81
  41. data/spec/lib/google_distance_matrix/url_builder_spec.rb +97 -48
  42. data/spec/spec_helper.rb +3 -1
  43. metadata +35 -7
@@ -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
@@ -1,23 +1,25 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
2
4
 
3
5
  describe GoogleDistanceMatrix::Place do
4
- let(:address) { "Karl Johans gate, Oslo" }
6
+ let(:address) { 'Karl Johans gate, Oslo' }
5
7
  let(:lat) { 1.4 }
6
8
  let(:lng) { 2.2 }
7
9
 
8
- describe "#initialize" do
9
- it "builds with an address" do
10
+ describe '#initialize' do
11
+ it 'builds with an address' do
10
12
  place = described_class.new(address: address)
11
13
  expect(place.address).to eq address
12
14
  end
13
15
 
14
- it "builds with lat lng" do
16
+ it 'builds with lat lng' do
15
17
  place = described_class.new(lat: lat, lng: lng)
16
18
  expect(place.lat).to eq lat
17
19
  expect(place.lng).to eq lng
18
20
  end
19
21
 
20
- it "builds with an object responding to lat and lng" do
22
+ it 'builds with an object responding to lat and lng' do
21
23
  point = double lat: 1, lng: 2
22
24
  place = described_class.new(point)
23
25
 
@@ -25,22 +27,21 @@ describe GoogleDistanceMatrix::Place do
25
27
  expect(place.lng).to eq point.lng
26
28
  end
27
29
 
28
-
29
- it "keeps a record of the object it built itself from" do
30
+ it 'keeps a record of the object it built itself from' do
30
31
  point = double lat: 1, lng: 2
31
32
  place = described_class.new(point)
32
33
 
33
34
  expect(place.extracted_attributes_from).to eq point
34
35
  end
35
- it "builds with an object responding to address" do
36
+ it 'builds with an object responding to address' do
36
37
  object = double address: address
37
38
  place = described_class.new(object)
38
39
 
39
40
  expect(place.address).to eq object.address
40
41
  end
41
42
 
42
- it "builds with an object responding to lat, lng and address" do
43
- object = double lat: 1, lng:2, address: address
43
+ it 'builds with an object responding to lat, lng and address' do
44
+ object = double lat: 1, lng: 2, address: address
44
45
  place = described_class.new(object)
45
46
 
46
47
  expect(place.lat).to eq object.lat
@@ -48,46 +49,50 @@ describe GoogleDistanceMatrix::Place do
48
49
  expect(place.address).to be_nil
49
50
  end
50
51
 
51
- it "fails if no valid attributes given" do
52
+ it 'fails if no valid attributes given' do
52
53
  expect { described_class.new }.to raise_error ArgumentError
53
54
  expect { described_class.new(lat: lat) }.to raise_error ArgumentError
54
55
  expect { described_class.new(lng: lng) }.to raise_error ArgumentError
55
56
  end
56
57
 
57
- it "fails if both address, lat ang lng is given" do
58
- expect { described_class.new(address: address, lat: lat, lng: lng) }.to raise_error ArgumentError
58
+ it 'fails if both address, lat ang lng is given' do
59
+ expect { described_class.new(address: address, lat: lat, lng: lng) }
60
+ .to raise_error ArgumentError
59
61
  end
60
62
  end
61
63
 
62
- describe "#to_param" do
63
- context "with address" do
64
+ describe '#to_param' do
65
+ context 'with address' do
64
66
  subject { described_class.new address: address }
65
67
 
66
68
  it { expect(subject.to_param).to eq address }
67
69
  end
68
70
 
69
- context "with lat lng" do
71
+ context 'with lat lng' do
70
72
  subject { described_class.new lng: lng, lat: lat }
71
73
 
72
74
  it { expect(subject.to_param).to eq "#{lat},#{lng}" }
73
75
  end
74
76
  end
75
77
 
76
- describe "#equal?" do
77
- it "is considered equal when address is the same" do
78
+ describe '#equal?' do
79
+ it 'is considered equal when address is the same' do
78
80
  expect(described_class.new(address: address)).to be_eql described_class.new(address: address)
79
81
  end
80
82
 
81
- it "is considered equal when lat and lng are the same" do
82
- expect(described_class.new(lat: lat, lng: lng)).to be_eql described_class.new(lat: lat, lng: lng)
83
+ it 'is considered equal when lat and lng are the same' do
84
+ expect(described_class.new(lat: lat, lng: lng))
85
+ .to be_eql described_class.new(lat: lat, lng: lng)
83
86
  end
84
87
 
85
- it "is not considered equal when address differs" do
86
- expect(described_class.new(address: address)).to_not be_eql described_class.new(address: address + ", Norway")
88
+ it 'is not considered equal when address differs' do
89
+ expect(described_class.new(address: address))
90
+ .to_not be_eql described_class.new(address: address + ', Norway')
87
91
  end
88
92
 
89
- it "is not considered equal when lat or lng differs" do
90
- expect(described_class.new(lat: lat, lng: lng)).to_not be_eql described_class.new(lat: lat, lng: lng + 1)
93
+ it 'is not considered equal when lat or lng differs' do
94
+ expect(described_class.new(lat: lat, lng: lng))
95
+ .to_not be_eql described_class.new(lat: lat, lng: lng + 1)
91
96
  end
92
97
  end
93
98
  end