mas-rad_core 0.0.101 → 0.0.102
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/office.rb +21 -6
- data/db/migrate/20160222091312_remove_other_accreditation.rb +19 -0
- data/lib/mas/office_result.rb +0 -6
- data/lib/mas/rad_core/version.rb +1 -1
- data/spec/dummy/db/schema.rb +1 -1
- data/spec/factories/office.rb +1 -1
- data/spec/factories/principal.rb +1 -1
- data/spec/lib/mas/office_result_spec.rb +1 -1
- data/spec/models/office_spec.rb +94 -13
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24f4ec598a3a7418e8ad65db835de6b4530f920d
|
4
|
+
data.tar.gz: 25aeb27b4f4d323b1c64efd6aff4d25b46ff4b25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f5791c9451f3f9604539b4cc9863ee40b51a5ec14533ca3fe349ba5d1c3e4369952090bea7c719d809c3817ee30c653e1c844a2975de50bfcaed3b03604ab8a
|
7
|
+
data.tar.gz: 005578a9bf1337789d312cb0138c6775d4aa1aa80a4fdd1b0dd6fb00949c8f00ecd26d8921a74e8209120358d503d6b599f023a86dd950c85565417a9a3b04a9
|
data/app/models/office.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'uk_postcode'
|
2
|
+
require 'uk_phone_numbers'
|
2
3
|
|
3
4
|
class Office < ActiveRecord::Base
|
4
5
|
include Geocodable
|
@@ -18,10 +19,7 @@ class Office < ActiveRecord::Base
|
|
18
19
|
length: { maximum: 50 },
|
19
20
|
format: { with: /.+@.+\..+/ }
|
20
21
|
|
21
|
-
|
22
|
-
presence: false,
|
23
|
-
length: { maximum: 30 },
|
24
|
-
format: { with: /\A[0-9 ]+\z/ }
|
22
|
+
validate :telephone_number_is_valid
|
25
23
|
|
26
24
|
validates :address_line_one,
|
27
25
|
presence: true,
|
@@ -61,8 +59,12 @@ class Office < ActiveRecord::Base
|
|
61
59
|
]
|
62
60
|
end
|
63
61
|
|
62
|
+
def telephone_number=(new_phone_number)
|
63
|
+
super cleanup_telephone_number(new_phone_number)
|
64
|
+
end
|
65
|
+
|
64
66
|
def telephone_number
|
65
|
-
|
67
|
+
return format_telephone_number(cleanup_telephone_number(super))
|
66
68
|
end
|
67
69
|
|
68
70
|
def full_street_address
|
@@ -95,5 +97,18 @@ class Office < ActiveRecord::Base
|
|
95
97
|
errors.add(:address_postcode, 'is invalid')
|
96
98
|
end
|
97
99
|
end
|
98
|
-
end
|
99
100
|
|
101
|
+
def telephone_number_is_valid
|
102
|
+
if telephone_number.nil? || !UKPhoneNumbers.valid?(telephone_number.gsub(' ', ''))
|
103
|
+
errors.add(:telephone_number, I18n.t("#{model_name.i18n_key}.telephone_number.invalid_format"))
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def cleanup_telephone_number(telephone_number)
|
108
|
+
telephone_number.try { |t| t.gsub(/\s+/, ' ').strip }
|
109
|
+
end
|
110
|
+
|
111
|
+
def format_telephone_number(telephone_number)
|
112
|
+
telephone_number.try { |t| UKPhoneNumbers.format(t) || t }
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class RemoveOtherAccreditation < ActiveRecord::Migration
|
2
|
+
class Accreditation < ActiveRecord::Base
|
3
|
+
end
|
4
|
+
|
5
|
+
def up
|
6
|
+
Accreditation.where(name: 'Other').destroy_all
|
7
|
+
end
|
8
|
+
|
9
|
+
def down
|
10
|
+
# Unfortunately we can't just insert the 'Other' record, as there are parts
|
11
|
+
# of `rad` and `rad_consumer` which rely on the 'Other' record having the
|
12
|
+
# ID of '5'. This is due to translations and configuring whether or not to
|
13
|
+
# show the record.
|
14
|
+
#
|
15
|
+
# You're allowed to roll back this migration, but be aware that if you're
|
16
|
+
# using an older version of `rad` or `rad_consumer` they may throw errors
|
17
|
+
# if this record doesn't exist.
|
18
|
+
end
|
19
|
+
end
|
data/lib/mas/office_result.rb
CHANGED
@@ -15,10 +15,4 @@ class OfficeResult
|
|
15
15
|
@disabled_access = data['disabled_access']
|
16
16
|
@location = Location.new data['location']['lat'], data['location']['lon']
|
17
17
|
end
|
18
|
-
|
19
|
-
def telephone_number
|
20
|
-
return nil unless @telephone_number
|
21
|
-
|
22
|
-
UKPhoneNumbers.format(@telephone_number)
|
23
|
-
end
|
24
18
|
end
|
data/lib/mas/rad_core/version.rb
CHANGED
data/spec/dummy/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20160222091312) do
|
15
15
|
|
16
16
|
# These are extensions that must be enabled in order to support this database
|
17
17
|
enable_extension "plpgsql"
|
data/spec/factories/office.rb
CHANGED
@@ -6,7 +6,7 @@ FactoryGirl.define do
|
|
6
6
|
address_county { Faker::Address.state }
|
7
7
|
address_postcode 'EC1N 2TD'
|
8
8
|
email_address { Faker::Internet.email }
|
9
|
-
telephone_number
|
9
|
+
telephone_number '07111 333 222'
|
10
10
|
disabled_access { [true, false].sample }
|
11
11
|
latitude { Faker::Address.latitude.to_f.round(6) }
|
12
12
|
longitude { Faker::Address.longitude.to_f.round(6) }
|
data/spec/factories/principal.rb
CHANGED
@@ -7,7 +7,7 @@ FactoryGirl.define do
|
|
7
7
|
last_name { Faker::Name.last_name }
|
8
8
|
email_address { Faker::Internet.email(first_name) }
|
9
9
|
job_title { Faker::Name.title }
|
10
|
-
telephone_number
|
10
|
+
telephone_number '07111 333 222'
|
11
11
|
confirmed_disclaimer true
|
12
12
|
|
13
13
|
after(:build) { |p| create(:lookup_firm, fca_number: p.fca_number) }
|
@@ -8,7 +8,7 @@ RSpec.describe OfficeResult do
|
|
8
8
|
'address_county' => 'Cumbria',
|
9
9
|
'address_postcode' => 'LA8 9BE',
|
10
10
|
'email_address' => 'postie@example.com',
|
11
|
-
'telephone_number' => '
|
11
|
+
'telephone_number' => '020 8595 2346',
|
12
12
|
'disabled_access' => true,
|
13
13
|
'location' => { 'lat' => 51.5180697, 'lon' => -0.1085203 }
|
14
14
|
}
|
data/spec/models/office_spec.rb
CHANGED
@@ -67,6 +67,28 @@ RSpec.describe Office do
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
+
describe '#telephone_number=' do
|
71
|
+
context 'when `nil`' do
|
72
|
+
before { office.telephone_number = nil }
|
73
|
+
|
74
|
+
it 'returns `nil`' do
|
75
|
+
expect(office.telephone_number).to be_nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'when provided' do
|
80
|
+
it 'removes whitespace from the front and back' do
|
81
|
+
office.telephone_number = ' 07715 930 457 '
|
82
|
+
expect(office.telephone_number).to eq('07715 930 457')
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'removes extraneous whitespace' do
|
86
|
+
office.telephone_number = '07715 930 457'
|
87
|
+
expect(office.telephone_number).to eq('07715 930 457')
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
70
92
|
describe '#telephone_number' do
|
71
93
|
context 'when `nil`' do
|
72
94
|
before { office.telephone_number = nil }
|
@@ -77,10 +99,19 @@ RSpec.describe Office do
|
|
77
99
|
end
|
78
100
|
|
79
101
|
context 'when provided' do
|
80
|
-
|
102
|
+
it 'removes whitespace from the front and back' do
|
103
|
+
office.update_column(:telephone_number, ' 07715 930 457 ')
|
104
|
+
expect(office.telephone_number).to eq('07715 930 457')
|
105
|
+
end
|
81
106
|
|
82
|
-
it 'removes whitespace' do
|
83
|
-
|
107
|
+
it 'removes extraneous whitespace' do
|
108
|
+
office.update_column(:telephone_number, '07715 930 457')
|
109
|
+
expect(office.telephone_number).to eq('07715 930 457')
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'formats if there is no whitespace at all' do
|
113
|
+
office.update_column(:telephone_number, '07715930457')
|
114
|
+
expect(office.telephone_number).to eq('07715 930457')
|
84
115
|
end
|
85
116
|
end
|
86
117
|
end
|
@@ -114,21 +145,71 @@ RSpec.describe Office do
|
|
114
145
|
end
|
115
146
|
|
116
147
|
describe 'telephone number' do
|
117
|
-
|
118
|
-
before { office.telephone_number = nil }
|
148
|
+
# See http://www.area-codes.org.uk/formatting.php#programmers for background info
|
119
149
|
|
120
|
-
|
121
|
-
|
150
|
+
context 'invalid inputs' do
|
151
|
+
context 'when not present' do
|
152
|
+
before { office.telephone_number = nil }
|
122
153
|
|
123
|
-
|
124
|
-
|
154
|
+
it { is_expected.to_not be_valid }
|
155
|
+
end
|
125
156
|
|
126
|
-
|
157
|
+
context 'when the input characters other than spaces or numbers' do
|
158
|
+
before { office.telephone_number = 'not-numbers-or-spaces' }
|
159
|
+
|
160
|
+
it { is_expected.to_not be_valid }
|
161
|
+
end
|
162
|
+
|
163
|
+
context 'when the area code is not specified' do
|
164
|
+
before { office.telephone_number = '917561' }
|
165
|
+
|
166
|
+
it { is_expected.to_not be_valid }
|
167
|
+
end
|
168
|
+
|
169
|
+
context 'when the prefix is not a 0' do
|
170
|
+
before { office.telephone_number = '7816917560' }
|
171
|
+
|
172
|
+
it { is_expected.to_not be_valid }
|
173
|
+
end
|
174
|
+
|
175
|
+
context 'when the prefix is not a real area code' do
|
176
|
+
# Currently 04 and 06 are not valid prefixes
|
177
|
+
before { office.telephone_number = '04816 917560' }
|
178
|
+
|
179
|
+
it { is_expected.to_not be_valid }
|
180
|
+
end
|
181
|
+
|
182
|
+
context 'when the prefix is a +nn country code' do
|
183
|
+
before { office.telephone_number = '+44 7816917560' }
|
184
|
+
|
185
|
+
it { is_expected.to_not be_valid }
|
186
|
+
end
|
187
|
+
|
188
|
+
context 'when the prefix is a 00nn international access code' do
|
189
|
+
before { office.telephone_number = '0044 7816917560' }
|
190
|
+
|
191
|
+
it { is_expected.to_not be_valid }
|
192
|
+
end
|
193
|
+
|
194
|
+
context 'when the prefix is a nn international access code' do
|
195
|
+
before { office.telephone_number = '447816917560' }
|
196
|
+
|
197
|
+
it { is_expected.to_not be_valid }
|
198
|
+
end
|
127
199
|
end
|
128
200
|
|
129
|
-
context '
|
130
|
-
|
131
|
-
|
201
|
+
context 'valid inputs' do
|
202
|
+
context 'when it has no spaces' do
|
203
|
+
before { office.telephone_number = '07816917561' }
|
204
|
+
|
205
|
+
it { is_expected.to be_valid }
|
206
|
+
end
|
207
|
+
|
208
|
+
context 'when it has spaces' do
|
209
|
+
before { office.telephone_number = '07816 917 561' }
|
210
|
+
|
211
|
+
it { is_expected.to be_valid }
|
212
|
+
end
|
132
213
|
end
|
133
214
|
end
|
134
215
|
|
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.102
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Lovell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -328,6 +328,7 @@ files:
|
|
328
328
|
- db/migrate/20151111132037_remove_latitude_and_longitude_from_firm.rb
|
329
329
|
- db/migrate/20160205150033_add_bypass_reference_number_check_to_advisers.rb
|
330
330
|
- db/migrate/20160211161127_create_snapshots.rb
|
331
|
+
- db/migrate/20160222091312_remove_other_accreditation.rb
|
331
332
|
- lib/mas/adviser_result.rb
|
332
333
|
- lib/mas/elastic_search_client.rb
|
333
334
|
- lib/mas/firm_indexer.rb
|