Skip to content

Commit

Permalink
Swap Urn class for Application::Urn
Browse files Browse the repository at this point in the history
This is to avoid the FiberError caused by a multithreaded app server
  • Loading branch information
fumimowdan committed Oct 30, 2023
1 parent b53fcbd commit 39eb8e1
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 173 deletions.
10 changes: 9 additions & 1 deletion app/models/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,20 @@ def mark_as_qa!
unique_by: %i[application_id status])
end

after_create :set_urn

validates(:application_date, presence: true)
validates(:application_route, presence: true)
validates(:date_of_entry, presence: true)
validates(:start_date, presence: true)
validates(:subject, presence: true)
validates(:visa_type, presence: true)
validates(:applicant, presence: true)
validates(:urn, uniqueness: true)
validates(:urn, uniqueness: true, allow_blank: true)

private

def set_urn
update(urn: Urn.new(self).urn) if urn.blank?
end
end
115 changes: 0 additions & 115 deletions app/models/urn.rb

This file was deleted.

1 change: 0 additions & 1 deletion app/services/submit_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def create_application
date_of_entry: form.date_of_entry,
start_date: form.start_date,
subject: SubjectStep.new(form).answer.formatted_value,
urn: Urn.next(form.application_route),
visa_type: form.visa_type,
)
end
Expand Down
7 changes: 0 additions & 7 deletions config/initializers/urn.rb

This file was deleted.

1 change: 0 additions & 1 deletion spec/factories/applications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
visa_type { VisaStep::VALID_ANSWERS_OPTIONS.reject { _1 == "Other" }.sample }
date_of_entry { Time.zone.today }
start_date { 1.month.from_now.to_date }
urn { Urn.next(application_route) }

factory :teacher_application do
application_route { "teacher" }
Expand Down
9 changes: 7 additions & 2 deletions spec/models/application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,16 @@
end

describe "#urn" do
it "is blank before creation" do
application = described_class.new
let(:application) { build(:application) }

it "is blank before creation" do
expect(application.urn).to be_blank
end

it "is set after creation" do
application.save
expect(application.urn).not_to be_blank
end
end

describe ".search" do
Expand Down
39 changes: 0 additions & 39 deletions spec/models/urn_spec.rb

This file was deleted.

8 changes: 1 addition & 7 deletions spec/services/submit_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@
date_of_entry: form.date_of_entry,
start_date: form.start_date,
subject: SubjectStep.new(form).answer.formatted_value,
urn: kind_of(String),
visa_type: form.visa_type,
}
end
Expand All @@ -135,16 +134,11 @@
end

context "applicant email" do
before do
allow(Urn).to receive(:next).and_return(urn)
end

let(:urn) { "SOMEURN" }
let(:expected_email_params) do
{
params: {
email: form.email_address,
urn: urn,
urn: kind_of(String),
},
args: [],
}
Expand Down

0 comments on commit 39eb8e1

Please sign in to comment.