mas-rad_core 0.0.80 → 0.0.81

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: 439f2ddeb557336ca2337cfbf574b802cb70d4bb
4
- data.tar.gz: e3bbba73a760d498ffaa5ac78cc9fb7a41bd2e3a
3
+ metadata.gz: e2f8947dfc7c45c34e1998ca8af771722f43f493
4
+ data.tar.gz: 6885e9c568e5100b60f6794e2416a6b59f88db2a
5
5
  SHA512:
6
- metadata.gz: c65f5254b56b84ef07cc0482a0fc63a5ae55a6e7fbcc63fcb11af08ae64a946e045c174cb59d851787fb31e9af6757dd33f160e4c1a4e1da9a885b49f303f7c1
7
- data.tar.gz: 0cbbb811bb47b2e00fec9b4d7292ba386c31cfba517c80974636d0bbd7180351e7df8113aabfb8af46d1f33ff8be8dc0a908da301fd8fea01b38a10b21c27440
6
+ metadata.gz: c715b56726070f6f800e7155434b4d418207bc22f776d19b0131997bd8f73c847928e26181a613007fad7939f7cd6d42253df5bbe41600c1a16c2e71bdc62860
7
+ data.tar.gz: 4ac0dec58ce440793367fbe0b3e56655cae7daf6981d4797cfd57adf322b14ac5a02709bfe2642be7db191e4392b3a71c6635d5d6e5cad83f58978dbc4e2bd81
@@ -4,6 +4,10 @@ class IndexFirmJob < ActiveJob::Base
4
4
  end
5
5
 
6
6
  def perform(firm)
7
- FirmRepository.new.store(firm) if firm.publishable?
7
+ if firm.publishable?
8
+ FirmRepository.new.store(firm)
9
+ else
10
+ DeleteFirmJob.perform_later(firm.id)
11
+ end
8
12
  end
9
13
  end
@@ -126,6 +126,10 @@ class Firm < ActiveRecord::Base
126
126
  to: :main_office,
127
127
  allow_nil: true
128
128
 
129
+ # A heuristic that allows us to infer validity
130
+ #
131
+ # This method is basically a cheap way to answer the question: has this
132
+ # record ever been saved with validation enabled?
129
133
  def registered?
130
134
  email_address.present?
131
135
  end
@@ -195,7 +199,7 @@ class Firm < ActiveRecord::Base
195
199
  end
196
200
 
197
201
  def publishable?
198
- valid? && main_office.present? && !missing_advisers?
202
+ registered? && offices.any? && !missing_advisers?
199
203
  end
200
204
 
201
205
  def missing_advisers?
@@ -71,35 +71,12 @@ class Principal < ActiveRecord::Base
71
71
  "#{first_name} #{last_name}"
72
72
  end
73
73
 
74
- def next_onboarding_action
75
- registered_firms = main_firm_with_trading_names.registered
76
-
77
- case
78
- when registered_firms.empty?
79
- :complete_a_firm
80
- when any_remote_firms?(registered_firms)
81
- :onboarded
82
- when needs_advisers?(registered_firms)
83
- :complete_an_adviser
84
- else
85
- :onboarded
86
- end
87
- end
88
-
89
74
  def onboarded?
90
- next_onboarding_action == :onboarded
75
+ main_firm_with_trading_names.any?(&:publishable?)
91
76
  end
92
77
 
93
78
  private
94
79
 
95
- def any_remote_firms?(firm_list)
96
- firm_list.any? { |f| f.primary_advice_method == :remote }
97
- end
98
-
99
- def needs_advisers?(firm_list)
100
- firm_list.none? { |f| f.advisers.present? }
101
- end
102
-
103
80
  def find_subsidiary(subsidiary)
