diff --git a/app/models/consent.rb b/app/models/consent.rb index 87043ea8b..63e4c49fc 100644 --- a/app/models/consent.rb +++ b/app/models/consent.rb @@ -118,7 +118,7 @@ def can_invalidate? end def responded_at - invalidated_at || withdrawn_at || created_at + invalidated_at || withdrawn_at || consent_form&.recorded_at || created_at end def triage_needed? diff --git a/spec/models/consent_spec.rb b/spec/models/consent_spec.rb index d4819522f..965b411dc 100644 --- a/spec/models/consent_spec.rb +++ b/spec/models/consent_spec.rb @@ -70,6 +70,35 @@ end end + describe "#responded_at" do + subject(:responded_at) { consent.responded_at } + + context "with a consent form" do + let(:consent) do + build( + :consent, + created_at: Time.current, + consent_form: + build(:consent_form, recorded_at: Time.zone.local(2024, 12, 20, 12)) + ) + end + + it { should eq(Time.zone.local(2024, 12, 20, 12)) } + end + + context "without a consent form" do + let(:consent) do + build( + :consent, + created_at: Time.zone.local(2024, 12, 20, 12), + consent_form: nil + ) + end + + it { should eq(Time.zone.local(2024, 12, 20, 12)) } + end + end + describe "#from_consent_form!" do describe "the created consent object" do subject(:consent) do