From 2fabd452dbf757e7e0cdcacf354b2676d43c7b31 Mon Sep 17 00:00:00 2001 From: Jack S Date: Tue, 11 Jul 2023 09:25:24 +0200 Subject: [PATCH] Persist user and org data while signing agreement --- app/controllers/organisations_controller.rb | 15 +++++++++++++-- spec/requests/organisations_controller_spec.rb | 18 +++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb index 83ca8405e..7c7e4720b 100644 --- a/app/controllers/organisations_controller.rb +++ b/app/controllers/organisations_controller.rb @@ -170,14 +170,25 @@ class OrganisationsController < ApplicationController @organisation.data_protection_confirmation.update!( confirmed: true, data_protection_officer: current_user, - # When it was signed created_at: Time.zone.now, + signed_at_at: Time.zone.now, + organisation_name: @organisation.name, + organisation_address: @organisation.address_row, + organisation_phone_number: @organisation.phone, + data_protection_officer_email: current_user.email, + data_protection_officer_name: current_user.name, ) else DataProtectionConfirmation.create!( - organisation: current_user.organisation, + organisation: @organisation, confirmed: true, data_protection_officer: current_user, + signed_at: Time.zone.now, + organisation_name: @organisation.name, + organisation_address: @organisation.address_row, + organisation_phone_number: @organisation.phone, + data_protection_officer_email: current_user.email, + data_protection_officer_name: current_user.name, ) end diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index f4a3c2083..b64f0ba8a 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -1544,6 +1544,14 @@ RSpec.describe OrganisationsController, type: :request do end context "when the organisation does not have a confirmation" do + before do + Timecop.freeze(Time.zone.local(2022, 2, 1)) + end + + after do + Timecop.unfreeze + end + let(:user) { create(:user, is_dpo: true, organisation:) } it "returns redirects to details page" do @@ -1561,10 +1569,14 @@ RSpec.describe OrganisationsController, type: :request do data_protection_confirmation = organisation.reload.data_protection_confirmation - expect(data_protection_confirmation.organisation.address_row).to eq(organisation.address_row) - expect(data_protection_confirmation.organisation.name).to eq(organisation.name) - expect(data_protection_confirmation.organisation.phone).to eq(organisation.phone) + expect(data_protection_confirmation.organisation).to eq(organisation) expect(data_protection_confirmation.data_protection_officer).to eq(user) + expect(data_protection_confirmation.signed_at).to eq(Time.zone.local(2022, 2, 1)) + expect(data_protection_confirmation.organisation_name).to eq(organisation.name) + expect(data_protection_confirmation.organisation_address).to eq(organisation.address_row) + expect(data_protection_confirmation.organisation_phone_number).to eq(organisation.phone) + expect(data_protection_confirmation.data_protection_officer_email).to eq(current_user.email) + expect(data_protection_confirmation.data_protection_officer_name).to eq(current_user.name) end context "when the user has already accepted the agreement" do