104
81
  firm.subsidiaries.find_or_initialize_by(
105
82
  registered_name: subsidiary.name,
@@ -1,5 +1,5 @@
1
1
  module MAS
2
2
  module RadCore
3
- VERSION = '0.0.80'
3
+ VERSION = '0.0.81'
4
4
  end
5
5
  end
Binary file
@@ -1,6 +1,7 @@
1
1
  RSpec.describe IndexFirmJob, '#perform' do
2
2
  let(:repository) { instance_double(FirmRepository) }
3
- let(:firm) { Firm.new }
3
+ let(:firm_id) { 3 }
4
+ let(:firm) { Firm.new(id: firm_id) }
4
5
 
5
6
  before do
6
7
  allow(FirmRepository).to receive(:new).and_return(repository)
@@ -26,5 +27,10 @@ RSpec.describe IndexFirmJob, '#perform' do
26
27
  expect(repository).not_to receive(:store).with(firm)
27
28
  described_class.new.perform(firm)
28
29
  end
30
+
31
+ it 'invokes the DeleteFirmJob to remove the firm from the directory' do
32
+ expect(DeleteFirmJob).to receive(:perform_later).with(firm_id)
33
+ described_class.new.perform(firm)
34
+ end
29
35
  end
30
36
  end
@@ -126,10 +126,7 @@ RSpec.describe Firm do
126
126
 
127
127
  context 'when the firm is not valid' do
128
128
  let(:firm) do
129
- FactoryGirl.create(:firm).tap do |f|
130
- f.email_address = nil
131
- f.save(validate: false)
132
- end
129
+ FactoryGirl.build(:invalid_firm).tap { |f| f.save(validate: false) }
133
130
  end
134
131
 
135
132
  it { is_expected.to be_falsey }
@@ -204,221 +204,35 @@ RSpec.describe Principal do
204
204
  end
205
205
 
206
206
  describe '#onboarded?' do
207
- context 'when a principal has been onboarded' do
208
- before :each do
209
- principal.firm.update_attributes(FactoryGirl.attributes_for :onboarded_firm, fca_number: principal.fca_number)
210
- create(:adviser, firm: principal.firm)
211
- end
207
+ context 'when no firms are publishable' do
208
+ before do
209
+ FactoryGirl.build(:invalid_firm,
210
+ fca_number: principal.fca_number,
211
+ parent: principal.firm).save(validate: false)
212
212
 
213
- it 'returns true' do
214
- expect(principal).to be_onboarded
215
- end
216
- end
217
-
218
- context 'when a principal has not been onboarded' do
219
- before :each do
220
- attrs = FactoryGirl.attributes_for :not_onboarded_firm, fca_number: principal.fca_number
221
- principal.firm.update_attributes(attrs)
213
+ expect(principal.main_firm_with_trading_names).to have(2).items
214
+ expect(principal.main_firm_with_trading_names)
215
+ .to all(have_attributes(publishable?: false))
222
216
  end
223
217
 
224
218
  it 'returns false' do
225
- expect(principal).not_to be_onboarded
226
- end
227
- end
228
- end
229
-
230
- describe '#next_onboarding_action' do
231
- context 'when principal has no firms or trading names' do
232
- before :each do
233
- principal.firm.destroy
234
- principal.reload
235
- expect(principal.main_firm_with_trading_names).to be_empty
236
- end
237
-
238
- it 'returns :complete_a_firm' do
239
- expect(principal.next_onboarding_action).to eql(:complete_a_firm)
240
- end
241
- end
242
-
243
- context 'when principal only has a parent firm' do
244
- before :each do
245
- expect(principal.firm).not_to be_nil
246
- expect(Firm.where(fca_number: principal.fca_number).count).to eql(1)
247
- end
248
-
249
- context 'and the parent firm is not registered' do
250
- before :each do
251
- expect(principal.firm).not_to be_registered
252
- end
253
-
254
- it 'returns :complete_a_firm' do
255
- expect(principal.next_onboarding_action).to eql(:complete_a_firm)
256
- end
257
- end
258
-
259
- context 'and the parent firm is registered' do
260
- before :each do
261
- principal.firm.update_column(:email_address, 'acme@example.com')
262
- principal.reload
263
- expect(principal.firm).to be_registered
264
- end
265
-
266
- context 'and the firm primarily gives remote advice' do
267
- before :each do
268
- principal.firm.in_person_advice_methods.destroy_all
269
- principal.firm.other_advice_methods << create(:other_advice_method)
270
- principal.reload
271
- end
272
-
273
- context 'and the firm has no advisers' do
274
- before :each do
275
- expect(principal.firm.advisers.any?).to eql(false)
276
- end
277
-
278
- it 'returns :onboarded' do
279
- expect(principal.next_onboarding_action).to eql(:onboarded)
280
- end
281
- end
282
-
283
- context 'and the firm has advisers' do
284
- before :each do
285
- create(:adviser, firm: principal.firm)
286
- principal.reload
287
- expect(principal.firm.advisers.any?).to eql(true)
288
- end
289
-
290
- it 'returns :onboarded' do
291
- expect(principal.next_onboarding_action).to eql(:onboarded)
292
- end
293
- end
294
- end
295
-
296
- context 'and the firm primarily gives in-person advice' do
297
- before :each do
298
- principal.firm.in_person_advice_methods << create(:in_person_advice_method)
299
- principal.reload
300
- end
301
-
302
- context 'and has at least one adviser' do
303
- before :each do
304
- create(:adviser, firm: principal.firm)
305
- principal.reload
306
- end
307
-
308
- it 'returns :onboarded' do
309
- expect(principal.next_onboarding_action).to eql(:onboarded)
310
- end
311
- end
312
-
313
- context 'and does not have at least one adviser' do
314
- before :each do
315
- expect(principal.firm.advisers.any?).to eql(false)
316
- end
317
-
318
- it 'returns :complete_an_adviser' do
319
- expect(principal.next_onboarding_action).to eql(:complete_an_adviser)
320
- end
321
- end
322
- end
219
+ expect(principal.onboarded?).to be(false)
323
220
  end
324
221
  end
325
222
 
326
- context 'when principal has a parent firm and a trading name' do
327
- let(:parent_firm) { principal.firm }
328
- let!(:trading_name) { create(:firm_without_advisers, registered_name: 'cabbage', parent_id: parent_firm.id, fca_number: principal.fca_number) }
223
+ context 'when one firm is publishable' do
224
+ before do
225
+ FactoryGirl.create(:publishable_firm,
226
+ fca_number: principal.fca_number,
227
+ parent: principal.firm)
329
228
 
330
- before :each do
331
- parent_firm.update_column(:email_address, 'acme@example.com')
332
- principal.reload
333
- expect(Firm.where(fca_number: principal.fca_number).count).to eql(2)
229
+ expect(principal.main_firm_with_trading_names).to have(2).items
230
+ expect(principal.firm).not_to be_publishable
231
+ expect(principal.firm.trading_names.first).to be_publishable
334
232
  end
335
233
 
336
- context 'and neither firm give in-person advice' do
337
- before :each do
338
- parent_firm.in_person_advice_methods.destroy_all
339
- parent_firm.other_advice_methods << create(:other_advice_method)
340
- trading_name.in_person_advice_methods.destroy_all
341
- trading_name.other_advice_methods << create(:other_advice_method)
342
- principal.reload
343
- end
344
-
345
- it_behaves_like 'at least one remote firm'
346
- end
347
-
348
- context 'if at least one firm gives remote advice' do
349
- context 'parent firm gives remote advice' do
350
- before :each do
351
- parent_firm.in_person_advice_methods.destroy_all
352
- parent_firm.other_advice_methods << create(:other_advice_method)
353
- trading_name.in_person_advice_methods << create(:in_person_advice_method)
354
- principal.reload
355
- end
356
-
357
- it_behaves_like 'at least one remote firm'
358
- end
359
-
360
- context 'trading name gives remote advice' do
361
- before :each do
362
- parent_firm.in_person_advice_methods << create(:in_person_advice_method)
363
- trading_name.in_person_advice_methods.destroy_all
364
- trading_name.other_advice_methods << create(:other_advice_method)
365
- principal.reload
366
- end
367
-
368
- it_behaves_like 'at least one remote firm'
369
- end
370
- end
371
-
372
- context 'and both firms give in-person advice' do
373
- before :each do
374
- parent_firm.in_person_advice_methods << create(:in_person_advice_method)
375
- trading_name.in_person_advice_methods << create(:in_person_advice_method)
376
- principal.reload
377
- end
378
-
379
- context 'and neither firm has advisers' do
380
- before :each do
381
- expect(parent_firm.advisers.any?).to eql(false)
382
- expect(trading_name.advisers.any?).to eql(false)
383
- end
384
-
385
- it 'returns :complete_an_adviser' do
386
- expect(principal.next_onboarding_action).to eql(:complete_an_adviser)
387
- end
388
- end
389
-
390
- context 'and parent firm has advisers' do
391
- before :each do
392
- create(:adviser, firm: parent_firm)
393
- expect(trading_name.advisers.any?).to eql(false)
394
- end
395
-
396
- it 'returns :onboarded' do
397
- expect(principal.next_onboarding_action).to eql(:onboarded)
398
- end
399
- end
400
-
401
- context 'and trading name has advisers' do
402
- before :each do
403
- expect(parent_firm.advisers.any?).to eql(false)
404
- create(:adviser, firm: trading_name)
405
- end
406
-
407
- it 'returns :onboarded' do
408
- expect(principal.next_onboarding_action).to eql(:onboarded)
409
- end
410
- end
411
-
412
- context 'and both firms have advisers' do
413
- before :each do
414
- create(:adviser, firm: parent_firm)
415
- create(:adviser, firm: trading_name)
416
- end
417
-
418
- it 'returns :onboarded' do
419
- expect(principal.next_onboarding_action).to eql(:onboarded)
420
- end
421
- end
234
+ it 'returns true' do
235
+ expect(principal.onboarded?).to be(true)
422
236
  end
423
237
  end
424
238
  end
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.80
4
+ version: 0.0.81
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-09-18 00:00:00.000000000 Z
11
+ date: 2015-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -414,7 +414,6 @@ files:
414
414
  - spec/spec_helper.rb
415
415
  - spec/support/field_length_validation_helpers.rb
416
416
  - spec/support/queue_spec_helper.rb
417
- - spec/support/shared_examples/at_least_one_remote_firm.rb
418
417
  - spec/support/shared_examples/friendly_named.rb
419
418
  - spec/support/shared_examples/geocodable_examples.rb
420
419
  - spec/support/shared_examples/reference_data.rb
@@ -541,7 +540,6 @@ test_files:
541
540
  - spec/spec_helper.rb
542
541
  - spec/support/field_length_validation_helpers.rb
543
542
  - spec/support/queue_spec_helper.rb
544
- - spec/support/shared_examples/at_least_one_remote_firm.rb
545
543
  - spec/support/shared_examples/friendly_named.rb
546
544
  - spec/support/shared_examples/geocodable_examples.rb
547
545
  - spec/support/shared_examples/reference_data.rb
@@ -1,53 +0,0 @@
1
- ##
2
- # Needs:
3
- # principal = instance of Principal with two firms attached (parent_firm and trading_name)
4
- # parent_firm = an instance of Firm with the same FCA Number as the Principal but no parent firm
5
- # trading_name = an instance of Firm with the same FCA Number as the Principal and the parent_firm as the parent firm
6
- RSpec.shared_examples 'at least one remote firm' do
7
- context 'and neither firm has advisers' do
8
- before :each do
9
- expect(parent_firm.advisers.any?).to eql(false)
10
- expect(trading_name.advisers.any?).to eql(false)
11
- end
12
-
13
- it 'returns :onboarded' do
14
- expect(principal.next_onboarding_action).to eql(:onboarded)
15
- end
16
- end
17
-
18
- context 'and the parent firm has advisers' do
19
- before :each do
20
- create(:adviser, firm: parent_firm)
21
- expect(trading_name.advisers.any?).to eql(false)
22
- principal.reload
23
- end
24
-
25
- it 'returns :onboarded' do
26
- expect(principal.next_onboarding_action).to eql(:onboarded)
27
- end
28
- end
29
-
30
- context 'and the trading name has advisers' do
31
- before :each do
32
- expect(parent_firm.advisers.any?).to eql(false)
33
- create(:adviser, firm: trading_name)
34
- principal.reload
35
- end
36
-
37
- it 'returns :onboarded' do
38
- expect(principal.next_onboarding_action).to eql(:onboarded)
39
- end
40
- end
41
-
42
- context 'and both firms have advisers' do
43
- before :each do
44
- create(:adviser, firm: parent_firm)
45
- create(:adviser, firm: trading_name)
46
- principal.reload
47
- end
48
-
49
- it 'returns :onboarded' do
50
- expect(principal.next_onboarding_action).to eql(:onboarded)
51
- end
52
- end
53
- end