Source

redmine-mq-issue4455 / repo-hg-test-speedup.diff

Full commit
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1292770312 -32400
# Node ID 0e72a41826621ac49d5bf3f96ebaf8fa1e8f7509
# Parent  a3d84e4946bcbfcfcaa62cdc3ba25c6ca67cba95
XXX should be reimplemented by legitimate way

I tried caching @repository object, but it looks the database is cleared
away on each test method.

diff --git a/test/unit/repository_mercurial_test.rb b/test/unit/repository_mercurial_test.rb
--- a/test/unit/repository_mercurial_test.rb
+++ b/test/unit/repository_mercurial_test.rb
@@ -27,8 +27,19 @@ class RepositoryMercurialTest < ActiveSu
     def setup
       @project = Project.find(1)
       assert @repository = Repository::Mercurial.create(:project => @project, :url => REPOSITORY_PATH)
-      @repository.fetch_changesets
-      @repository.reload
+      # XXX WORKAROUND for speed up test cases
+      @@changesets ||= nil
+      unless @@changesets
+        @repository.fetch_changesets
+        @repository.reload
+        @repository.changesets.each { |c| c.changes.to_a }
+        @@changesets = @repository.changesets.to_a.sort { |a, b| a.id <=> b.id } # XXX
+      else
+        @@changesets.each do |c|
+          nc = Changeset.create(c.attributes.update({:repository => @repository}))
+          c.changes.each { |e| Change.create(e.attributes.update({:changeset => nc})) }
+        end
+      end
     end
 
     def test_fetch_changesets_from_scratch