Commit cbc1b00b authored by Robert Speicher's avatar Robert Speicher

Merge branch 'philipcunningham-failed-validations-341116' into 'master'

Clean up DAST site tokens when site deleted

See merge request gitlab-org/gitlab!71238
parents 0325a34e 96482cac
......@@ -11,8 +11,14 @@ class DastSite < ApplicationRecord
validates :project_id, presence: true
validate :dast_site_validation_project_id_fk
after_destroy :cleanup_dast_site_token
private
def cleanup_dast_site_token
DastSiteToken.where(project_id: project.id, url: url).delete_all
end
def dast_site_validation_project_id_fk
return unless dast_site_validation_id
......
......@@ -44,4 +44,16 @@ RSpec.describe DastSite, type: :model do
end
end
end
describe 'callbacks' do
context 'when there is a related site token' do
let_it_be(:dast_site) { create(:dast_site, project: project) }
let_it_be(:dast_site_token) { create(:dast_site_token, project: dast_site.project, url: dast_site.url) }
let_it_be(:dast_site_validations) { create_list(:dast_site_validation, 5, dast_site_token: dast_site_token) }
it 'ensures it and associated site validations cleaned up on destroy' do
expect { dast_site.destroy! }.to change { DastSiteToken.count }.from(1).to(0).and change { DastSiteValidation.count }.from(5).to(0)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment