-
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 #2023 from DFE-Digital/consent-document-generated-…
…form Add UnsignedConsentDocumentForm
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
app/forms/assessor_interface/unsigned_consent_document_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,20 @@ | ||
# frozen_string_literal: true | ||
|
||
class AssessorInterface::UnsignedConsentDocumentForm | ||
include ActiveModel::Model | ||
include ActiveModel::Attributes | ||
|
||
attr_accessor :assessment | ||
validates :assessment, presence: true | ||
|
||
attribute :generated, :boolean | ||
validates :generated, presence: true | ||
|
||
def save | ||
return false if invalid? | ||
|
||
assessment.update!(unsigned_consent_document_generated: true) if generated | ||
|
||
true | ||
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
42 changes: 42 additions & 0 deletions
42
spec/forms/assessor_interface/unsigned_consent_document_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,42 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe AssessorInterface::UnsignedConsentDocumentForm, type: :model do | ||
let(:assessment) { create(:assessment) } | ||
|
||
subject(:form) { described_class.new(assessment:, generated:) } | ||
|
||
describe "validations" do | ||
let(:generated) { "" } | ||
|
||
it { is_expected.to validate_presence_of(:assessment) } | ||
it { is_expected.to validate_presence_of(:generated) } | ||
end | ||
|
||
describe "#save" do | ||
subject(:save) { form.save } | ||
|
||
context "with a positive response" do | ||
let(:generated) { "true" } | ||
|
||
it "sets unsigned_consent_document_downloaded" do | ||
expect { save }.to change( | ||
assessment, | ||
:unsigned_consent_document_generated, | ||
).to(true) | ||
end | ||
end | ||
|
||
context "with a negative response" do | ||
let(:generated) { "false" } | ||
|
||
it "doesn't set unsigned_consent_document_downloaded" do | ||
expect { save }.to_not change( | ||
assessment, | ||
:unsigned_consent_document_generated, | ||
) | ||
end | ||
end | ||
end | ||
end |