]> source.dussan.org Git - redmine.git/commitdiff
adjust tests to awesome_nested_set new node lft and rgt value behavior change
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Fri, 24 Jan 2014 16:26:50 +0000 (16:26 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Fri, 24 Jan 2014 16:26:50 +0000 (16:26 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@12693 e93f8b46-1217-0410-a6f0-8f06a7374b81

test/test_helper.rb
test/unit/issue_nested_set_test.rb
test/unit/issue_transaction_test.rb
test/unit/mail_handler_test.rb

index 725b1f596aad752e42eec82d1a9f5eddf934f0d9..6973d5fb44683eb5f1eda70758c62cf728939900 100644 (file)
@@ -24,6 +24,8 @@ require Rails.root.join('test', 'mocks', 'open_id_authentication_mock.rb').to_s
 require File.expand_path(File.dirname(__FILE__) + '/object_helpers')
 include ObjectHelpers
 
+require 'awesome_nested_set/version'
+
 class ActiveSupport::TestCase
   include ActionDispatch::TestProcess
 
@@ -197,6 +199,16 @@ class ActiveSupport::TestCase
   def mail_body(mail)
     mail.parts.first.body.encoded
   end
+
+  # awesome_nested_set new node lft and rgt value changed this refactor revision.
+  #   https://github.com/collectiveidea/awesome_nested_set/commit/199fca9bb938e40200cd90714dc69247ef017c61
+  # The reason of behavior change is "self.class.base_class.unscoped" added this line.
+  #   https://github.com/collectiveidea/awesome_nested_set/commit/199fca9bb9#diff-f61b59a5e6319024e211b0ffdd0e4ef1R273
+  # It seems correct behavior because of this line comment.
+  #   https://github.com/collectiveidea/awesome_nested_set/blame/199fca9bb9/lib/awesome_nested_set/model.rb#L278
+  def new_issue_lft
+    ::AwesomeNestedSet::VERSION > "2.1.6" ? Issue.maximum(:rgt) + 1 : 1
+  end
 end
 
 module Redmine
index 899344937bf1db3da5ff146fc99a9078a4bfde95..9c4060b208fd9c478fad4d90375c14705bde8d93 100644 (file)
@@ -30,23 +30,24 @@ class IssueNestedSetTest < ActiveSupport::TestCase
   end
 
   def test_create_root_issue
+    lft1 = new_issue_lft
     issue1 = Issue.generate!
+    lft2 = new_issue_lft
     issue2 = Issue.generate!
     issue1.reload
     issue2.reload
-
-    assert_equal [issue1.id, nil, 1, 2], [issue1.root_id, issue1.parent_id, issue1.lft, issue1.rgt]
-    assert_equal [issue2.id, nil, 1, 2], [issue2.root_id, issue2.parent_id, issue2.lft, issue2.rgt]
+    assert_equal [issue1.id, nil, lft1, lft1 + 1], [issue1.root_id, issue1.parent_id, issue1.lft, issue1.rgt]
+    assert_equal [issue2.id, nil, lft2, lft2 + 1], [issue2.root_id, issue2.parent_id, issue2.lft, issue2.rgt]
   end
 
   def test_create_child_issue
+    lft = new_issue_lft
     parent = Issue.generate!
     child =  Issue.generate!(:parent_issue_id => parent.id)
     parent.reload
     child.reload
-
-    assert_equal [parent.id, nil, 1, 4], [parent.root_id, parent.parent_id, parent.lft, parent.rgt]
-    assert_equal [parent.id, parent.id, 2, 3], [child.root_id, child.parent_id, child.lft, child.rgt]
+    assert_equal [parent.id, nil,       lft,     lft + 3], [parent.root_id, parent.parent_id, parent.lft, parent.rgt]
+    assert_equal [parent.id, parent.id, lft + 1, lft + 2], [child.root_id, child.parent_id, child.lft, child.rgt]
   end
 
   def test_creating_a_child_in_a_subproject_should_validate
@@ -66,95 +67,91 @@ class IssueNestedSetTest < ActiveSupport::TestCase
   end
 
   def test_move_a_root_to_child
+    lft = new_issue_lft
     parent1 = Issue.generate!
     parent2 = Issue.generate!
     child = Issue.generate!(:parent_issue_id => parent1.id)
-
     parent2.parent_issue_id = parent1.id
     parent2.save!
     child.reload
     parent1.reload
     parent2.reload
-
-    assert_equal [parent1.id, 1, 6], [parent1.root_id, parent1.lft, parent1.rgt]
-    assert_equal [parent1.id, 4, 5], [parent2.root_id, parent2.lft, parent2.rgt]
-    assert_equal [parent1.id, 2, 3], [child.root_id, child.lft, child.rgt]
+    assert_equal [parent1.id, lft,     lft + 5], [parent1.root_id, parent1.lft, parent1.rgt]
+    assert_equal [parent1.id, lft + 3, lft + 4], [parent2.root_id, parent2.lft, parent2.rgt]
+    assert_equal [parent1.id, lft + 1, lft + 2], [child.root_id, child.lft, child.rgt]
   end
 
   def test_move_a_child_to_root
+    lft1 = new_issue_lft
     parent1 = Issue.generate!
+    lft2 = new_issue_lft
     parent2 = Issue.generate!
     child =   Issue.generate!(:parent_issue_id => parent1.id)
-
     child.parent_issue_id = nil
     child.save!
     child.reload
     parent1.reload
     parent2.reload
-
-    assert_equal [parent1.id, 1, 2], [parent1.root_id, parent1.lft, parent1.rgt]
-    assert_equal [parent2.id, 1, 2], [parent2.root_id, parent2.lft, parent2.rgt]
+    assert_equal [parent1.id, lft1, lft1 + 1], [parent1.root_id, parent1.lft, parent1.rgt]
+    assert_equal [parent2.id, lft2, lft2 + 1], [parent2.root_id, parent2.lft, parent2.rgt]
     assert_equal [child.id, 1, 2], [child.root_id, child.lft, child.rgt]
   end
 
   def test_move_a_child_to_another_issue
+    lft1 = new_issue_lft
     parent1 = Issue.generate!
+    lft2 = new_issue_lft
     parent2 = Issue.generate!
     child =   Issue.generate!(:parent_issue_id => parent1.id)
-
     child.parent_issue_id = parent2.id
     child.save!
     child.reload
     parent1.reload
     parent2.reload
-
-    assert_equal [parent1.id, 1, 2], [parent1.root_id, parent1.lft, parent1.rgt]
-    assert_equal [parent2.id, 1, 4], [parent2.root_id, parent2.lft, parent2.rgt]
-    assert_equal [parent2.id, 2, 3], [child.root_id, child.lft, child.rgt]
+    assert_equal [parent1.id, lft1,     lft1 + 1], [parent1.root_id, parent1.lft, parent1.rgt]
+    assert_equal [parent2.id, lft2,     lft2 + 3], [parent2.root_id, parent2.lft, parent2.rgt]
+    assert_equal [parent2.id, lft2 + 1, lft2 + 2], [child.root_id,   child.lft,   child.rgt]
   end
 
   def test_move_a_child_with_descendants_to_another_issue
+    lft1 = new_issue_lft
     parent1 = Issue.generate!
+    lft2 = new_issue_lft
     parent2 = Issue.generate!
     child =   Issue.generate!(:parent_issue_id => parent1.id)
     grandchild = Issue.generate!(:parent_issue_id => child.id)
-
     parent1.reload
     parent2.reload
     child.reload
     grandchild.reload
-
-    assert_equal [parent1.id, 1, 6], [parent1.root_id, parent1.lft, parent1.rgt]
-    assert_equal [parent2.id, 1, 2], [parent2.root_id, parent2.lft, parent2.rgt]
-    assert_equal [parent1.id, 2, 5], [child.root_id, child.lft, child.rgt]
-    assert_equal [parent1.id, 3, 4], [grandchild.root_id, grandchild.lft, grandchild.rgt]
-
+    assert_equal [parent1.id, lft1,     lft1 + 5], [parent1.root_id, parent1.lft, parent1.rgt]
+    assert_equal [parent2.id, lft2,     lft2 + 1], [parent2.root_id, parent2.lft, parent2.rgt]
+    assert_equal [parent1.id, lft1 + 1, lft1 + 4], [child.root_id, child.lft, child.rgt]
+    assert_equal [parent1.id, lft1 + 2, lft1 + 3], [grandchild.root_id, grandchild.lft, grandchild.rgt]
     child.reload.parent_issue_id = parent2.id
     child.save!
     child.reload
     grandchild.reload
     parent1.reload
     parent2.reload
-
-    assert_equal [parent1.id, 1, 2], [parent1.root_id, parent1.lft, parent1.rgt]
-    assert_equal [parent2.id, 1, 6], [parent2.root_id, parent2.lft, parent2.rgt]
-    assert_equal [parent2.id, 2, 5], [child.root_id, child.lft, child.rgt]
-    assert_equal [parent2.id, 3, 4], [grandchild.root_id, grandchild.lft, grandchild.rgt]
+    assert_equal [parent1.id, lft1,     lft1 + 1], [parent1.root_id, parent1.lft, parent1.rgt]
+    assert_equal [parent2.id, lft2,     lft2 + 5], [parent2.root_id, parent2.lft, parent2.rgt]
+    assert_equal [parent2.id, lft2 + 1, lft2 + 4], [child.root_id, child.lft, child.rgt]
+    assert_equal [parent2.id, lft2 + 2, lft2 + 3], [grandchild.root_id, grandchild.lft, grandchild.rgt]
   end
 
   def test_move_a_child_with_descendants_to_another_project
+    lft1 = new_issue_lft
     parent1 = Issue.generate!
     child =   Issue.generate!(:parent_issue_id => parent1.id)
     grandchild = Issue.generate!(:parent_issue_id => child.id)
-
     child.reload
     child.project = Project.find(2)
     assert child.save
     child.reload
     grandchild.reload
     parent1.reload
-
-    assert_equal [1, parent1.id, 1, 2], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt]
+    assert_equal [1, parent1.id, lft1, lft1 + 1], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt]
     assert_equal [2, child.id, 1, 4], [child.project_id, child.root_id, child.lft, child.rgt]
     assert_equal [2, child.id, 2, 3], [grandchild.project_id, grandchild.root_id, grandchild.lft, grandchild.rgt]
   end
