User groups branch added.
git-svn-id: http://redmine.rubyforge.org/svn/branches/work@1372 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'account_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class AccountController; def rescue_action(e) raise e end; end
|
||||
|
||||
class AccountControllerTest < Test::Unit::TestCase
|
||||
fixtures :users
|
||||
|
||||
def setup
|
||||
@controller = AccountController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_show
|
||||
get :show, :id => 2
|
||||
assert_response :success
|
||||
assert_template 'show'
|
||||
assert_not_nil assigns(:user)
|
||||
end
|
||||
|
||||
def test_show_inactive
|
||||
get :show, :id => 5
|
||||
assert_response 404
|
||||
assert_nil assigns(:user)
|
||||
end
|
||||
|
||||
def test_login_with_wrong_password
|
||||
post :login, :username => 'admin', :password => 'bad'
|
||||
assert_response :success
|
||||
assert_template 'login'
|
||||
assert_tag 'div',
|
||||
:attributes => { :class => "flash error" },
|
||||
:content => /Invalid user or password/
|
||||
end
|
||||
|
||||
def test_autologin
|
||||
Setting.autologin = "7"
|
||||
Token.delete_all
|
||||
post :login, :username => 'admin', :password => 'admin', :autologin => 1
|
||||
assert_redirected_to 'my/page'
|
||||
token = Token.find :first
|
||||
assert_not_nil token
|
||||
assert_equal User.find_by_login('admin'), token.user
|
||||
assert_equal 'autologin', token.action
|
||||
end
|
||||
|
||||
def test_logout
|
||||
@request.session[:user_id] = 2
|
||||
get :logout
|
||||
assert_redirected_to ''
|
||||
assert_nil @request.session[:user_id]
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,75 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'admin_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class AdminController; def rescue_action(e) raise e end; end
|
||||
|
||||
class AdminControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :users, :roles
|
||||
|
||||
def setup
|
||||
@controller = AdminController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
User.current = nil
|
||||
@request.session[:user_id] = 1 # admin
|
||||
end
|
||||
|
||||
def test_index
|
||||
get :index
|
||||
assert_no_tag :tag => 'div',
|
||||
:attributes => { :class => /nodata/ }
|
||||
end
|
||||
|
||||
def test_index_with_no_configuration_data
|
||||
delete_configuration_data
|
||||
get :index
|
||||
assert_tag :tag => 'div',
|
||||
:attributes => { :class => /nodata/ }
|
||||
end
|
||||
|
||||
def test_load_default_configuration_data
|
||||
delete_configuration_data
|
||||
post :default_configuration, :lang => 'fr'
|
||||
assert IssueStatus.find_by_name('Nouveau')
|
||||
end
|
||||
|
||||
def test_test_email
|
||||
get :test_email
|
||||
assert_redirected_to 'settings/edit'
|
||||
mail = ActionMailer::Base.deliveries.last
|
||||
assert_kind_of TMail::Mail, mail
|
||||
user = User.find(1)
|
||||
assert_equal [user.mail], mail.bcc
|
||||
end
|
||||
|
||||
def test_info
|
||||
get :info
|
||||
assert_response :success
|
||||
assert_template 'info'
|
||||
end
|
||||
|
||||
def delete_configuration_data
|
||||
Role.delete_all('builtin = 0')
|
||||
Tracker.delete_all
|
||||
IssueStatus.delete_all
|
||||
Enumeration.delete_all
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,40 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'application'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class ApplicationController; def rescue_action(e) raise e end; end
|
||||
|
||||
class ApplicationControllerTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@controller = ApplicationController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
end
|
||||
|
||||
# check that all language files are valid
|
||||
def test_localization
|
||||
lang_files_count = Dir["#{RAILS_ROOT}/lang/*.yml"].size
|
||||
assert_equal lang_files_count, GLoc.valid_languages.size
|
||||
GLoc.valid_languages.each do |lang|
|
||||
assert set_language_if_valid(lang)
|
||||
end
|
||||
set_language_if_valid('en')
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,50 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'boards_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class BoardsController; def rescue_action(e) raise e end; end
|
||||
|
||||
class BoardsControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :users, :members, :roles, :boards, :messages, :enabled_modules
|
||||
|
||||
def setup
|
||||
@controller = BoardsController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_index
|
||||
get :index, :project_id => 1
|
||||
assert_response :success
|
||||
assert_template 'index'
|
||||
assert_not_nil assigns(:boards)
|
||||
assert_not_nil assigns(:project)
|
||||
end
|
||||
|
||||
def test_show
|
||||
get :show, :project_id => 1, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'show'
|
||||
assert_not_nil assigns(:board)
|
||||
assert_not_nil assigns(:project)
|
||||
assert_not_nil assigns(:topics)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,64 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'documents_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class DocumentsController; def rescue_action(e) raise e end; end
|
||||
|
||||
class DocumentsControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :users, :roles, :members, :enabled_modules, :documents, :enumerations
|
||||
|
||||
def setup
|
||||
@controller = DocumentsController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_index
|
||||
get :index, :project_id => 'ecookbook'
|
||||
assert_response :success
|
||||
assert_template 'index'
|
||||
assert_not_nil assigns(:grouped)
|
||||
end
|
||||
|
||||
def test_new_with_one_attachment
|
||||
@request.session[:user_id] = 2
|
||||
post :new, :project_id => 'ecookbook',
|
||||
:document => { :title => 'DocumentsControllerTest#test_post_new',
|
||||
:description => 'This is a new document',
|
||||
:category_id => 2},
|
||||
:attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}}
|
||||
|
||||
assert_redirected_to 'projects/ecookbook/documents'
|
||||
|
||||
document = Document.find_by_title('DocumentsControllerTest#test_post_new')
|
||||
assert_not_nil document
|
||||
assert_equal Enumeration.find(2), document.category
|
||||
assert_equal 1, document.attachments.size
|
||||
assert_equal 'testfile.txt', document.attachments.first.filename
|
||||
end
|
||||
|
||||
def test_destroy
|
||||
@request.session[:user_id] = 2
|
||||
post :destroy, :id => 1
|
||||
assert_redirected_to 'projects/ecookbook/documents'
|
||||
assert_nil Document.find_by_id(1)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,507 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'issues_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class IssuesController; def rescue_action(e) raise e end; end
|
||||
|
||||
class IssuesControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects,
|
||||
:users,
|
||||
:roles,
|
||||
:members,
|
||||
:issues,
|
||||
:issue_statuses,
|
||||
:trackers,
|
||||
:projects_trackers,
|
||||
:issue_categories,
|
||||
:enabled_modules,
|
||||
:enumerations,
|
||||
:attachments,
|
||||
:workflows,
|
||||
:custom_fields,
|
||||
:custom_values,
|
||||
:custom_fields_trackers,
|
||||
:time_entries
|
||||
|
||||
def setup
|
||||
@controller = IssuesController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_index
|
||||
get :index
|
||||
assert_response :success
|
||||
assert_template 'index.rhtml'
|
||||
assert_not_nil assigns(:issues)
|
||||
assert_nil assigns(:project)
|
||||
end
|
||||
|
||||
def test_index_with_project
|
||||
get :index, :project_id => 1
|
||||
assert_response :success
|
||||
assert_template 'index.rhtml'
|
||||
assert_not_nil assigns(:issues)
|
||||
end
|
||||
|
||||
def test_index_with_project_and_filter
|
||||
get :index, :project_id => 1, :set_filter => 1
|
||||
assert_response :success
|
||||
assert_template 'index.rhtml'
|
||||
assert_not_nil assigns(:issues)
|
||||
end
|
||||
|
||||
def test_index_csv_with_project
|
||||
get :index, :format => 'csv'
|
||||
assert_response :success
|
||||
assert_not_nil assigns(:issues)
|
||||
assert_equal 'text/csv', @response.content_type
|
||||
|
||||
get :index, :project_id => 1, :format => 'csv'
|
||||
assert_response :success
|
||||
assert_not_nil assigns(:issues)
|
||||
assert_equal 'text/csv', @response.content_type
|
||||
end
|
||||
|
||||
def test_index_pdf
|
||||
get :index, :format => 'pdf'
|
||||
assert_response :success
|
||||
assert_not_nil assigns(:issues)
|
||||
assert_equal 'application/pdf', @response.content_type
|
||||
|
||||
get :index, :project_id => 1, :format => 'pdf'
|
||||
assert_response :success
|
||||
assert_not_nil assigns(:issues)
|
||||
assert_equal 'application/pdf', @response.content_type
|
||||
end
|
||||
|
||||
def test_changes
|
||||
get :changes, :project_id => 1
|
||||
assert_response :success
|
||||
assert_not_nil assigns(:journals)
|
||||
assert_equal 'application/atom+xml', @response.content_type
|
||||
end
|
||||
|
||||
def test_show_by_anonymous
|
||||
get :show, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'show.rhtml'
|
||||
assert_not_nil assigns(:issue)
|
||||
assert_equal Issue.find(1), assigns(:issue)
|
||||
|
||||
# anonymous role is allowed to add a note
|
||||
assert_tag :tag => 'form',
|
||||
:descendant => { :tag => 'fieldset',
|
||||
:child => { :tag => 'legend',
|
||||
:content => /Notes/ } }
|
||||
end
|
||||
|
||||
def test_show_by_manager
|
||||
@request.session[:user_id] = 2
|
||||
get :show, :id => 1
|
||||
assert_response :success
|
||||
|
||||
assert_tag :tag => 'form',
|
||||
:descendant => { :tag => 'fieldset',
|
||||
:child => { :tag => 'legend',
|
||||
:content => /Change properties/ } },
|
||||
:descendant => { :tag => 'fieldset',
|
||||
:child => { :tag => 'legend',
|
||||
:content => /Log time/ } },
|
||||
:descendant => { :tag => 'fieldset',
|
||||
:child => { :tag => 'legend',
|
||||
:content => /Notes/ } }
|
||||
end
|
||||
|
||||
def test_get_new
|
||||
@request.session[:user_id] = 2
|
||||
get :new, :project_id => 1, :tracker_id => 1
|
||||
assert_response :success
|
||||
assert_template 'new'
|
||||
|
||||
assert_tag :tag => 'input', :attributes => { :name => 'custom_fields[2]',
|
||||
:value => 'Default string' }
|
||||
end
|
||||
|
||||
def test_get_new_without_tracker_id
|
||||
@request.session[:user_id] = 2
|
||||
get :new, :project_id => 1
|
||||
assert_response :success
|
||||
assert_template 'new'
|
||||
|
||||
issue = assigns(:issue)
|
||||
assert_not_nil issue
|
||||
assert_equal Project.find(1).trackers.first, issue.tracker
|
||||
end
|
||||
|
||||
def test_update_new_form
|
||||
@request.session[:user_id] = 2
|
||||
xhr :post, :new, :project_id => 1,
|
||||
:issue => {:tracker_id => 2,
|
||||
:subject => 'This is the test_new issue',
|
||||
:description => 'This is the description',
|
||||
:priority_id => 5}
|
||||
assert_response :success
|
||||
assert_template 'new'
|
||||
end
|
||||
|
||||
def test_post_new
|
||||
@request.session[:user_id] = 2
|
||||
post :new, :project_id => 1,
|
||||
:issue => {:tracker_id => 1,
|
||||
:subject => 'This is the test_new issue',
|
||||
:description => 'This is the description',
|
||||
:priority_id => 5},
|
||||
:custom_fields => {'2' => 'Value for field 2'}
|
||||
assert_redirected_to 'issues/show'
|
||||
|
||||
issue = Issue.find_by_subject('This is the test_new issue')
|
||||
assert_not_nil issue
|
||||
assert_equal 2, issue.author_id
|
||||
v = issue.custom_values.find_by_custom_field_id(2)
|
||||
assert_not_nil v
|
||||
assert_equal 'Value for field 2', v.value
|
||||
end
|
||||
|
||||
def test_post_new_without_custom_fields_param
|
||||
@request.session[:user_id] = 2
|
||||
post :new, :project_id => 1,
|
||||
:issue => {:tracker_id => 1,
|
||||
:subject => 'This is the test_new issue',
|
||||
:description => 'This is the description',
|
||||
:priority_id => 5}
|
||||
assert_redirected_to 'issues/show'
|
||||
end
|
||||
|
||||
def test_copy_issue
|
||||
@request.session[:user_id] = 2
|
||||
get :new, :project_id => 1, :copy_from => 1
|
||||
assert_template 'new'
|
||||
assert_not_nil assigns(:issue)
|
||||
orig = Issue.find(1)
|
||||
assert_equal orig.subject, assigns(:issue).subject
|
||||
end
|
||||
|
||||
def test_get_edit
|
||||
@request.session[:user_id] = 2
|
||||
get :edit, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'edit'
|
||||
assert_not_nil assigns(:issue)
|
||||
assert_equal Issue.find(1), assigns(:issue)
|
||||
end
|
||||
|
||||
def test_get_edit_with_params
|
||||
@request.session[:user_id] = 2
|
||||
get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }
|
||||
assert_response :success
|
||||
assert_template 'edit'
|
||||
|
||||
issue = assigns(:issue)
|
||||
assert_not_nil issue
|
||||
|
||||
assert_equal 5, issue.status_id
|
||||
assert_tag :select, :attributes => { :name => 'issue[status_id]' },
|
||||
:child => { :tag => 'option',
|
||||
:content => 'Closed',
|
||||
:attributes => { :selected => 'selected' } }
|
||||
|
||||
assert_equal 7, issue.priority_id
|
||||
assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
|
||||
:child => { :tag => 'option',
|
||||
:content => 'Urgent',
|
||||
:attributes => { :selected => 'selected' } }
|
||||
end
|
||||
|
||||
def test_post_edit
|
||||
@request.session[:user_id] = 2
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
issue = Issue.find(1)
|
||||
old_subject = issue.subject
|
||||
new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
|
||||
|
||||
post :edit, :id => 1, :issue => {:subject => new_subject}
|
||||
assert_redirected_to 'issues/show/1'
|
||||
issue.reload
|
||||
assert_equal new_subject, issue.subject
|
||||
|
||||
mail = ActionMailer::Base.deliveries.last
|
||||
assert_kind_of TMail::Mail, mail
|
||||
assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
|
||||
assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
|
||||
end
|
||||
|
||||
def test_post_edit_with_status_and_assignee_change
|
||||
issue = Issue.find(1)
|
||||
assert_equal 1, issue.status_id
|
||||
@request.session[:user_id] = 2
|
||||
post :edit,
|
||||
:id => 1,
|
||||
:issue => { :status_id => 2, :assigned_to_id => 3 },
|
||||
:notes => 'Assigned to dlopper'
|
||||
assert_redirected_to 'issues/show/1'
|
||||
issue.reload
|
||||
assert_equal 2, issue.status_id
|
||||
j = issue.journals.find(:first, :order => 'id DESC')
|
||||
assert_equal 'Assigned to dlopper', j.notes
|
||||
assert_equal 2, j.details.size
|
||||
|
||||
mail = ActionMailer::Base.deliveries.last
|
||||
assert mail.body.include?("Status changed from New to Assigned")
|
||||
end
|
||||
|
||||
def test_post_edit_with_note_only
|
||||
notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
|
||||
# anonymous user
|
||||
post :edit,
|
||||
:id => 1,
|
||||
:notes => notes
|
||||
assert_redirected_to 'issues/show/1'
|
||||
j = Issue.find(1).journals.find(:first, :order => 'id DESC')
|
||||
assert_equal notes, j.notes
|
||||
assert_equal 0, j.details.size
|
||||
assert_equal User.anonymous, j.user
|
||||
|
||||
mail = ActionMailer::Base.deliveries.last
|
||||
assert mail.body.include?(notes)
|
||||
end
|
||||
|
||||
def test_post_edit_with_note_and_spent_time
|
||||
@request.session[:user_id] = 2
|
||||
spent_hours_before = Issue.find(1).spent_hours
|
||||
post :edit,
|
||||
:id => 1,
|
||||
:notes => '2.5 hours added',
|
||||
:time_entry => { :hours => '2.5', :comments => '', :activity_id => Enumeration.get_values('ACTI').first }
|
||||
assert_redirected_to 'issues/show/1'
|
||||
|
||||
issue = Issue.find(1)
|
||||
|
||||
j = issue.journals.find(:first, :order => 'id DESC')
|
||||
assert_equal '2.5 hours added', j.notes
|
||||
assert_equal 0, j.details.size
|
||||
|
||||
t = issue.time_entries.find(:first, :order => 'id DESC')
|
||||
assert_not_nil t
|
||||
assert_equal 2.5, t.hours
|
||||
assert_equal spent_hours_before + 2.5, issue.spent_hours
|
||||
end
|
||||
|
||||
def test_post_edit_with_attachment_only
|
||||
# anonymous user
|
||||
post :edit,
|
||||
:id => 1,
|
||||
:notes => '',
|
||||
:attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}}
|
||||
assert_redirected_to 'issues/show/1'
|
||||
j = Issue.find(1).journals.find(:first, :order => 'id DESC')
|
||||
assert j.notes.blank?
|
||||
assert_equal 1, j.details.size
|
||||
assert_equal 'testfile.txt', j.details.first.value
|
||||
assert_equal User.anonymous, j.user
|
||||
|
||||
mail = ActionMailer::Base.deliveries.last
|
||||
assert mail.body.include?('testfile.txt')
|
||||
end
|
||||
|
||||
def test_post_edit_with_no_change
|
||||
issue = Issue.find(1)
|
||||
issue.journals.clear
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
post :edit,
|
||||
:id => 1,
|
||||
:notes => ''
|
||||
assert_redirected_to 'issues/show/1'
|
||||
|
||||
issue.reload
|
||||
assert issue.journals.empty?
|
||||
# No email should be sent
|
||||
assert ActionMailer::Base.deliveries.empty?
|
||||
end
|
||||
|
||||
def test_bulk_edit
|
||||
@request.session[:user_id] = 2
|
||||
# update issues priority
|
||||
post :bulk_edit, :ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => ''
|
||||
assert_response 302
|
||||
# check that the issues were updated
|
||||
assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
|
||||
assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes
|
||||
end
|
||||
|
||||
def test_bulk_unassign
|
||||
assert_not_nil Issue.find(2).assigned_to
|
||||
@request.session[:user_id] = 2
|
||||
# unassign issues
|
||||
post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :assigned_to_id => 'none'
|
||||
assert_response 302
|
||||
# check that the issues were updated
|
||||
assert_nil Issue.find(2).assigned_to
|
||||
end
|
||||
|
||||
def test_move_one_issue_to_another_project
|
||||
@request.session[:user_id] = 1
|
||||
post :move, :id => 1, :new_project_id => 2
|
||||
assert_redirected_to 'projects/ecookbook/issues'
|
||||
assert_equal 2, Issue.find(1).project_id
|
||||
end
|
||||
|
||||
def test_bulk_move_to_another_project
|
||||
@request.session[:user_id] = 1
|
||||
post :move, :ids => [1, 2], :new_project_id => 2
|
||||
assert_redirected_to 'projects/ecookbook/issues'
|
||||
# Issues moved to project 2
|
||||
assert_equal 2, Issue.find(1).project_id
|
||||
assert_equal 2, Issue.find(2).project_id
|
||||
# No tracker change
|
||||
assert_equal 1, Issue.find(1).tracker_id
|
||||
assert_equal 2, Issue.find(2).tracker_id
|
||||
end
|
||||
|
||||
def test_bulk_move_to_another_tracker
|
||||
@request.session[:user_id] = 1
|
||||
post :move, :ids => [1, 2], :new_tracker_id => 2
|
||||
assert_redirected_to 'projects/ecookbook/issues'
|
||||
assert_equal 2, Issue.find(1).tracker_id
|
||||
assert_equal 2, Issue.find(2).tracker_id
|
||||
end
|
||||
|
||||
def test_context_menu_one_issue
|
||||
@request.session[:user_id] = 2
|
||||
get :context_menu, :ids => [1]
|
||||
assert_response :success
|
||||
assert_template 'context_menu'
|
||||
assert_tag :tag => 'a', :content => 'Edit',
|
||||
:attributes => { :href => '/issues/edit/1',
|
||||
:class => 'icon-edit' }
|
||||
assert_tag :tag => 'a', :content => 'Closed',
|
||||
:attributes => { :href => '/issues/edit/1?issue%5Bstatus_id%5D=5',
|
||||
:class => '' }
|
||||
assert_tag :tag => 'a', :content => 'Immediate',
|
||||
:attributes => { :href => '/issues/edit/1?issue%5Bpriority_id%5D=8',
|
||||
:class => '' }
|
||||
assert_tag :tag => 'a', :content => 'Dave Lopper',
|
||||
:attributes => { :href => '/issues/edit/1?issue%5Bassigned_to_id%5D=3',
|
||||
:class => '' }
|
||||
assert_tag :tag => 'a', :content => 'Copy',
|
||||
:attributes => { :href => '/projects/ecookbook/issues/new?copy_from=1',
|
||||
:class => 'icon-copy' }
|
||||
assert_tag :tag => 'a', :content => 'Move',
|
||||
:attributes => { :href => '/issues/move?ids%5B%5D=1',
|
||||
:class => 'icon-move' }
|
||||
assert_tag :tag => 'a', :content => 'Delete',
|
||||
:attributes => { :href => '/issues/destroy?ids%5B%5D=1',
|
||||
:class => 'icon-del' }
|
||||
end
|
||||
|
||||
def test_context_menu_one_issue_by_anonymous
|
||||
get :context_menu, :ids => [1]
|
||||
assert_response :success
|
||||
assert_template 'context_menu'
|
||||
assert_tag :tag => 'a', :content => 'Delete',
|
||||
:attributes => { :href => '#',
|
||||
:class => 'icon-del disabled' }
|
||||
end
|
||||
|
||||
def test_context_menu_multiple_issues_of_same_project
|
||||
@request.session[:user_id] = 2
|
||||
get :context_menu, :ids => [1, 2]
|
||||
assert_response :success
|
||||
assert_template 'context_menu'
|
||||
assert_tag :tag => 'a', :content => 'Edit',
|
||||
:attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&ids%5B%5D=2',
|
||||
:class => 'icon-edit' }
|
||||
assert_tag :tag => 'a', :content => 'Move',
|
||||
:attributes => { :href => '/issues/move?ids%5B%5D=1&ids%5B%5D=2',
|
||||
:class => 'icon-move' }
|
||||
assert_tag :tag => 'a', :content => 'Delete',
|
||||
:attributes => { :href => '/issues/destroy?ids%5B%5D=1&ids%5B%5D=2',
|
||||
:class => 'icon-del' }
|
||||
end
|
||||
|
||||
def test_context_menu_multiple_issues_of_different_project
|
||||
@request.session[:user_id] = 2
|
||||
get :context_menu, :ids => [1, 2, 4]
|
||||
assert_response :success
|
||||
assert_template 'context_menu'
|
||||
assert_tag :tag => 'a', :content => 'Delete',
|
||||
:attributes => { :href => '#',
|
||||
:class => 'icon-del disabled' }
|
||||
end
|
||||
|
||||
def test_destroy_issue_with_no_time_entries
|
||||
assert_nil TimeEntry.find_by_issue_id(2)
|
||||
@request.session[:user_id] = 2
|
||||
post :destroy, :id => 2
|
||||
assert_redirected_to 'projects/ecookbook/issues'
|
||||
assert_nil Issue.find_by_id(2)
|
||||
end
|
||||
|
||||
def test_destroy_issues_with_time_entries
|
||||
@request.session[:user_id] = 2
|
||||
post :destroy, :ids => [1, 3]
|
||||
assert_response :success
|
||||
assert_template 'destroy'
|
||||
assert_not_nil assigns(:hours)
|
||||
assert Issue.find_by_id(1) && Issue.find_by_id(3)
|
||||
end
|
||||
|
||||
def test_destroy_issues_and_destroy_time_entries
|
||||
@request.session[:user_id] = 2
|
||||
post :destroy, :ids => [1, 3], :todo => 'destroy'
|
||||
assert_redirected_to 'projects/ecookbook/issues'
|
||||
assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
|
||||
assert_nil TimeEntry.find_by_id([1, 2])
|
||||
end
|
||||
|
||||
def test_destroy_issues_and_assign_time_entries_to_project
|
||||
@request.session[:user_id] = 2
|
||||
post :destroy, :ids => [1, 3], :todo => 'nullify'
|
||||
assert_redirected_to 'projects/ecookbook/issues'
|
||||
assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
|
||||
assert_nil TimeEntry.find(1).issue_id
|
||||
assert_nil TimeEntry.find(2).issue_id
|
||||
end
|
||||
|
||||
def test_destroy_issues_and_reassign_time_entries_to_another_issue
|
||||
@request.session[:user_id] = 2
|
||||
post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
|
||||
assert_redirected_to 'projects/ecookbook/issues'
|
||||
assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
|
||||
assert_equal 2, TimeEntry.find(1).issue_id
|
||||
assert_equal 2, TimeEntry.find(2).issue_id
|
||||
end
|
||||
|
||||
def test_destroy_attachment
|
||||
issue = Issue.find(3)
|
||||
a = issue.attachments.size
|
||||
@request.session[:user_id] = 2
|
||||
post :destroy_attachment, :id => 3, :attachment_id => 1
|
||||
assert_redirected_to 'issues/show/3'
|
||||
assert_nil Attachment.find_by_id(1)
|
||||
issue.reload
|
||||
assert_equal((a-1), issue.attachments.size)
|
||||
j = issue.journals.find(:first, :order => 'created_on DESC')
|
||||
assert_equal 'attachment', j.details.first.property
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,59 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'journals_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class JournalsController; def rescue_action(e) raise e end; end
|
||||
|
||||
class JournalsControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :users, :members, :roles, :issues, :journals, :journal_details, :enabled_modules
|
||||
|
||||
def setup
|
||||
@controller = JournalsController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_get_edit
|
||||
@request.session[:user_id] = 1
|
||||
xhr :get, :edit, :id => 2
|
||||
assert_response :success
|
||||
assert_select_rjs :insert, :after, 'journal-2-notes' do
|
||||
assert_select 'form[id=journal-2-form]'
|
||||
assert_select 'textarea'
|
||||
end
|
||||
end
|
||||
|
||||
def test_post_edit
|
||||
@request.session[:user_id] = 1
|
||||
xhr :post, :edit, :id => 2, :notes => 'Updated notes'
|
||||
assert_response :success
|
||||
assert_select_rjs :replace, 'journal-2-notes'
|
||||
assert_equal 'Updated notes', Journal.find(2).notes
|
||||
end
|
||||
|
||||
def test_post_edit_with_empty_notes
|
||||
@request.session[:user_id] = 1
|
||||
xhr :post, :edit, :id => 2, :notes => ''
|
||||
assert_response :success
|
||||
assert_select_rjs :remove, 'change-2'
|
||||
assert_nil Journal.find_by_id(2)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,111 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'messages_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class MessagesController; def rescue_action(e) raise e end; end
|
||||
|
||||
class MessagesControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :users, :members, :roles, :boards, :messages, :enabled_modules
|
||||
|
||||
def setup
|
||||
@controller = MessagesController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_show
|
||||
get :show, :board_id => 1, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'show'
|
||||
assert_not_nil assigns(:board)
|
||||
assert_not_nil assigns(:project)
|
||||
assert_not_nil assigns(:topic)
|
||||
end
|
||||
|
||||
def test_show_message_not_found
|
||||
get :show, :board_id => 1, :id => 99999
|
||||
assert_response 404
|
||||
end
|
||||
|
||||
def test_get_new
|
||||
@request.session[:user_id] = 2
|
||||
get :new, :board_id => 1
|
||||
assert_response :success
|
||||
assert_template 'new'
|
||||
end
|
||||
|
||||
def test_post_new
|
||||
@request.session[:user_id] = 2
|
||||
ActionMailer::Base.deliveries.clear
|
||||
Setting.notified_events << 'message_posted'
|
||||
|
||||
post :new, :board_id => 1,
|
||||
:message => { :subject => 'Test created message',
|
||||
:content => 'Message body'}
|
||||
assert_redirected_to 'messages/show'
|
||||
message = Message.find_by_subject('Test created message')
|
||||
assert_not_nil message
|
||||
assert_equal 'Message body', message.content
|
||||
assert_equal 2, message.author_id
|
||||
assert_equal 1, message.board_id
|
||||
|
||||
mail = ActionMailer::Base.deliveries.last
|
||||
assert_kind_of TMail::Mail, mail
|
||||
assert_equal "[#{message.board.project.name} - #{message.board.name}] Test created message", mail.subject
|
||||
assert mail.body.include?('Message body')
|
||||
# author
|
||||
assert mail.bcc.include?('jsmith@somenet.foo')
|
||||
# project member
|
||||
assert mail.bcc.include?('dlopper@somenet.foo')
|
||||
end
|
||||
|
||||
def test_get_edit
|
||||
@request.session[:user_id] = 2
|
||||
get :edit, :board_id => 1, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'edit'
|
||||
end
|
||||
|
||||
def test_post_edit
|
||||
@request.session[:user_id] = 2
|
||||
post :edit, :board_id => 1, :id => 1,
|
||||
:message => { :subject => 'New subject',
|
||||
:content => 'New body'}
|
||||
assert_redirected_to 'messages/show'
|
||||
message = Message.find(1)
|
||||
assert_equal 'New subject', message.subject
|
||||
assert_equal 'New body', message.content
|
||||
end
|
||||
|
||||
def test_reply
|
||||
@request.session[:user_id] = 2
|
||||
post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' }
|
||||
assert_redirected_to 'messages/show'
|
||||
assert Message.find_by_subject('Test reply')
|
||||
end
|
||||
|
||||
def test_destroy_topic
|
||||
@request.session[:user_id] = 2
|
||||
post :destroy, :board_id => 1, :id => 1
|
||||
assert_redirected_to 'boards/show'
|
||||
assert_nil Message.find_by_id(1)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,91 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'my_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class MyController; def rescue_action(e) raise e end; end
|
||||
|
||||
class MyControllerTest < Test::Unit::TestCase
|
||||
fixtures :users, :issues, :issue_statuses, :trackers, :enumerations
|
||||
|
||||
def setup
|
||||
@controller = MyController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@request.session[:user_id] = 2
|
||||
@response = ActionController::TestResponse.new
|
||||
end
|
||||
|
||||
def test_index
|
||||
get :index
|
||||
assert_response :success
|
||||
assert_template 'page'
|
||||
end
|
||||
|
||||
def test_page
|
||||
get :page
|
||||
assert_response :success
|
||||
assert_template 'page'
|
||||
end
|
||||
|
||||
def test_get_account
|
||||
get :account
|
||||
assert_response :success
|
||||
assert_template 'account'
|
||||
assert_equal User.find(2), assigns(:user)
|
||||
end
|
||||
|
||||
def test_update_account
|
||||
post :account, :user => {:firstname => "Joe", :login => "root", :admin => 1}
|
||||
assert_redirected_to 'my/account'
|
||||
user = User.find(2)
|
||||
assert_equal user, assigns(:user)
|
||||
assert_equal "Joe", user.firstname
|
||||
assert_equal "jsmith", user.login
|
||||
assert !user.admin?
|
||||
end
|
||||
|
||||
def test_change_password
|
||||
get :password
|
||||
assert_response :success
|
||||
assert_template 'password'
|
||||
|
||||
# non matching password confirmation
|
||||
post :password, :password => 'jsmith',
|
||||
:new_password => 'hello',
|
||||
:new_password_confirmation => 'hello2'
|
||||
assert_response :success
|
||||
assert_template 'password'
|
||||
assert_tag :tag => "div", :attributes => { :class => "errorExplanation" }
|
||||
|
||||
# wrong password
|
||||
post :password, :password => 'wrongpassword',
|
||||
:new_password => 'hello',
|
||||
:new_password_confirmation => 'hello'
|
||||
assert_response :success
|
||||
assert_template 'password'
|
||||
assert_equal 'Wrong password', flash[:error]
|
||||
|
||||
# good password
|
||||
post :password, :password => 'jsmith',
|
||||
:new_password => 'hello',
|
||||
:new_password_confirmation => 'hello'
|
||||
assert_redirected_to 'my/account'
|
||||
assert User.try_to_login('jsmith', 'hello')
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,147 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'news_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class NewsController; def rescue_action(e) raise e end; end
|
||||
|
||||
class NewsControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :users, :roles, :members, :enabled_modules, :news, :comments
|
||||
|
||||
def setup
|
||||
@controller = NewsController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_index
|
||||
get :index
|
||||
assert_response :success
|
||||
assert_template 'index'
|
||||
assert_not_nil assigns(:newss)
|
||||
assert_nil assigns(:project)
|
||||
end
|
||||
|
||||
def test_index_with_project
|
||||
get :index, :project_id => 1
|
||||
assert_response :success
|
||||
assert_template 'index'
|
||||
assert_not_nil assigns(:newss)
|
||||
end
|
||||
|
||||
def test_show
|
||||
get :show, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'show'
|
||||
assert_tag :tag => 'h2', :content => /eCookbook first release/
|
||||
end
|
||||
|
||||
def test_show_not_found
|
||||
get :show, :id => 999
|
||||
assert_response 404
|
||||
end
|
||||
|
||||
def test_get_new
|
||||
@request.session[:user_id] = 2
|
||||
get :new, :project_id => 1
|
||||
assert_response :success
|
||||
assert_template 'new'
|
||||
end
|
||||
|
||||
def test_post_new
|
||||
@request.session[:user_id] = 2
|
||||
post :new, :project_id => 1, :news => { :title => 'NewsControllerTest',
|
||||
:description => 'This is the description',
|
||||
:summary => '' }
|
||||
assert_redirected_to 'projects/ecookbook/news'
|
||||
|
||||
news = News.find_by_title('NewsControllerTest')
|
||||
assert_not_nil news
|
||||
assert_equal 'This is the description', news.description
|
||||
assert_equal User.find(2), news.author
|
||||
assert_equal Project.find(1), news.project
|
||||
end
|
||||
|
||||
def test_get_edit
|
||||
@request.session[:user_id] = 2
|
||||
get :edit, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'edit'
|
||||
end
|
||||
|
||||
def test_post_edit
|
||||
@request.session[:user_id] = 2
|
||||
post :edit, :id => 1, :news => { :description => 'Description changed by test_post_edit' }
|
||||
assert_redirected_to 'news/show/1'
|
||||
news = News.find(1)
|
||||
assert_equal 'Description changed by test_post_edit', news.description
|
||||
end
|
||||
|
||||
def test_post_new_with_validation_failure
|
||||
@request.session[:user_id] = 2
|
||||
post :new, :project_id => 1, :news => { :title => '',
|
||||
:description => 'This is the description',
|
||||
:summary => '' }
|
||||
assert_response :success
|
||||
assert_template 'new'
|
||||
assert_not_nil assigns(:news)
|
||||
assert assigns(:news).new_record?
|
||||
assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' },
|
||||
:content => /1 error/
|
||||
end
|
||||
|
||||
def test_add_comment
|
||||
@request.session[:user_id] = 2
|
||||
post :add_comment, :id => 1, :comment => { :comments => 'This is a NewsControllerTest comment' }
|
||||
assert_redirected_to 'news/show/1'
|
||||
|
||||
comment = News.find(1).comments.find(:first, :order => 'created_on DESC')
|
||||
assert_not_nil comment
|
||||
assert_equal 'This is a NewsControllerTest comment', comment.comments
|
||||
assert_equal User.find(2), comment.author
|
||||
end
|
||||
|
||||
def test_destroy_comment
|
||||
comments_count = News.find(1).comments.size
|
||||
@request.session[:user_id] = 2
|
||||
post :destroy_comment, :id => 1, :comment_id => 2
|
||||
assert_redirected_to 'news/show/1'
|
||||
assert_nil Comment.find_by_id(2)
|
||||
assert_equal comments_count - 1, News.find(1).comments.size
|
||||
end
|
||||
|
||||
def test_destroy
|
||||
@request.session[:user_id] = 2
|
||||
post :destroy, :id => 1
|
||||
assert_redirected_to 'projects/ecookbook/news'
|
||||
assert_nil News.find_by_id(1)
|
||||
end
|
||||
|
||||
def test_preview
|
||||
get :preview, :project_id => 1,
|
||||
:news => {:title => '',
|
||||
:description => 'News description',
|
||||
:summary => ''}
|
||||
assert_response :success
|
||||
assert_template 'common/_preview'
|
||||
assert_tag :tag => 'fieldset', :attributes => { :class => 'preview' },
|
||||
:content => /News description/
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,268 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'projects_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class ProjectsController; def rescue_action(e) raise e end; end
|
||||
|
||||
class ProjectsControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :versions, :users, :roles, :members, :issues, :journals, :journal_details,
|
||||
:trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages
|
||||
|
||||
def setup
|
||||
@controller = ProjectsController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
end
|
||||
|
||||
def test_index
|
||||
get :index
|
||||
assert_response :success
|
||||
assert_template 'list'
|
||||
end
|
||||
|
||||
def test_list
|
||||
get :list
|
||||
assert_response :success
|
||||
assert_template 'list'
|
||||
assert_not_nil assigns(:project_tree)
|
||||
# Root project as hash key
|
||||
assert assigns(:project_tree).has_key?(Project.find(1))
|
||||
# Subproject in corresponding value
|
||||
assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3))
|
||||
end
|
||||
|
||||
def test_show_by_id
|
||||
get :show, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'show'
|
||||
assert_not_nil assigns(:project)
|
||||
end
|
||||
|
||||
def test_show_by_identifier
|
||||
get :show, :id => 'ecookbook'
|
||||
assert_response :success
|
||||
assert_template 'show'
|
||||
assert_not_nil assigns(:project)
|
||||
assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
|
||||
end
|
||||
|
||||
def test_settings
|
||||
@request.session[:user_id] = 2 # manager
|
||||
get :settings, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'settings'
|
||||
end
|
||||
|
||||
def test_edit
|
||||
@request.session[:user_id] = 2 # manager
|
||||
post :edit, :id => 1, :project => {:name => 'Test changed name',
|
||||
:custom_field_ids => ['']}
|
||||
assert_redirected_to 'projects/settings/ecookbook'
|
||||
project = Project.find(1)
|
||||
assert_equal 'Test changed name', project.name
|
||||
end
|
||||
|
||||
def test_get_destroy
|
||||
@request.session[:user_id] = 1 # admin
|
||||
get :destroy, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'destroy'
|
||||
assert_not_nil Project.find_by_id(1)
|
||||
end
|
||||
|
||||
def test_post_destroy
|
||||
@request.session[:user_id] = 1 # admin
|
||||
post :destroy, :id => 1, :confirm => 1
|
||||
assert_redirected_to 'admin/projects'
|
||||
assert_nil Project.find_by_id(1)
|
||||
end
|
||||
|
||||
def test_list_files
|
||||
get :list_files, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'list_files'
|
||||
assert_not_nil assigns(:versions)
|
||||
end
|
||||
|
||||
def test_changelog
|
||||
get :changelog, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'changelog'
|
||||
assert_not_nil assigns(:versions)
|
||||
end
|
||||
|
||||
def test_roadmap
|
||||
get :roadmap, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'roadmap'
|
||||
assert_not_nil assigns(:versions)
|
||||
# Version with no date set appears
|
||||
assert assigns(:versions).include?(Version.find(3))
|
||||
# Completed version doesn't appear
|
||||
assert !assigns(:versions).include?(Version.find(1))
|
||||
end
|
||||
|
||||
def test_roadmap_with_completed_versions
|
||||
get :roadmap, :id => 1, :completed => 1
|
||||
assert_response :success
|
||||
assert_template 'roadmap'
|
||||
assert_not_nil assigns(:versions)
|
||||
# Version with no date set appears
|
||||
assert assigns(:versions).include?(Version.find(3))
|
||||
# Completed version appears
|
||||
assert assigns(:versions).include?(Version.find(1))
|
||||
end
|
||||
|
||||
def test_project_activity
|
||||
get :activity, :id => 1, :with_subprojects => 0
|
||||
assert_response :success
|
||||
assert_template 'activity'
|
||||
assert_not_nil assigns(:events_by_day)
|
||||
assert_not_nil assigns(:events)
|
||||
|
||||
# subproject issue not included by default
|
||||
assert !assigns(:events).include?(Issue.find(5))
|
||||
|
||||
assert_tag :tag => "h3",
|
||||
:content => /#{2.days.ago.to_date.day}/,
|
||||
:sibling => { :tag => "dl",
|
||||
:child => { :tag => "dt",
|
||||
:attributes => { :class => 'issue-edit' },
|
||||
:child => { :tag => "a",
|
||||
:content => /(#{IssueStatus.find(2).name})/,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get :activity, :id => 1, :from => 3.days.ago.to_date
|
||||
assert_response :success
|
||||
assert_template 'activity'
|
||||
assert_not_nil assigns(:events_by_day)
|
||||
|
||||
assert_tag :tag => "h3",
|
||||
:content => /#{3.day.ago.to_date.day}/,
|
||||
:sibling => { :tag => "dl",
|
||||
:child => { :tag => "dt",
|
||||
:attributes => { :class => 'issue' },
|
||||
:child => { :tag => "a",
|
||||
:content => /#{Issue.find(1).subject}/,
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_activity_with_subprojects
|
||||
get :activity, :id => 1, :with_subprojects => 1
|
||||
assert_response :success
|
||||
assert_template 'activity'
|
||||
assert_not_nil assigns(:events)
|
||||
|
||||
assert assigns(:events).include?(Issue.find(1))
|
||||
assert !assigns(:events).include?(Issue.find(4))
|
||||
# subproject issue
|
||||
assert assigns(:events).include?(Issue.find(5))
|
||||
end
|
||||
|
||||
def test_global_activity_anonymous
|
||||
get :activity
|
||||
assert_response :success
|
||||
assert_template 'activity'
|
||||
assert_not_nil assigns(:events)
|
||||
|
||||
assert assigns(:events).include?(Issue.find(1))
|
||||
# Issue of a private project
|
||||
assert !assigns(:events).include?(Issue.find(4))
|
||||
end
|
||||
|
||||
def test_global_activity_logged_user
|
||||
@request.session[:user_id] = 2 # manager
|
||||
get :activity
|
||||
assert_response :success
|
||||
assert_template 'activity'
|
||||
assert_not_nil assigns(:events)
|
||||
|
||||
assert assigns(:events).include?(Issue.find(1))
|
||||
# Issue of a private project the user belongs to
|
||||
assert assigns(:events).include?(Issue.find(4))
|
||||
end
|
||||
|
||||
|
||||
def test_global_activity_with_all_types
|
||||
get :activity, :show_issues => 1, :show_news => 1, :show_files => 1, :show_documents => 1, :show_changesets => 1, :show_wiki_pages => 1, :show_messages => 1
|
||||
assert_response :success
|
||||
assert_template 'activity'
|
||||
assert_not_nil assigns(:events)
|
||||
|
||||
assert assigns(:events).include?(Issue.find(1))
|
||||
assert !assigns(:events).include?(Issue.find(4))
|
||||
assert assigns(:events).include?(Message.find(5))
|
||||
end
|
||||
|
||||
def test_calendar
|
||||
get :calendar, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'calendar'
|
||||
assert_not_nil assigns(:calendar)
|
||||
end
|
||||
|
||||
def test_calendar_with_subprojects
|
||||
get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
|
||||
assert_response :success
|
||||
assert_template 'calendar'
|
||||
assert_not_nil assigns(:calendar)
|
||||
end
|
||||
|
||||
def test_gantt
|
||||
get :gantt, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'gantt.rhtml'
|
||||
assert_not_nil assigns(:events)
|
||||
end
|
||||
|
||||
def test_gantt_with_subprojects
|
||||
get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
|
||||
assert_response :success
|
||||
assert_template 'gantt.rhtml'
|
||||
assert_not_nil assigns(:events)
|
||||
end
|
||||
|
||||
def test_gantt_export_to_pdf
|
||||
get :gantt, :id => 1, :format => 'pdf'
|
||||
assert_response :success
|
||||
assert_template 'gantt.rfpdf'
|
||||
assert_equal 'application/pdf', @response.content_type
|
||||
assert_not_nil assigns(:events)
|
||||
end
|
||||
|
||||
def test_archive
|
||||
@request.session[:user_id] = 1 # admin
|
||||
post :archive, :id => 1
|
||||
assert_redirected_to 'admin/projects'
|
||||
assert !Project.find(1).active?
|
||||
end
|
||||
|
||||
def test_unarchive
|
||||
@request.session[:user_id] = 1 # admin
|
||||
Project.find(1).archive
|
||||
post :unarchive, :id => 1
|
||||
assert_redirected_to 'admin/projects'
|
||||
assert Project.find(1).active?
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,211 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'queries_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class QueriesController; def rescue_action(e) raise e end; end
|
||||
|
||||
class QueriesControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :users, :members, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries
|
||||
|
||||
def setup
|
||||
@controller = QueriesController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_get_new_project_query
|
||||
@request.session[:user_id] = 2
|
||||
get :new, :project_id => 1
|
||||
assert_response :success
|
||||
assert_template 'new'
|
||||
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
||||
:name => 'query[is_public]',
|
||||
:checked => nil }
|
||||
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
||||
:name => 'query_is_for_all',
|
||||
:checked => nil,
|
||||
:disabled => nil }
|
||||
end
|
||||
|
||||
def test_get_new_global_query
|
||||
@request.session[:user_id] = 2
|
||||
get :new
|
||||
assert_response :success
|
||||
assert_template 'new'
|
||||
assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
||||
:name => 'query[is_public]' }
|
||||
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
||||
:name => 'query_is_for_all',
|
||||
:checked => 'checked',
|
||||
:disabled => nil }
|
||||
end
|
||||
|
||||
def test_new_project_public_query
|
||||
@request.session[:user_id] = 2
|
||||
post :new,
|
||||
:project_id => 'ecookbook',
|
||||
:confirm => '1',
|
||||
:default_columns => '1',
|
||||
:fields => ["status_id", "assigned_to_id"],
|
||||
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
|
||||
:values => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
|
||||
:query => {"name" => "test_new_project_public_query", "is_public" => "1"}
|
||||
|
||||
q = Query.find_by_name('test_new_project_public_query')
|
||||
assert_redirected_to :controller => 'issues', :action => 'index', :query_id => q
|
||||
assert q.is_public?
|
||||
assert q.has_default_columns?
|
||||
assert q.valid?
|
||||
end
|
||||
|
||||
def test_new_project_private_query
|
||||
@request.session[:user_id] = 3
|
||||
post :new,
|
||||
:project_id => 'ecookbook',
|
||||
:confirm => '1',
|
||||
:default_columns => '1',
|
||||
:fields => ["status_id", "assigned_to_id"],
|
||||
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
|
||||
:values => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
|
||||
:query => {"name" => "test_new_project_private_query", "is_public" => "1"}
|
||||
|
||||
q = Query.find_by_name('test_new_project_private_query')
|
||||
assert_redirected_to :controller => 'issues', :action => 'index', :query_id => q
|
||||
assert !q.is_public?
|
||||
assert q.has_default_columns?
|
||||
assert q.valid?
|
||||
end
|
||||
|
||||
def test_new_global_private_query_with_custom_columns
|
||||
@request.session[:user_id] = 3
|
||||
post :new,
|
||||
:confirm => '1',
|
||||
:fields => ["status_id", "assigned_to_id"],
|
||||
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
|
||||
:values => { "assigned_to_id" => ["me"], "status_id" => ["1"]},
|
||||
:query => {"name" => "test_new_global_private_query", "is_public" => "1", "column_names" => ["", "tracker", "subject", "priority", "category"]}
|
||||
|
||||
q = Query.find_by_name('test_new_global_private_query')
|
||||
assert_redirected_to :controller => 'issues', :action => 'index', :query_id => q
|
||||
assert !q.is_public?
|
||||
assert !q.has_default_columns?
|
||||
assert_equal [:tracker, :subject, :priority, :category], q.columns.collect {|c| c.name}
|
||||
assert q.valid?
|
||||
end
|
||||
|
||||
def test_get_edit_global_public_query
|
||||
@request.session[:user_id] = 1
|
||||
get :edit, :id => 4
|
||||
assert_response :success
|
||||
assert_template 'edit'
|
||||
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
||||
:name => 'query[is_public]',
|
||||
:checked => 'checked' }
|
||||
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
||||
:name => 'query_is_for_all',
|
||||
:checked => 'checked',
|
||||
:disabled => 'disabled' }
|
||||
end
|
||||
|
||||
def test_edit_global_public_query
|
||||
@request.session[:user_id] = 1
|
||||
post :edit,
|
||||
:id => 4,
|
||||
:confirm => '1',
|
||||
:default_columns => '1',
|
||||
:fields => ["status_id", "assigned_to_id"],
|
||||
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
|
||||
:values => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
|
||||
:query => {"name" => "test_edit_global_public_query", "is_public" => "1"}
|
||||
|
||||
assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4
|
||||
q = Query.find_by_name('test_edit_global_public_query')
|
||||
assert q.is_public?
|
||||
assert q.has_default_columns?
|
||||
assert q.valid?
|
||||
end
|
||||
|
||||
def test_get_edit_global_private_query
|
||||
@request.session[:user_id] = 3
|
||||
get :edit, :id => 3
|
||||
assert_response :success
|
||||
assert_template 'edit'
|
||||
assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
||||
:name => 'query[is_public]' }
|
||||
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
||||
:name => 'query_is_for_all',
|
||||
:checked => 'checked',
|
||||
:disabled => 'disabled' }
|
||||
end
|
||||
|
||||
def test_edit_global_private_query
|
||||
@request.session[:user_id] = 3
|
||||
post :edit,
|
||||
:id => 3,
|
||||
:confirm => '1',
|
||||
:default_columns => '1',
|
||||
:fields => ["status_id", "assigned_to_id"],
|
||||
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
|
||||
:values => { "assigned_to_id" => ["me"], "status_id" => ["1"]},
|
||||
:query => {"name" => "test_edit_global_private_query", "is_public" => "1"}
|
||||
|
||||
assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3
|
||||
q = Query.find_by_name('test_edit_global_private_query')
|
||||
assert !q.is_public?
|
||||
assert q.has_default_columns?
|
||||
assert q.valid?
|
||||
end
|
||||
|
||||
def test_get_edit_project_private_query
|
||||
@request.session[:user_id] = 3
|
||||
get :edit, :id => 2
|
||||
assert_response :success
|
||||
assert_template 'edit'
|
||||
assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
||||
:name => 'query[is_public]' }
|
||||
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
||||
:name => 'query_is_for_all',
|
||||
:checked => nil,
|
||||
:disabled => nil }
|
||||
end
|
||||
|
||||
def test_get_edit_project_public_query
|
||||
@request.session[:user_id] = 2
|
||||
get :edit, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'edit'
|
||||
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
||||
:name => 'query[is_public]',
|
||||
:checked => 'checked'
|
||||
}
|
||||
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
||||
:name => 'query_is_for_all',
|
||||
:checked => nil,
|
||||
:disabled => 'disabled' }
|
||||
end
|
||||
|
||||
def test_destroy
|
||||
@request.session[:user_id] = 2
|
||||
post :destroy, :id => 1
|
||||
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil
|
||||
assert_nil Query.find_by_id(1)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,137 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'repositories_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class RepositoriesController; def rescue_action(e) raise e end; end
|
||||
|
||||
class RepositoriesBazaarControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :users, :roles, :members, :repositories, :enabled_modules
|
||||
|
||||
# No '..' in the repository path
|
||||
REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/bazaar_repository'
|
||||
|
||||
def setup
|
||||
@controller = RepositoriesController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
User.current = nil
|
||||
Repository::Bazaar.create(:project => Project.find(3), :url => REPOSITORY_PATH)
|
||||
end
|
||||
|
||||
if File.directory?(REPOSITORY_PATH)
|
||||
def test_show
|
||||
get :show, :id => 3
|
||||
assert_response :success
|
||||
assert_template 'show'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_not_nil assigns(:changesets)
|
||||
end
|
||||
|
||||
def test_browse_root
|
||||
get :browse, :id => 3
|
||||
assert_response :success
|
||||
assert_template 'browse'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_equal 2, assigns(:entries).size
|
||||
assert assigns(:entries).detect {|e| e.name == 'directory' && e.kind == 'dir'}
|
||||
assert assigns(:entries).detect {|e| e.name == 'doc-mkdir.txt' && e.kind == 'file'}
|
||||
end
|
||||
|
||||
def test_browse_directory
|
||||
get :browse, :id => 3, :path => ['directory']
|
||||
assert_response :success
|
||||
assert_template 'browse'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_equal ['doc-ls.txt', 'document.txt', 'edit.png'], assigns(:entries).collect(&:name)
|
||||
entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
|
||||
assert_not_nil entry
|
||||
assert_equal 'file', entry.kind
|
||||
assert_equal 'directory/edit.png', entry.path
|
||||
end
|
||||
|
||||
def test_browse_at_given_revision
|
||||
get :browse, :id => 3, :path => [], :rev => 3
|
||||
assert_response :success
|
||||
assert_template 'browse'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_equal ['directory', 'doc-deleted.txt', 'doc-ls.txt', 'doc-mkdir.txt'], assigns(:entries).collect(&:name)
|
||||
end
|
||||
|
||||
def test_changes
|
||||
get :changes, :id => 3, :path => ['doc-mkdir.txt']
|
||||
assert_response :success
|
||||
assert_template 'changes'
|
||||
assert_tag :tag => 'h2', :content => 'doc-mkdir.txt'
|
||||
end
|
||||
|
||||
def test_entry_show
|
||||
get :entry, :id => 3, :path => ['directory', 'doc-ls.txt']
|
||||
assert_response :success
|
||||
assert_template 'entry'
|
||||
# Line 19
|
||||
assert_tag :tag => 'th',
|
||||
:content => /29/,
|
||||
:attributes => { :class => /line-num/ },
|
||||
:sibling => { :tag => 'td', :content => /Show help message/ }
|
||||
end
|
||||
|
||||
def test_entry_download
|
||||
get :entry, :id => 3, :path => ['directory', 'doc-ls.txt'], :format => 'raw'
|
||||
assert_response :success
|
||||
# File content
|
||||
assert @response.body.include?('Show help message')
|
||||
end
|
||||
|
||||
def test_directory_entry
|
||||
get :entry, :id => 3, :path => ['directory']
|
||||
assert_response :success
|
||||
assert_template 'browse'
|
||||
assert_not_nil assigns(:entry)
|
||||
assert_equal 'directory', assigns(:entry).name
|
||||
end
|
||||
|
||||
def test_diff
|
||||
# Full diff of changeset 3
|
||||
get :diff, :id => 3, :rev => 3
|
||||
assert_response :success
|
||||
assert_template 'diff'
|
||||
# Line 22 removed
|
||||
assert_tag :tag => 'th',
|
||||
:content => /2/,
|
||||
:sibling => { :tag => 'td',
|
||||
:attributes => { :class => /diff_in/ },
|
||||
:content => /Main purpose/ }
|
||||
end
|
||||
|
||||
def test_annotate
|
||||
get :annotate, :id => 3, :path => ['doc-mkdir.txt']
|
||||
assert_response :success
|
||||
assert_template 'annotate'
|
||||
# Line 2, revision 3
|
||||
assert_tag :tag => 'th', :content => /2/,
|
||||
:sibling => { :tag => 'td', :child => { :tag => 'a', :content => /3/ } },
|
||||
:sibling => { :tag => 'td', :content => /jsmith/ },
|
||||
:sibling => { :tag => 'td', :content => /Main purpose/ }
|
||||
end
|
||||
else
|
||||
puts "Bazaar test repository NOT FOUND. Skipping functional tests !!!"
|
||||
def test_fake; assert true end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,64 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'repositories_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class RepositoriesController; def rescue_action(e) raise e end; end
|
||||
|
||||
class RepositoriesControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :users, :roles, :members, :repositories, :issues, :issue_statuses, :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
|
||||
|
||||
def setup
|
||||
@controller = RepositoriesController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_revisions
|
||||
get :revisions, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'revisions'
|
||||
assert_not_nil assigns(:changesets)
|
||||
end
|
||||
|
||||
def test_revision_with_before_nil_and_afer_normal
|
||||
get :revision, {:id => 1, :rev => 1}
|
||||
assert_response :success
|
||||
assert_template 'revision'
|
||||
assert_no_tag :tag => "div", :attributes => { :class => "contextual" },
|
||||
:child => { :tag => "a", :attributes => { :href => '/repositories/revision/ecookbook?rev=0'}
|
||||
}
|
||||
assert_tag :tag => "div", :attributes => { :class => "contextual" },
|
||||
:child => { :tag => "a", :attributes => { :href => '/repositories/revision/ecookbook?rev=2'}
|
||||
}
|
||||
end
|
||||
|
||||
def test_graph_commits_per_month
|
||||
get :graph, :id => 1, :graph => 'commits_per_month'
|
||||
assert_response :success
|
||||
assert_equal 'image/svg+xml', @response.content_type
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
@@ -0,0 +1,152 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'repositories_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class RepositoriesController; def rescue_action(e) raise e end; end
|
||||
|
||||
class RepositoriesCvsControllerTest < Test::Unit::TestCase
|
||||
|
||||
# No '..' in the repository path
|
||||
REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/cvs_repository'
|
||||
REPOSITORY_PATH.gsub!(/\//, "\\") if RUBY_PLATFORM =~ /mswin/
|
||||
# CVS module
|
||||
MODULE_NAME = 'test'
|
||||
|
||||
def setup
|
||||
@controller = RepositoriesController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
Setting.default_language = 'en'
|
||||
User.current = nil
|
||||
|
||||
@project = Project.find(1)
|
||||
@project.repository = Repository::Cvs.create(:root_url => REPOSITORY_PATH,
|
||||
:url => MODULE_NAME)
|
||||
end
|
||||
|
||||
if File.directory?(REPOSITORY_PATH)
|
||||
def test_show
|
||||
get :show, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'show'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_not_nil assigns(:changesets)
|
||||
end
|
||||
|
||||
def test_browse_root
|
||||
get :browse, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'browse'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_equal 3, assigns(:entries).size
|
||||
|
||||
entry = assigns(:entries).detect {|e| e.name == 'images'}
|
||||
assert_equal 'dir', entry.kind
|
||||
|
||||
entry = assigns(:entries).detect {|e| e.name == 'README'}
|
||||
assert_equal 'file', entry.kind
|
||||
end
|
||||
|
||||
def test_browse_directory
|
||||
get :browse, :id => 1, :path => ['images']
|
||||
assert_response :success
|
||||
assert_template 'browse'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_equal ['add.png', 'delete.png', 'edit.png'], assigns(:entries).collect(&:name)
|
||||
entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
|
||||
assert_not_nil entry
|
||||
assert_equal 'file', entry.kind
|
||||
assert_equal 'images/edit.png', entry.path
|
||||
end
|
||||
|
||||
def test_browse_at_given_revision
|
||||
Project.find(1).repository.fetch_changesets
|
||||
get :browse, :id => 1, :path => ['images'], :rev => 1
|
||||
assert_response :success
|
||||
assert_template 'browse'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
|
||||
end
|
||||
|
||||
def test_entry
|
||||
get :entry, :id => 1, :path => ['sources', 'watchers_controller.rb']
|
||||
assert_response :success
|
||||
assert_template 'entry'
|
||||
end
|
||||
|
||||
def test_entry_not_found
|
||||
get :entry, :id => 1, :path => ['sources', 'zzz.c']
|
||||
assert_tag :tag => 'div', :attributes => { :class => /error/ },
|
||||
:content => /The entry or revision was not found in the repository/
|
||||
end
|
||||
|
||||
def test_entry_download
|
||||
get :entry, :id => 1, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
def test_directory_entry
|
||||
get :entry, :id => 1, :path => ['sources']
|
||||
assert_response :success
|
||||
assert_template 'browse'
|
||||
assert_not_nil assigns(:entry)
|
||||
assert_equal 'sources', assigns(:entry).name
|
||||
end
|
||||
|
||||
def test_diff
|
||||
Project.find(1).repository.fetch_changesets
|
||||
get :diff, :id => 1, :rev => 3, :type => 'inline'
|
||||
assert_response :success
|
||||
assert_template 'diff'
|
||||
assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_out' },
|
||||
:content => /watched.remove_watcher/
|
||||
assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
|
||||
:content => /watched.remove_all_watcher/
|
||||
end
|
||||
|
||||
def test_annotate
|
||||
Project.find(1).repository.fetch_changesets
|
||||
get :annotate, :id => 1, :path => ['sources', 'watchers_controller.rb']
|
||||
assert_response :success
|
||||
assert_template 'annotate'
|
||||
# 1.1 line
|
||||
assert_tag :tag => 'th', :attributes => { :class => 'line-num' },
|
||||
:content => '18',
|
||||
:sibling => { :tag => 'td', :attributes => { :class => 'revision' },
|
||||
:content => /1.1/,
|
||||
:sibling => { :tag => 'td', :attributes => { :class => 'author' },
|
||||
:content => /LANG/
|
||||
}
|
||||
}
|
||||
# 1.2 line
|
||||
assert_tag :tag => 'th', :attributes => { :class => 'line-num' },
|
||||
:content => '32',
|
||||
:sibling => { :tag => 'td', :attributes => { :class => 'revision' },
|
||||
:content => /1.2/,
|
||||
:sibling => { :tag => 'td', :attributes => { :class => 'author' },
|
||||
:content => /LANG/
|
||||
}
|
||||
}
|
||||
end
|
||||
else
|
||||
puts "CVS test repository NOT FOUND. Skipping functional tests !!!"
|
||||
def test_fake; assert true end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,103 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'repositories_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class RepositoriesController; def rescue_action(e) raise e end; end
|
||||
|
||||
class RepositoriesDarcsControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :users, :roles, :members, :repositories, :enabled_modules
|
||||
|
||||
# No '..' in the repository path
|
||||
REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/darcs_repository'
|
||||
|
||||
def setup
|
||||
@controller = RepositoriesController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
User.current = nil
|
||||
Repository::Darcs.create(:project => Project.find(3), :url => REPOSITORY_PATH)
|
||||
end
|
||||
|
||||
if File.directory?(REPOSITORY_PATH)
|
||||
def test_show
|
||||
get :show, :id => 3
|
||||
assert_response :success
|
||||
assert_template 'show'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_not_nil assigns(:changesets)
|
||||
end
|
||||
|
||||
def test_browse_root
|
||||
get :browse, :id => 3
|
||||
assert_response :success
|
||||
assert_template 'browse'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_equal 3, assigns(:entries).size
|
||||
assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
|
||||
assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
|
||||
assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
|
||||
end
|
||||
|
||||
def test_browse_directory
|
||||
get :browse, :id => 3, :path => ['images']
|
||||
assert_response :success
|
||||
assert_template 'browse'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
|
||||
entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
|
||||
assert_not_nil entry
|
||||
assert_equal 'file', entry.kind
|
||||
assert_equal 'images/edit.png', entry.path
|
||||
end
|
||||
|
||||
def test_browse_at_given_revision
|
||||
Project.find(3).repository.fetch_changesets
|
||||
get :browse, :id => 3, :path => ['images'], :rev => 1
|
||||
assert_response :success
|
||||
assert_template 'browse'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_equal ['delete.png'], assigns(:entries).collect(&:name)
|
||||
end
|
||||
|
||||
def test_changes
|
||||
get :changes, :id => 3, :path => ['images', 'edit.png']
|
||||
assert_response :success
|
||||
assert_template 'changes'
|
||||
assert_tag :tag => 'h2', :content => 'edit.png'
|
||||
end
|
||||
|
||||
def test_diff
|
||||
Project.find(3).repository.fetch_changesets
|
||||
# Full diff of changeset 5
|
||||
get :diff, :id => 3, :rev => 5
|
||||
assert_response :success
|
||||
assert_template 'diff'
|
||||
# Line 22 removed
|
||||
assert_tag :tag => 'th',
|
||||
:content => /22/,
|
||||
:sibling => { :tag => 'td',
|
||||
:attributes => { :class => /diff_out/ },
|
||||
:content => /def remove/ }
|
||||
end
|
||||
else
|
||||
puts "Darcs test repository NOT FOUND. Skipping functional tests !!!"
|
||||
def test_fake; assert true end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,146 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'repositories_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class RepositoriesController; def rescue_action(e) raise e end; end
|
||||
|
||||
class RepositoriesGitControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :users, :roles, :members, :repositories, :enabled_modules
|
||||
|
||||
# No '..' in the repository path
|
||||
REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
|
||||
REPOSITORY_PATH.gsub!(/\//, "\\") if RUBY_PLATFORM =~ /mswin/
|
||||
|
||||
def setup
|
||||
@controller = RepositoriesController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
User.current = nil
|
||||
Repository::Git.create(:project => Project.find(3), :url => REPOSITORY_PATH)
|
||||
end
|
||||
|
||||
if File.directory?(REPOSITORY_PATH)
|
||||
def test_show
|
||||
get :show, :id => 3
|
||||
assert_response :success
|
||||
assert_template 'show'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_not_nil assigns(:changesets)
|
||||
end
|
||||
|
||||
def test_browse_root
|
||||
get :browse, :id => 3
|
||||
assert_response :success
|
||||
assert_template 'browse'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_equal 3, assigns(:entries).size
|
||||
assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
|
||||
assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
|
||||
assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
|
||||
end
|
||||
|
||||
def test_browse_directory
|
||||
get :browse, :id => 3, :path => ['images']
|
||||
assert_response :success
|
||||
assert_template 'browse'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
|
||||
entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
|
||||
assert_not_nil entry
|
||||
assert_equal 'file', entry.kind
|
||||
assert_equal 'images/edit.png', entry.path
|
||||
end
|
||||
|
||||
def test_browse_at_given_revision
|
||||
get :browse, :id => 3, :path => ['images'], :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
|
||||
assert_response :success
|
||||
assert_template 'browse'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_equal ['delete.png'], assigns(:entries).collect(&:name)
|
||||
end
|
||||
|
||||
def test_changes
|
||||
get :changes, :id => 3, :path => ['images', 'edit.png']
|
||||
assert_response :success
|
||||
assert_template 'changes'
|
||||
assert_tag :tag => 'h2', :content => 'edit.png'
|
||||
end
|
||||
|
||||
def test_entry_show
|
||||
get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
|
||||
assert_response :success
|
||||
assert_template 'entry'
|
||||
# Line 19
|
||||
assert_tag :tag => 'th',
|
||||
:content => /10/,
|
||||
:attributes => { :class => /line-num/ },
|
||||
:sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
|
||||
end
|
||||
|
||||
def test_entry_download
|
||||
get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
|
||||
assert_response :success
|
||||
# File content
|
||||
assert @response.body.include?('WITHOUT ANY WARRANTY')
|
||||
end
|
||||
|
||||
def test_directory_entry
|
||||
get :entry, :id => 3, :path => ['sources']
|
||||
assert_response :success
|
||||
assert_template 'browse'
|
||||
assert_not_nil assigns(:entry)
|
||||
assert_equal 'sources', assigns(:entry).name
|
||||
end
|
||||
|
||||
def test_diff
|
||||
# Full diff of changeset 2f9c0091
|
||||
get :diff, :id => 3, :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
|
||||
assert_response :success
|
||||
assert_template 'diff'
|
||||
# Line 22 removed
|
||||
assert_tag :tag => 'th',
|
||||
:content => /22/,
|
||||
:sibling => { :tag => 'td',
|
||||
:attributes => { :class => /diff_out/ },
|
||||
:content => /def remove/ }
|
||||
end
|
||||
|
||||
def test_annotate
|
||||
get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
|
||||
assert_response :success
|
||||
assert_template 'annotate'
|
||||
# Line 23, changeset 2f9c0091
|
||||
assert_tag :tag => 'th', :content => /23/,
|
||||
:sibling => { :tag => 'td', :child => { :tag => 'a', :content => /2f9c0091/ } },
|
||||
:sibling => { :tag => 'td', :content => /jsmith/ },
|
||||
:sibling => { :tag => 'td', :content => /watcher =/ }
|
||||
end
|
||||
|
||||
def test_annotate_binary_file
|
||||
get :annotate, :id => 3, :path => ['images', 'delete.png']
|
||||
assert_response 500
|
||||
assert_tag :tag => 'div', :attributes => { :class => /error/ },
|
||||
:content => /can not be annotated/
|
||||
end
|
||||
else
|
||||
puts "Git test repository NOT FOUND. Skipping functional tests !!!"
|
||||
def test_fake; assert true end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,138 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'repositories_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class RepositoriesController; def rescue_action(e) raise e end; end
|
||||
|
||||
class RepositoriesMercurialControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :users, :roles, :members, :repositories, :enabled_modules
|
||||
|
||||
# No '..' in the repository path
|
||||
REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
|
||||
|
||||
def setup
|
||||
@controller = RepositoriesController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
User.current = nil
|
||||
Repository::Mercurial.create(:project => Project.find(3), :url => REPOSITORY_PATH)
|
||||
end
|
||||
|
||||
if File.directory?(REPOSITORY_PATH)
|
||||
def test_show
|
||||
get :show, :id => 3
|
||||
assert_response :success
|
||||
assert_template 'show'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_not_nil assigns(:changesets)
|
||||
end
|
||||
|
||||
def test_browse_root
|
||||
get :browse, :id => 3
|
||||
assert_response :success
|
||||
assert_template 'browse'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_equal 3, assigns(:entries).size
|
||||
assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
|
||||
assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
|
||||
assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
|
||||
end
|
||||
|
||||
def test_browse_directory
|
||||
get :browse, :id => 3, :path => ['images']
|
||||
assert_response :success
|
||||
assert_template 'browse'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
|
||||
entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
|
||||
assert_not_nil entry
|
||||
assert_equal 'file', entry.kind
|
||||
assert_equal 'images/edit.png', entry.path
|
||||
end
|
||||
|
||||
def test_browse_at_given_revision
|
||||
get :browse, :id => 3, :path => ['images'], :rev => 0
|
||||
assert_response :success
|
||||
assert_template 'browse'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_equal ['delete.png'], assigns(:entries).collect(&:name)
|
||||
end
|
||||
|
||||
def test_changes
|
||||
get :changes, :id => 3, :path => ['images', 'edit.png']
|
||||
assert_response :success
|
||||
assert_template 'changes'
|
||||
assert_tag :tag => 'h2', :content => 'edit.png'
|
||||
end
|
||||
|
||||
def test_entry_show
|
||||
get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
|
||||
assert_response :success
|
||||
assert_template 'entry'
|
||||
# Line 19
|
||||
assert_tag :tag => 'th',
|
||||
:content => /10/,
|
||||
:attributes => { :class => /line-num/ },
|
||||
:sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
|
||||
end
|
||||
|
||||
def test_entry_download
|
||||
get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
|
||||
assert_response :success
|
||||
# File content
|
||||
assert @response.body.include?('WITHOUT ANY WARRANTY')
|
||||
end
|
||||
|
||||
def test_directory_entry
|
||||
get :entry, :id => 3, :path => ['sources']
|
||||
assert_response :success
|
||||
assert_template 'browse'
|
||||
assert_not_nil assigns(:entry)
|
||||
assert_equal 'sources', assigns(:entry).name
|
||||
end
|
||||
|
||||
def test_diff
|
||||
# Full diff of changeset 4
|
||||
get :diff, :id => 3, :rev => 4
|
||||
assert_response :success
|
||||
assert_template 'diff'
|
||||
# Line 22 removed
|
||||
assert_tag :tag => 'th',
|
||||
:content => /22/,
|
||||
:sibling => { :tag => 'td',
|
||||
:attributes => { :class => /diff_out/ },
|
||||
:content => /def remove/ }
|
||||
end
|
||||
|
||||
def test_annotate
|
||||
get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
|
||||
assert_response :success
|
||||
assert_template 'annotate'
|
||||
# Line 23, revision 4
|
||||
assert_tag :tag => 'th', :content => /23/,
|
||||
:sibling => { :tag => 'td', :child => { :tag => 'a', :content => /4/ } },
|
||||
:sibling => { :tag => 'td', :content => /jsmith/ },
|
||||
:sibling => { :tag => 'td', :content => /watcher =/ }
|
||||
end
|
||||
else
|
||||
puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
|
||||
def test_fake; assert true end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,115 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'repositories_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class RepositoriesController; def rescue_action(e) raise e end; end
|
||||
|
||||
class RepositoriesSubversionControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :users, :roles, :members, :repositories, :issues, :issue_statuses, :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
|
||||
|
||||
# No '..' in the repository path for svn
|
||||
REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/subversion_repository'
|
||||
|
||||
def setup
|
||||
@controller = RepositoriesController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
Setting.default_language = 'en'
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
if File.directory?(REPOSITORY_PATH)
|
||||
def test_show
|
||||
get :show, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'show'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_not_nil assigns(:changesets)
|
||||
end
|
||||
|
||||
def test_browse_root
|
||||
get :browse, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'browse'
|
||||
assert_not_nil assigns(:entries)
|
||||
entry = assigns(:entries).detect {|e| e.name == 'subversion_test'}
|
||||
assert_equal 'dir', entry.kind
|
||||
end
|
||||
|
||||
def test_browse_directory
|
||||
get :browse, :id => 1, :path => ['subversion_test']
|
||||
assert_response :success
|
||||
assert_template 'browse'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_equal ['folder', '.project', 'helloworld.c', 'textfile.txt'], assigns(:entries).collect(&:name)
|
||||
entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'}
|
||||
assert_equal 'file', entry.kind
|
||||
assert_equal 'subversion_test/helloworld.c', entry.path
|
||||
end
|
||||
|
||||
def test_browse_at_given_revision
|
||||
get :browse, :id => 1, :path => ['subversion_test'], :rev => 4
|
||||
assert_response :success
|
||||
assert_template 'browse'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'], assigns(:entries).collect(&:name)
|
||||
end
|
||||
|
||||
def test_entry
|
||||
get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c']
|
||||
assert_response :success
|
||||
assert_template 'entry'
|
||||
end
|
||||
|
||||
def test_entry_not_found
|
||||
get :entry, :id => 1, :path => ['subversion_test', 'zzz.c']
|
||||
assert_tag :tag => 'div', :attributes => { :class => /error/ },
|
||||
:content => /The entry or revision was not found in the repository/
|
||||
end
|
||||
|
||||
def test_entry_download
|
||||
get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'], :format => 'raw'
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
def test_directory_entry
|
||||
get :entry, :id => 1, :path => ['subversion_test', 'folder']
|
||||
assert_response :success
|
||||
assert_template 'browse'
|
||||
assert_not_nil assigns(:entry)
|
||||
assert_equal 'folder', assigns(:entry).name
|
||||
end
|
||||
|
||||
def test_diff
|
||||
get :diff, :id => 1, :rev => 3
|
||||
assert_response :success
|
||||
assert_template 'diff'
|
||||
end
|
||||
|
||||
def test_annotate
|
||||
get :annotate, :id => 1, :path => ['subversion_test', 'helloworld.c']
|
||||
assert_response :success
|
||||
assert_template 'annotate'
|
||||
end
|
||||
else
|
||||
puts "Subversion test repository NOT FOUND. Skipping functional tests !!!"
|
||||
def test_fake; assert true end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,220 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'roles_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class RolesController; def rescue_action(e) raise e end; end
|
||||
|
||||
class RolesControllerTest < Test::Unit::TestCase
|
||||
fixtures :roles, :users, :members, :workflows
|
||||
|
||||
def setup
|
||||
@controller = RolesController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
User.current = nil
|
||||
@request.session[:user_id] = 1 # admin
|
||||
end
|
||||
|
||||
def test_get_index
|
||||
get :index
|
||||
assert_response :success
|
||||
assert_template 'list'
|
||||
|
||||
assert_not_nil assigns(:roles)
|
||||
assert_equal Role.find(:all, :order => 'builtin, position'), assigns(:roles)
|
||||
|
||||
assert_tag :tag => 'a', :attributes => { :href => '/roles/edit/1' },
|
||||
:content => 'Manager'
|
||||
end
|
||||
|
||||
def test_get_new
|
||||
get :new
|
||||
assert_response :success
|
||||
assert_template 'new'
|
||||
end
|
||||
|
||||
def test_post_new_with_validaton_failure
|
||||
post :new, :role => {:name => '',
|
||||
:permissions => ['add_issues', 'edit_issues', 'log_time', ''],
|
||||
:assignable => '0'}
|
||||
|
||||
assert_response :success
|
||||
assert_template 'new'
|
||||
assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' }
|
||||
end
|
||||
|
||||
def test_post_new_without_workflow_copy
|
||||
post :new, :role => {:name => 'RoleWithoutWorkflowCopy',
|
||||
:permissions => ['add_issues', 'edit_issues', 'log_time', ''],
|
||||
:assignable => '0'}
|
||||
|
||||
assert_redirected_to 'roles/list'
|
||||
role = Role.find_by_name('RoleWithoutWorkflowCopy')
|
||||
assert_not_nil role
|
||||
assert_equal [:add_issues, :edit_issues, :log_time], role.permissions
|
||||
assert !role.assignable?
|
||||
end
|
||||
|
||||
def test_post_new_with_workflow_copy
|
||||
post :new, :role => {:name => 'RoleWithWorkflowCopy',
|
||||
:permissions => ['add_issues', 'edit_issues', 'log_time', ''],
|
||||
:assignable => '0'},
|
||||
:copy_workflow_from => '1'
|
||||
|
||||
assert_redirected_to 'roles/list'
|
||||
role = Role.find_by_name('RoleWithWorkflowCopy')
|
||||
assert_not_nil role
|
||||
assert_equal Role.find(1).workflows.size, role.workflows.size
|
||||
end
|
||||
|
||||
def test_get_edit
|
||||
get :edit, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'edit'
|
||||
assert_equal Role.find(1), assigns(:role)
|
||||
end
|
||||
|
||||
def test_post_edit
|
||||
post :edit, :id => 1,
|
||||
:role => {:name => 'Manager',
|
||||
:permissions => ['edit_project', ''],
|
||||
:assignable => '0'}
|
||||
|
||||
assert_redirected_to 'roles/list'
|
||||
role = Role.find(1)
|
||||
assert_equal [:edit_project], role.permissions
|
||||
end
|
||||
|
||||
def test_destroy
|
||||
r = Role.new(:name => 'ToBeDestroyed', :permissions => [:view_wiki_pages])
|
||||
assert r.save
|
||||
|
||||
post :destroy, :id => r
|
||||
assert_redirected_to 'roles/list'
|
||||
assert_nil Role.find_by_id(r.id)
|
||||
end
|
||||
|
||||
def test_destroy_role_in_use
|
||||
post :destroy, :id => 1
|
||||
assert_redirected_to 'roles'
|
||||
assert flash[:error] == 'This role is in use and can not be deleted.'
|
||||
assert_not_nil Role.find_by_id(1)
|
||||
end
|
||||
|
||||
def test_get_workflow
|
||||
get :workflow
|
||||
assert_response :success
|
||||
assert_template 'workflow'
|
||||
assert_not_nil assigns(:roles)
|
||||
assert_not_nil assigns(:trackers)
|
||||
end
|
||||
|
||||
def test_get_workflow_with_role_and_tracker
|
||||
get :workflow, :role_id => 2, :tracker_id => 1
|
||||
assert_response :success
|
||||
assert_template 'workflow'
|
||||
# allowed transitions
|
||||
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
||||
:name => 'issue_status[2][]',
|
||||
:value => '1',
|
||||
:checked => 'checked' }
|
||||
# not allowed
|
||||
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
||||
:name => 'issue_status[2][]',
|
||||
:value => '3',
|
||||
:checked => nil }
|
||||
end
|
||||
|
||||
def test_post_workflow
|
||||
post :workflow, :role_id => 2, :tracker_id => 1, :issue_status => {'4' => ['5'], '3' => ['1', '2']}
|
||||
assert_redirected_to 'roles/workflow'
|
||||
|
||||
assert_equal 3, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2})
|
||||
assert_not_nil Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2})
|
||||
assert_nil Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4})
|
||||
end
|
||||
|
||||
def test_clear_workflow
|
||||
assert Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2}) > 0
|
||||
|
||||
post :workflow, :role_id => 2, :tracker_id => 1
|
||||
assert_equal 0, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2})
|
||||
end
|
||||
|
||||
def test_get_report
|
||||
get :report
|
||||
assert_response :success
|
||||
assert_template 'report'
|
||||
|
||||
assert_not_nil assigns(:roles)
|
||||
assert_equal Role.find(:all, :order => 'builtin, position'), assigns(:roles)
|
||||
|
||||
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
||||
:name => 'permissions[3][]',
|
||||
:value => 'add_issues',
|
||||
:checked => 'checked' }
|
||||
|
||||
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
||||
:name => 'permissions[3][]',
|
||||
:value => 'delete_issues',
|
||||
:checked => nil }
|
||||
end
|
||||
|
||||
def test_post_report
|
||||
post :report, :permissions => { '0' => '', '1' => ['edit_issues'], '3' => ['add_issues', 'delete_issues']}
|
||||
assert_redirected_to 'roles/list'
|
||||
|
||||
assert_equal [:edit_issues], Role.find(1).permissions
|
||||
assert_equal [:add_issues, :delete_issues], Role.find(3).permissions
|
||||
assert Role.find(2).permissions.empty?
|
||||
end
|
||||
|
||||
def test_clear_all_permissions
|
||||
post :report, :permissions => { '0' => '' }
|
||||
assert_redirected_to 'roles/list'
|
||||
assert Role.find(1).permissions.empty?
|
||||
end
|
||||
|
||||
def test_move_highest
|
||||
post :move, :id => 3, :position => 'highest'
|
||||
assert_redirected_to 'roles/list'
|
||||
assert_equal 1, Role.find(3).position
|
||||
end
|
||||
|
||||
def test_move_higher
|
||||
position = Role.find(3).position
|
||||
post :move, :id => 3, :position => 'higher'
|
||||
assert_redirected_to 'roles/list'
|
||||
assert_equal position - 1, Role.find(3).position
|
||||
end
|
||||
|
||||
def test_move_lower
|
||||
position = Role.find(2).position
|
||||
post :move, :id => 2, :position => 'lower'
|
||||
assert_redirected_to 'roles/list'
|
||||
assert_equal position + 1, Role.find(2).position
|
||||
end
|
||||
|
||||
def test_move_lowest
|
||||
post :move, :id => 2, :position => 'lowest'
|
||||
assert_redirected_to 'roles/list'
|
||||
assert_equal Role.count, Role.find(2).position
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,102 @@
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'search_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class SearchController; def rescue_action(e) raise e end; end
|
||||
|
||||
class SearchControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :enabled_modules, :issues, :custom_fields, :custom_values
|
||||
|
||||
def setup
|
||||
@controller = SearchController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_search_for_projects
|
||||
get :index
|
||||
assert_response :success
|
||||
assert_template 'index'
|
||||
|
||||
get :index, :q => "cook"
|
||||
assert_response :success
|
||||
assert_template 'index'
|
||||
assert assigns(:results).include?(Project.find(1))
|
||||
end
|
||||
|
||||
def test_search_without_searchable_custom_fields
|
||||
CustomField.update_all "searchable = #{ActiveRecord::Base.connection.quoted_false}"
|
||||
|
||||
get :index, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'index'
|
||||
assert_not_nil assigns(:project)
|
||||
|
||||
get :index, :id => 1, :q => "can"
|
||||
assert_response :success
|
||||
assert_template 'index'
|
||||
end
|
||||
|
||||
def test_search_with_searchable_custom_fields
|
||||
get :index, :id => 1, :q => "stringforcustomfield"
|
||||
assert_response :success
|
||||
results = assigns(:results)
|
||||
assert_not_nil results
|
||||
assert_equal 1, results.size
|
||||
assert results.include?(Issue.find(3))
|
||||
end
|
||||
|
||||
def test_search_all_words
|
||||
# 'all words' is on by default
|
||||
get :index, :id => 1, :q => 'recipe updating saving'
|
||||
results = assigns(:results)
|
||||
assert_not_nil results
|
||||
assert_equal 1, results.size
|
||||
assert results.include?(Issue.find(3))
|
||||
end
|
||||
|
||||
def test_search_one_of_the_words
|
||||
get :index, :id => 1, :q => 'recipe updating saving', :submit => 'Search'
|
||||
results = assigns(:results)
|
||||
assert_not_nil results
|
||||
assert_equal 3, results.size
|
||||
assert results.include?(Issue.find(3))
|
||||
end
|
||||
|
||||
def test_search_titles_only_without_result
|
||||
get :index, :id => 1, :q => 'recipe updating saving', :all_words => '1', :titles_only => '1', :submit => 'Search'
|
||||
results = assigns(:results)
|
||||
assert_not_nil results
|
||||
assert_equal 0, results.size
|
||||
end
|
||||
|
||||
def test_search_titles_only
|
||||
get :index, :id => 1, :q => 'recipe', :titles_only => '1', :submit => 'Search'
|
||||
results = assigns(:results)
|
||||
assert_not_nil results
|
||||
assert_equal 2, results.size
|
||||
end
|
||||
|
||||
def test_search_with_invalid_project_id
|
||||
get :index, :id => 195, :q => 'recipe'
|
||||
assert_response 404
|
||||
assert_nil assigns(:results)
|
||||
end
|
||||
|
||||
def test_quick_jump_to_issue
|
||||
# issue of a public project
|
||||
get :index, :q => "3"
|
||||
assert_redirected_to 'issues/show/3'
|
||||
|
||||
# issue of a private project
|
||||
get :index, :q => "4"
|
||||
assert_response :success
|
||||
assert_template 'index'
|
||||
end
|
||||
|
||||
def test_tokens_with_quotes
|
||||
get :index, :id => 1, :q => '"good bye" hello "bye bye"'
|
||||
assert_equal ["good bye", "hello", "bye bye"], assigns(:tokens)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,53 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'settings_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class SettingsController; def rescue_action(e) raise e end; end
|
||||
|
||||
class SettingsControllerTest < Test::Unit::TestCase
|
||||
fixtures :users
|
||||
|
||||
def setup
|
||||
@controller = SettingsController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
User.current = nil
|
||||
@request.session[:user_id] = 1 # admin
|
||||
end
|
||||
|
||||
def test_get_edit
|
||||
get :edit
|
||||
assert_response :success
|
||||
assert_template 'edit'
|
||||
end
|
||||
|
||||
def test_post_edit_notifications
|
||||
post :edit, :settings => {:mail_from => 'functional@test.foo',
|
||||
:bcc_recipients => '0',
|
||||
:notified_events => %w(issue_added issue_updated news_added),
|
||||
:emails_footer => 'Test footer'
|
||||
}
|
||||
assert_redirected_to 'settings/edit'
|
||||
assert_equal 'functional@test.foo', Setting.mail_from
|
||||
assert !Setting.bcc_recipients?
|
||||
assert_equal %w(issue_added issue_updated news_added), Setting.notified_events
|
||||
assert_equal 'Test footer', Setting.emails_footer
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,31 @@
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'sys_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class SysController; def rescue_action(e) raise e end; end
|
||||
|
||||
class SysControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :repositories
|
||||
|
||||
def setup
|
||||
@controller = SysController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
# Enable WS
|
||||
Setting.sys_api_enabled = 1
|
||||
end
|
||||
|
||||
def test_projects
|
||||
result = invoke :projects
|
||||
assert_equal Project.count, result.size
|
||||
assert result.first.is_a?(Project)
|
||||
end
|
||||
|
||||
def test_repository_created
|
||||
project = Project.find(3)
|
||||
assert_nil project.repository
|
||||
assert invoke(:repository_created, project.identifier, 'http://localhost/svn')
|
||||
project.reload
|
||||
assert_not_nil project.repository
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,208 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'timelog_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class TimelogController; def rescue_action(e) raise e end; end
|
||||
|
||||
class TimelogControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :enabled_modules, :roles, :members, :issues, :time_entries, :users, :trackers, :enumerations, :issue_statuses, :custom_fields, :custom_values
|
||||
|
||||
def setup
|
||||
@controller = TimelogController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
end
|
||||
|
||||
def test_create
|
||||
@request.session[:user_id] = 3
|
||||
post :edit, :project_id => 1,
|
||||
:time_entry => {:comments => 'Some work on TimelogControllerTest',
|
||||
:activity_id => '10',
|
||||
:spent_on => '2008-03-14',
|
||||
:issue_id => '1',
|
||||
:hours => '7.3'}
|
||||
assert_redirected_to 'projects/ecookbook/timelog/details'
|
||||
|
||||
i = Issue.find(1)
|
||||
t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
|
||||
assert_not_nil t
|
||||
assert_equal 7.3, t.hours
|
||||
assert_equal 3, t.user_id
|
||||
assert_equal i, t.issue
|
||||
assert_equal i.project, t.project
|
||||
end
|
||||
|
||||
def test_update
|
||||
entry = TimeEntry.find(1)
|
||||
assert_equal 1, entry.issue_id
|
||||
assert_equal 2, entry.user_id
|
||||
|
||||
@request.session[:user_id] = 1
|
||||
post :edit, :id => 1,
|
||||
:time_entry => {:issue_id => '2',
|
||||
:hours => '8'}
|
||||
assert_redirected_to 'projects/ecookbook/timelog/details'
|
||||
entry.reload
|
||||
|
||||
assert_equal 8, entry.hours
|
||||
assert_equal 2, entry.issue_id
|
||||
assert_equal 2, entry.user_id
|
||||
end
|
||||
|
||||
def destroy
|
||||
@request.session[:user_id] = 2
|
||||
post :destroy, :id => 1
|
||||
assert_redirected_to 'projects/ecookbook/timelog/details'
|
||||
assert_nil TimeEntry.find_by_id(1)
|
||||
end
|
||||
|
||||
def test_report_no_criteria
|
||||
get :report, :project_id => 1
|
||||
assert_response :success
|
||||
assert_template 'report'
|
||||
end
|
||||
|
||||
def test_report_all_time
|
||||
get :report, :project_id => 1, :criterias => ['project', 'issue']
|
||||
assert_response :success
|
||||
assert_template 'report'
|
||||
assert_not_nil assigns(:total_hours)
|
||||
assert_equal "162.90", "%.2f" % assigns(:total_hours)
|
||||
end
|
||||
|
||||
def test_report_all_time_by_day
|
||||
get :report, :project_id => 1, :criterias => ['project', 'issue'], :columns => 'day'
|
||||
assert_response :success
|
||||
assert_template 'report'
|
||||
assert_not_nil assigns(:total_hours)
|
||||
assert_equal "162.90", "%.2f" % assigns(:total_hours)
|
||||
assert_tag :tag => 'th', :content => '2007-03-12'
|
||||
end
|
||||
|
||||
def test_report_one_criteria
|
||||
get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project']
|
||||
assert_response :success
|
||||
assert_template 'report'
|
||||
assert_not_nil assigns(:total_hours)
|
||||
assert_equal "8.65", "%.2f" % assigns(:total_hours)
|
||||
end
|
||||
|
||||
def test_report_two_criterias
|
||||
get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"]
|
||||
assert_response :success
|
||||
assert_template 'report'
|
||||
assert_not_nil assigns(:total_hours)
|
||||
assert_equal "162.90", "%.2f" % assigns(:total_hours)
|
||||
end
|
||||
|
||||
def test_report_custom_field_criteria
|
||||
get :report, :project_id => 1, :criterias => ['project', 'cf_1']
|
||||
assert_response :success
|
||||
assert_template 'report'
|
||||
assert_not_nil assigns(:total_hours)
|
||||
assert_not_nil assigns(:criterias)
|
||||
assert_equal 2, assigns(:criterias).size
|
||||
assert_equal "162.90", "%.2f" % assigns(:total_hours)
|
||||
# Custom field column
|
||||
assert_tag :tag => 'th', :content => 'Database'
|
||||
# Custom field row
|
||||
assert_tag :tag => 'td', :content => 'MySQL',
|
||||
:sibling => { :tag => 'td', :attributes => { :class => 'hours' },
|
||||
:child => { :tag => 'span', :attributes => { :class => 'hours hours-int' },
|
||||
:content => '1' }}
|
||||
end
|
||||
|
||||
def test_report_one_criteria_no_result
|
||||
get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criterias => ['project']
|
||||
assert_response :success
|
||||
assert_template 'report'
|
||||
assert_not_nil assigns(:total_hours)
|
||||
assert_equal "0.00", "%.2f" % assigns(:total_hours)
|
||||
end
|
||||
|
||||
def test_report_csv_export
|
||||
get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv"
|
||||
assert_response :success
|
||||
assert_equal 'text/csv', @response.content_type
|
||||
lines = @response.body.chomp.split("\n")
|
||||
# Headers
|
||||
assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first
|
||||
# Total row
|
||||
assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last
|
||||
end
|
||||
|
||||
def test_details_at_project_level
|
||||
get :details, :project_id => 1
|
||||
assert_response :success
|
||||
assert_template 'details'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_equal 4, assigns(:entries).size
|
||||
# project and subproject
|
||||
assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort
|
||||
assert_not_nil assigns(:total_hours)
|
||||
assert_equal "162.90", "%.2f" % assigns(:total_hours)
|
||||
# display all time by default
|
||||
assert_equal '2007-03-11'.to_date, assigns(:from)
|
||||
assert_equal '2007-04-22'.to_date, assigns(:to)
|
||||
end
|
||||
|
||||
def test_details_at_project_level_with_date_range
|
||||
get :details, :project_id => 1, :from => '2007-03-20', :to => '2007-04-30'
|
||||
assert_response :success
|
||||
assert_template 'details'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_equal 3, assigns(:entries).size
|
||||
assert_not_nil assigns(:total_hours)
|
||||
assert_equal "12.90", "%.2f" % assigns(:total_hours)
|
||||
assert_equal '2007-03-20'.to_date, assigns(:from)
|
||||
assert_equal '2007-04-30'.to_date, assigns(:to)
|
||||
end
|
||||
|
||||
def test_details_at_project_level_with_period
|
||||
get :details, :project_id => 1, :period => '7_days'
|
||||
assert_response :success
|
||||
assert_template 'details'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_not_nil assigns(:total_hours)
|
||||
assert_equal Date.today - 7, assigns(:from)
|
||||
assert_equal Date.today, assigns(:to)
|
||||
end
|
||||
|
||||
def test_details_at_issue_level
|
||||
get :details, :issue_id => 1
|
||||
assert_response :success
|
||||
assert_template 'details'
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_equal 2, assigns(:entries).size
|
||||
assert_not_nil assigns(:total_hours)
|
||||
assert_equal 154.25, assigns(:total_hours)
|
||||
# display all time by default
|
||||
assert_equal '2007-03-11'.to_date, assigns(:from)
|
||||
assert_equal '2007-04-22'.to_date, assigns(:to)
|
||||
end
|
||||
|
||||
def test_details_csv_export
|
||||
get :details, :project_id => 1, :format => 'csv'
|
||||
assert_response :success
|
||||
assert_equal 'text/csv', @response.content_type
|
||||
assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n")
|
||||
assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n")
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,62 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'users_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class UsersController; def rescue_action(e) raise e end; end
|
||||
|
||||
class UsersControllerTest < Test::Unit::TestCase
|
||||
fixtures :users, :projects, :members
|
||||
|
||||
def setup
|
||||
@controller = UsersController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
User.current = nil
|
||||
@request.session[:user_id] = 1 # admin
|
||||
end
|
||||
|
||||
def test_index
|
||||
get :index
|
||||
assert_response :success
|
||||
assert_template 'list'
|
||||
end
|
||||
|
||||
def test_list
|
||||
get :list
|
||||
assert_response :success
|
||||
assert_template 'list'
|
||||
assert_not_nil assigns(:users)
|
||||
# active users only
|
||||
assert_nil assigns(:users).detect {|u| !u.active?}
|
||||
end
|
||||
|
||||
def test_edit_membership
|
||||
post :edit_membership, :id => 2, :membership_id => 1,
|
||||
:membership => { :role_id => 2}
|
||||
assert_redirected_to 'users/edit/2'
|
||||
assert_equal 2, Member.find(1).role_id
|
||||
end
|
||||
|
||||
def test_destroy_membership
|
||||
post :destroy_membership, :id => 2, :membership_id => 1
|
||||
assert_redirected_to 'users/edit/2'
|
||||
assert_nil Member.find_by_id(1)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,73 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'versions_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class VersionsController; def rescue_action(e) raise e end; end
|
||||
|
||||
class VersionsControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :versions, :users, :roles, :members, :enabled_modules
|
||||
|
||||
def setup
|
||||
@controller = VersionsController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_show
|
||||
get :show, :id => 2
|
||||
assert_response :success
|
||||
assert_template 'show'
|
||||
assert_not_nil assigns(:version)
|
||||
|
||||
assert_tag :tag => 'h2', :content => /1.0/
|
||||
end
|
||||
|
||||
def test_get_edit
|
||||
@request.session[:user_id] = 2
|
||||
get :edit, :id => 2
|
||||
assert_response :success
|
||||
assert_template 'edit'
|
||||
end
|
||||
|
||||
def test_post_edit
|
||||
@request.session[:user_id] = 2
|
||||
post :edit, :id => 2,
|
||||
:version => { :name => 'New version name',
|
||||
:effective_date => Date.today.strftime("%Y-%m-%d")}
|
||||
assert_redirected_to 'projects/settings/ecookbook'
|
||||
version = Version.find(2)
|
||||
assert_equal 'New version name', version.name
|
||||
assert_equal Date.today, version.effective_date
|
||||
end
|
||||
|
||||
def test_destroy
|
||||
@request.session[:user_id] = 2
|
||||
post :destroy, :id => 2
|
||||
assert_redirected_to 'projects/settings/ecookbook'
|
||||
assert_nil Version.find_by_id(2)
|
||||
end
|
||||
|
||||
def test_issue_status_by
|
||||
xhr :get, :status_by, :id => 2
|
||||
assert_response :success
|
||||
assert_template '_issue_counts'
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,49 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'welcome_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class WelcomeController; def rescue_action(e) raise e end; end
|
||||
|
||||
class WelcomeControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :news
|
||||
|
||||
def setup
|
||||
@controller = WelcomeController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_index
|
||||
get :index
|
||||
assert_response :success
|
||||
assert_template 'index'
|
||||
assert_not_nil assigns(:news)
|
||||
assert_not_nil assigns(:projects)
|
||||
assert !assigns(:projects).include?(Project.find(:first, :conditions => {:is_public => false}))
|
||||
end
|
||||
|
||||
def test_browser_language
|
||||
Setting.default_language = 'en'
|
||||
@request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
|
||||
get :index
|
||||
assert_equal :fr, @controller.current_language
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,163 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'wiki_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class WikiController; def rescue_action(e) raise e end; end
|
||||
|
||||
class WikiControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :users, :roles, :members, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :attachments
|
||||
|
||||
def setup
|
||||
@controller = WikiController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_show_start_page
|
||||
get :index, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'show'
|
||||
assert_tag :tag => 'h1', :content => /CookBook documentation/
|
||||
end
|
||||
|
||||
def test_show_page_with_name
|
||||
get :index, :id => 1, :page => 'Another_page'
|
||||
assert_response :success
|
||||
assert_template 'show'
|
||||
assert_tag :tag => 'h1', :content => /Another page/
|
||||
# Included page with an inline image
|
||||
assert_tag :tag => 'p', :content => /This is an inline image/
|
||||
assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3',
|
||||
:alt => 'This is a logo' }
|
||||
end
|
||||
|
||||
def test_show_unexistent_page_without_edit_right
|
||||
get :index, :id => 1, :page => 'Unexistent page'
|
||||
assert_response 404
|
||||
end
|
||||
|
||||
def test_show_unexistent_page_with_edit_right
|
||||
@request.session[:user_id] = 2
|
||||
get :index, :id => 1, :page => 'Unexistent page'
|
||||
assert_response :success
|
||||
assert_template 'edit'
|
||||
end
|
||||
|
||||
def test_create_page
|
||||
@request.session[:user_id] = 2
|
||||
post :edit, :id => 1,
|
||||
:page => 'New page',
|
||||
:content => {:comments => 'Created the page',
|
||||
:text => "h1. New page\n\nThis is a new page",
|
||||
:version => 0}
|
||||
assert_redirected_to 'wiki/ecookbook/New_page'
|
||||
page = Project.find(1).wiki.find_page('New page')
|
||||
assert !page.new_record?
|
||||
assert_not_nil page.content
|
||||
assert_equal 'Created the page', page.content.comments
|
||||
end
|
||||
|
||||
def test_preview
|
||||
@request.session[:user_id] = 2
|
||||
xhr :post, :preview, :id => 1, :page => 'CookBook_documentation',
|
||||
:content => { :comments => '',
|
||||
:text => 'this is a *previewed text*',
|
||||
:version => 3 }
|
||||
assert_response :success
|
||||
assert_template 'common/_preview'
|
||||
assert_tag :tag => 'strong', :content => /previewed text/
|
||||
end
|
||||
|
||||
def test_history
|
||||
get :history, :id => 1, :page => 'CookBook_documentation'
|
||||
assert_response :success
|
||||
assert_template 'history'
|
||||
assert_not_nil assigns(:versions)
|
||||
assert_equal 3, assigns(:versions).size
|
||||
end
|
||||
|
||||
def test_diff
|
||||
get :diff, :id => 1, :page => 'CookBook_documentation', :version => 2, :version_from => 1
|
||||
assert_response :success
|
||||
assert_template 'diff'
|
||||
assert_tag :tag => 'span', :attributes => { :class => 'diff_in'},
|
||||
:content => /updated/
|
||||
end
|
||||
|
||||
def test_annotate
|
||||
get :annotate, :id => 1, :page => 'CookBook_documentation', :version => 2
|
||||
assert_response :success
|
||||
assert_template 'annotate'
|
||||
# Line 1
|
||||
assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1' },
|
||||
:child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/ },
|
||||
:child => { :tag => 'td', :content => /h1\. CookBook documentation/ }
|
||||
# Line 2
|
||||
assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '2' },
|
||||
:child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/ },
|
||||
:child => { :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ }
|
||||
end
|
||||
|
||||
def test_rename_with_redirect
|
||||
@request.session[:user_id] = 2
|
||||
post :rename, :id => 1, :page => 'Another_page',
|
||||
:wiki_page => { :title => 'Another renamed page',
|
||||
:redirect_existing_links => 1 }
|
||||
assert_redirected_to 'wiki/ecookbook/Another_renamed_page'
|
||||
wiki = Project.find(1).wiki
|
||||
# Check redirects
|
||||
assert_not_nil wiki.find_page('Another page')
|
||||
assert_nil wiki.find_page('Another page', :with_redirect => false)
|
||||
end
|
||||
|
||||
def test_rename_without_redirect
|
||||
@request.session[:user_id] = 2
|
||||
post :rename, :id => 1, :page => 'Another_page',
|
||||
:wiki_page => { :title => 'Another renamed page',
|
||||
:redirect_existing_links => "0" }
|
||||
assert_redirected_to 'wiki/ecookbook/Another_renamed_page'
|
||||
wiki = Project.find(1).wiki
|
||||
# Check that there's no redirects
|
||||
assert_nil wiki.find_page('Another page')
|
||||
end
|
||||
|
||||
def test_destroy
|
||||
@request.session[:user_id] = 2
|
||||
post :destroy, :id => 1, :page => 'CookBook_documentation'
|
||||
assert_redirected_to 'wiki/ecookbook/Page_index/special'
|
||||
end
|
||||
|
||||
def test_page_index
|
||||
get :special, :id => 'ecookbook', :page => 'Page_index'
|
||||
assert_response :success
|
||||
assert_template 'special_page_index'
|
||||
pages = assigns(:pages)
|
||||
assert_not_nil pages
|
||||
assert_equal Project.find(1).wiki.pages.size, pages.size
|
||||
assert_tag :tag => 'a', :attributes => { :href => '/wiki/ecookbook/CookBook_documentation' },
|
||||
:content => /CookBook documentation/
|
||||
end
|
||||
|
||||
def test_not_found
|
||||
get :index, :id => 999
|
||||
assert_response 404
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,56 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'wikis_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class WikisController; def rescue_action(e) raise e end; end
|
||||
|
||||
class WikisControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :users, :roles, :members, :enabled_modules, :wikis
|
||||
|
||||
def setup
|
||||
@controller = WikisController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_create
|
||||
@request.session[:user_id] = 1
|
||||
assert_nil Project.find(3).wiki
|
||||
post :edit, :id => 3, :wiki => { :start_page => 'Start page' }
|
||||
assert_response :success
|
||||
wiki = Project.find(3).wiki
|
||||
assert_not_nil wiki
|
||||
assert_equal 'Start page', wiki.start_page
|
||||
end
|
||||
|
||||
def test_destroy
|
||||
@request.session[:user_id] = 1
|
||||
post :destroy, :id => 1, :confirm => 1
|
||||
assert_redirected_to 'projects/settings/ecookbook'
|
||||
assert_nil Project.find(1).wiki
|
||||
end
|
||||
|
||||
def test_not_found
|
||||
@request.session[:user_id] = 1
|
||||
post :destroy, :id => 999, :confirm => 1
|
||||
assert_response 404
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user