diff --git a/Gemfile.lock b/Gemfile.lock index 342024da..d6cfe519 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -166,7 +166,8 @@ GEM console (1.17.0) fiber-annotation fiber-local - crack (0.4.5) + crack (1.0.0) + bigdecimal rexml crass (1.0.6) date (3.3.4) @@ -241,7 +242,7 @@ GEM activemodel (>= 6.1) activesupport (>= 6.1) html-attributes-utils (~> 1) - hashdiff (1.0.1) + hashdiff (1.1.0) high_voltage (3.1.2) html-attributes-utils (1.0.2) activesupport (>= 6.1.4.4) @@ -280,7 +281,7 @@ GEM minitest (5.21.2) multi_json (1.15.0) mutex_m (0.2.0) - net-imap (0.4.9.1) + net-imap (0.4.10) date net-protocol net-pop (0.1.2) @@ -291,10 +292,10 @@ GEM net-protocol netrc (0.11.0) nio4r (2.7.0) - nokogiri (1.16.0) + nokogiri (1.16.2) mini_portile2 (~> 2.8.2) racc (~> 1.4) - nokogiri (1.16.0-x86_64-linux) + nokogiri (1.16.2-x86_64-linux) racc (~> 1.4) notifications-ruby-client (6.0.0) jwt (>= 1.5, < 3) @@ -481,7 +482,7 @@ GEM validates_email_format_of (1.7.2) i18n vcr (6.2.0) - webmock (3.19.1) + webmock (3.20.0) addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) diff --git a/app/models/flood_risk_engine/enrollment.rb b/app/models/flood_risk_engine/enrollment.rb index 699f9034..c60bff94 100644 --- a/app/models/flood_risk_engine/enrollment.rb +++ b/app/models/flood_risk_engine/enrollment.rb @@ -4,9 +4,6 @@ module FloodRiskEngine class Enrollment < ApplicationRecord has_secure_token - # We don't define the inverse relationship of applicant_contact as, in WEX at least, - # we query never from contact to its enrollment - belongs_to :applicant_contact, class_name: "Contact" belongs_to :organisation delegate :org_type, :partners, to: :organisation, allow_nil: true @@ -22,8 +19,8 @@ class Enrollment < ApplicationRecord belongs_to :secondary_contact, class_name: "Contact" belongs_to :reference_number - def reference_number - super.try(:number) + def ref_number + reference_number.number end has_one( diff --git a/app/models/flood_risk_engine/location.rb b/app/models/flood_risk_engine/location.rb index 154a8b19..99ffec69 100644 --- a/app/models/flood_risk_engine/location.rb +++ b/app/models/flood_risk_engine/location.rb @@ -5,7 +5,7 @@ module FloodRiskEngine class Location < ApplicationRecord belongs_to :locatable, polymorphic: true - belongs_to :water_management_area + belongs_to :water_management_area, optional: true before_save :process_grid_reference diff --git a/app/services/flood_risk_engine/notify/enrollment_submitted_email_service.rb b/app/services/flood_risk_engine/notify/enrollment_submitted_email_service.rb index 22989681..de0a0d2c 100644 --- a/app/services/flood_risk_engine/notify/enrollment_submitted_email_service.rb +++ b/app/services/flood_risk_engine/notify/enrollment_submitted_email_service.rb @@ -10,7 +10,7 @@ def notify_options email_address: @recipient_address, template_id:, personalisation: { - registration_number: @enrollment.reference_number, + registration_number: @enrollment.ref_number, exemption_description: enrollment_description } } diff --git a/app/services/flood_risk_engine/registration_completion_service.rb b/app/services/flood_risk_engine/registration_completion_service.rb index 10a3b7df..6c578862 100644 --- a/app/services/flood_risk_engine/registration_completion_service.rb +++ b/app/services/flood_risk_engine/registration_completion_service.rb @@ -8,8 +8,6 @@ def run(transient_registration:) @registration = nil @transient_registration.with_lock do - @transient_registration.update(workflow_state: :creating_registration) - @registration = Enrollment.new transfer_data @registration.save! @@ -22,8 +20,8 @@ def run(transient_registration:) @registration rescue StandardError => e - Airbrake.notify(e, reference: @registration&.reference_number) if defined?(Airbrake) - Rails.logger.error "Completing registration error: #{e}" + Airbrake.notify(e, reference: @registration&.ref_number) if defined?(Airbrake) + Rails.logger.error "Completing registration error: #{e}\n#{@registration.errors.inspect}" raise e end @@ -70,7 +68,7 @@ def add_secondary_contact end def add_partnership_organisation - @registration.organisation = Organisation.new( + @registration.organisation = Organisation.create!( org_type: ) @@ -137,6 +135,9 @@ def update_status_and_assistance_mode end def update_water_management_area + # location.id must be present for ActiveJob serialization: + @registration.exemption_location.save! + UpdateWaterManagementAreaJob.perform_later(@registration.exemption_location) end diff --git a/app/views/flood_risk_engine/enrollment_mailer/submitted.html.erb b/app/views/flood_risk_engine/enrollment_mailer/submitted.html.erb index 7adb482a..1a1d44fd 100644 --- a/app/views/flood_risk_engine/enrollment_mailer/submitted.html.erb +++ b/app/views/flood_risk_engine/enrollment_mailer/submitted.html.erb @@ -5,7 +5,7 @@ <% end %>