@@ -207,15 +204,14 @@ class IssueNestedSetTest < ActiveSupport::TestCase
   end
 
   def test_destroy_should_destroy_children
+    lft1 = new_issue_lft
     issue1 = Issue.generate!
     issue2 = Issue.generate!
     issue3 = Issue.generate!(:parent_issue_id => issue2.id)
     issue4 = Issue.generate!(:parent_issue_id => issue1.id)
-
     issue3.init_journal(User.find(2))
     issue3.subject = 'child with journal'
     issue3.save!
-
     assert_difference 'Issue.count', -2 do
       assert_difference 'Journal.count', -1 do
         assert_difference 'JournalDetail.count', -1 do
@@ -223,27 +219,24 @@ class IssueNestedSetTest < ActiveSupport::TestCase
         end
       end
     end
-
     issue1.reload
     issue4.reload
     assert !Issue.exists?(issue2.id)
     assert !Issue.exists?(issue3.id)
-    assert_equal [issue1.id, 1, 4], [issue1.root_id, issue1.lft, issue1.rgt]
-    assert_equal [issue1.id, 2, 3], [issue4.root_id, issue4.lft, issue4.rgt]
+    assert_equal [issue1.id, lft1,     lft1 + 3], [issue1.root_id, issue1.lft, issue1.rgt]
+    assert_equal [issue1.id, lft1 + 1, lft1 + 2], [issue4.root_id, issue4.lft, issue4.rgt]
   end
