Skip to content

Commit

Permalink
Fix back link when creating a claim
Browse files Browse the repository at this point in the history
When creating a claim you can end up on the edit page of a claim, or
mentors list.

These edit pages were programmed to always go to the check page, so when
a user would click them it would try to redirect them to the check page.

This commit fixes this with a reviewed boolean field which is set to
true when the user lands on the check page.

We use this boolean to know where to redirect the user, back to the
check page or through the steps ending on the index page.

Once a user lands on the check page, the back buttons should always
redirect him to the check page.
  • Loading branch information
CatalinVoineag committed May 3, 2024
1 parent bc6d9bb commit cd4f518
Show file tree
Hide file tree
Showing 25 changed files with 386 additions and 12 deletions.
3 changes: 2 additions & 1 deletion app/controllers/claims/schools/claims_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def show; end

def check
last_mentor_training = @claim.mentor_trainings.order_by_mentor_full_name.last
Claims::Claim::Review.call(claim: @claim)

@back_path = edit_claims_school_claim_mentor_training_path(
@school,
Expand All @@ -38,7 +39,7 @@ def edit; end

def update
if claim_provider_form.save
redirect_to check_claims_school_claim_path(@school, claim_provider_form.claim)
redirect_to claim_provider_form.update_success_path
else
render :edit
end
Expand Down
11 changes: 6 additions & 5 deletions app/controllers/claims/support/schools/claims_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def create

def check
last_mentor_training = @claim.mentor_trainings.order_by_mentor_full_name.last
Claims::Claim::Review.call(claim: @claim)

@back_path = edit_claims_support_school_claim_mentor_training_path(
@school,
Expand All @@ -47,7 +48,7 @@ def edit; end

def update
if claim_provider_form.save
redirect_to check_claims_support_school_claim_path(@school, claim_provider_form.claim)
redirect_to claim_provider_form.update_success_path
else
render :edit
end
Expand All @@ -67,7 +68,7 @@ def rejected; end
private

def claim_params
params.require(:claims_claim_provider_form)
params.require(:claims_support_claim_provider_form)
.permit(:id, :provider_id)
.merge(default_params)
end
Expand All @@ -86,10 +87,10 @@ def set_claim

def claim_provider_form
@claim_provider_form ||=
if params[:claims_claim_provider_form].present?
Claims::Claim::ProviderForm.new(claim_params)
if params[:claims_support_claim_provider_form].present?
Claims::Support::Claim::ProviderForm.new(claim_params)
else
Claims::Claim::ProviderForm.new(default_params.merge(id: claim_id))
Claims::Support::Claim::ProviderForm.new(default_params.merge(id: claim_id))
end
end

Expand Down
8 changes: 8 additions & 0 deletions app/forms/claims/claim/mentors_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ def persist
claim.save!
end

def edit_back_path
if claim.reviewed?
check_claims_school_claim_path(claim.school, claim)
else
edit_claims_school_claim_path(claim.school, claim)
end
end

def update_success_path
if claim.mentor_trainings.without_hours.any?
edit_claims_school_claim_mentor_training_path(
Expand Down
18 changes: 17 additions & 1 deletion app/forms/claims/claim/provider_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(attributes = {})
end

def persist
return if claim.provider_id == provider_id
return true if claim.provider_id == provider_id

ActiveRecord::Base.transaction do
claim.provider_id = provider_id
Expand All @@ -21,6 +21,22 @@ def persist
end
end

def edit_back_path
if claim.reviewed?
check_claims_school_claim_path(claim.school, claim)
else
claims_school_claims_path(claim.school)
end
end

def update_success_path
if claim.reviewed?
check_claims_school_claim_path(claim.school, claim)
else
edit_claims_school_claim_mentors_path(claim.school, claim)
end
end

def claim
@claim ||= school.claims.find_or_initialize_by(id:)
end
Expand Down
8 changes: 8 additions & 0 deletions app/forms/claims/support/claim/mentors_form.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
class Claims::Support::Claim::MentorsForm < Claims::Claim::MentorsForm
def edit_back_path
if claim.reviewed?
check_claims_support_school_claim_path(claim.school, claim)
else
edit_claims_support_school_claim_path(claim.school, claim)
end
end

def update_success_path
if claim.mentor_trainings.without_hours.any?
edit_claims_support_school_claim_mentor_training_path(
Expand Down
17 changes: 17 additions & 0 deletions app/forms/claims/support/claim/provider_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Claims::Support::Claim::ProviderForm < Claims::Claim::ProviderForm
def edit_back_path
if claim.reviewed?
check_claims_support_school_claim_path(claim.school, claim)
else
claims_support_school_claims_path(claim.school)
end
end

def update_success_path
if claim.reviewed?
check_claims_support_school_claim_path(claim.school, claim)
else
edit_claims_support_school_claim_mentors_path(claim.school, claim)
end
end
end
1 change: 1 addition & 0 deletions app/models/claims/claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# provider_id :uuid
# school_id :uuid not null
# submitted_by_id :uuid
# reviewed :boolean default(FALSE)
#
# Indexes
#
Expand Down
15 changes: 15 additions & 0 deletions app/services/claims/claim/review.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Claims::Claim::Review
include ServicePattern

def initialize(claim:)
@claim = claim
end

def call
claim.update!(reviewed: true)
end

private

attr_reader :claim
end
2 changes: 1 addition & 1 deletion app/views/claims/schools/claims/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<% render "claims/schools/primary_navigation", school: @school, current: :claims %>
<%= content_for(:before_content) do %>
<%= govuk_back_link(href: check_claims_school_claim_path(@school, claim_provider_form.claim)) %>
<%= govuk_back_link(href: claim_provider_form.edit_back_path) %>
<% end %>

<div class="govuk-width-container">
Expand Down
2 changes: 1 addition & 1 deletion app/views/claims/schools/claims/mentors/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<% render "claims/schools/primary_navigation", school: @school, current: :claims %>
<%= content_for(:before_content) do %>
<%= govuk_back_link(href: check_claims_school_claim_path(@school, claim_mentors_form.claim)) %>
<%= govuk_back_link(href: claim_mentors_form.edit_back_path) %>
<% end %>

<div class="govuk-width-container">
Expand Down
2 changes: 1 addition & 1 deletion app/views/claims/support/schools/claims/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<% render "claims/support/primary_navigation", current: :organisations %>
<%= content_for(:before_content) do %>
<%= govuk_back_link(href: check_claims_support_school_claim_path(@school, claim_provider_form.claim)) %>
<%= govuk_back_link(href: claim_provider_form.edit_back_path) %>
<% end %>

<div class="govuk-width-container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<% render "claims/support/primary_navigation", current: :organisations %>
<%= content_for(:before_content) do %>
<%= govuk_back_link(href: check_claims_support_school_claim_path(@school, claim_mentors_form.claim)) %>
<%= govuk_back_link(href: claim_mentors_form.edit_back_path) %>
<% end %>

<div class="govuk-width-container">
Expand Down
1 change: 1 addition & 0 deletions config/analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ shared:
- status
- submitted_by_type
- submitted_by_id
- reviewed
:schools:
- id
- urn
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20240501065503_add_reviewed_by_user_to_claim.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddReviewedByUserToClaim < ActiveRecord::Migration[7.1]
def change
add_column(:claims, :reviewed, :boolean, default: false)
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2024_04_29_133246) do
ActiveRecord::Schema[7.1].define(version: 2024_05_01_065503) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm"
enable_extension "plpgsql"
Expand Down Expand Up @@ -58,6 +58,7 @@
t.enum "status", enum_type: "claim_status"
t.string "submitted_by_type"
t.uuid "submitted_by_id"
t.boolean "reviewed", default: false
t.index ["created_by_type", "created_by_id"], name: "index_claims_on_created_by"
t.index ["provider_id"], name: "index_claims_on_provider_id"
t.index ["reference"], name: "index_claims_on_reference", unique: true
Expand Down
1 change: 1 addition & 0 deletions spec/factories/claims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# provider_id :uuid
# school_id :uuid not null
# submitted_by_id :uuid
# reviewed :boolean default(FALSE)
#
# Indexes
#
Expand Down
23 changes: 23 additions & 0 deletions spec/forms/claims/claim/mentors_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,27 @@
end
end
end

describe "#edit_back_path" do
context "when reviewed is false" do
it "returns the path to the mentor training hours form" do
form = described_class.new(claim:)

expect(form.edit_back_path).to eq(
"/schools/#{claim.school.id}/claims/#{claim.id}/edit",
)
end
end

context "when reviewed is true" do
it "returns the path to the claim check page" do
claim_reviewed = create(:claim, reviewed: true)
form = described_class.new(claim: claim_reviewed)

expect(form.update_success_path).to eq(
"/schools/#{claim_reviewed.school.id}/claims/#{claim_reviewed.id}/check",
)
end
end
end
end
46 changes: 46 additions & 0 deletions spec/forms/claims/claim/provider_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,50 @@
end
end
end

describe "#edit_back_path" do
context "when reviewed is false" do
it "returns the edit claim path" do
form = described_class.new(id: existing_claim.id, school:)

expect(form.edit_back_path).to eq(
"/schools/#{school.id}/claims",
)
end
end

context "when reviewed is true" do
it "returns the check claim path" do
claim = create(:claim, school:, reviewed: true)
form = described_class.new(id: claim.id, school:)

expect(form.edit_back_path).to eq(
"/schools/#{school.id}/claims/#{claim.id}/check",
)
end
end
end

describe "#update_success_path" do
context "when reviewed is false" do
it "returns the edit claim mentor training path" do
form = described_class.new(id: existing_claim.id, school:)

expect(form.update_success_path).to eq(
"/schools/#{school.id}/claims/#{existing_claim.id}/mentors/edit",
)
end
end

context "when reviewed is true" do
it "returns the check claim path" do
claim = create(:claim, school:, reviewed: true)
form = described_class.new(id: claim.id, school:)

expect(form.update_success_path).to eq(
"/schools/#{school.id}/claims/#{claim.id}/check",
)
end
end
end
end
23 changes: 23 additions & 0 deletions spec/forms/claims/support/claim/mentors_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,27 @@
end
end
end

describe "#edit_back_path" do
context "when reviewed is nil" do
it "returns the path to the mentor training hours form" do
form = described_class.new(claim:)

expect(form.edit_back_path).to eq(
"/support/schools/#{claim.school.id}/claims/#{claim.id}/edit",
)
end
end

context "when reviewed is true" do
it "returns the path to the claim check page" do
claim_reviewed = create(:claim, reviewed: true)
form = described_class.new(claim: claim_reviewed)

expect(form.update_success_path).to eq(
"/support/schools/#{claim_reviewed.school.id}/claims/#{claim_reviewed.id}/check",
)
end
end
end
end
Loading

0 comments on commit cd4f518

Please sign in to comment.