-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2317 from DFE-Digital/archive-suitability-record
Add ability to archive suitability records
- Loading branch information
Showing
12 changed files
with
173 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
app/forms/assessor_interface/archive_suitability_record_form.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
class AssessorInterface::ArchiveSuitabilityRecordForm | ||
include ActiveModel::Model | ||
include ActiveModel::Attributes | ||
|
||
attr_accessor :suitability_record, :user | ||
validates :suitability_record, :user, presence: true | ||
|
||
attribute :note | ||
validates :note, presence: true | ||
|
||
def save | ||
return false if invalid? | ||
|
||
suitability_record.update!( | ||
archived_at: Time.zone.now, | ||
archived_by: user, | ||
archive_note: note, | ||
) | ||
|
||
true | ||
end | ||
end |
16 changes: 16 additions & 0 deletions
16
app/views/assessor_interface/suitability_records/archive.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<% title = "Archive suitability record for #{@suitability_record.name}" %> | ||
|
||
<% content_for :page_title, title %> | ||
<% content_for :back_link_url, assessor_interface_suitability_records_path %> | ||
|
||
<%= form_with model: @form, url: [:assessor_interface, @suitability_record], method: :delete do |f| %> | ||
<%= f.govuk_error_summary %> | ||
|
||
<h1 class="govuk-heading-l"><%= title %></h1> | ||
|
||
<%= f.govuk_text_area :note %> | ||
|
||
<%= f.govuk_submit "Archive record" do %> | ||
<%= govuk_link_to "Cancel", %i[assessor_interface suitability_records] %> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
spec/forms/assessor_interface/archive_suitability_record_form_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe AssessorInterface::ArchiveSuitabilityRecordForm, type: :model do | ||
subject(:form) { described_class.new(suitability_record:, user:, note:) } | ||
|
||
let(:suitability_record) { create(:suitability_record) } | ||
let(:user) { create(:staff) } | ||
let(:note) { "A note." } | ||
|
||
describe "validations" do | ||
it { is_expected.to validate_presence_of(:suitability_record) } | ||
it { is_expected.to validate_presence_of(:user) } | ||
it { is_expected.to validate_presence_of(:note) } | ||
end | ||
|
||
describe "#save" do | ||
subject(:save) { form.save } | ||
|
||
it "updates the fields" do | ||
expect(save).to be true | ||
|
||
expect(suitability_record).to be_archived | ||
expect(suitability_record.archive_note).to eq("A note.") | ||
end | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
spec/support/autoload/page_objects/assessor_interface/archive_suitability_record.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module PageObjects | ||
module AssessorInterface | ||
class ArchiveSuitabilityRecord < SitePrism::Page | ||
set_url "/assessor/suitability-records/{id}/archive" | ||
|
||
section :form, "form" do | ||
element :note_field, | ||
"#assessor-interface-archive-suitability-record-form-note-field" | ||
element :submit_button, ".govuk-button:not(.govuk-button--secondary)" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters