mas-rad_core 0.0.85 → 0.0.87
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/jobs/geocode_adviser_job.rb +5 -9
- data/app/jobs/geocode_firm_job.rb +5 -9
- data/app/models/geocodable.rb +1 -1
- data/lib/mas/firm_result.rb +3 -10
- data/lib/mas/model_geocoder.rb +11 -0
- data/lib/mas/rad_core/version.rb +1 -1
- data/spec/dummy/config/database.yml +2 -7
- data/spec/dummy/db/schema.rb +1 -1
- data/spec/dummy/log/development.log +77396 -0
- data/spec/dummy/log/test.log +0 -0
- data/spec/lib/mas/firm_result_spec.rb +5 -20
- data/spec/lib/mas/model_geocoder_spec.rb +81 -0
- data/spec/support/shared_examples/geocodable_examples.rb +2 -2
- metadata +8 -3
data/spec/dummy/log/test.log
CHANGED
Binary file
|
@@ -156,25 +156,10 @@ RSpec.describe FirmResult do
|
|
156
156
|
end
|
157
157
|
|
158
158
|
describe '#closest_adviser' do
|
159
|
-
|
159
|
+
before { data['sort'] = [1.23456789, 2.34567890] }
|
160
160
|
|
161
|
-
|
162
|
-
|
163
|
-
search: { result: { miles_away_alt: text, miles_away: 'miles away' } }
|
164
|
-
end
|
165
|
-
|
166
|
-
context 'when it is less than 1 mile away' do
|
167
|
-
it 'returns `less than a mile away` localised text' do
|
168
|
-
expect(subject.closest_adviser).to eq(text)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
context 'when it is a mile away or more' do
|
173
|
-
before { data['sort'] = [1.23456789] }
|
174
|
-
|
175
|
-
it 'returns the formatted distance' do
|
176
|
-
expect(subject.closest_adviser).to eq('1.2 miles away')
|
177
|
-
end
|
161
|
+
it 'returns the first distance' do
|
162
|
+
expect(subject.closest_adviser).to eq(1.23456789)
|
178
163
|
end
|
179
164
|
end
|
180
165
|
|
@@ -193,8 +178,8 @@ RSpec.describe FirmResult do
|
|
193
178
|
end
|
194
179
|
end
|
195
180
|
|
196
|
-
context 'has a value
|
197
|
-
let(:value) {
|
181
|
+
context 'has a value > 0 (true)' do
|
182
|
+
let(:value) { 1 }
|
198
183
|
|
199
184
|
it 'returns true' do
|
200
185
|
expect(subject.includes_advice_type?(key)).to eq(true)
|
@@ -0,0 +1,81 @@
|
|
1
|
+
RSpec.describe ModelGeocoder do
|
2
|
+
let(:model_class) do
|
3
|
+
Class.new do
|
4
|
+
attr_accessor :address_line_one, :address_line_two, :address_postcode, :longitude, :latitude
|
5
|
+
|
6
|
+
def update_coordinates!(*args); end
|
7
|
+
|
8
|
+
def full_street_address
|
9
|
+
[address_line_one, address_line_two, address_postcode, 'United Kingdom'].reject(&:blank?).join(', ')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:model) do
|
15
|
+
model_class.new.tap do |thing|
|
16
|
+
thing.address_line_one = address_line_one
|
17
|
+
thing.address_line_two = address_line_two
|
18
|
+
thing.address_postcode = address_postcode
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:address_line_one) { '120 Holborn' }
|
23
|
+
let(:address_line_two) { 'London' }
|
24
|
+
let(:address_postcode) { 'EC1N 2TD' }
|
25
|
+
let(:expected_coordinates) { [51.5180697, -0.1085203] }
|
26
|
+
|
27
|
+
describe '#geocode' do
|
28
|
+
context 'when the model address can be geocoded' do
|
29
|
+
it 'returns the coordinates' do
|
30
|
+
VCR.use_cassette('geocode-one-result') do
|
31
|
+
expect(ModelGeocoder.geocode(model)).to eql(expected_coordinates)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when model address cannot be geocoded' do
|
37
|
+
let(:address_line_one) { '1000 Fantasy Ave' }
|
38
|
+
let(:address_line_two) { 'Neverland' }
|
39
|
+
let(:address_postcode) { 'ABC 123' }
|
40
|
+
|
41
|
+
it 'returns nil' do
|
42
|
+
VCR.use_cassette('geocode-no-results') do
|
43
|
+
expect(ModelGeocoder.geocode(model)).to be(nil)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#geocode!' do
|
50
|
+
context 'when the model address can be geocoded' do
|
51
|
+
before do
|
52
|
+
allow(ModelGeocoder).to receive(:geocode).and_return(expected_coordinates)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'calls model.update_coordinates! with the coordinates' do
|
56
|
+
expect(model).to receive(:update_coordinates!).with(expected_coordinates)
|
57
|
+
ModelGeocoder.geocode!(model)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'returns the true' do
|
61
|
+
expect(ModelGeocoder.geocode!(model)).to be(true)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'when model address cannot be geocoded' do
|
66
|
+
before do
|
67
|
+
allow(ModelGeocoder).to receive(:geocode).and_return(nil)
|
68
|
+
end
|
69
|
+
|
70
|
+
# This side effect is required while the geocoding is done on a background job
|
71
|
+
it 'calls model.update_coordinates! with nil' do
|
72
|
+
expect(model).to receive(:update_coordinates!).with(nil)
|
73
|
+
ModelGeocoder.geocode!(model)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'returns false' do
|
77
|
+
expect(ModelGeocoder.geocode!(model)).to be(false)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -35,12 +35,12 @@ RSpec.shared_examples 'geocodable' do
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
describe '#
|
38
|
+
describe '#update_coordinates!' do
|
39
39
|
let(:coordinates) { [Faker::Address.latitude, Faker::Address.longitude] }
|
40
40
|
|
41
41
|
before do
|
42
42
|
expect(job_class).not_to receive(:perform_later)
|
43
|
-
subject.
|
43
|
+
subject.update_coordinates!(coordinates)
|
44
44
|
subject.reload
|
45
45
|
end
|
46
46
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mas-rad_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.87
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Lovell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -312,6 +312,7 @@ files:
|
|
312
312
|
- lib/mas/firm_repository.rb
|
313
313
|
- lib/mas/firm_result.rb
|
314
314
|
- lib/mas/languages.rb
|
315
|
+
- lib/mas/model_geocoder.rb
|
315
316
|
- lib/mas/paginateable.rb
|
316
317
|
- lib/mas/rad_core.rb
|
317
318
|
- lib/mas/rad_core/engine.rb
|
@@ -352,6 +353,7 @@ files:
|
|
352
353
|
- spec/dummy/config/routes.rb
|
353
354
|
- spec/dummy/config/secrets.yml
|
354
355
|
- spec/dummy/db/schema.rb
|
356
|
+
- spec/dummy/log/development.log
|
355
357
|
- spec/dummy/log/test.log
|
356
358
|
- spec/dummy/public/404.html
|
357
359
|
- spec/dummy/public/422.html
|
@@ -393,6 +395,7 @@ files:
|
|
393
395
|
- spec/lib/mas/firm_repository_spec.rb
|
394
396
|
- spec/lib/mas/firm_result_spec.rb
|
395
397
|
- spec/lib/mas/languages_spec.rb
|
398
|
+
- spec/lib/mas/model_geocoder_spec.rb
|
396
399
|
- spec/lib/mas/search_result_spec.rb
|
397
400
|
- spec/models/accreditation_spec.rb
|
398
401
|
- spec/models/adviser_spec.rb
|
@@ -441,7 +444,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
441
444
|
version: '0'
|
442
445
|
requirements: []
|
443
446
|
rubyforge_project:
|
444
|
-
rubygems_version: 2.4.
|
447
|
+
rubygems_version: 2.4.5
|
445
448
|
signing_key:
|
446
449
|
specification_version: 4
|
447
450
|
summary: MAS RAD Core.
|
@@ -477,6 +480,7 @@ test_files:
|
|
477
480
|
- spec/dummy/config/secrets.yml
|
478
481
|
- spec/dummy/config.ru
|
479
482
|
- spec/dummy/db/schema.rb
|
483
|
+
- spec/dummy/log/development.log
|
480
484
|
- spec/dummy/log/test.log
|
481
485
|
- spec/dummy/public/404.html
|
482
486
|
- spec/dummy/public/422.html
|
@@ -519,6 +523,7 @@ test_files:
|
|
519
523
|
- spec/lib/mas/firm_repository_spec.rb
|
520
524
|
- spec/lib/mas/firm_result_spec.rb
|
521
525
|
- spec/lib/mas/languages_spec.rb
|
526
|
+
- spec/lib/mas/model_geocoder_spec.rb
|
522
527
|
- spec/lib/mas/search_result_spec.rb
|
523
528
|
- spec/models/accreditation_spec.rb
|
524
529
|
- spec/models/adviser_spec.rb
|