summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2009-09-20 15:20:22 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2009-09-20 15:20:22 +0000
commit30ad78e57da31443a2026b60bd5d8727d9503321 (patch)
tree39f271f7ba8d107304b605680033866b6e9e9c8c
parente89d4825dd2d4da780af0faae210c7a2517f1651 (diff)
downloadredmine-30ad78e57da31443a2026b60bd5d8727d9503321.tar.gz
redmine-30ad78e57da31443a2026b60bd5d8727d9503321.zip
Fixed: RepositoriesController#revision may show wrong revision (#3779).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2898 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/repositories_controller.rb2
-rw-r--r--app/models/repository.rb5
-rw-r--r--test/fixtures/changesets.yml20
-rw-r--r--test/fixtures/repositories/subversion_repository.dump.gzbin11015 -> 12611 bytes
-rw-r--r--test/functional/repositories_controller_test.rb7
-rw-r--r--test/functional/repositories_subversion_controller_test.rb2
-rw-r--r--test/unit/changeset_test.rb2
-rw-r--r--test/unit/repository_subversion_test.rb6
8 files changed, 38 insertions, 6 deletions
diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb
index 42405468f..7527f0d9a 100644
--- a/app/controllers/repositories_controller.rb
+++ b/app/controllers/repositories_controller.rb
@@ -130,7 +130,7 @@ class RepositoriesController < ApplicationController
end
def revision
- @changeset = @repository.changesets.find(:first, :conditions => ["revision LIKE ?", @rev + '%'])
+ @changeset = @repository.find_changeset_by_name(@rev)
raise ChangesetNotFound unless @changeset
respond_to do |format|
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 8440bc685..2947d1cd9 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -92,6 +92,11 @@ class Repository < ActiveRecord::Base
path
end
+ # Finds and returns a revision with a number or the beginning of a hash
+ def find_changeset_by_name(name)
+ changesets.find(:first, :conditions => (name.match(/^\d*$/) ? ["revision = ?", name.to_i] : ["revision LIKE ?", name + '%']))
+ end
+
def latest_changeset
@latest_changeset ||= changesets.find(:first)
end
diff --git a/test/fixtures/changesets.yml b/test/fixtures/changesets.yml
index 3eda7c52f..41f077a3f 100644
--- a/test/fixtures/changesets.yml
+++ b/test/fixtures/changesets.yml
@@ -81,4 +81,24 @@ changesets_008:
user_id: 3
repository_id: 10
committer: dlopper
+changesets_009:
+ commit_date: "2009-09-10"
+ comments: One file added.
+ committed_on: 2009-09-10 19:04:35
+ revision: "9"
+ id: 108
+ scmid:
+ user_id: 3
+ repository_id: 10
+ committer: dlopper
+changesets_010:
+ commit_date: "2009-09-10"
+ comments: Same file modified.
+ committed_on: 2009-09-10 19:04:35
+ revision: "10"
+ id: 109
+ scmid:
+ user_id: 3
+ repository_id: 10
+ committer: dlopper
\ No newline at end of file
diff --git a/test/fixtures/repositories/subversion_repository.dump.gz b/test/fixtures/repositories/subversion_repository.dump.gz
index 997835048..79ef77fa7 100644
--- a/test/fixtures/repositories/subversion_repository.dump.gz
+++ b/test/fixtures/repositories/subversion_repository.dump.gz
Binary files differ
diff --git a/test/functional/repositories_controller_test.rb b/test/functional/repositories_controller_test.rb
index d786c2e21..5ff2a6a92 100644
--- a/test/functional/repositories_controller_test.rb
+++ b/test/functional/repositories_controller_test.rb
@@ -77,6 +77,13 @@ class RepositoriesControllerTest < ActionController::TestCase
)
end
+ def test_revision
+ get :revision, :id => 1, :rev => 1
+ assert_response :success
+ assert_not_nil assigns(:changeset)
+ assert_equal "1", assigns(:changeset).revision
+ end
+
def test_revision_with_before_nil_and_afer_normal
get :revision, {:id => 1, :rev => 1}
assert_response :success
diff --git a/test/functional/repositories_subversion_controller_test.rb b/test/functional/repositories_subversion_controller_test.rb
index 865bae35c..f07c7ea1a 100644
--- a/test/functional/repositories_subversion_controller_test.rb
+++ b/test/functional/repositories_subversion_controller_test.rb
@@ -102,7 +102,7 @@ class RepositoriesSubversionControllerTest < ActionController::TestCase
changesets = assigns(:changesets)
assert_not_nil changesets
- assert_equal %w(7 6 5 2), changesets.collect(&:revision)
+ assert_equal %w(10 9 7 6 5 2), changesets.collect(&:revision)
end
def test_entry
diff --git a/test/unit/changeset_test.rb b/test/unit/changeset_test.rb
index 9af53a3ca..02736a9a0 100644
--- a/test/unit/changeset_test.rb
+++ b/test/unit/changeset_test.rb
@@ -91,7 +91,7 @@ class ChangesetTest < ActiveSupport::TestCase
end
def test_next_nil
- changeset = Changeset.find_by_revision('8')
+ changeset = Changeset.find_by_revision('10')
assert_nil changeset.next
end
end
diff --git a/test/unit/repository_subversion_test.rb b/test/unit/repository_subversion_test.rb
index 17a0a42b0..f0ad212ca 100644
--- a/test/unit/repository_subversion_test.rb
+++ b/test/unit/repository_subversion_test.rb
@@ -33,8 +33,8 @@ class RepositorySubversionTest < ActiveSupport::TestCase
@repository.fetch_changesets
@repository.reload
- assert_equal 8, @repository.changesets.count
- assert_equal 16, @repository.changes.count
+ assert_equal 10, @repository.changesets.count
+ assert_equal 18, @repository.changes.count
assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments
end
@@ -46,7 +46,7 @@ class RepositorySubversionTest < ActiveSupport::TestCase
assert_equal 5, @repository.changesets.count
@repository.fetch_changesets
- assert_equal 8, @repository.changesets.count
+ assert_equal 10, @repository.changesets.count
end
def test_latest_changesets_with_limit