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 %>