Skip to content

Commit

Permalink
Merge pull request #1460 from DFE-Digital/fix/161102-clear-support-gr…
Browse files Browse the repository at this point in the history
…ant-type

(Fix) Clear the value of sponsored_support_grant_type if "Not applicable" ticked
  • Loading branch information
lozette authored Mar 27, 2024
2 parents 1e2b85d + d8b43bd commit f9f3041
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased][unreleased]

### Fixed

- Clear any radio button values in the Sponsored support grant type task if the
task is later saved as "Not applicable"

## [Release-61][release-61]

### Added
Expand Down
10 changes: 10 additions & 0 deletions app/forms/conversion/task/sponsored_support_grant_task_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@ class Conversion::Task::SponsoredSupportGrantTaskForm < BaseOptionalTaskForm
def type_options
Conversion::TasksData.sponsored_support_grant_types.values
end

def save
if not_applicable
@tasks_data.sponsored_support_grant_type = nil
@tasks_data.assign_attributes prefixed_attributes.except("sponsored_support_grant_type")
else
@tasks_data.assign_attributes prefixed_attributes
end
@tasks_data.save!
end
end
10 changes: 10 additions & 0 deletions app/forms/transfer/task/sponsored_support_grant_task_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,14 @@ class Transfer::Task::SponsoredSupportGrantTaskForm < BaseOptionalTaskForm
def type_options
Transfer::TasksData.sponsored_support_grant_types.values
end

def save
if not_applicable
@tasks_data.sponsored_support_grant_type = nil
@tasks_data.assign_attributes prefixed_attributes.except("sponsored_support_grant_type")
else
@tasks_data.assign_attributes prefixed_attributes
end
@tasks_data.save!
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require "rails_helper"

RSpec.describe Conversion::Task::SponsoredSupportGrantTaskForm do
let(:user) { create(:user) }
let(:project) { create(:conversion_project) }

describe "#save" do
before { mock_successful_api_response_to_create_any_project }

it "clears the value of 'type' if 'Not applicable' is ticked" do
form = described_class.new(project.tasks_data, user)
form.assign_attributes(type: "fast_track")
form.save

expect(project.tasks_data.sponsored_support_grant_type).to eq("fast_track")

form.assign_attributes(not_applicable: true)
form.save

expect(project.tasks_data.sponsored_support_grant_type).to be_nil
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require "rails_helper"

RSpec.describe Transfer::Task::SponsoredSupportGrantTaskForm do
let(:user) { create(:user) }
let(:project) { create(:transfer_project) }

describe "#save" do
before { mock_successful_api_response_to_create_any_project }

it "clears the value of 'type' if 'Not applicable' is ticked" do
form = described_class.new(project.tasks_data, user)
form.assign_attributes(type: "fast_track")
form.save

expect(project.tasks_data.sponsored_support_grant_type).to eq("fast_track")

form.assign_attributes(not_applicable: true)
form.save

expect(project.tasks_data.sponsored_support_grant_type).to be_nil
end
end
end

0 comments on commit f9f3041

Please sign in to comment.