Skip to content

Commit 6f8a623

Browse files
Update flow to delete entire reference rather than just the file
1 parent bdafc0e commit 6f8a623

8 files changed

Lines changed: 47 additions & 38 deletions

File tree

app/controllers/publishers/vacancies/job_applications/reference_requests_controller.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ def mark_as_complete
4949
redirect_to organisation_job_job_application_reference_request_path(@vacancy.id, @job_application.id, @reference_request.id)
5050
end
5151

52-
def reference_form
53-
@reference_request.reference_form.purge_later
54-
redirect_to organisation_job_job_application_reference_request_path(@vacancy.id, @job_application.id, @reference_request.id),
55-
success: t(".success")
56-
end
57-
5852
private
5953

6054
def email_form_class

app/controllers/publishers/vacancies/job_applications/references_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ def new
1111
@referee = RefereeForm.new
1212
end
1313

14+
def destroy
15+
@job_application.referees.find(params[:id]).destroy
16+
redirect_to pre_interview_checks_organisation_job_job_application_path(@vacancy.id, @job_application),
17+
success: t(".success")
18+
end
19+
1420
def create
1521
@note = @job_application.notes.build
1622
@referee = RefereeForm.new(referee_form_params)

app/views/publishers/vacancies/job_applications/reference_requests/show.html.slim

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@
5050
= summary_list.with_row do |row|
5151
- row.with_key(text: key)
5252
- row.with_value(text: value)
53+
- if @reference_request.reference_form.attached?
54+
= summary_list.with_row do |row|
55+
- row.with_key(text: t(".uploaded_reference.heading"))
56+
- row.with_value do
57+
= govuk_link_to "#{@reference_request.reference_form.filename} (#{number_to_human_size(@reference_request.reference_form.byte_size)})", @reference_request.reference_form
5358

5459
- if @reference_request.reference_form.attached?
55-
h2.govuk-heading-m = t(".uploaded_reference.heading")
56-
p.govuk-body
57-
= govuk_link_to "#{@reference_request.reference_form.filename} (#{number_to_human_size(@reference_request.reference_form.byte_size)})", @reference_request.reference_form
58-
= govuk_link_to t(".uploaded_reference.delete"), reference_form_organisation_job_job_application_reference_request_path(@vacancy.id, @job_application.id, @reference_request.id), method: :delete, class: "govuk-link govuk-link--no-visited-state"
60+
= govuk_button_link_to t(".uploaded_reference.delete"), organisation_job_job_application_reference_path(@vacancy.id, @job_application.id, @reference_request.referee), method: :delete, class: "govuk-button--warning"
5961

6062
- if @reference_request.sent?
6163
- if @job_reference.complete?

config/locales/publishers/vacancies/job_applications.en.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ en:
1313
vacancies:
1414
job_applications:
1515
references:
16+
destroy:
17+
success: Reference deleted successfully
1618
new:
1719
page_title: Create reference
1820
caption: Reference
@@ -165,12 +167,10 @@ en:
165167
edit:
166168
caption: Update referee information
167169
heading: What is the correct email address for %{name}?
168-
reference_form:
169-
success: Reference document deleted successfully
170170
show:
171171
uploaded_reference:
172172
heading: Uploaded reference
173-
delete: Delete uploaded reference
173+
delete: Delete reference
174174
print: Download reference
175175
how_would_you_rate: How would you rate %{name}?
176176
page_title: Reference

config/routes.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,6 @@
449449
patch :mark_as_received
450450
patch :mark_as_complete
451451
patch :send_reminder_email
452-
delete :reference_form
453452
end
454453
end
455454
get :download
@@ -462,7 +461,7 @@
462461
get :pre_employment_checks
463462
end
464463
resource :religious_reference, only: %i[edit update], controller: "publishers/vacancies/job_applications/religious_references"
465-
resources :references, only: %i[new create], controller: "publishers/vacancies/job_applications/references"
464+
resources :references, only: %i[new create destroy], controller: "publishers/vacancies/job_applications/references"
466465
resource :online_checks, only: %i[edit update], controller: "publishers/vacancies/job_applications/online_checks"
467466
resource :pre_employment_check_set, only: %i[update], controller: "publishers/vacancies/job_applications/pre_employment_checks"
468467
member do

spec/requests/publishers/vacancies/job_applications/reference_requests_spec.rb

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,6 @@
2020

2121
after { sign_out(publisher) }
2222

23-
describe "DELETE #reference_form" do
24-
context "when a reference form is attached" do
25-
before do
26-
reference_request.reference_form.attach(
27-
io: Rails.root.join("spec/fixtures/files/blank_job_spec.pdf").open,
28-
filename: "reference.pdf",
29-
content_type: "application/pdf",
30-
)
31-
end
32-
33-
it "purges the reference form and redirects to the show page" do
34-
delete reference_form_organisation_job_job_application_reference_request_path(vacancy.id, job_application.id, reference_request.id)
35-
36-
expect(reference_request.reload.reference_form).not_to be_attached
37-
expect(response).to redirect_to(organisation_job_job_application_reference_request_path(vacancy.id, job_application.id, reference_request.id))
38-
end
39-
end
40-
end
41-
4223
describe "GET #show" do
4324
context "when request format is pdf" do
4425
it "returns the pdf file" do
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require "rails_helper"
2+
3+
RSpec.describe "Job applications references" do
4+
let(:vacancy) { create(:vacancy) }
5+
let(:organisation) { vacancy.organisations.first }
6+
let(:job_application) { create(:job_application, :status_submitted, vacancy:) }
7+
let(:referee) { create(:referee, job_application:) }
8+
let(:publisher) { create(:publisher, accepted_terms_at: 1.day.ago) }
9+
10+
before do
11+
# rubocop:disable RSpec/AnyInstance
12+
allow_any_instance_of(ApplicationController).to receive(:current_organisation).and_return(organisation)
13+
# rubocop:enable RSpec/AnyInstance
14+
sign_in(publisher, scope: :publisher)
15+
end
16+
17+
after { sign_out(publisher) }
18+
19+
describe "DELETE #destroy" do
20+
it "destroys the referee and redirects to pre-interview checks" do
21+
delete organisation_job_job_application_reference_path(vacancy.id, job_application.id, referee.id)
22+
23+
expect { referee.reload }.to raise_error(ActiveRecord::RecordNotFound)
24+
expect(response).to redirect_to(pre_interview_checks_organisation_job_job_application_path(vacancy.id, job_application.id))
25+
end
26+
end
27+
end

spec/system/publishers/publishers_can_add_a_manual_reference_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@
7878
expect(page).to have_content("Uploaded reference")
7979
expect(page).to have_content("blank_job_spec.pdf")
8080

81-
click_on "Delete uploaded reference"
82-
expect(page).to have_content("Reference document deleted successfully")
83-
expect(page).to have_no_content("Uploaded reference")
84-
expect(ReferenceRequest.last.reference_form.attached?).to be false
81+
click_on "Delete reference"
82+
expect(page).to have_current_path(pre_interview_checks_organisation_job_job_application_path(vacancy.id, job_application.id))
83+
expect(page).to have_content("Reference deleted successfully")
84+
expect(page).to have_no_content(referee_name)
8585
end
8686
end
8787
end

0 commit comments

Comments
 (0)