From: Marius Balteanu Date: Thu, 24 Feb 2022 19:44:36 +0000 (+0000) Subject: Destroy overridden time entry activities and rows from the habtm join table @queries_... X-Git-Tag: 5.0.0~60 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=96d32a522652a29aaddb5c6ec727c7780004afff;p=redmine.git Destroy overridden time entry activities and rows from the habtm join table @queries_roles@ on project deletion (#36416). Patch by Holger Just. git-svn-id: http://svn.redmine.org/redmine/trunk@21437 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/project.rb b/app/models/project.rb index fa910fdfe..4e15b19c8 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -30,7 +30,7 @@ class Project < ActiveRecord::Base IDENTIFIER_MAX_LENGTH = 100 # Specific overridden Activities - has_many :time_entry_activities + has_many :time_entry_activities, :dependent => :destroy has_many :memberships, :class_name => 'Member', :inverse_of => :project # Memberships of active users only has_many :members, @@ -43,7 +43,7 @@ class Project < ActiveRecord::Base belongs_to :default_version, :class_name => 'Version' belongs_to :default_assigned_to, :class_name => 'Principal' has_many :time_entries, :dependent => :destroy - has_many :queries, :dependent => :delete_all + has_many :queries, :dependent => :destroy has_many :documents, :dependent => :destroy has_many :news, lambda {includes(:author)}, :dependent => :destroy has_many :issue_categories, lambda {order(:name)}, :dependent => :delete_all diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index 676029a14..cf457a48c 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -233,6 +233,12 @@ class ProjectTest < ActiveSupport::TestCase # some boards assert @ecookbook.boards.any? + # generate some dependent objects + overridden_activity = TimeEntryActivity.new({:name => "Project", :project => @ecookbook}) + assert overridden_activity.save! + + query = IssueQuery.generate!(:project => @ecookbook, :visibility => Query::VISIBILITY_ROLES, :roles => Role.where(:id => [1, 3]).to_a) + @ecookbook.destroy # make sure that the project non longer exists assert_raise(ActiveRecord::RecordNotFound) {Project.find(@ecookbook.id)} @@ -240,6 +246,10 @@ class ProjectTest < ActiveSupport::TestCase assert_not Member.where(:project_id => @ecookbook.id).exists? assert_not Board.where(:project_id => @ecookbook.id).exists? assert_not Issue.where(:project_id => @ecookbook.id).exists? + assert_not Enumeration.where(:project_id => @ecookbook.id).exists? + + assert_not Query.where(:project_id => @ecookbook.id).exists? + assert_nil ActiveRecord::Base.connection.select_value("SELECT 1 FROM queries_roles WHERE query_id = #{query.id}") end def test_destroy_should_destroy_subtasks