]> source.dussan.org Git - redmine.git/commitdiff
Destroy overridden time entry activities and rows from the habtm join table @queries_...
authorMarius Balteanu <marius.balteanu@zitec.com>
Thu, 24 Feb 2022 19:44:36 +0000 (19:44 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Thu, 24 Feb 2022 19:44:36 +0000 (19:44 +0000)
Patch by Holger Just.

git-svn-id: http://svn.redmine.org/redmine/trunk@21437 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/project.rb
test/unit/project_test.rb

index fa910fdfe03094f24274cab3e168cd4de2f9a50e..4e15b19c8a65839fc906788247dae4f18791def0 100644 (file)
@@ -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
index 676029a141ef1ac2bed1f9968418e6af5034894c..cf457a48c841bdadf41fcf91376d2a5816c67fac 100644 (file)
@@ -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