Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/ruby 2805 active record #737

Merged
merged 5 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 2 additions & 5 deletions app/models/flood_risk_engine/enrollment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion app/models/flood_risk_engine/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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
Expand Down Expand Up @@ -70,7 +68,7 @@ def add_secondary_contact
end

def add_partnership_organisation
@registration.organisation = Organisation.new(
@registration.organisation = Organisation.create!(
org_type:
)

Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<% end %>

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

<h2 class="border-top"><%= t('.exemption_heading') %></h2>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 %>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div class="govuk-panel__body">
<%= t(".reference") %><br />
<strong>
<span id="reg_identifier"><%= @enrollment.reference_number %></span>
<span id="reg_identifier"><%= @enrollment.ref_number %></span>
</strong>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions spec/models/flood_risk_engine/enrollment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Loading