2011-05-08 07:11:22 +02:00
|
|
|
# Redmine - project management software
|
2016-03-13 11:30:10 +01:00
|
|
|
# Copyright (C) 2006-2016 Jean-Philippe Lang
|
2008-02-16 19:09:26 +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-08 07:11:22 +02:00
|
|
|
#
|
2008-02-16 19:09:26 +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-08 07:11:22 +02:00
|
|
|
#
|
2008-02-16 19:09:26 +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__)
|
2008-02-16 19:09:26 +01:00
|
|
|
|
2016-07-14 11:35:49 +02:00
|
|
|
class RepositoriesCvsControllerTest < Redmine::ControllerTest
|
2011-12-03 16:13:47 +01:00
|
|
|
tests RepositoriesController
|
|
|
|
|
2015-01-17 15:14:12 +01:00
|
|
|
fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles,
|
2011-06-10 14:54:02 +02:00
|
|
|
:repositories, :enabled_modules
|
2008-02-16 19:09:26 +01:00
|
|
|
|
2011-06-10 14:54:02 +02:00
|
|
|
REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
|
2008-08-25 13:01:37 +02:00
|
|
|
REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
|
2008-02-16 19:09:26 +01:00
|
|
|
# CVS module
|
|
|
|
MODULE_NAME = 'test'
|
2011-02-02 05:00:59 +01:00
|
|
|
PRJ_ID = 3
|
2011-09-12 12:02:11 +02:00
|
|
|
NUM_REV = 7
|
2011-02-02 05:00:59 +01:00
|
|
|
|
2008-02-16 19:09:26 +01:00
|
|
|
def setup
|
|
|
|
Setting.default_language = 'en'
|
|
|
|
User.current = nil
|
|
|
|
|
2011-02-02 05:00:59 +01:00
|
|
|
@project = Project.find(PRJ_ID)
|
2011-03-11 01:42:21 +01:00
|
|
|
@repository = Repository::Cvs.create(:project => Project.find(PRJ_ID),
|
|
|
|
:root_url => REPOSITORY_PATH,
|
|
|
|
:url => MODULE_NAME,
|
2011-03-01 11:27:30 +01:00
|
|
|
:log_encoding => 'UTF-8')
|
2011-02-02 05:00:59 +01:00
|
|
|
assert @repository
|
2008-02-16 19:09:26 +01:00
|
|
|
end
|
2011-03-11 01:42:21 +01:00
|
|
|
|
2008-02-16 19:09:26 +01:00
|
|
|
if File.directory?(REPOSITORY_PATH)
|
2012-01-15 15:23:06 +01:00
|
|
|
def test_get_new
|
2011-12-03 16:13:47 +01:00
|
|
|
@request.session[:user_id] = 1
|
|
|
|
@project.repository.destroy
|
2012-01-15 15:23:06 +01:00
|
|
|
get :new, :project_id => 'subproject1', :repository_scm => 'Cvs'
|
2011-12-03 16:13:47 +01:00
|
|
|
assert_response :success
|
2016-07-21 19:48:05 +02:00
|
|
|
|
|
|
|
assert_select 'select[name=?]', 'repository_scm' do
|
|
|
|
assert_select 'option[value=?][selected=selected]', 'Cvs'
|
|
|
|
end
|
2011-12-03 16:13:47 +01:00
|
|
|
end
|
|
|
|
|
2008-02-16 19:09:26 +01:00
|
|
|
def test_browse_root
|
2011-09-12 12:02:44 +02:00
|
|
|
assert_equal 0, @repository.changesets.count
|
2011-02-02 05:00:59 +01:00
|
|
|
@repository.fetch_changesets
|
2011-09-12 12:02:44 +02:00
|
|
|
@project.reload
|
|
|
|
assert_equal NUM_REV, @repository.changesets.count
|
2011-02-02 05:00:59 +01:00
|
|
|
get :show, :id => PRJ_ID
|
2008-02-16 19:09:26 +01:00
|
|
|
assert_response :success
|
2011-03-11 01:42:21 +01:00
|
|
|
|
2016-07-21 19:48:05 +02:00
|
|
|
assert_select 'table.entries tbody' do
|
|
|
|
assert_select 'tr', 3
|
|
|
|
assert_select 'tr.dir td.filename a', :text => 'images'
|
|
|
|
assert_select 'tr.file td.filename a', :text => 'README'
|
|
|
|
end
|
2011-03-22 05:17:58 +01:00
|
|
|
|
2016-07-21 19:48:05 +02:00
|
|
|
assert_select 'table.changesets tbody' do
|
|
|
|
assert_select 'tr'
|
|
|
|
end
|
2008-02-16 19:09:26 +01:00
|
|
|
end
|
2011-03-11 01:42:21 +01:00
|
|
|
|
2008-02-16 19:09:26 +01:00
|
|
|
def test_browse_directory
|
2011-09-12 13:38:31 +02:00
|
|
|
assert_equal 0, @repository.changesets.count
|
2011-02-02 05:00:59 +01:00
|
|
|
@repository.fetch_changesets
|
2011-09-12 13:38:31 +02:00
|
|
|
@project.reload
|
|
|
|
assert_equal NUM_REV, @repository.changesets.count
|
2012-02-23 08:33:44 +01:00
|
|
|
get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
|
2008-02-16 19:09:26 +01:00
|
|
|
assert_response :success
|
2016-07-21 19:48:05 +02:00
|
|
|
|
|
|
|
assert_select 'table.entries tbody' do
|
|
|
|
assert_select 'tr', 3
|
|
|
|
assert_select 'tr.file td.filename a', :text => 'add.png'
|
|
|
|
assert_select 'tr.file td.filename a', :text => 'delete.png'
|
|
|
|
assert_select 'tr.file td.filename a', :text => 'edit.png'
|
|
|
|
end
|
2008-04-06 12:35:55 +02:00
|
|
|
end
|
2011-03-11 01:42:21 +01:00
|
|
|
|
2008-04-06 12:35:55 +02:00
|
|
|
def test_browse_at_given_revision
|
2011-09-12 13:39:01 +02:00
|
|
|
assert_equal 0, @repository.changesets.count
|
2011-02-02 05:00:59 +01:00
|
|
|
@repository.fetch_changesets
|
2011-09-12 13:39:01 +02:00
|
|
|
@project.reload
|
|
|
|
assert_equal NUM_REV, @repository.changesets.count
|
2012-02-23 08:33:44 +01:00
|
|
|
get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
|
|
|
|
:rev => 1
|
2008-04-06 12:35:55 +02:00
|
|
|
assert_response :success
|
2016-07-21 19:48:05 +02:00
|
|
|
|
|
|
|
assert_select 'table.entries tbody' do
|
|
|
|
assert_select 'tr', 2
|
|
|
|
assert_select 'tr.file td.filename a', :text => 'delete.png'
|
|
|
|
assert_select 'tr.file td.filename a', :text => 'edit.png'
|
|
|
|
end
|
2008-02-16 19:09:26 +01:00
|
|
|
end
|
2011-03-11 01:42:21 +01:00
|
|
|
|
2008-02-16 19:09:26 +01:00
|
|
|
def test_entry
|
2011-09-12 13:39:36 +02:00
|
|
|
assert_equal 0, @repository.changesets.count
|
2011-02-02 05:00:59 +01:00
|
|
|
@repository.fetch_changesets
|
2011-09-12 13:39:36 +02:00
|
|
|
@project.reload
|
|
|
|
assert_equal NUM_REV, @repository.changesets.count
|
2012-02-23 08:33:44 +01:00
|
|
|
get :entry, :id => PRJ_ID,
|
|
|
|
:path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
|
2008-02-16 19:09:26 +01:00
|
|
|
assert_response :success
|
2016-07-21 19:48:05 +02:00
|
|
|
|
2014-11-22 10:38:21 +01:00
|
|
|
assert_select 'td.line-code', :text => /before_filter/, :count => 0
|
2008-06-15 17:47:28 +02:00
|
|
|
end
|
2011-03-11 01:42:21 +01:00
|
|
|
|
2008-06-15 17:47:28 +02:00
|
|
|
def test_entry_at_given_revision
|
|
|
|
# changesets must be loaded
|
2011-09-12 13:40:08 +02:00
|
|
|
assert_equal 0, @repository.changesets.count
|
2011-02-02 05:00:59 +01:00
|
|
|
@repository.fetch_changesets
|
2011-09-12 13:40:08 +02:00
|
|
|
@project.reload
|
|
|
|
assert_equal NUM_REV, @repository.changesets.count
|
2012-02-23 08:33:44 +01:00
|
|
|
get :entry, :id => PRJ_ID,
|
|
|
|
:path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
|
|
|
|
:rev => 2
|
2008-06-15 17:47:28 +02:00
|
|
|
assert_response :success
|
2016-07-21 19:48:05 +02:00
|
|
|
|
2008-06-15 17:47:28 +02:00
|
|
|
# this line was removed in r3
|
2014-11-22 10:38:21 +01:00
|
|
|
assert_select 'td.line-code', :text => /before_filter/
|
2008-02-16 19:09:26 +01:00
|
|
|
end
|
2011-03-11 01:42:21 +01:00
|
|
|
|
2008-02-16 19:09:26 +01:00
|
|
|
def test_entry_not_found
|
2011-09-12 13:40:36 +02:00
|
|
|
assert_equal 0, @repository.changesets.count
|
2011-02-02 05:00:59 +01:00
|
|
|
@repository.fetch_changesets
|
2011-09-12 13:40:36 +02:00
|
|
|
@project.reload
|
|
|
|
assert_equal NUM_REV, @repository.changesets.count
|
2012-02-23 08:33:44 +01:00
|
|
|
get :entry, :id => PRJ_ID,
|
|
|
|
:path => repository_path_hash(['sources', 'zzz.c'])[:param]
|
2014-11-22 10:38:21 +01:00
|
|
|
assert_select 'p#errorExplanation', :text => /The entry or revision was not found in the repository/
|
2008-02-16 19:09:26 +01:00
|
|
|
end
|
2011-03-11 01:42:21 +01:00
|
|
|
|
2008-02-16 19:09:26 +01:00
|
|
|
def test_entry_download
|
2011-09-12 13:41:24 +02:00
|
|
|
assert_equal 0, @repository.changesets.count
|
2011-02-02 05:00:59 +01:00
|
|
|
@repository.fetch_changesets
|
2011-09-12 13:41:24 +02:00
|
|
|
@project.reload
|
|
|
|
assert_equal NUM_REV, @repository.changesets.count
|
2012-02-23 08:33:44 +01:00
|
|
|
get :entry, :id => PRJ_ID,
|
|
|
|
:path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
|
2011-09-12 12:19:17 +02:00
|
|
|
:format => 'raw'
|
2008-02-16 19:09:26 +01:00
|
|
|
assert_response :success
|
|
|
|
end
|
2008-04-27 12:12:15 +02:00
|
|
|
|
|
|
|
def test_directory_entry
|
2011-09-12 13:42:03 +02:00
|
|
|
assert_equal 0, @repository.changesets.count
|
2011-02-02 05:00:59 +01:00
|
|
|
@repository.fetch_changesets
|
2011-09-12 13:42:03 +02:00
|
|
|
@project.reload
|
|
|
|
assert_equal NUM_REV, @repository.changesets.count
|
2012-02-23 08:33:44 +01:00
|
|
|
get :entry, :id => PRJ_ID,
|
|
|
|
:path => repository_path_hash(['sources'])[:param]
|
2008-04-27 12:12:15 +02:00
|
|
|
assert_response :success
|
2016-07-21 19:48:05 +02:00
|
|
|
assert_select 'table.entries tbody'
|
2008-04-27 12:12:15 +02:00
|
|
|
end
|
2011-03-11 01:42:21 +01:00
|
|
|
|
2008-02-16 19:09:26 +01:00
|
|
|
def test_diff
|
2011-09-12 13:42:33 +02:00
|
|
|
assert_equal 0, @repository.changesets.count
|
2011-02-02 05:00:59 +01:00
|
|
|
@repository.fetch_changesets
|
2011-09-12 13:42:33 +02:00
|
|
|
@project.reload
|
|
|
|
assert_equal NUM_REV, @repository.changesets.count
|
2011-06-01 08:10:37 +02:00
|
|
|
['inline', 'sbs'].each do |dt|
|
|
|
|
get :diff, :id => PRJ_ID, :rev => 3, :type => dt
|
|
|
|
assert_response :success
|
2016-07-21 19:48:05 +02:00
|
|
|
|
2014-11-22 10:38:21 +01:00
|
|
|
assert_select 'td.line-code.diff_out', :text => /before_filter :require_login/
|
|
|
|
assert_select 'td.line-code.diff_in', :text => /with one change/
|
2011-06-01 08:10:37 +02:00
|
|
|
end
|
2008-02-16 19:09:26 +01:00
|
|
|
end
|
2011-03-11 01:42:21 +01:00
|
|
|
|
2011-02-24 05:03:43 +01:00
|
|
|
def test_diff_new_files
|
2011-09-12 13:15:45 +02:00
|
|
|
assert_equal 0, @repository.changesets.count
|
2011-02-24 05:03:43 +01:00
|
|
|
@repository.fetch_changesets
|
2011-09-12 13:15:45 +02:00
|
|
|
@project.reload
|
|
|
|
assert_equal NUM_REV, @repository.changesets.count
|
2011-06-01 08:11:02 +02:00
|
|
|
['inline', 'sbs'].each do |dt|
|
|
|
|
get :diff, :id => PRJ_ID, :rev => 1, :type => dt
|
|
|
|
assert_response :success
|
2016-07-21 19:48:05 +02:00
|
|
|
|
2014-11-22 10:38:21 +01:00
|
|
|
assert_select 'td.line-code.diff_in', :text => /watched.remove_watcher/
|
|
|
|
assert_select 'th.filename', :text => /test\/README/
|
|
|
|
assert_select 'th.filename', :text => /test\/images\/delete.png/
|
|
|
|
assert_select 'th.filename', :text => /test\/images\/edit.png/
|
|
|
|
assert_select 'th.filename', :text => /test\/sources\/watchers_controller.rb/
|
2011-06-01 08:11:02 +02:00
|
|
|
end
|
2011-02-24 05:03:43 +01:00
|
|
|
end
|
2008-02-16 19:09:26 +01:00
|
|
|
|
|
|
|
def test_annotate
|
2011-09-12 13:16:10 +02:00
|
|
|
assert_equal 0, @repository.changesets.count
|
2011-02-02 05:00:59 +01:00
|
|
|
@repository.fetch_changesets
|
2011-09-12 13:16:10 +02:00
|
|
|
@project.reload
|
|
|
|
assert_equal NUM_REV, @repository.changesets.count
|
2012-02-23 08:33:44 +01:00
|
|
|
get :annotate, :id => PRJ_ID,
|
|
|
|
:path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
|
2008-02-16 19:09:26 +01:00
|
|
|
assert_response :success
|
2012-07-28 20:16:55 +02:00
|
|
|
|
2008-02-16 19:09:26 +01:00
|
|
|
# 1.1 line
|
2012-07-28 20:16:55 +02:00
|
|
|
assert_select 'tr' do
|
|
|
|
assert_select 'th.line-num', :text => '21'
|
|
|
|
assert_select 'td.revision', :text => /1.1/
|
|
|
|
assert_select 'td.author', :text => /LANG/
|
|
|
|
end
|
2008-02-16 19:09:26 +01:00
|
|
|
# 1.2 line
|
2012-07-28 20:16:55 +02:00
|
|
|
assert_select 'tr' do
|
|
|
|
assert_select 'th.line-num', :text => '32'
|
|
|
|
assert_select 'td.revision', :text => /1.2/
|
|
|
|
assert_select 'td.author', :text => /LANG/
|
|
|
|
end
|
2008-02-16 19:09:26 +01:00
|
|
|
end
|
2011-07-11 01:55:15 +02:00
|
|
|
|
|
|
|
def test_destroy_valid_repository
|
|
|
|
@request.session[:user_id] = 1 # admin
|
2011-09-12 12:52:58 +02:00
|
|
|
assert_equal 0, @repository.changesets.count
|
2011-07-11 01:55:15 +02:00
|
|
|
@repository.fetch_changesets
|
2011-09-12 12:52:58 +02:00
|
|
|
@project.reload
|
|
|
|
assert_equal NUM_REV, @repository.changesets.count
|
2011-07-11 01:55:15 +02:00
|
|
|
|
2012-01-15 15:23:06 +01:00
|
|
|
assert_difference 'Repository.count', -1 do
|
|
|
|
delete :destroy, :id => @repository.id
|
|
|
|
end
|
2011-07-11 01:55:15 +02:00
|
|
|
assert_response 302
|
|
|
|
@project.reload
|
|
|
|
assert_nil @project.repository
|
|
|
|
end
|
2011-07-11 01:55:38 +02:00
|
|
|
|
|
|
|
def test_destroy_invalid_repository
|
|
|
|
@request.session[:user_id] = 1 # admin
|
2012-01-15 15:23:06 +01:00
|
|
|
@project.repository.destroy
|
|
|
|
@repository = Repository::Cvs.create!(
|
2011-07-11 01:55:38 +02:00
|
|
|
:project => Project.find(PRJ_ID),
|
|
|
|
:root_url => "/invalid",
|
|
|
|
:url => MODULE_NAME,
|
|
|
|
:log_encoding => 'UTF-8'
|
|
|
|
)
|
|
|
|
@repository.fetch_changesets
|
2011-09-12 12:53:20 +02:00
|
|
|
@project.reload
|
2011-07-11 01:55:38 +02:00
|
|
|
assert_equal 0, @repository.changesets.count
|
|
|
|
|
2012-01-15 15:23:06 +01:00
|
|
|
assert_difference 'Repository.count', -1 do
|
|
|
|
delete :destroy, :id => @repository.id
|
|
|
|
end
|
2011-07-11 01:55:38 +02:00
|
|
|
assert_response 302
|
|
|
|
@project.reload
|
|
|
|
assert_nil @project.repository
|
|
|
|
end
|
2008-02-16 19:09:26 +01:00
|
|
|
else
|
|
|
|
puts "CVS test repository NOT FOUND. Skipping functional tests !!!"
|
|
|
|
def test_fake; assert true end
|
|
|
|
end
|
|
|
|
end
|