- <%= t('.reference_number_heading', reference_number: @enrollment.reference_number) %> + <%= t('.ref_number_heading', reference_number: @enrollment.ref_number) %>

<%= t('.exemption_heading') %>

diff --git a/app/views/flood_risk_engine/enrollment_mailer/submitted.text.erb b/app/views/flood_risk_engine/enrollment_mailer/submitted.text.erb index 50acd607..56ee5101 100644 --- a/app/views/flood_risk_engine/enrollment_mailer/submitted.text.erb +++ b/app/views/flood_risk_engine/enrollment_mailer/submitted.text.erb @@ -1,7 +1,7 @@ <%= t('.registration_submitted') %> <%= t('.please_wait') %> -------------------------------------------------------- <%= "\r\n" %> -<%= t('.text_reference_number', reference_number: @enrollment.reference_number) %> +<%= t('.text_reference_number', reference_number: @enrollment.ref_number) %> <%= "\r\n" %> <%= t(".exemption_heading") %> <%= @exemption.summary %> <%= @exemption.code %>. diff --git a/app/views/flood_risk_engine/registration_complete_forms/new.html.erb b/app/views/flood_risk_engine/registration_complete_forms/new.html.erb index 9d6e9fa3..ed8652d0 100644 --- a/app/views/flood_risk_engine/registration_complete_forms/new.html.erb +++ b/app/views/flood_risk_engine/registration_complete_forms/new.html.erb @@ -13,7 +13,7 @@
<%= t(".reference") %>
- <%= @enrollment.reference_number %> + <%= @enrollment.ref_number %>
diff --git a/config/locales/flood_risk_engine/company_address_manual_forms.en.yml b/config/locales/flood_risk_engine/company_address_manual_forms.en.yml index a626c72a..450b8052 100644 --- a/config/locales/flood_risk_engine/company_address_manual_forms.en.yml +++ b/config/locales/flood_risk_engine/company_address_manual_forms.en.yml @@ -10,8 +10,8 @@ en: soleTrader: What’s the address of the business? charity: What’s the address of the charity or trust? title: *heading - os_places_error_heading: Our address finder is not working - os_places_error_text: Please enter the address below. + address_finder_error_heading: Our address finder is not working + address_finder_error_text: Please enter the address below. preset_postcode_label: Postcode postcode_change_link: Change postcode error_heading: Something is wrong diff --git a/spec/models/flood_risk_engine/enrollment_spec.rb b/spec/models/flood_risk_engine/enrollment_spec.rb index 8898dac6..34b0c03a 100644 --- a/spec/models/flood_risk_engine/enrollment_spec.rb +++ b/spec/models/flood_risk_engine/enrollment_spec.rb @@ -6,7 +6,6 @@ module FloodRiskEngine RSpec.describe Enrollment do let(:enrollment) { create(:enrollment) } - it { is_expected.to belong_to(:applicant_contact) } it { is_expected.to belong_to(:organisation) } it { is_expected.to have_one(:exemption_location).dependent(:restrict_with_exception) } @@ -16,7 +15,7 @@ module FloodRiskEngine end it "is of the right format" do - expect(enrollment.reference_number).to match(/EXFRA\d{6}/) + expect(enrollment.ref_number).to match(/EXFRA\d{6}/) end end diff --git a/spec/services/flood_risk_engine/notify/enrollment_submitted_email_service_spec.rb b/spec/services/flood_risk_engine/notify/enrollment_submitted_email_service_spec.rb index 812ade2a..32570a9b 100644 --- a/spec/services/flood_risk_engine/notify/enrollment_submitted_email_service_spec.rb +++ b/spec/services/flood_risk_engine/notify/enrollment_submitted_email_service_spec.rb @@ -23,7 +23,7 @@ module Notify email_address: recipient_address, template_id:, personalisation: { - registration_number: enrollment.reference_number, + registration_number: enrollment.ref_number, exemption_description: } } diff --git a/spec/services/flood_risk_engine/registration_completion_service_spec.rb b/spec/services/flood_risk_engine/registration_completion_service_spec.rb index ebe6bed3..35967401 100644 --- a/spec/services/flood_risk_engine/registration_completion_service_spec.rb +++ b/spec/services/flood_risk_engine/registration_completion_service_spec.rb @@ -31,7 +31,7 @@ module FloodRiskEngine expect(enrollment.submitted_at).to eq(stub_time) end - it "assigns the correct correspondance contact to the new enrollment" do + it "assigns the correct correspondence contact to the new enrollment" do correspondence_contact_attributes = { "full_name" => new_registration.contact_name, "email_address" => new_registration.contact_email, @@ -117,7 +117,7 @@ module FloodRiskEngine it "assigns the correct reference number" do run_service - expect(enrollment.reference_number).to eq(ReferenceNumber.last.number) + expect(enrollment.ref_number).to eq(ReferenceNumber.last.number) end it "assigns the status" do