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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc90386da6d397b1372dca8f68182393a58b11cd
4
- data.tar.gz: 50628c928c75c79ea774fc00f21510811e119fea
3
+ metadata.gz: 24f4ec598a3a7418e8ad65db835de6b4530f920d
4
+ data.tar.gz: 25aeb27b4f4d323b1c64efd6aff4d25b46ff4b25
5
5
  SHA512:
6
- metadata.gz: 2543c14010a5ed3f4571c0505d99b87da999c7762a78e9f563baaa571c2149f887f897af6234b5f7de80efbb3e2a258bc62a78eb7c577e827bc1bd4d8a4360e5
7
- data.tar.gz: f297e1105ad4cad9a9157d5bdcff4219db957feae360984c0bb539d21d859edc4e2d5f6728e9f617dd1351bcc50f9318b55e7c66b5484a3f8b4808a31d37783d
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
- validates :telephone_number,
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
- super.try { |x| x.gsub(' ', '') }
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  module MAS
2
2
  module RadCore
3
- VERSION = '0.0.101'
3
+ VERSION = '0.0.102'
4
4
  end
5
5
  end
@@ -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: 20160211161127) do
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"
@@ -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 { Faker::Base.numerify('##### ### ###') }
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) }
@@ -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 { Faker::Base.numerify('##### ### ###') }
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' => '02085952346',
11
+ 'telephone_number' => '020 8595 2346',
12
12
  'disabled_access' => true,
13
13
  'location' => { 'lat' => 51.5180697, 'lon' => -0.1085203 }
14
14
  }
@@ -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
- before { office.telephone_number = ' 07715 930 457 ' }
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
- expect(office.telephone_number).to eq('07715930457')
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
- context 'when not present' do
118
- before { office.telephone_number = nil }
148
+ # See http://www.area-codes.org.uk/formatting.php#programmers for background info
119
149
 
120
- it { is_expected.to_not be_valid }
121
- end
150
+ context 'invalid inputs' do
151
+ context 'when not present' do
152
+ before { office.telephone_number = nil }
122
153
 
123
- context 'when badly formatted' do
124
- before { office.telephone_number = 'not-valid' }
154
+ it { is_expected.to_not be_valid }
155
+ end
125
156
 
126
- it { is_expected.to_not be_valid }
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 'length' do
130
- specify { expect_length_of(office, :telephone_number, 30, fill_char: '0').to be_valid }
131
- specify { expect_length_of(office, :telephone_number, 31, fill_char: '0').not_to be_valid }
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.101
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-22 00:00:00.000000000 Z
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