-  
+
   def test_destroy_child_should_update_parent
+    lft1 = new_issue_lft
     issue = Issue.generate!
     child1 = Issue.generate!(:parent_issue_id => issue.id)
     child2 = Issue.generate!(:parent_issue_id => issue.id)
-    
     issue.reload
-    assert_equal [issue.id, 1, 6], [issue.root_id, issue.lft, issue.rgt]
-    
+    assert_equal [issue.id, lft1, lft1 + 5], [issue.root_id, issue.lft, issue.rgt]
     child2.reload.destroy
-    
     issue.reload
-    assert_equal [issue.id, 1, 4], [issue.root_id, issue.lft, issue.rgt]
+    assert_equal [issue.id, lft1, lft1 + 3], [issue.root_id, issue.lft, issue.rgt]
   end
 
   def test_destroy_parent_issue_updated_during_children_destroy
@@ -277,16 +270,16 @@ class IssueNestedSetTest < ActiveSupport::TestCase
   end
 
   def test_destroy_issue_with_grand_child
+    lft1 = new_issue_lft
     parent = Issue.generate!
     issue = Issue.generate!(:parent_issue_id => parent.id)
     child = Issue.generate!(:parent_issue_id => issue.id)
     grandchild1 = Issue.generate!(:parent_issue_id => child.id)
     grandchild2 = Issue.generate!(:parent_issue_id => child.id)
