Skip to content

Commit

Permalink
Merge pull request #8805 from CitizenLabDotCo/TAN-2512-dependent-dest…
Browse files Browse the repository at this point in the history
…roy-idea-import-files

[TAN-2512] Dependent destroy idea_import_files
  • Loading branch information
jinjagit authored Aug 30, 2024
2 parents 9a52ea6 + 8b8b7a4 commit 293614b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions back/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,4 @@ def old_folder_moderators
Project.include(ContentBuilder::Patches::Project)
Project.include(Analysis::Patches::Project)
Project.include(EmailCampaigns::Extensions::Project)
Project.include(BulkImportIdeas::Patches::Project)
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class IdeaImportFile < ApplicationRecord
belongs_to :project, optional: true

belongs_to :parent, class_name: 'BulkImportIdeas::IdeaImportFile', optional: true
has_many :children, class_name: 'BulkImportIdeas::IdeaImportFile', foreign_key: 'parent_id'
has_many :children, class_name: 'BulkImportIdeas::IdeaImportFile', foreign_key: 'parent_id', dependent: :destroy

validates :name, presence: true
validates :file, presence: true, unless: proc { Current.loading_tenant_template }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module BulkImportIdeas::Patches::Project
def self.included(base)
base.class_eval do
has_many :idea_import_files, class_name: 'BulkImportIdeas::IdeaImportFile', dependent: :destroy
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'rails_helper'
require 'rspec_api_documentation/dsl'

resource 'Projects' do
before do
@user = create(:admin)
header_token_for @user
header 'Content-Type', 'application/json'
end

delete 'web_api/v1/projects/:id' do
let(:project) { create(:project) }
let!(:idea_import_file1) { create(:idea_import_file, project: project) }
let!(:idea_import_file2) { create(:idea_import_file, project: project, parent: idea_import_file1) }
let(:id) { project.id }

example_request 'Delete a project that has associated idea_import_files' do
expect(response_status).to eq 200
expect { Project.find(id) }.to raise_error(ActiveRecord::RecordNotFound)
expect { BulkImportIdeas::IdeaImportFile.find(idea_import_file1.id) }.to raise_error(ActiveRecord::RecordNotFound)
expect { BulkImportIdeas::IdeaImportFile.find(idea_import_file2.id) }.to raise_error(ActiveRecord::RecordNotFound)
end
end
end

0 comments on commit 293614b

Please sign in to comment.