2011-05-24 03:58:29 +02:00
|
|
|
# Redmine - project management software
|
2016-03-13 11:30:10 +01:00
|
|
|
# Copyright (C) 2006-2016 Jean-Philippe Lang
|
2007-12-01 18:15:42 +01:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-05-24 03:58:29 +02:00
|
|
|
#
|
2007-12-01 18:15:42 +01:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2011-05-24 03:58:29 +02:00
|
|
|
#
|
2007-12-01 18:15:42 +01:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
2010-12-13 00:24:34 +01:00
|
|
|
require File.expand_path('../../test_helper', __FILE__)
|
2007-12-01 18:15:42 +01:00
|
|
|
|
2016-07-14 11:35:49 +02:00
|
|
|
class RepositoriesControllerTest < Redmine::ControllerTest
|
2015-01-17 15:14:12 +01:00
|
|
|
fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, :enabled_modules,
|
2011-03-22 08:48:04 +01:00
|
|
|
:repositories, :issues, :issue_statuses, :changesets, :changes,
|
|
|
|
:issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
|
|
|
|
|
2007-12-01 18:15:42 +01:00
|
|
|
def setup
|
|
|
|
User.current = nil
|
|
|
|
end
|
2011-03-22 08:48:04 +01:00
|
|
|
|
2012-01-15 15:23:06 +01:00
|
|
|
def test_new
|
|
|
|
@request.session[:user_id] = 1
|
|
|
|
get :new, :project_id => 'subproject1'
|
|
|
|
assert_response :success
|
2016-07-21 19:48:05 +02:00
|
|
|
assert_select 'select[name=?]', 'repository_scm' do
|
|
|
|
assert_select 'option[value=?][selected=selected]', 'Subversion'
|
|
|
|
end
|
2014-11-22 10:38:21 +01:00
|
|
|
assert_select 'input[name=?]:not([disabled])', 'repository[url]'
|
2012-01-15 15:23:06 +01:00
|
|
|
end
|
|
|
|
|
2012-01-15 23:23:56 +01:00
|
|
|
def test_new_should_propose_enabled_scm_only
|
|
|
|
@request.session[:user_id] = 1
|
|
|
|
with_settings :enabled_scm => ['Mercurial', 'Git'] do
|
|
|
|
get :new, :project_id => 'subproject1'
|
|
|
|
end
|
|
|
|
assert_response :success
|
2014-11-22 10:38:21 +01:00
|
|
|
|
|
|
|
assert_select 'select[name=repository_scm]' do
|
|
|
|
assert_select 'option', 3
|
|
|
|
assert_select 'option[value=Mercurial][selected=selected]'
|
|
|
|
assert_select 'option[value=Git]:not([selected])'
|
|
|
|
end
|
2012-01-15 23:23:56 +01:00
|
|
|
end
|
2016-10-04 18:40:24 +02:00
|
|
|
|
|
|
|
def test_get_new_with_type
|
|
|
|
@request.session[:user_id] = 1
|
|
|
|
get :new, :project_id => 'subproject1', :repository_scm => 'Git'
|
|
|
|
assert_response :success
|
|
|
|
|
|
|
|
assert_select 'select[name=?]', 'repository_scm' do
|
|
|
|
assert_select 'option[value=?][selected=selected]', 'Git'
|
|
|
|
end
|
|
|
|
end
|
2012-01-15 23:23:56 +01:00
|
|
|
|
2012-01-15 15:23:06 +01:00
|
|
|
def test_create
|
|
|
|
@request.session[:user_id] = 1
|
|
|
|
assert_difference 'Repository.count' do
|
|
|
|
post :create, :project_id => 'subproject1',
|
|
|
|
:repository_scm => 'Subversion',
|
2012-01-15 19:19:19 +01:00
|
|
|
:repository => {:url => 'file:///test', :is_default => '1', :identifier => ''}
|
2012-01-15 15:23:06 +01:00
|
|
|
end
|
|
|
|
assert_response 302
|
2014-01-11 11:13:21 +01:00
|
|
|
repository = Repository.order('id DESC').first
|
2012-01-15 15:23:06 +01:00
|
|
|
assert_kind_of Repository::Subversion, repository
|
|
|
|
assert_equal 'file:///test', repository.url
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_create_with_failure
|
|
|
|
@request.session[:user_id] = 1
|
|
|
|
assert_no_difference 'Repository.count' do
|
|
|
|
post :create, :project_id => 'subproject1',
|
|
|
|
:repository_scm => 'Subversion',
|
|
|
|
:repository => {:url => 'invalid'}
|
|
|
|
end
|
|
|
|
assert_response :success
|
2016-07-21 19:48:05 +02:00
|
|
|
assert_select_error /URL is invalid/
|
|
|
|
assert_select 'select[name=?]', 'repository_scm' do
|
|
|
|
assert_select 'option[value=?][selected=selected]', 'Subversion'
|
|
|
|
end
|
2012-01-15 15:23:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_edit
|
|
|
|
@request.session[:user_id] = 1
|
|
|
|
get :edit, :id => 11
|
|
|
|
assert_response :success
|
2014-11-22 10:38:21 +01:00
|
|
|
assert_select 'input[name=?][value=?][disabled=disabled]', 'repository[url]', 'svn://localhost/test'
|
2012-01-15 15:23:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_update
|
|
|
|
@request.session[:user_id] = 1
|
|
|
|
put :update, :id => 11, :repository => {:password => 'test_update'}
|
|
|
|
assert_response 302
|
|
|
|
assert_equal 'test_update', Repository.find(11).password
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_update_with_failure
|
|
|
|
@request.session[:user_id] = 1
|
|
|
|
put :update, :id => 11, :repository => {:password => 'x'*260}
|
|
|
|
assert_response :success
|
2016-07-21 19:48:05 +02:00
|
|
|
assert_select_error /Password is too long/
|
2012-01-15 15:23:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_destroy
|
|
|
|
@request.session[:user_id] = 1
|
|
|
|
assert_difference 'Repository.count', -1 do
|
|
|
|
delete :destroy, :id => 11
|
|
|
|
end
|
|
|
|
assert_response 302
|
|
|
|
assert_nil Repository.find_by_id(11)
|
|
|
|
end
|
|
|
|
|
2013-05-12 12:05:35 +02:00
|
|
|
def test_show_with_autofetch_changesets_enabled_should_fetch_changesets
|
|
|
|
Repository::Subversion.any_instance.expects(:fetch_changesets).once
|
|
|
|
|
|
|
|
with_settings :autofetch_changesets => '1' do
|
|
|
|
get :show, :id => 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_show_with_autofetch_changesets_disabled_should_not_fetch_changesets
|
|
|
|
Repository::Subversion.any_instance.expects(:fetch_changesets).never
|
|
|
|
|
|
|
|
with_settings :autofetch_changesets => '0' do
|
|
|
|
get :show, :id => 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_show_with_closed_project_should_not_fetch_changesets
|
|
|
|
Repository::Subversion.any_instance.expects(:fetch_changesets).never
|
|
|
|
Project.find(1).close
|
|
|
|
|
|
|
|
with_settings :autofetch_changesets => '1' do
|
|
|
|
get :show, :id => 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-12-12 21:56:22 +01:00
|
|
|
def test_revisions
|
|
|
|
get :revisions, :id => 1
|
|
|
|
assert_response :success
|
2016-07-21 19:48:05 +02:00
|
|
|
assert_select 'table.changesets'
|
2012-01-15 19:19:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_revisions_for_other_repository
|
|
|
|
repository = Repository::Subversion.create!(:project_id => 1, :identifier => 'foo', :url => 'file:///foo')
|
|
|
|
|
|
|
|
get :revisions, :id => 1, :repository_id => 'foo'
|
|
|
|
assert_response :success
|
2016-07-21 19:48:05 +02:00
|
|
|
assert_select 'table.changesets'
|
2007-12-12 21:56:22 +01:00
|
|
|
end
|
2009-01-26 02:47:51 +01:00
|
|
|
|
2012-01-15 19:19:19 +01:00
|
|
|
def test_revisions_for_invalid_repository
|
|
|
|
get :revisions, :id => 1, :repository_id => 'foo'
|
|
|
|
assert_response 404
|
|
|
|
end
|
|
|
|
|
2009-09-20 17:20:22 +02:00
|
|
|
def test_revision
|
|
|
|
get :revision, :id => 1, :rev => 1
|
|
|
|
assert_response :success
|
2016-07-21 19:48:05 +02:00
|
|
|
assert_select 'h2', :text => 'Revision 1'
|
2009-09-20 17:20:22 +02:00
|
|
|
end
|
2011-03-22 08:48:04 +01:00
|
|
|
|
2016-12-12 22:19:59 +01:00
|
|
|
def test_revision_should_not_format_comments_when_disabled
|
|
|
|
Changeset.where(:id => 100).update_all(:comments => 'Simple *text*')
|
|
|
|
|
|
|
|
with_settings :commit_logs_formatting => '0' do
|
|
|
|
get :revision, :id => 1, :rev => 1
|
|
|
|
assert_response :success
|
2016-12-18 10:35:43 +01:00
|
|
|
assert_select '.changeset-comments', :text => 'Simple *text*'
|
2016-12-12 22:19:59 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-28 08:59:54 +01:00
|
|
|
def test_revision_should_show_add_related_issue_form
|
|
|
|
Role.find(1).add_permission! :manage_related_issues
|
|
|
|
@request.session[:user_id] = 2
|
|
|
|
|
|
|
|
get :revision, :id => 1, :rev => 1
|
|
|
|
assert_response :success
|
|
|
|
|
|
|
|
assert_select 'form[action=?]', '/projects/ecookbook/repository/revisions/1/issues' do
|
|
|
|
assert_select 'input[name=?]', 'issue_id'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-27 16:26:35 +01:00
|
|
|
def test_revision_should_not_change_the_project_menu_link
|
|
|
|
get :revision, :id => 1, :rev => 1
|
|
|
|
assert_response :success
|
|
|
|
|
2014-11-22 10:38:21 +01:00
|
|
|
assert_select '#main-menu a.repository[href=?]', '/projects/ecookbook/repository'
|
2012-02-27 16:26:35 +01:00
|
|
|
end
|
|
|
|
|
2007-12-01 18:15:42 +01:00
|
|
|
def test_revision_with_before_nil_and_afer_normal
|
|
|
|
get :revision, {:id => 1, :rev => 1}
|
|
|
|
assert_response :success
|
2014-11-22 10:38:21 +01:00
|
|
|
|
|
|
|
assert_select 'div.contextual' do
|
|
|
|
assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/0', 0
|
|
|
|
assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/2'
|
|
|
|
end
|
2007-12-01 18:15:42 +01:00
|
|
|
end
|
2011-03-22 08:48:04 +01:00
|
|
|
|
2012-02-05 11:56:27 +01:00
|
|
|
def test_add_related_issue
|
|
|
|
@request.session[:user_id] = 2
|
|
|
|
assert_difference 'Changeset.find(103).issues.size' do
|
2012-07-19 19:27:14 +02:00
|
|
|
xhr :post, :add_related_issue, :id => 1, :rev => 4, :issue_id => 2, :format => 'js'
|
2012-02-05 11:56:27 +01:00
|
|
|
assert_response :success
|
2012-07-19 19:27:14 +02:00
|
|
|
assert_equal 'text/javascript', response.content_type
|
2012-02-05 11:56:27 +01:00
|
|
|
end
|
|
|
|
assert_equal [2], Changeset.find(103).issue_ids
|
2012-07-19 19:27:14 +02:00
|
|
|
assert_include 'related-issues', response.body
|
|
|
|
assert_include 'Feature request #2', response.body
|
2012-02-05 11:56:27 +01:00
|
|
|
end
|
|
|
|
|
2013-11-09 12:09:50 +01:00
|
|
|
def test_add_related_issue_should_accept_issue_id_with_sharp
|
|
|
|
@request.session[:user_id] = 2
|
|
|
|
assert_difference 'Changeset.find(103).issues.size' do
|
|
|
|
xhr :post, :add_related_issue, :id => 1, :rev => 4, :issue_id => "#2", :format => 'js'
|
|
|
|
end
|
|
|
|
assert_equal [2], Changeset.find(103).issue_ids
|
|
|
|
end
|
|
|
|
|
2012-02-05 11:56:27 +01:00
|
|
|
def test_add_related_issue_with_invalid_issue_id
|
|
|
|
@request.session[:user_id] = 2
|
|
|
|
assert_no_difference 'Changeset.find(103).issues.size' do
|
2012-07-19 19:27:14 +02:00
|
|
|
xhr :post, :add_related_issue, :id => 1, :rev => 4, :issue_id => 9999, :format => 'js'
|
2012-02-05 11:56:27 +01:00
|
|
|
assert_response :success
|
2012-07-19 19:27:14 +02:00
|
|
|
assert_equal 'text/javascript', response.content_type
|
2012-02-05 11:56:27 +01:00
|
|
|
end
|
2012-07-19 19:27:14 +02:00
|
|
|
assert_include 'alert("Issue is invalid")', response.body
|
2012-02-05 11:56:27 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_remove_related_issue
|
|
|
|
Changeset.find(103).issues << Issue.find(1)
|
|
|
|
Changeset.find(103).issues << Issue.find(2)
|
|
|
|
|
|
|
|
@request.session[:user_id] = 2
|
|
|
|
assert_difference 'Changeset.find(103).issues.size', -1 do
|
2012-07-19 19:27:14 +02:00
|
|
|
xhr :delete, :remove_related_issue, :id => 1, :rev => 4, :issue_id => 2, :format => 'js'
|
2012-02-05 11:56:27 +01:00
|
|
|
assert_response :success
|
2012-07-19 19:27:14 +02:00
|
|
|
assert_equal 'text/javascript', response.content_type
|
2012-02-05 11:56:27 +01:00
|
|
|
end
|
|
|
|
assert_equal [1], Changeset.find(103).issue_ids
|
2012-07-19 19:27:14 +02:00
|
|
|
assert_include 'related-issue-2', response.body
|
2012-02-05 11:56:27 +01:00
|
|
|
end
|
|
|
|
|
2007-12-12 21:56:22 +01:00
|
|
|
def test_graph_commits_per_month
|
2012-05-01 23:12:47 +02:00
|
|
|
# Make sure there's some data to display
|
|
|
|
latest = Project.find(1).repository.changesets.maximum(:commit_date)
|
|
|
|
assert_not_nil latest
|
|
|
|
Date.stubs(:today).returns(latest.to_date + 10)
|
|
|
|
|
2007-12-12 21:56:22 +01:00
|
|
|
get :graph, :id => 1, :graph => 'commits_per_month'
|
|
|
|
assert_response :success
|
|
|
|
assert_equal 'image/svg+xml', @response.content_type
|
|
|
|
end
|
2011-03-22 08:48:04 +01:00
|
|
|
|
2007-12-12 21:56:22 +01:00
|
|
|
def test_graph_commits_per_author
|
|
|
|
get :graph, :id => 1, :graph => 'commits_per_author'
|
|
|
|
assert_response :success
|
|
|
|
assert_equal 'image/svg+xml', @response.content_type
|
|
|
|
end
|
2011-03-22 08:48:04 +01:00
|
|
|
|
2012-01-15 15:23:06 +01:00
|
|
|
def test_get_committers
|
2008-11-10 19:59:06 +01:00
|
|
|
@request.session[:user_id] = 2
|
|
|
|
# add a commit with an unknown user
|
2011-03-22 08:48:04 +01:00
|
|
|
Changeset.create!(
|
|
|
|
:repository => Project.find(1).repository,
|
|
|
|
:committer => 'foo',
|
|
|
|
:committed_on => Time.now,
|
|
|
|
:revision => 100,
|
|
|
|
:comments => 'Committed by foo.'
|
|
|
|
)
|
|
|
|
|
2012-01-15 15:23:06 +01:00
|
|
|
get :committers, :id => 10
|
2008-11-10 19:59:06 +01:00
|
|
|
assert_response :success
|
2011-05-24 03:58:29 +02:00
|
|
|
|
2015-01-17 18:02:55 +01:00
|
|
|
assert_select 'input[value=dlopper] + select option[value="3"][selected=selected]', :text => 'Dave Lopper'
|
|
|
|
assert_select 'input[value=foo] + select option[selected=selected]', 0 # no option selected
|
2008-11-10 19:59:06 +01:00
|
|
|
end
|
|
|
|
|
2015-03-07 17:21:59 +01:00
|
|
|
def test_get_committers_without_changesets
|
|
|
|
Changeset.delete_all
|
|
|
|
@request.session[:user_id] = 2
|
|
|
|
|
|
|
|
get :committers, :id => 10
|
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
2012-01-15 15:23:06 +01:00
|
|
|
def test_post_committers
|
2008-11-10 19:59:06 +01:00
|
|
|
@request.session[:user_id] = 2
|
|
|
|
# add a commit with an unknown user
|
2011-03-22 08:48:04 +01:00
|
|
|
c = Changeset.create!(
|
|
|
|
:repository => Project.find(1).repository,
|
|
|
|
:committer => 'foo',
|
|
|
|
:committed_on => Time.now,
|
|
|
|
:revision => 100,
|
|
|
|
:comments => 'Committed by foo.'
|
|
|
|
)
|
2013-06-12 21:13:25 +02:00
|
|
|
assert_no_difference "Changeset.where(:user_id => 3).count" do
|
2012-01-15 15:23:06 +01:00
|
|
|
post :committers, :id => 10, :committers => { '0' => ['foo', '2'], '1' => ['dlopper', '3']}
|
|
|
|
assert_response 302
|
2008-11-10 19:59:06 +01:00
|
|
|
assert_equal User.find(2), c.reload.user
|
|
|
|
end
|
|
|
|
end
|
2007-12-01 18:15:42 +01:00
|
|
|
end
|