-
     assert_difference 'Issue.count', -4 do
       Issue.find(issue.id).destroy
       parent.reload
-      assert_equal [1, 2], [parent.lft, parent.rgt]
+      assert_equal [lft1, lft1 + 1], [parent.lft, parent.rgt]
     end
   end
 
index 77c3ab108a1516a913a554d259f64830e367a760..6d69652bd83ede29ca3b41ecd3ea36532233e39b 100644 (file)
@@ -30,14 +30,13 @@ class IssueTransactionTest < ActiveSupport::TestCase
   self.use_transactional_fixtures = false
 
   def test_invalid_move_to_another_project
+    lft1 = new_issue_lft
     parent1 = Issue.generate!
     child =   Issue.generate!(:parent_issue_id => parent1.id)
     grandchild = Issue.generate!(:parent_issue_id => child.id, :tracker_id => 2)
     Project.find(2).tracker_ids = [1]
-
     parent1.reload
-    assert_equal [1, parent1.id, 1, 6], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt]
-
+    assert_equal [1, parent1.id, lft1, lft1 + 5], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt]
     # child can not be moved to Project 2 because its child is on a disabled tracker
     child = Issue.find(child.id)
     child.project = Project.find(2)
@@ -45,10 +44,9 @@ class IssueTransactionTest < ActiveSupport::TestCase
     child.reload
     grandchild.reload
     parent1.reload
-
     # no change
-    assert_equal [1, parent1.id, 1, 6], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt]
-    assert_equal [1, parent1.id, 2, 5], [child.project_id, child.root_id, child.lft, child.rgt]
-    assert_equal [1, parent1.id, 3, 4], [grandchild.project_id, grandchild.root_id, grandchild.lft, grandchild.rgt]
+    assert_equal [1, parent1.id, lft1,     lft1 + 5], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt]
+    assert_equal [1, parent1.id, lft1 + 1, lft1 + 4], [child.project_id, child.root_id, child.lft, child.rgt]
+    assert_equal [1, parent1.id, lft1 + 2, lft1 + 3], [grandchild.project_id, grandchild.root_id, grandchild.lft, grandchild.rgt]
   end
 end
index 570cdd662dba0e010c8f87f9e0c2434ee9886ef5..1a036daded45f3497231350b9bd9e3e48bdd5b75 100644 (file)
@@ -41,6 +41,7 @@ class MailHandlerTest < ActiveSupport::TestCase
 
   def test_add_issue
     ActionMailer::Base.deliveries.clear
+    lft1 = new_issue_lft
     # This email contains: 'Project: onlinestore'
     issue = submit_email('ticket_on_given_project.eml')
     assert issue.is_a?(Issue)
@@ -58,7 +59,7 @@ class MailHandlerTest < ActiveSupport::TestCase
     assert_equal Version.find_by_name('Alpha'), issue.fixed_version
     assert_equal 2.5, issue.estimated_hours
     assert_equal 30, issue.done_ratio
-    assert_equal [issue.id, 1, 2], [issue.root_id, issue.lft, issue.rgt]
+    assert_equal [issue.id, lft1, lft1 + 1], [issue.root_id, issue.lft, issue.rgt]
     # keywords should be removed from the email body
     assert !issue.description.match(/^Project:/i)
     assert !issue.description.match(/^Status:/i)
@@ -264,6 +265,7 @@ class MailHandlerTest < ActiveSupport::TestCase
   end
 
   def test_add_issue_by_anonymous_user_on_private_project_without_permission_check
+    lft1 = new_issue_lft
     assert_no_difference 'User.count' do
       assert_difference 'Issue.count' do
         issue = submit_email(
@@ -275,7 +277,7 @@ class MailHandlerTest < ActiveSupport::TestCase
         assert issue.is_a?(Issue)
         assert issue.author.anonymous?
         assert !issue.project.is_public?
-        assert_equal [issue.id, 1, 2], [issue.root_id, issue.lft, issue.rgt]
+        assert_equal [issue.id, lft1, lft1 + 1], [issue.root_id, issue.lft, issue.rgt]
       end
     end
   end