google_distance_matrix 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38cca78e153cdfc6eca4ccb53116f4d5224872342179ce20bc9869961e0abffe
4
- data.tar.gz: 12f845ae5fad59d60bd6f9796da24c4ce736ab7766cf1fd95e9cfe315d1660ba
3
+ metadata.gz: 9d95262e2f29c248bbf1d42d16d95b9148ef0d16354a4e4dc8e4f5af23364980
4
+ data.tar.gz: 8911ea692148753e4325908ae0c3b6dffa2c08fbcef4b0585afe5d4f2e45f10d
5
5
  SHA512:
6
- metadata.gz: b4dd69ed7bf22b3c8ee1c8443aa63f486bbfe4139f4dfc3aea7671018ff01a4997253837812c92d552047132e6fb0e2c5cb348f980a969bbe2f6dc943212d959
7
- data.tar.gz: b25399a083d05f99b7345cd1ba167701e00b79265302131bcbea76608419210d7d094238134d86e31e1dfbc83590d0686143eac7ae5909eb3f690b9d136e9832
6
+ metadata.gz: 9149df909c7604f327b4d342d34e3df99c5898e109a434ef30a123e848cd5591ab01d51d921460907ba53b3a31deccd5ad484fe89e7027aafdbb7a3309eb7ac8
7
+ data.tar.gz: c8c1054b9060e0ecec7648313931f1d3349ec24cd74ce2f0ffec14cc893c7eda47654cd6df2422b1b162d51c57d1e92222f568d4c9ba25a0d67ff554b9f1aaa5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,7 @@
1
1
  ## v.0.6.1 (to be released)
2
2
 
3
+ * fix: when matrix places were built from hashes, passing hashes to route/s_for doesnt't work (by brauliomartinezlm)
4
+ * fix: place comparison was not working with == (by brauliomartinezlm)
3
5
 
4
6
  ## v.0.6.0
5
7
 
@@ -22,6 +22,7 @@ module GoogleDistanceMatrix
22
22
  if respond_to_needed_attributes? attributes_or_object
23
23
  extract_and_assign_attributes_from_object attributes_or_object
24
24
  elsif attributes_or_object.is_a? Hash
25
+ @extracted_attributes_from = attributes_or_object.with_indifferent_access
25
26
  assign_attributes attributes_or_object
26
27
  else
27
28
  raise ArgumentError, 'Must be either hash or object responding to lat, lng or address. '
@@ -36,12 +37,15 @@ module GoogleDistanceMatrix
36
37
  end
37
38
 
38
39
  def eql?(other)
40
+ return false unless other.is_a? self.class
41
+
39
42
  if address.present?
40
43
  address == other.address
41
44
  else
42
45
  lat_lng == other.lat_lng
43
46
  end
44
47
  end
48
+ alias == eql?
45
49
 
46
50
  def lat_lng?
47
51
  lat.present? && lng.present?
@@ -142,6 +142,8 @@ module GoogleDistanceMatrix
142
142
  if object.is_a? Place
143
143
  object
144
144
  else
145
+ object = object.with_indifferent_access if object.is_a? Hash
146
+
145
147
  find_place_for_object(origins, object) ||
146
148
  find_place_for_object(destinations, object)
147
149
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GoogleDistanceMatrix
4
- VERSION = '0.6.0'
4
+ VERSION = '0.6.1'
5
5
  end
@@ -95,4 +95,12 @@ describe GoogleDistanceMatrix::Place do
95
95
  .to_not be_eql described_class.new(lat: lat, lng: lng + 1)
96
96
  end
97
97
  end
98
+
99
+ describe '#==' do
100
+ it 'is considered equal when places are compared with ==' do
101
+ expect(described_class.new(address: address) ==
102
+ GoogleDistanceMatrix::Place.new(address: address))
103
+ .to be_truthy
104
+ end
105
+ end
98
106
  end
@@ -3,7 +3,8 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe GoogleDistanceMatrix::RoutesFinder, :request_recordings do
6
- let(:origin_1) { GoogleDistanceMatrix::Place.new address: 'Karl Johans gate, Oslo' }
6
+ let(:origin_1_attributes) { { address: 'Karl Johans gate, Oslo' } }
7
+ let(:origin_1) { GoogleDistanceMatrix::Place.new origin_1_attributes }
7
8
  let(:origin_2) { GoogleDistanceMatrix::Place.new address: 'Askerveien 1, Asker' }
8
9
 
9
10
  let(:destination_1) { GoogleDistanceMatrix::Place.new address: 'Drammensveien 1, Oslo' }
@@ -70,6 +71,13 @@ describe GoogleDistanceMatrix::RoutesFinder, :request_recordings do
70
71
  expect(routes.map(&:origin).all? { |o| o == origin_1 }).to be true
71
72
  end
72
73
 
74
+ it 'still returns routes for origin if it has same address but different object_id' do
75
+ routes = subject.routes_for GoogleDistanceMatrix::Place.new origin_1_attributes
76
+
77
+ expect(routes.length).to eq 2
78
+ expect(routes.map(&:origin).all? { |o| o == origin_1 }).to be true
79
+ end
80
+
73
81
  it 'returns routes for given destination' do
74
82
  routes = subject.routes_for destination_2
75
83
 
@@ -83,6 +91,17 @@ describe GoogleDistanceMatrix::RoutesFinder, :request_recordings do
83
91
  expect(routes.length).to eq 2
84
92
  expect(routes.map(&:destination).all? { |d| d == destination_2 }).to be true
85
93
  end
94
+
95
+ context 'place built from hash' do
96
+ let(:destination_2_built_from) { { address: 'Skjellestadhagen, Heggedal' } }
97
+
98
+ it 'returns routes for given hash a place was built from' do
99
+ routes = subject.routes_for destination_2_built_from
100
+
101
+ expect(routes.length).to eq 2
102
+ expect(routes.map(&:destination).all? { |d| d == destination_2 }).to be true
103
+ end
104
+ end
86
105
  end
87
106
 
88
107
  describe '#routes_for!' do
@@ -104,6 +123,16 @@ describe GoogleDistanceMatrix::RoutesFinder, :request_recordings do
104
123
  expect(route.destination).to eq destination_2
105
124
  end
106
125
 
126
+ context 'place built from hash' do
127
+ let(:destination_2_built_from) { { address: 'Skjellestadhagen, Heggedal' } }
128
+
129
+ it 'returns route when you give it the hash the place was built from' do
130
+ route = subject.route_for(origin: origin_1, destination: destination_2_built_from)
131
+ expect(route.origin).to eq origin_1
132
+ expect(route.destination).to eq destination_2
133
+ end
134
+ end
135
+
107
136
  it 'fails with argument error if origin is missing' do
108
137
  expect { subject.route_for destination: destination_2 }.to raise_error ArgumentError
109
138
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_distance_matrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thorbjørn Hermansen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-19 00:00:00.000000000 Z
11
+ date: 2019-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel