summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-11-10 18:59:06 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-11-10 18:59:06 +0000
commit79c33bbc838fd837e516fd60569dbcf7917bd534 (patch)
tree20695e6f03f08925d6be3c96846668d979b4b3b3 /test
parentf6b2be81b9cb09485a08e58fc73d9290fd544148 (diff)
downloadredmine-79c33bbc838fd837e516fd60569dbcf7917bd534.tar.gz
redmine-79c33bbc838fd837e516fd60569dbcf7917bd534.zip
Maps repository users to Redmine users (#1383).
Users with same username or email are automatically mapped. Mapping can be manually adjusted in repository settings. Multiple usernames can be mapped to the same Redmine user. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2006 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/changesets.yml4
-rw-r--r--test/fixtures/roles.yml1
-rw-r--r--test/functional/repositories_controller_test.rb34
-rw-r--r--test/unit/repository_git_test.rb1
-rw-r--r--test/unit/repository_test.rb22
5 files changed, 62 insertions, 0 deletions
diff --git a/test/fixtures/changesets.yml b/test/fixtures/changesets.yml
index 3b47eecd8..cbc00eb83 100644
--- a/test/fixtures/changesets.yml
+++ b/test/fixtures/changesets.yml
@@ -7,6 +7,7 @@ changesets_001:
comments: My very first commit
repository_id: 10
committer: dlopper
+ user_id: 3
changesets_002:
commit_date: 2007-04-12
committed_on: 2007-04-12 15:14:44 +02:00
@@ -15,6 +16,7 @@ changesets_002:
comments: 'This commit fixes #1, #2 and references #1 & #3'
repository_id: 10
committer: dlopper
+ user_id: 3
changesets_003:
commit_date: 2007-04-12
committed_on: 2007-04-12 15:14:44 +02:00
@@ -25,6 +27,7 @@ changesets_003:
IssueID 666 3
repository_id: 10
committer: dlopper
+ user_id: 3
changesets_004:
commit_date: 2007-04-12
committed_on: 2007-04-12 15:14:44 +02:00
@@ -35,4 +38,5 @@ changesets_004:
IssueID 4 2
repository_id: 10
committer: dlopper
+ user_id: 3
\ No newline at end of file
diff --git a/test/fixtures/roles.yml b/test/fixtures/roles.yml
index 78e0f0329..5bc6809d7 100644
--- a/test/fixtures/roles.yml
+++ b/test/fixtures/roles.yml
@@ -43,6 +43,7 @@ roles_001:
- :view_files
- :manage_files
- :browse_repository
+ - :manage_repository
- :view_changesets
position: 1
diff --git a/test/functional/repositories_controller_test.rb b/test/functional/repositories_controller_test.rb
index 2892f3bd1..4bb9c3fa3 100644
--- a/test/functional/repositories_controller_test.rb
+++ b/test/functional/repositories_controller_test.rb
@@ -61,4 +61,38 @@ class RepositoriesControllerTest < Test::Unit::TestCase
assert_response :success
assert_equal 'image/svg+xml', @response.content_type
end
+
+ def test_committers
+ @request.session[:user_id] = 2
+ # add a commit with an unknown user
+ Changeset.create!(:repository => Project.find(1).repository, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.')
+
+ get :committers, :id => 1
+ assert_response :success
+ assert_template 'committers'
+
+ assert_tag :td, :content => 'dlopper',
+ :sibling => { :tag => 'td',
+ :child => { :tag => 'select', :attributes => { :name => 'committers[dlopper]' },
+ :child => { :tag => 'option', :content => 'Dave Lopper',
+ :attributes => { :value => '3', :selected => 'selected' }}}}
+ assert_tag :td, :content => 'foo',
+ :sibling => { :tag => 'td',
+ :child => { :tag => 'select', :attributes => { :name => 'committers[foo]' }}}
+ assert_no_tag :td, :content => 'foo',
+ :sibling => { :tag => 'td',
+ :descendant => { :tag => 'option', :attributes => { :selected => 'selected' }}}
+ end
+
+ def test_map_committers
+ @request.session[:user_id] = 2
+ # add a commit with an unknown user
+ c = Changeset.create!(:repository => Project.find(1).repository, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.')
+
+ assert_no_difference "Changeset.count(:conditions => 'user_id = 3')" do
+ post :committers, :id => 1, :committers => { 'foo' => '2', 'dlopper' => '3'}
+ assert_redirected_to '/repositories/committers/ecookbook'
+ assert_equal User.find(2), c.reload.user
+ end
+ end
end
diff --git a/test/unit/repository_git_test.rb b/test/unit/repository_git_test.rb
index da95d439f..bc997b96c 100644
--- a/test/unit/repository_git_test.rb
+++ b/test/unit/repository_git_test.rb
@@ -40,6 +40,7 @@ class RepositoryGitTest < Test::Unit::TestCase
commit = @repository.changesets.find(:first, :order => 'committed_on ASC')
assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
assert_equal "jsmith <jsmith@foo.bar>", commit.committer
+ assert_equal User.find_by_login('jsmith'), commit.user
# TODO: add a commit with commit time <> author time to the test repository
assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on
assert_equal "2007-12-14".to_date, commit.commit_date
diff --git a/test/unit/repository_test.rb b/test/unit/repository_test.rb
index 9ea9fdd45..47230cf56 100644
--- a/test/unit/repository_test.rb
+++ b/test/unit/repository_test.rb
@@ -127,4 +127,26 @@ class RepositoryTest < Test::Unit::TestCase
assert_equal ':pserver:login:password@host:/path/to/the/repository', repository.url
assert_equal 'foo', repository.root_url
end
+
+ def test_manual_user_mapping
+ assert_no_difference "Changeset.count(:conditions => 'user_id <> 2')" do
+ c = Changeset.create!(:repository => @repository, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.')
+ assert_nil c.user
+ @repository.committer_ids = {'foo' => '2'}
+ assert_equal User.find(2), c.reload.user
+ # committer is now mapped
+ c = Changeset.create!(:repository => @repository, :committer => 'foo', :committed_on => Time.now, :revision => 101, :comments => 'Another commit by foo.')
+ assert_equal User.find(2), c.user
+ end
+ end
+
+ def test_auto_user_mapping_by_username
+ c = Changeset.create!(:repository => @repository, :committer => 'jsmith', :committed_on => Time.now, :revision => 100, :comments => 'Committed by john.')
+ assert_equal User.find(2), c.user
+ end
+
+ def test_auto_user_mapping_by_email
+ c = Changeset.create!(:repository => @repository, :committer => 'john <jsmith@somenet.foo>', :committed_on => Time.now, :revision => 100, :comments => 'Committed by john.')
+ assert_equal User.find(2), c.user
+ end
end