添加测试用例

competition
nwb 11 years ago
parent dec77da33c
commit 801025d967

@ -0,0 +1,165 @@
# Redmine - project management software
# Copyright (C) 2006-2013 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.expand_path('../../test_helper', __FILE__)
class AccountControllerOpenidTest < ActionController::TestCase
tests AccountController
fixtures :users, :roles
def setup
User.current = nil
Setting.openid = '1'
end
def teardown
Setting.openid = '0'
end
if Object.const_defined?(:OpenID)
def test_login_with_openid_for_existing_user
Setting.self_registration = '3'
existing_user = User.new(:firstname => 'Cool',
:lastname => 'User',
:mail => 'user@somedomain.com',
:identity_url => 'http://openid.example.com/good_user')
existing_user.login = 'cool_user'
assert existing_user.save!
post :login, :openid_url => existing_user.identity_url
assert_redirected_to '/my/page'
end
def test_login_with_invalid_openid_provider
Setting.self_registration = '0'
post :login, :openid_url => 'http;//openid.example.com/good_user'
assert_redirected_to home_url
end
def test_login_with_openid_for_existing_non_active_user
Setting.self_registration = '2'
existing_user = User.new(:firstname => 'Cool',
:lastname => 'User',
:mail => 'user@somedomain.com',
:identity_url => 'http://openid.example.com/good_user',
:status => User::STATUS_REGISTERED)
existing_user.login = 'cool_user'
assert existing_user.save!
post :login, :openid_url => existing_user.identity_url
assert_redirected_to '/login'
end
def test_login_with_openid_with_new_user_created
Setting.self_registration = '3'
post :login, :openid_url => 'http://openid.example.com/good_user'
assert_redirected_to '/my/account'
user = User.find_by_login('cool_user')
assert user
assert_equal 'Cool', user.firstname
assert_equal 'User', user.lastname
end
def test_login_with_openid_with_new_user_and_self_registration_off
Setting.self_registration = '0'
post :login, :openid_url => 'http://openid.example.com/good_user'
assert_redirected_to home_url
user = User.find_by_login('cool_user')
assert_nil user
end
def test_login_with_openid_with_new_user_created_with_email_activation_should_have_a_token
Setting.self_registration = '1'
post :login, :openid_url => 'http://openid.example.com/good_user'
assert_redirected_to '/login'
user = User.find_by_login('cool_user')
assert user
token = Token.find_by_user_id_and_action(user.id, 'register')
assert token
end
def test_login_with_openid_with_new_user_created_with_manual_activation
Setting.self_registration = '2'
post :login, :openid_url => 'http://openid.example.com/good_user'
assert_redirected_to '/login'
user = User.find_by_login('cool_user')
assert user
assert_equal User::STATUS_REGISTERED, user.status
end
def test_login_with_openid_with_new_user_with_conflict_should_register
Setting.self_registration = '3'
existing_user = User.new(:firstname => 'Cool', :lastname => 'User', :mail => 'user@somedomain.com')
existing_user.login = 'cool_user'
assert existing_user.save!
post :login, :openid_url => 'http://openid.example.com/good_user'
assert_response :success
assert_template 'register'
assert assigns(:user)
assert_equal 'http://openid.example.com/good_user', assigns(:user)[:identity_url]
end
def test_login_with_openid_with_new_user_with_missing_information_should_register
Setting.self_registration = '3'
post :login, :openid_url => 'http://openid.example.com/good_blank_user'
assert_response :success
assert_template 'register'
assert assigns(:user)
assert_equal 'http://openid.example.com/good_blank_user', assigns(:user)[:identity_url]
assert_select 'input[name=?]', 'user[login]'
assert_select 'input[name=?]', 'user[password]'
assert_select 'input[name=?]', 'user[password_confirmation]'
assert_select 'input[name=?][value=?]', 'user[identity_url]', 'http://openid.example.com/good_blank_user'
end
def test_register_after_login_failure_should_not_require_user_to_enter_a_password
Setting.self_registration = '3'
assert_difference 'User.count' do
post :register, :user => {
:login => 'good_blank_user',
:password => '',
:password_confirmation => '',
:firstname => 'Cool',
:lastname => 'User',
:mail => 'user@somedomain.com',
:identity_url => 'http://openid.example.com/good_blank_user'
}
assert_response 302
end
user = User.first(:order => 'id DESC')
assert_equal 'http://openid.example.com/good_blank_user', user.identity_url
assert user.hashed_password.blank?, "Hashed password was #{user.hashed_password}"
end
def test_setting_openid_should_return_true_when_set_to_true
assert_equal true, Setting.openid?
end
else
puts "Skipping openid tests."
def test_dummy
end
end
end

File diff suppressed because it is too large Load Diff

@ -0,0 +1,150 @@
# Redmine - project management software
# Copyright (C) 2006-2013 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.expand_path('../../test_helper', __FILE__)
class ActivitiesControllerTest < ActionController::TestCase
fixtures :projects, :trackers, :issue_statuses, :issues,
:enumerations, :users, :issue_categories,
:projects_trackers,
:roles,
:member_roles,
:members,
:groups_users,
:enabled_modules,
:journals, :journal_details
def test_project_index
get :index, :id => 1, :with_subprojects => 0
assert_response :success
assert_template 'index'
assert_not_nil assigns(:events_by_day)
assert_select 'h3', :text => /#{2.days.ago.to_date.day}/
assert_select 'dl dt.issue-edit a', :text => /(#{IssueStatus.find(2).name})/
end
def test_project_index_with_invalid_project_id_should_respond_404
get :index, :id => 299
assert_response 404
end
def test_previous_project_index
get :index, :id => 1, :from => 2.days.ago.to_date
assert_response :success
assert_template 'index'
assert_not_nil assigns(:events_by_day)
assert_select 'h3', :text => /#{3.days.ago.to_date.day}/
assert_select 'dl dt.issue a', :text => /Can&#x27;t print recipes/
end
def test_global_index
@request.session[:user_id] = 1
get :index
assert_response :success
assert_template 'index'
assert_not_nil assigns(:events_by_day)
i5 = Issue.find(5)
d5 = User.find(1).time_to_date(i5.created_on)
assert_select 'h3', :text => /#{d5.day}/
assert_select 'dl dt.issue a', :text => /Subproject issue/
end
def test_user_index
@request.session[:user_id] = 1
get :index, :user_id => 2
assert_response :success
assert_template 'index'
assert_not_nil assigns(:events_by_day)
assert_select 'h2 a[href=/users/2]', :text => 'John Smith'
i1 = Issue.find(1)
d1 = User.find(1).time_to_date(i1.created_on)
assert_select 'h3', :text => /#{d1.day}/
assert_select 'dl dt.issue a', :text => /Can&#x27;t print recipes/
end
def test_user_index_with_invalid_user_id_should_respond_404
get :index, :user_id => 299
assert_response 404
end
def test_index_atom_feed
get :index, :format => 'atom', :with_subprojects => 0
assert_response :success
assert_template 'common/feed'
assert_select 'feed' do
assert_select 'link[rel=self][href=?]', 'http://test.host/activity.atom?with_subprojects=0'
assert_select 'link[rel=alternate][href=?]', 'http://test.host/activity?with_subprojects=0'
assert_select 'entry' do
assert_select 'link[href=?]', 'http://test.host/issues/11'
end
end
end
def test_index_atom_feed_with_explicit_selection
get :index, :format => 'atom', :with_subprojects => 0,
:show_changesets => 1,
:show_documents => 1,
:show_files => 1,
:show_issues => 1,
:show_messages => 1,
:show_news => 1,
:show_time_entries => 1,
:show_wiki_edits => 1
assert_response :success
assert_template 'common/feed'
assert_select 'feed' do
assert_select 'link[rel=self][href=?]', 'http://test.host/activity.atom?show_changesets=1&amp;show_documents=1&amp;show_files=1&amp;show_issues=1&amp;show_messages=1&amp;show_news=1&amp;show_time_entries=1&amp;show_wiki_edits=1&amp;with_subprojects=0'
assert_select 'link[rel=alternate][href=?]', 'http://test.host/activity?show_changesets=1&amp;show_documents=1&amp;show_files=1&amp;show_issues=1&amp;show_messages=1&amp;show_news=1&amp;show_time_entries=1&amp;show_wiki_edits=1&amp;with_subprojects=0'
assert_select 'entry' do
assert_select 'link[href=?]', 'http://test.host/issues/11'
end
end
end
def test_index_atom_feed_with_one_item_type
get :index, :format => 'atom', :show_issues => '1'
assert_response :success
assert_template 'common/feed'
assert_select 'title', :text => /Issues/
end
def test_index_should_show_private_notes_with_permission_only
journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Private notes with searchkeyword', :private_notes => true)
@request.session[:user_id] = 2
get :index
assert_response :success
assert_include journal, assigns(:events_by_day).values.flatten
Role.find(1).remove_permission! :view_private_notes
get :index
assert_response :success
assert_not_include journal, assigns(:events_by_day).values.flatten
end
end

@ -0,0 +1,167 @@
# Redmine - project management software
# Copyright (C) 2006-2013 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.expand_path('../../test_helper', __FILE__)
class AdminControllerTest < ActionController::TestCase
fixtures :projects, :users, :roles
def setup
User.current = nil
@request.session[:user_id] = 1 # admin
end
def test_index
get :index
assert_select 'div.nodata', 0
end
def test_index_with_no_configuration_data
delete_configuration_data
get :index
assert_select 'div.nodata'
end
def test_projects
get :projects
assert_response :success
assert_template 'projects'
assert_not_nil assigns(:projects)
# active projects only
assert_nil assigns(:projects).detect {|u| !u.active?}
end
def test_projects_with_status_filter
get :projects, :status => 1
assert_response :success
assert_template 'projects'
assert_not_nil assigns(:projects)
# active projects only
assert_nil assigns(:projects).detect {|u| !u.active?}
end
def test_projects_with_name_filter
get :projects, :name => 'store', :status => ''
assert_response :success
assert_template 'projects'
projects = assigns(:projects)
assert_not_nil projects
assert_equal 1, projects.size
assert_equal 'OnlineStore', projects.first.name
end
def test_load_default_configuration_data
delete_configuration_data
post :default_configuration, :lang => 'fr'
assert_response :redirect
assert_nil flash[:error]
assert IssueStatus.find_by_name('Nouveau')
end
def test_load_default_configuration_data_should_rescue_error
delete_configuration_data
Redmine::DefaultData::Loader.stubs(:load).raises(Exception.new("Something went wrong"))
post :default_configuration, :lang => 'fr'
assert_response :redirect
assert_not_nil flash[:error]
assert_match /Something went wrong/, flash[:error]
end
def test_test_email
user = User.find(1)
user.pref.no_self_notified = '1'
user.pref.save!
ActionMailer::Base.deliveries.clear
get :test_email
assert_redirected_to '/settings?tab=notifications'
mail = ActionMailer::Base.deliveries.last
assert_not_nil mail
user = User.find(1)
assert_equal [user.mail], mail.bcc
end
def test_test_email_failure_should_display_the_error
Mailer.stubs(:test_email).raises(Exception, 'Some error message')
get :test_email
assert_redirected_to '/settings?tab=notifications'
assert_match /Some error message/, flash[:error]
end
def test_no_plugins
Redmine::Plugin.clear
get :plugins
assert_response :success
assert_template 'plugins'
end
def test_plugins
# Register a few plugins
Redmine::Plugin.register :foo do
name 'Foo plugin'
author 'John Smith'
description 'This is a test plugin'
version '0.0.1'
settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings'
end
Redmine::Plugin.register :bar do
end
get :plugins
assert_response :success
assert_template 'plugins'
assert_select 'tr#plugin-foo' do
assert_select 'td span.name', :text => 'Foo plugin'
assert_select 'td.configure a[href=/settings/plugin/foo]'
end
assert_select 'tr#plugin-bar' do
assert_select 'td span.name', :text => 'Bar'
assert_select 'td.configure a', 0
end
end
def test_info
get :info
assert_response :success
assert_template 'info'
end
def test_admin_menu_plugin_extension
Redmine::MenuManager.map :admin_menu do |menu|
menu.push :test_admin_menu_plugin_extension, '/foo/bar', :caption => 'Test'
end
get :index
assert_response :success
assert_select 'div#admin-menu a[href=/foo/bar]', :text => 'Test'
Redmine::MenuManager.map :admin_menu do |menu|
menu.delete :test_admin_menu_plugin_extension
end
end
private
def delete_configuration_data
Role.delete_all('builtin = 0')
Tracker.delete_all
IssueStatus.delete_all
Enumeration.delete_all
end
end

File diff suppressed because it is too large Load Diff

@ -0,0 +1,168 @@
# Redmine - project management software
# Copyright (C) 2006-2013 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.expand_path('../../test_helper', __FILE__)
class AuthSourcesControllerTest < ActionController::TestCase
fixtures :users, :auth_sources
def setup
@request.session[:user_id] = 1
end
def test_index
get :index
assert_response :success
assert_template 'index'
assert_not_nil assigns(:auth_sources)
end
def test_new
get :new
assert_response :success
assert_template 'new'
source = assigns(:auth_source)
assert_equal AuthSourceLdap, source.class
assert source.new_record?
assert_select 'form#auth_source_form' do
assert_select 'input[name=type][value=AuthSourceLdap]'
assert_select 'input[name=?]', 'auth_source[host]'
end
end
def test_new_with_invalid_type_should_respond_with_404
get :new, :type => 'foo'
assert_response 404
end
def test_create
assert_difference 'AuthSourceLdap.count' do
post :create, :type => 'AuthSourceLdap', :auth_source => {:name => 'Test', :host => '127.0.0.1', :port => '389', :attr_login => 'cn'}
assert_redirected_to '/auth_sources'
end
source = AuthSourceLdap.order('id DESC').first
assert_equal 'Test', source.name
assert_equal '127.0.0.1', source.host
assert_equal 389, source.port
assert_equal 'cn', source.attr_login
end
def test_create_with_failure
assert_no_difference 'AuthSourceLdap.count' do
post :create, :type => 'AuthSourceLdap', :auth_source => {:name => 'Test', :host => '', :port => '389', :attr_login => 'cn'}
assert_response :success
assert_template 'new'
end
assert_error_tag :content => /host can&#x27;t be blank/i
end
def test_edit
get :edit, :id => 1
assert_response :success
assert_template 'edit'
assert_select 'form#auth_source_form' do
assert_select 'input[name=?]', 'auth_source[host]'
end
end
def test_edit_should_not_contain_password
AuthSource.find(1).update_column :account_password, 'secret'
get :edit, :id => 1
assert_response :success
assert_select 'input[value=secret]', 0
assert_select 'input[name=dummy_password][value=?]', /x+/
end
def test_edit_invalid_should_respond_with_404
get :edit, :id => 99
assert_response 404
end
def test_update
put :update, :id => 1, :auth_source => {:name => 'Renamed', :host => '192.168.0.10', :port => '389', :attr_login => 'uid'}
assert_redirected_to '/auth_sources'
source = AuthSourceLdap.find(1)
assert_equal 'Renamed', source.name
assert_equal '192.168.0.10', source.host
end
def test_update_with_failure
put :update, :id => 1, :auth_source => {:name => 'Renamed', :host => '', :port => '389', :attr_login => 'uid'}
assert_response :success
assert_template 'edit'
assert_error_tag :content => /host can&#x27;t be blank/i
end
def test_destroy
assert_difference 'AuthSourceLdap.count', -1 do
delete :destroy, :id => 1
assert_redirected_to '/auth_sources'
end
end
def test_destroy_auth_source_in_use
User.find(2).update_attribute :auth_source_id, 1
assert_no_difference 'AuthSourceLdap.count' do
delete :destroy, :id => 1
assert_redirected_to '/auth_sources'
end
end
def test_test_connection
AuthSourceLdap.any_instance.stubs(:test_connection).returns(true)
get :test_connection, :id => 1
assert_redirected_to '/auth_sources'
assert_not_nil flash[:notice]
assert_match /successful/i, flash[:notice]
end
def test_test_connection_with_failure
AuthSourceLdap.any_instance.stubs(:initialize_ldap_con).raises(Net::LDAP::LdapError.new("Something went wrong"))
get :test_connection, :id => 1
assert_redirected_to '/auth_sources'
assert_not_nil flash[:error]
assert_include 'Something went wrong', flash[:error]
end
def test_autocomplete_for_new_user
AuthSource.expects(:search).with('foo').returns([
{:login => 'foo1', :firstname => 'John', :lastname => 'Smith', :mail => 'foo1@example.net', :auth_source_id => 1},
{:login => 'Smith', :firstname => 'John', :lastname => 'Doe', :mail => 'foo2@example.net', :auth_source_id => 1}
])
get :autocomplete_for_new_user, :term => 'foo'
assert_response :success
assert_equal 'application/json', response.content_type
json = ActiveSupport::JSON.decode(response.body)
assert_kind_of Array, json
assert_equal 2, json.size
assert_equal 'foo1', json.first['value']
assert_equal 'foo1 (John Smith)', json.first['label']
end
end

@ -0,0 +1,217 @@
# Redmine - project management software
# Copyright (C) 2006-2013 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.expand_path('../../test_helper', __FILE__)
class BoardsControllerTest < ActionController::TestCase
fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
def setup
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_index_not_found
get :index, :project_id => 97
assert_response 404
end
def test_index_should_show_messages_if_only_one_board
Project.find(1).boards.slice(1..-1).each(&:destroy)
get :index, :project_id => 1
assert_response :success
assert_template 'show'
assert_not_nil assigns(:topics)
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
def test_show_should_display_sticky_messages_first
Message.update_all(:sticky => 0)
Message.update_all({:sticky => 1}, {:id => 1})
get :show, :project_id => 1, :id => 1
assert_response :success
topics = assigns(:topics)
assert_not_nil topics
assert topics.size > 1, "topics size was #{topics.size}"
assert topics.first.sticky?
assert topics.first.updated_on < topics.second.updated_on
end
def test_show_should_display_message_with_last_reply_first
Message.update_all(:sticky => 0)
# Reply to an old topic
old_topic = Message.where(:board_id => 1, :parent_id => nil).order('created_on ASC').first
reply = Message.new(:board_id => 1, :subject => 'New reply', :content => 'New reply', :author_id => 2)
old_topic.children << reply
get :show, :project_id => 1, :id => 1
assert_response :success
topics = assigns(:topics)
assert_not_nil topics
assert_equal old_topic, topics.first
end
def test_show_with_permission_should_display_the_new_message_form
@request.session[:user_id] = 2
get :show, :project_id => 1, :id => 1
assert_response :success
assert_template 'show'
assert_select 'form#message-form' do
assert_select 'input[name=?]', 'message[subject]'
end
end
def test_show_atom
get :show, :project_id => 1, :id => 1, :format => 'atom'
assert_response :success
assert_template 'common/feed'
assert_not_nil assigns(:board)
assert_not_nil assigns(:project)
assert_not_nil assigns(:messages)
end
def test_show_not_found
get :index, :project_id => 1, :id => 97
assert_response 404
end
def test_new
@request.session[:user_id] = 2
get :new, :project_id => 1
assert_response :success
assert_template 'new'
assert_select 'select[name=?]', 'board[parent_id]' do
assert_select 'option', (Project.find(1).boards.size + 1)
assert_select 'option[value=]', :text => ''
assert_select 'option[value=1]', :text => 'Help'
end
end
def test_new_without_project_boards
Project.find(1).boards.delete_all
@request.session[:user_id] = 2
get :new, :project_id => 1
assert_response :success
assert_template 'new'
assert_select 'select[name=?]', 'board[parent_id]', 0
end
def test_create
@request.session[:user_id] = 2
assert_difference 'Board.count' do
post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing board creation'}
end
assert_redirected_to '/projects/ecookbook/settings/boards'
board = Board.first(:order => 'id DESC')
assert_equal 'Testing', board.name
assert_equal 'Testing board creation', board.description
end
def test_create_with_parent
@request.session[:user_id] = 2
assert_difference 'Board.count' do
post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing', :parent_id => 2}
end
assert_redirected_to '/projects/ecookbook/settings/boards'
board = Board.first(:order => 'id DESC')
assert_equal Board.find(2), board.parent
end
def test_create_with_failure
@request.session[:user_id] = 2
assert_no_difference 'Board.count' do
post :create, :project_id => 1, :board => { :name => '', :description => 'Testing board creation'}
end
assert_response :success
assert_template 'new'
end
def test_edit
@request.session[:user_id] = 2
get :edit, :project_id => 1, :id => 2
assert_response :success
assert_template 'edit'
end
def test_edit_with_parent
board = Board.generate!(:project_id => 1, :parent_id => 2)
@request.session[:user_id] = 2
get :edit, :project_id => 1, :id => board.id
assert_response :success
assert_template 'edit'
assert_select 'select[name=?]', 'board[parent_id]' do
assert_select 'option[value=2][selected=selected]'
end
end
def test_update
@request.session[:user_id] = 2
assert_no_difference 'Board.count' do
put :update, :project_id => 1, :id => 2, :board => { :name => 'Testing', :description => 'Testing board update'}
end
assert_redirected_to '/projects/ecookbook/settings/boards'
assert_equal 'Testing', Board.find(2).name
end
def test_update_position
@request.session[:user_id] = 2
put :update, :project_id => 1, :id => 2, :board => { :move_to => 'highest'}
assert_redirected_to '/projects/ecookbook/settings/boards'
board = Board.find(2)
assert_equal 1, board.position
end
def test_update_with_failure
@request.session[:user_id] = 2
put :update, :project_id => 1, :id => 2, :board => { :name => '', :description => 'Testing board update'}
assert_response :success
assert_template 'edit'
end
def test_destroy
@request.session[:user_id] = 2
assert_difference 'Board.count', -1 do
delete :destroy, :project_id => 1, :id => 2
end
assert_redirected_to '/projects/ecookbook/settings/boards'
assert_nil Board.find_by_id(2)
end
end

@ -0,0 +1,84 @@
# Redmine - project management software
# Copyright (C) 2006-2013 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.expand_path('../../test_helper', __FILE__)
class CalendarsControllerTest < ActionController::TestCase
fixtures :projects,
:trackers,
:projects_trackers,
:roles,
:member_roles,
:members,
:enabled_modules
def test_show
get :show, :project_id => 1
assert_response :success
assert_template 'calendar'
assert_not_nil assigns(:calendar)
end
def test_show_should_run_custom_queries
@query = IssueQuery.create!(:name => 'Calendar', :is_public => true)
get :show, :query_id => @query.id
assert_response :success
end
def test_cross_project_calendar
get :show
assert_response :success
assert_template 'calendar'
assert_not_nil assigns(:calendar)
end
def test_week_number_calculation
Setting.start_of_week = 7
get :show, :month => '1', :year => '2010'
assert_response :success
assert_select 'tr' do
assert_select 'td.week-number', :text => '53'
assert_select 'td.odd', :text => '27'
assert_select 'td.even', :text => '2'
end
assert_select 'tr' do
assert_select 'td.week-number', :text => '1'
assert_select 'td.odd', :text => '3'
assert_select 'td.even', :text => '9'
end
Setting.start_of_week = 1
get :show, :month => '1', :year => '2010'
assert_response :success
assert_select 'tr' do
assert_select 'td.week-number', :text => '53'
assert_select 'td.even', :text => '28'
assert_select 'td.even', :text => '3'
end
assert_select 'tr' do
assert_select 'td.week-number', :text => '1'
assert_select 'td.even', :text => '4'
assert_select 'td.even', :text => '10'
end
end
end

@ -0,0 +1,64 @@
# Redmine - project management software
# Copyright (C) 2006-2013 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.expand_path('../../test_helper', __FILE__)
class CommentsControllerTest < ActionController::TestCase
fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :news, :comments
def setup
User.current = nil
end
def test_add_comment
@request.session[:user_id] = 2
post :create, :id => 1, :comment => { :comments => 'This is a test comment' }
assert_redirected_to '/news/1'
comment = News.find(1).comments.last
assert_not_nil comment
assert_equal 'This is a test comment', comment.comments
assert_equal User.find(2), comment.author
end
def test_empty_comment_should_not_be_added
@request.session[:user_id] = 2
assert_no_difference 'Comment.count' do
post :create, :id => 1, :comment => { :comments => '' }
assert_response :redirect
assert_redirected_to '/news/1'
end
end
def test_create_should_be_denied_if_news_is_not_commentable
News.any_instance.stubs(:commentable?).returns(false)
@request.session[:user_id] = 2
assert_no_difference 'Comment.count' do
post :create, :id => 1, :comment => { :comments => 'This is a test comment' }
assert_response 403
end
end
def test_destroy_comment
comments_count = News.find(1).comments.size
@request.session[:user_id] = 2
delete :destroy, :id => 1, :comment_id => 2
assert_redirected_to '/news/1'
assert_nil Comment.find_by_id(2)
assert_equal comments_count - 1, News.find(1).comments.size
end
end

File diff suppressed because it is too large Load Diff

@ -0,0 +1,176 @@
# Redmine - project management software
# Copyright (C) 2006-2013 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.expand_path('../../test_helper', __FILE__)
class CustomFieldsControllerTest < ActionController::TestCase
fixtures :custom_fields, :custom_values, :trackers, :users
def setup
@request.session[:user_id] = 1
end
def test_index
get :index
assert_response :success
assert_template 'index'
end
def test_new
custom_field_classes.each do |klass|
get :new, :type => klass.name
assert_response :success
assert_template 'new'
assert_kind_of klass, assigns(:custom_field)
assert_select 'form#custom_field_form' do
assert_select 'select#custom_field_field_format[name=?]', 'custom_field[field_format]'
assert_select 'input[type=hidden][name=type][value=?]', klass.name
end
end
end
def test_new_issue_custom_field
get :new, :type => 'IssueCustomField'
assert_response :success
assert_template 'new'
assert_select 'form#custom_field_form' do
assert_select 'select#custom_field_field_format[name=?]', 'custom_field[field_format]' do
assert_select 'option[value=user]', :text => 'User'
assert_select 'option[value=version]', :text => 'Version'
end
assert_select 'input[type=hidden][name=type][value=IssueCustomField]'
end
end
def test_default_value_should_be_an_input_for_string_custom_field
get :new, :type => 'IssueCustomField', :custom_field => {:field_format => 'string'}
assert_response :success
assert_select 'input[name=?]', 'custom_field[default_value]'
end
def test_default_value_should_be_a_textarea_for_text_custom_field
get :new, :type => 'IssueCustomField', :custom_field => {:field_format => 'text'}
assert_response :success
assert_select 'textarea[name=?]', 'custom_field[default_value]'
end
def test_default_value_should_be_a_checkbox_for_bool_custom_field
get :new, :type => 'IssueCustomField', :custom_field => {:field_format => 'bool'}
assert_response :success
assert_select 'input[name=?][type=checkbox]', 'custom_field[default_value]'
end
def test_default_value_should_not_be_present_for_user_custom_field
get :new, :type => 'IssueCustomField', :custom_field => {:field_format => 'user'}
assert_response :success
assert_select '[name=?]', 'custom_field[default_value]', 0
end
def test_new_js
get :new, :type => 'IssueCustomField', :custom_field => {:field_format => 'list'}, :format => 'js'
assert_response :success
assert_template 'new'
assert_equal 'text/javascript', response.content_type
field = assigns(:custom_field)
assert_equal 'list', field.field_format
end
def test_new_with_invalid_custom_field_class_should_render_404
get :new, :type => 'UnknownCustomField'
assert_response 404
end
def test_create_list_custom_field
assert_difference 'CustomField.count' do
post :create, :type => "IssueCustomField",
:custom_field => {:name => "test_post_new_list",
:default_value => "",
:min_length => "0",
:searchable => "0",
:regexp => "",
:is_for_all => "1",
:possible_values => "0.1\n0.2\n",
:max_length => "0",
:is_filter => "0",
:is_required =>"0",
:field_format => "list",
:tracker_ids => ["1", ""]}
end
assert_redirected_to '/custom_fields?tab=IssueCustomField'
field = IssueCustomField.find_by_name('test_post_new_list')
assert_not_nil field
assert_equal ["0.1", "0.2"], field.possible_values
assert_equal 1, field.trackers.size
end
def test_create_with_failure
assert_no_difference 'CustomField.count' do
post :create, :type => "IssueCustomField", :custom_field => {:name => ''}
end
assert_response :success
assert_template 'new'
end
def test_edit
get :edit, :id => 1
assert_response :success
assert_template 'edit'
assert_tag 'input', :attributes => {:name => 'custom_field[name]', :value => 'Database'}
end
def test_edit_invalid_custom_field_should_render_404
get :edit, :id => 99
assert_response 404
end
def test_update
put :update, :id => 1, :custom_field => {:name => 'New name'}
assert_redirected_to '/custom_fields?tab=IssueCustomField'
field = CustomField.find(1)
assert_equal 'New name', field.name
end
def test_update_with_failure
put :update, :id => 1, :custom_field => {:name => ''}
assert_response :success
assert_template 'edit'
end
def test_destroy
custom_values_count = CustomValue.count(:conditions => {:custom_field_id => 1})
assert custom_values_count > 0
assert_difference 'CustomField.count', -1 do
assert_difference 'CustomValue.count', - custom_values_count do
delete :destroy, :id => 1
end
end
assert_redirected_to '/custom_fields?tab=IssueCustomField'
assert_nil CustomField.find_by_id(1)
assert_nil CustomValue.find_by_custom_field_id(1)
end
def custom_field_classes
files = Dir.glob(File.join(Rails.root, 'app/models/*_custom_field.rb')).map {|f| File.basename(f).sub(/\.rb$/, '') }
classes = files.map(&:classify).map(&:constantize)
assert classes.size > 0
classes
end
end

@ -0,0 +1,186 @@
# Redmine - project management software
# Copyright (C) 2006-2013 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.expand_path('../../test_helper', __FILE__)
class DocumentsControllerTest < ActionController::TestCase
fixtures :projects, :users, :roles, :members, :member_roles,
:enabled_modules, :documents, :enumerations,
:groups_users, :attachments
def setup
User.current = nil
end
def test_index
# Sets a default category
e = Enumeration.find_by_name('Technical documentation')
e.update_attributes(:is_default => true)
get :index, :project_id => 'ecookbook'
assert_response :success
assert_template 'index'
assert_not_nil assigns(:grouped)
# Default category selected in the new document form
assert_tag :select, :attributes => {:name => 'document[category_id]'},
:child => {:tag => 'option', :attributes => {:selected => 'selected'},
:content => 'Technical documentation'}
assert ! DocumentCategory.find(16).active?
assert_no_tag :option, :attributes => {:value => '16'},
:parent => {:tag => 'select', :attributes => {:id => 'document_category_id'} }
end
def test_index_grouped_by_date
get :index, :project_id => 'ecookbook', :sort_by => 'date'
assert_response :success
assert_tag 'h3', :content => '2007-02-12'
end
def test_index_grouped_by_title
get :index, :project_id => 'ecookbook', :sort_by => 'title'
assert_response :success
assert_tag 'h3', :content => 'T'
end
def test_index_grouped_by_author
get :index, :project_id => 'ecookbook', :sort_by => 'author'
assert_response :success
assert_tag 'h3', :content => 'John Smith'
end
def test_index_with_long_description
# adds a long description to the first document
doc = documents(:documents_001)
doc.update_attributes(:description => <<LOREM)
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut egestas, mi vehicula varius varius, ipsum massa fermentum orci, eget tristique ante sem vel mi. Nulla facilisi. Donec enim libero, luctus ac sagittis sit amet, vehicula sagittis magna. Duis ultrices molestie ante, eget scelerisque sem iaculis vitae. Etiam fermentum mauris vitae metus pharetra condimentum fermentum est pretium. Proin sollicitudin elementum quam quis pharetra. Aenean facilisis nunc quis elit volutpat mollis. Aenean eleifend varius euismod. Ut dolor est, congue eget dapibus eget, elementum eu odio. Integer et lectus neque, nec scelerisque nisi. EndOfLineHere
Vestibulum non velit mi. Aliquam scelerisque libero ut nulla fringilla a sollicitudin magna rhoncus. Praesent a nunc lorem, ac porttitor eros. Sed ac diam nec neque interdum adipiscing quis quis justo. Donec arcu nunc, fringilla eu dictum at, venenatis ac sem. Vestibulum quis elit urna, ac mattis sapien. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
LOREM
get :index, :project_id => 'ecookbook'
assert_response :success
assert_template 'index'
# should only truncate on new lines to avoid breaking wiki formatting
assert_select '.wiki p', :text => (doc.description.split("\n").first + '...')
assert_select '.wiki p', :text => Regexp.new(Regexp.escape("EndOfLineHere..."))
end
def test_show
get :show, :id => 1
assert_response :success
assert_template 'show'
end
def test_new
@request.session[:user_id] = 2
get :new, :project_id => 1
assert_response :success
assert_template 'new'
end
def test_create_with_one_attachment
ActionMailer::Base.deliveries.clear
@request.session[:user_id] = 2
set_tmp_attachments_directory
with_settings :notified_events => %w(document_added) do
post :create, :project_id => 'ecookbook',
:document => { :title => 'DocumentsControllerTest#test_post_new',
:description => 'This is a new document',
:category_id => 2},
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
end
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
assert_equal 1, ActionMailer::Base.deliveries.size
end
def test_create_with_failure
@request.session[:user_id] = 2
assert_no_difference 'Document.count' do
post :create, :project_id => 'ecookbook', :document => { :title => ''}
end
assert_response :success
assert_template 'new'
end
def test_create_non_default_category
@request.session[:user_id] = 2
category2 = Enumeration.find_by_name('User documentation')
category2.update_attributes(:is_default => true)
category1 = Enumeration.find_by_name('Uncategorized')
post :create,
:project_id => 'ecookbook',
:document => { :title => 'no default',
:description => 'This is a new document',
:category_id => category1.id }
assert_redirected_to '/projects/ecookbook/documents'
doc = Document.find_by_title('no default')
assert_not_nil doc
assert_equal category1.id, doc.category_id
assert_equal category1, doc.category
end
def test_edit
@request.session[:user_id] = 2
get :edit, :id => 1
assert_response :success
assert_template 'edit'
end
def test_update
@request.session[:user_id] = 2
put :update, :id => 1, :document => {:title => 'test_update'}
assert_redirected_to '/documents/1'
document = Document.find(1)
assert_equal 'test_update', document.title
end
def test_update_with_failure
@request.session[:user_id] = 2
put :update, :id => 1, :document => {:title => ''}
assert_response :success
assert_template 'edit'
end
def test_destroy
@request.session[:user_id] = 2
assert_difference 'Document.count', -1 do
delete :destroy, :id => 1
end
assert_redirected_to '/projects/ecookbook/documents'
assert_nil Document.find_by_id(1)
end
def test_add_attachment
@request.session[:user_id] = 2
assert_difference 'Attachment.count' do
post :add_attachment, :id => 1,
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
end
attachment = Attachment.first(:order => 'id DESC')
assert_equal Document.find(1), attachment.container
end
end

@ -0,0 +1,136 @@
# Redmine - project management software
# Copyright (C) 2006-2013 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.expand_path('../../test_helper', __FILE__)
class EnumerationsControllerTest < ActionController::TestCase
fixtures :enumerations, :issues, :users
def setup
@request.session[:user_id] = 1 # admin
end
def test_index
get :index
assert_response :success
assert_template 'index'
end
def test_index_should_require_admin
@request.session[:user_id] = nil
get :index
assert_response 302
end
def test_new
get :new, :type => 'IssuePriority'
assert_response :success
assert_template 'new'
assert_kind_of IssuePriority, assigns(:enumeration)
assert_tag 'input', :attributes => {:name => 'enumeration[type]', :value => 'IssuePriority'}
assert_tag 'input', :attributes => {:name => 'enumeration[name]'}
end
def test_new_with_invalid_type_should_respond_with_404
get :new, :type => 'UnknownType'
assert_response 404
end
def test_create
assert_difference 'IssuePriority.count' do
post :create, :enumeration => {:type => 'IssuePriority', :name => 'Lowest'}
end
assert_redirected_to '/enumerations'
e = IssuePriority.find_by_name('Lowest')
assert_not_nil e
end
def test_create_with_failure
assert_no_difference 'IssuePriority.count' do
post :create, :enumeration => {:type => 'IssuePriority', :name => ''}
end
assert_response :success
assert_template 'new'
end
def test_edit
get :edit, :id => 6
assert_response :success
assert_template 'edit'
assert_tag 'input', :attributes => {:name => 'enumeration[name]', :value => 'High'}
end
def test_edit_invalid_should_respond_with_404
get :edit, :id => 999
assert_response 404
end
def test_update
assert_no_difference 'IssuePriority.count' do
put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => 'New name'}
end
assert_redirected_to '/enumerations'
e = IssuePriority.find(6)
assert_equal 'New name', e.name
end
def test_update_with_failure
assert_no_difference 'IssuePriority.count' do
put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => ''}
end
assert_response :success
assert_template 'edit'
end
def test_destroy_enumeration_not_in_use
assert_difference 'IssuePriority.count', -1 do
delete :destroy, :id => 7
end
assert_redirected_to :controller => 'enumerations', :action => 'index'
assert_nil Enumeration.find_by_id(7)
end
def test_destroy_enumeration_in_use
assert_no_difference 'IssuePriority.count' do
delete :destroy, :id => 4
end
assert_response :success
assert_template 'destroy'
assert_not_nil Enumeration.find_by_id(4)
assert_select 'select[name=reassign_to_id]' do
assert_select 'option[value=6]', :text => 'High'
end
end
def test_destroy_enumeration_in_use_with_reassignment
issue = Issue.where(:priority_id => 4).first
assert_difference 'IssuePriority.count', -1 do
delete :destroy, :id => 4, :reassign_to_id => 6
end
assert_redirected_to :controller => 'enumerations', :action => 'index'
assert_nil Enumeration.find_by_id(4)
# check that the issue was reassign
assert_equal 6, issue.reload.priority_id
end
def test_destroy_enumeration_in_use_with_blank_reassignment
assert_no_difference 'IssuePriority.count' do
delete :destroy, :id => 4, :reassign_to_id => ''
end
assert_response :success
end
end

@ -0,0 +1,109 @@
# Redmine - project management software
# Copyright (C) 2006-2013 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.expand_path('../../test_helper', __FILE__)
class FilesControllerTest < ActionController::TestCase
fixtures :projects, :trackers, :issue_statuses, :issues,
:enumerations, :users, :issue_categories,
:projects_trackers,
:roles,
:member_roles,
:members,
:enabled_modules,
:journals, :journal_details,
:attachments,
:versions
def setup
@request.session[:user_id] = nil
Setting.default_language = 'en'
end
def test_index
get :index, :project_id => 1
assert_response :success
assert_template 'index'
assert_not_nil assigns(:containers)
# file attached to the project
assert_tag :a, :content => 'project_file.zip',
:attributes => { :href => '/attachments/download/8/project_file.zip' }
# file attached to a project's version
assert_tag :a, :content => 'version_file.zip',
:attributes => { :href => '/attachments/download/9/version_file.zip' }
end
def test_new
@request.session[:user_id] = 2
get :new, :project_id => 1
assert_response :success
assert_template 'new'
assert_tag 'select', :attributes => {:name => 'version_id'}
end
def test_new_without_versions
Version.delete_all
@request.session[:user_id] = 2
get :new, :project_id => 1
assert_response :success
assert_template 'new'
assert_no_tag 'select', :attributes => {:name => 'version_id'}
end
def test_create_file
set_tmp_attachments_directory
@request.session[:user_id] = 2
ActionMailer::Base.deliveries.clear
with_settings :notified_events => %w(file_added) do
assert_difference 'Attachment.count' do
post :create, :project_id => 1, :version_id => '',
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
assert_response :redirect
end
end
assert_redirected_to '/projects/ecookbook/files'
a = Attachment.order('created_on DESC').first
assert_equal 'testfile.txt', a.filename
assert_equal Project.find(1), a.container
mail = ActionMailer::Base.deliveries.last
assert_not_nil mail
assert_equal "[eCookbook] New file", mail.subject
assert_mail_body_match 'testfile.txt', mail
end
def test_create_version_file
set_tmp_attachments_directory
@request.session[:user_id] = 2
assert_difference 'Attachment.count' do
post :create, :project_id => 1, :version_id => '2',
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
assert_response :redirect
end
assert_redirected_to '/projects/ecookbook/files'
a = Attachment.order('created_on DESC').first
assert_equal 'testfile.txt', a.filename
assert_equal Version.find(2), a.container
end
end

@ -0,0 +1,122 @@
# Redmine - project management software
# Copyright (C) 2006-2013 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.expand_path('../../test_helper', __FILE__)
class GanttsControllerTest < ActionController::TestCase
fixtures :projects, :trackers, :issue_statuses, :issues,
:enumerations, :users, :issue_categories,
:projects_trackers,
:roles,
:member_roles,
:members,
:enabled_modules,
:versions
def test_gantt_should_work
i2 = Issue.find(2)
i2.update_attribute(:due_date, 1.month.from_now)
get :show, :project_id => 1
assert_response :success
assert_template 'gantts/show'
assert_not_nil assigns(:gantt)
# Issue with start and due dates
i = Issue.find(1)
assert_not_nil i.due_date
assert_select "div a.issue", /##{i.id}/
# Issue with on a targeted version should not be in the events but loaded in the html
i = Issue.find(2)
assert_select "div a.issue", /##{i.id}/
end
def test_gantt_should_work_without_issue_due_dates
Issue.update_all("due_date = NULL")
get :show, :project_id => 1
assert_response :success
assert_template 'gantts/show'
assert_not_nil assigns(:gantt)
end
def test_gantt_should_work_without_issue_and_version_due_dates
Issue.update_all("due_date = NULL")
Version.update_all("effective_date = NULL")
get :show, :project_id => 1
assert_response :success
assert_template 'gantts/show'
assert_not_nil assigns(:gantt)
end
def test_gantt_should_work_cross_project
get :show
assert_response :success
assert_template 'gantts/show'
assert_not_nil assigns(:gantt)
assert_not_nil assigns(:gantt).query
assert_nil assigns(:gantt).project
end
def test_gantt_should_not_disclose_private_projects
get :show
assert_response :success
assert_template 'gantts/show'
assert_tag 'a', :content => /eCookbook/
# Root private project
assert_no_tag 'a', {:content => /OnlineStore/}
# Private children of a public project
assert_no_tag 'a', :content => /Private child of eCookbook/
end
def test_gantt_should_display_relations
IssueRelation.delete_all
issue1 = Issue.generate!(:start_date => 1.day.from_now, :due_date => 3.day.from_now)
issue2 = Issue.generate!(:start_date => 1.day.from_now, :due_date => 3.day.from_now)
IssueRelation.create!(:issue_from => issue1, :issue_to => issue2, :relation_type => 'precedes')
get :show
assert_response :success
relations = assigns(:gantt).relations
assert_kind_of Hash, relations
assert relations.present?
assert_select 'div.task_todo[id=?][data-rels*=?]', "task-todo-issue-#{issue1.id}", issue2.id.to_s
assert_select 'div.task_todo[id=?]:not([data-rels])', "task-todo-issue-#{issue2.id}"
end
def test_gantt_should_export_to_pdf
get :show, :project_id => 1, :format => 'pdf'
assert_response :success
assert_equal 'application/pdf', @response.content_type
assert @response.body.starts_with?('%PDF')
assert_not_nil assigns(:gantt)
end
def test_gantt_should_export_to_pdf_cross_project
get :show, :format => 'pdf'
assert_response :success
assert_equal 'application/pdf', @response.content_type
assert @response.body.starts_with?('%PDF')
assert_not_nil assigns(:gantt)
end
if Object.const_defined?(:Magick)
def test_gantt_should_export_to_png
get :show, :project_id => 1, :format => 'png'
assert_response :success
assert_equal 'image/png', @response.content_type
end
end
end

@ -0,0 +1,202 @@
# Redmine - project management software
# Copyright (C) 2006-2013 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.expand_path('../../test_helper', __FILE__)
class GroupsControllerTest < ActionController::TestCase
fixtures :projects, :users, :members, :member_roles, :roles, :groups_users
def setup
@request.session[:user_id] = 1
end
def test_index
get :index
assert_response :success
assert_template 'index'
end
def test_show
get :show, :id => 10
assert_response :success
assert_template 'show'
end
def test_show_invalid_should_return_404
get :show, :id => 99
assert_response 404
end
def test_new
get :new
assert_response :success
assert_template 'new'
assert_select 'input[name=?]', 'group[name]'
end
def test_create
assert_difference 'Group.count' do
post :create, :group => {:name => 'New group'}
end
assert_redirected_to '/groups'
group = Group.first(:order => 'id DESC')
assert_equal 'New group', group.name
assert_equal [], group.users
end
def test_create_and_continue
assert_difference 'Group.count' do
post :create, :group => {:name => 'New group'}, :continue => 'Create and continue'
end
assert_redirected_to '/groups/new'
group = Group.first(:order => 'id DESC')
assert_equal 'New group', group.name
end
def test_create_with_failure
assert_no_difference 'Group.count' do
post :create, :group => {:name => ''}
end
assert_response :success
assert_template 'new'
end
def test_edit
get :edit, :id => 10
assert_response :success
assert_template 'edit'
assert_select 'div#tab-content-users'
assert_select 'div#tab-content-memberships' do
assert_select 'a', :text => 'Private child of eCookbook'
end
end
def test_update
new_name = 'New name'
put :update, :id => 10, :group => {:name => new_name}
assert_redirected_to '/groups'
group = Group.find(10)
assert_equal new_name, group.name
end
def test_update_with_failure
put :update, :id => 10, :group => {:name => ''}
assert_response :success
assert_template 'edit'
end
def test_destroy
assert_difference 'Group.count', -1 do
post :destroy, :id => 10
end
assert_redirected_to '/groups'
end
def test_add_users
assert_difference 'Group.find(10).users.count', 2 do
post :add_users, :id => 10, :user_ids => ['2', '3']
end
end
def test_xhr_add_users
assert_difference 'Group.find(10).users.count', 2 do
xhr :post, :add_users, :id => 10, :user_ids => ['2', '3']
assert_response :success
assert_template 'add_users'
assert_equal 'text/javascript', response.content_type
end
assert_match /John Smith/, response.body
end
def test_remove_user
assert_difference 'Group.find(10).users.count', -1 do
delete :remove_user, :id => 10, :user_id => '8'
end
end
def test_xhr_remove_user
assert_difference 'Group.find(10).users.count', -1 do
xhr :delete, :remove_user, :id => 10, :user_id => '8'
assert_response :success
assert_template 'remove_user'
assert_equal 'text/javascript', response.content_type
end
end
def test_new_membership
assert_difference 'Group.find(10).members.count' do
post :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']}
end
end
def test_xhr_new_membership
assert_difference 'Group.find(10).members.count' do
xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']}
assert_response :success
assert_template 'edit_membership'
assert_equal 'text/javascript', response.content_type
end
assert_match /OnlineStore/, response.body
end
def test_xhr_new_membership_with_failure
assert_no_difference 'Group.find(10).members.count' do
xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 999, :role_ids => ['1', '2']}
assert_response :success
assert_template 'edit_membership'
assert_equal 'text/javascript', response.content_type
end
assert_match /alert/, response.body, "Alert message not sent"
end
def test_edit_membership
assert_no_difference 'Group.find(10).members.count' do
post :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']}
end
end
def test_xhr_edit_membership
assert_no_difference 'Group.find(10).members.count' do
xhr :post, :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']}
assert_response :success
assert_template 'edit_membership'
assert_equal 'text/javascript', response.content_type
end
end
def test_destroy_membership
assert_difference 'Group.find(10).members.count', -1 do
post :destroy_membership, :id => 10, :membership_id => 6
end
end
def test_xhr_destroy_membership
assert_difference 'Group.find(10).members.count', -1 do
xhr :post, :destroy_membership, :id => 10, :membership_id => 6
assert_response :success
assert_template 'destroy_membership'
assert_equal 'text/javascript', response.content_type
end
end
def test_autocomplete_for_user
get :autocomplete_for_user, :id => 10, :q => 'smi', :format => 'js'
assert_response :success
assert_include 'John Smith', response.body
end
end

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,147 @@
# Redmine - project management software
# Copyright (C) 2006-2013 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.expand_path('../../test_helper', __FILE__)
class JournalsControllerTest < ActionController::TestCase
fixtures :projects, :users, :members, :member_roles, :roles, :issues, :journals, :journal_details, :enabled_modules,
:trackers, :issue_statuses, :enumerations, :custom_fields, :custom_values, :custom_fields_projects
def setup
User.current = nil
end
def test_index
get :index, :project_id => 1
assert_response :success
assert_not_nil assigns(:journals)
assert_equal 'application/atom+xml', @response.content_type
end
def test_index_should_return_privates_notes_with_permission_only
journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
@request.session[:user_id] = 2
get :index, :project_id => 1
assert_response :success
assert_include journal, assigns(:journals)
Role.find(1).remove_permission! :view_private_notes
get :index, :project_id => 1
assert_response :success
assert_not_include journal, assigns(:journals)
end
def test_diff
get :diff, :id => 3, :detail_id => 4
assert_response :success
assert_template 'diff'
assert_tag 'span',
:attributes => {:class => 'diff_out'},
:content => /removed/
assert_tag 'span',
:attributes => {:class => 'diff_in'},
:content => /added/
end
def test_reply_to_issue
@request.session[:user_id] = 2
xhr :get, :new, :id => 6
assert_response :success
assert_template 'new'
assert_equal 'text/javascript', response.content_type
assert_include '> This is an issue', response.body
end
def test_reply_to_issue_without_permission
@request.session[:user_id] = 7
xhr :get, :new, :id => 6
assert_response 403
end
def test_reply_to_note
@request.session[:user_id] = 2
xhr :get, :new, :id => 6, :journal_id => 4
assert_response :success
assert_template 'new'
assert_equal 'text/javascript', response.content_type
assert_include '> A comment with a private version', response.body
end
def test_reply_to_private_note_should_fail_without_permission
journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true)
@request.session[:user_id] = 2
xhr :get, :new, :id => 2, :journal_id => journal.id
assert_response :success
assert_template 'new'
assert_equal 'text/javascript', response.content_type
assert_include '> Privates notes', response.body
Role.find(1).remove_permission! :view_private_notes
xhr :get, :new, :id => 2, :journal_id => journal.id
assert_response 404
end
def test_edit_xhr
@request.session[:user_id] = 1
xhr :get, :edit, :id => 2
assert_response :success
assert_template 'edit'
assert_equal 'text/javascript', response.content_type
assert_include 'textarea', response.body
end
def test_edit_private_note_should_fail_without_permission
journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true)
@request.session[:user_id] = 2
Role.find(1).add_permission! :edit_issue_notes
xhr :get, :edit, :id => journal.id
assert_response :success
assert_template 'edit'
assert_equal 'text/javascript', response.content_type
assert_include 'textarea', response.body
Role.find(1).remove_permission! :view_private_notes
xhr :get, :edit, :id => journal.id
assert_response 404
end
def test_update_xhr
@request.session[:user_id] = 1
xhr :post, :edit, :id => 2, :notes => 'Updated notes'
assert_response :success
assert_template 'update'
assert_equal 'text/javascript', response.content_type
assert_equal 'Updated notes', Journal.find(2).notes
assert_include 'journal-2-notes', response.body
end
def test_update_xhr_with_empty_notes_should_delete_the_journal
@request.session[:user_id] = 1
assert_difference 'Journal.count', -1 do
xhr :post, :edit, :id => 2, :notes => ''
assert_response :success
assert_template 'update'
assert_equal 'text/javascript', response.content_type
end
assert_nil Journal.find_by_id(2)
assert_include 'change-2', response.body
end
end

@ -0,0 +1,74 @@
# Redmine - project management software
# Copyright (C) 2006-2013 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.expand_path('../../test_helper', __FILE__)
class MailHandlerControllerTest < ActionController::TestCase
fixtures :users, :projects, :enabled_modules, :roles, :members, :member_roles, :issues, :issue_statuses,
:trackers, :projects_trackers, :enumerations
FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler'
def setup
User.current = nil
end
def test_should_create_issue
# Enable API and set a key
Setting.mail_handler_api_enabled = 1
Setting.mail_handler_api_key = 'secret'
assert_difference 'Issue.count' do
post :index, :key => 'secret', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
end
assert_response 201
end
def test_should_respond_with_422_if_not_created
Project.find('onlinestore').destroy
Setting.mail_handler_api_enabled = 1
Setting.mail_handler_api_key = 'secret'
assert_no_difference 'Issue.count' do
post :index, :key => 'secret', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
end
assert_response 422
end
def test_should_not_allow_with_api_disabled
# Disable API
Setting.mail_handler_api_enabled = 0
Setting.mail_handler_api_key = 'secret'
assert_no_difference 'Issue.count' do
post :index, :key => 'secret', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
end
assert_response 403
end
def test_should_not_allow_with_wrong_key
# Disable API
Setting.mail_handler_api_enabled = 1
Setting.mail_handler_api_key = 'secret'
assert_no_difference 'Issue.count' do
post :index, :key => 'wrong', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
end
assert_response 403
end
end

@ -0,0 +1,111 @@
# Redmine - project management software
# Copyright (C) 2006-2013 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.expand_path('../../test_helper', __FILE__)
class MembersControllerTest < ActionController::TestCase
fixtures :projects, :members, :member_roles, :roles, :users
def setup
User.current = nil
@request.session[:user_id] = 2
end
def test_create
assert_difference 'Member.count' do
post :create, :project_id => 1, :membership => {:role_ids => [1], :user_id => 7}
end
assert_redirected_to '/projects/ecookbook/settings/members'
assert User.find(7).member_of?(Project.find(1))
end
def test_create_multiple
assert_difference 'Member.count', 3 do
post :create, :project_id => 1, :membership => {:role_ids => [1], :user_ids => [7, 8, 9]}
end
assert_redirected_to '/projects/ecookbook/settings/members'
assert User.find(7).member_of?(Project.find(1))
end
def test_xhr_create
assert_difference 'Member.count', 3 do
xhr :post, :create, :project_id => 1, :membership => {:role_ids => [1], :user_ids => [7, 8, 9]}
assert_response :success
assert_template 'create'
assert_equal 'text/javascript', response.content_type
end
assert User.find(7).member_of?(Project.find(1))
assert User.find(8).member_of?(Project.find(1))
assert User.find(9).member_of?(Project.find(1))
assert_include 'tab-content-members', response.body
end
def test_xhr_create_with_failure
assert_no_difference 'Member.count' do
xhr :post, :create, :project_id => 1, :membership => {:role_ids => [], :user_ids => [7, 8, 9]}
assert_response :success
assert_template 'create'
assert_equal 'text/javascript', response.content_type
end
assert_match /alert/, response.body, "Alert message not sent"
end
def test_edit
assert_no_difference 'Member.count' do
put :update, :id => 2, :membership => {:role_ids => [1], :user_id => 3}
end
assert_redirected_to '/projects/ecookbook/settings/members'
end
def test_xhr_edit
assert_no_difference 'Member.count' do
xhr :put, :update, :id => 2, :membership => {:role_ids => [1], :user_id => 3}
assert_response :success
assert_template 'update'
assert_equal 'text/javascript', response.content_type
end
member = Member.find(2)
assert_equal [1], member.role_ids
assert_equal 3, member.user_id
assert_include 'tab-content-members', response.body
end
def test_destroy
assert_difference 'Member.count', -1 do
delete :destroy, :id => 2
end
assert_redirected_to '/projects/ecookbook/settings/members'
assert !User.find(3).member_of?(Project.find(1))
end
def test_xhr_destroy
assert_difference 'Member.count', -1 do
xhr :delete, :destroy, :id => 2
assert_response :success
assert_template 'destroy'
assert_equal 'text/javascript', response.content_type
end
assert_nil Member.find_by_id(2)
assert_include 'tab-content-members', response.body
end
def test_autocomplete
get :autocomplete, :project_id => 1, :q => 'mis', :format => 'js'
assert_response :success
assert_include 'User Misc', response.body
end
end

@ -0,0 +1,217 @@
# Redmine - project management software
# Copyright (C) 2006-2013 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.expand_path('../../test_helper', __FILE__)
class MessagesControllerTest < ActionController::TestCase
fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
def setup
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_should_contain_reply_field_tags_for_quoting
@request.session[:user_id] = 2
get :show, :board_id => 1, :id => 1
assert_response :success
# tags required by MessagesController#quote
assert_tag 'input', :attributes => {:id => 'message_subject'}
assert_tag 'textarea', :attributes => {:id => 'message_content'}
assert_tag 'div', :attributes => {:id => 'reply'}
end
def test_show_with_pagination
message = Message.find(1)
assert_difference 'Message.count', 30 do
30.times do
message.children << Message.new(:subject => 'Reply', :content => 'Reply body', :author_id => 2, :board_id => 1)
end
end
get :show, :board_id => 1, :id => 1, :r => message.children.last(:order => 'id').id
assert_response :success
assert_template 'show'
replies = assigns(:replies)
assert_not_nil replies
assert !replies.include?(message.children.first(:order => 'id'))
assert replies.include?(message.children.last(:order => 'id'))
end
def test_show_with_reply_permission
@request.session[:user_id] = 2
get :show, :board_id => 1, :id => 1
assert_response :success
assert_template 'show'
assert_tag :div, :attributes => { :id => 'reply' },
:descendant => { :tag => 'textarea', :attributes => { :id => 'message_content' } }
end
def test_show_message_not_found
get :show, :board_id => 1, :id => 99999
assert_response 404
end
def test_show_message_from_invalid_board_should_respond_with_404
get :show, :board_id => 999, :id => 1
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_get_new_with_invalid_board
@request.session[:user_id] = 2
get :new, :board_id => 99
assert_response 404
end
def test_post_new
@request.session[:user_id] = 2
ActionMailer::Base.deliveries.clear
with_settings :notified_events => %w(message_posted) do
post :new, :board_id => 1,
:message => { :subject => 'Test created message',
:content => 'Message body'}
end
message = Message.find_by_subject('Test created message')
assert_not_nil message
assert_redirected_to "/boards/1/topics/#{message.to_param}"
assert_equal 'Message body', message.content
assert_equal 2, message.author_id
assert_equal 1, message.board_id
mail = ActionMailer::Base.deliveries.last
assert_not_nil mail
assert_equal "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] Test created message", mail.subject
assert_mail_body_match 'Message body', mail
# 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 '/boards/1/topics/1'
message = Message.find(1)
assert_equal 'New subject', message.subject
assert_equal 'New body', message.content
end
def test_post_edit_sticky_and_locked
@request.session[:user_id] = 2
post :edit, :board_id => 1, :id => 1,
:message => { :subject => 'New subject',
:content => 'New body',
:locked => '1',
:sticky => '1'}
assert_redirected_to '/boards/1/topics/1'
message = Message.find(1)
assert_equal true, message.sticky?
assert_equal true, message.locked?
end
def test_post_edit_should_allow_to_change_board
@request.session[:user_id] = 2
post :edit, :board_id => 1, :id => 1,
:message => { :subject => 'New subject',
:content => 'New body',
:board_id => 2}
assert_redirected_to '/boards/2/topics/1'
message = Message.find(1)
assert_equal Board.find(2), message.board
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' }
reply = Message.order('id DESC').first
assert_redirected_to "/boards/1/topics/1?r=#{reply.id}"
assert Message.find_by_subject('Test reply')
end
def test_destroy_topic
@request.session[:user_id] = 2
assert_difference 'Message.count', -3 do
post :destroy, :board_id => 1, :id => 1
end
assert_redirected_to '/projects/ecookbook/boards/1'
assert_nil Message.find_by_id(1)
end
def test_destroy_reply
@request.session[:user_id] = 2
assert_difference 'Message.count', -1 do
post :destroy, :board_id => 1, :id => 2
end
assert_redirected_to '/boards/1/topics/1?r=2'
assert_nil Message.find_by_id(2)
end
def test_quote
@request.session[:user_id] = 2
xhr :get, :quote, :board_id => 1, :id => 3
assert_response :success
assert_equal 'text/javascript', response.content_type
assert_template 'quote'
assert_include 'RE: First post', response.body
assert_include '> An other reply', response.body
end
def test_preview_new
@request.session[:user_id] = 2
post :preview,
:board_id => 1,
:message => {:subject => "", :content => "Previewed text"}
assert_response :success
assert_template 'common/_preview'
end
def test_preview_edit
@request.session[:user_id] = 2
post :preview,
:id => 4,
:board_id => 1,
:message => {:subject => "", :content => "Previewed text"}
assert_response :success
assert_template 'common/_preview'
end
end

@ -0,0 +1,248 @@
# Redmine - project management software
# Copyright (C) 2006-2013 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.expand_path('../../test_helper', __FILE__)
class MyControllerTest < ActionController::TestCase
fixtures :users, :user_preferences, :roles, :projects, :members, :member_roles,
:issues, :issue_statuses, :trackers, :enumerations, :custom_fields, :auth_sources
def setup
@request.session[:user_id] = 2
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_page_with_timelog_block
preferences = User.find(2).pref
preferences[:my_page_layout] = {'top' => ['timelog']}
preferences.save!
TimeEntry.create!(:user => User.find(2), :spent_on => Date.yesterday, :issue_id => 1, :hours => 2.5, :activity_id => 10)
get :page
assert_response :success
assert_select 'tr.time-entry' do
assert_select 'td.subject a[href=/issues/1]'
assert_select 'td.hours', :text => '2.50'
end
end
def test_page_with_all_blocks
blocks = MyController::BLOCKS.keys
preferences = User.find(2).pref
preferences[:my_page_layout] = {'top' => blocks}
preferences.save!
get :page
assert_response :success
assert_select 'div.mypage-box', blocks.size
end
def test_my_account_should_show_editable_custom_fields
get :account
assert_response :success
assert_template 'account'
assert_equal User.find(2), assigns(:user)
assert_tag :input, :attributes => { :name => 'user[custom_field_values][4]'}
end
def test_my_account_should_not_show_non_editable_custom_fields
UserCustomField.find(4).update_attribute :editable, false
get :account
assert_response :success
assert_template 'account'
assert_equal User.find(2), assigns(:user)
assert_no_tag :input, :attributes => { :name => 'user[custom_field_values][4]'}
end
def test_update_account
post :account,
:user => {
:firstname => "Joe",
:login => "root",
:admin => 1,
:group_ids => ['10'],
:custom_field_values => {"4" => "0100562500"}
}
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_equal "0100562500", user.custom_value_for(4).value
# ignored
assert !user.admin?
assert user.groups.empty?
end
def test_my_account_should_show_destroy_link
get :account
assert_select 'a[href=/my/account/destroy]'
end
def test_get_destroy_should_display_the_destroy_confirmation
get :destroy
assert_response :success
assert_template 'destroy'
assert_select 'form[action=/my/account/destroy]' do
assert_select 'input[name=confirm]'
end
end
def test_post_destroy_without_confirmation_should_not_destroy_account
assert_no_difference 'User.count' do
post :destroy
end
assert_response :success
assert_template 'destroy'
end
def test_post_destroy_without_confirmation_should_destroy_account
assert_difference 'User.count', -1 do
post :destroy, :confirm => '1'
end
assert_redirected_to '/'
assert_match /deleted/i, flash[:notice]
end
def test_post_destroy_with_unsubscribe_not_allowed_should_not_destroy_account
User.any_instance.stubs(:own_account_deletable?).returns(false)
assert_no_difference 'User.count' do
post :destroy, :confirm => '1'
end
assert_redirected_to '/my/account'
end
def test_change_password
get :password
assert_response :success
assert_template 'password'
# non matching password confirmation
post :password, :password => 'jsmith',
:new_password => 'secret123',
:new_password_confirmation => 'secret1234'
assert_response :success
assert_template 'password'
assert_error_tag :content => /Password doesn&#x27;t match confirmation/
# wrong password
post :password, :password => 'wrongpassword',
:new_password => 'secret123',
:new_password_confirmation => 'secret123'
assert_response :success
assert_template 'password'
assert_equal 'Wrong password', flash[:error]
# good password
post :password, :password => 'jsmith',
:new_password => 'secret123',
:new_password_confirmation => 'secret123'
assert_redirected_to '/my/account'
assert User.try_to_login('jsmith', 'secret123')
end
def test_change_password_should_redirect_if_user_cannot_change_its_password
User.find(2).update_attribute(:auth_source_id, 1)
get :password
assert_not_nil flash[:error]
assert_redirected_to '/my/account'
end
def test_page_layout
get :page_layout
assert_response :success
assert_template 'page_layout'
end
def test_add_block
post :add_block, :block => 'issuesreportedbyme'
assert_redirected_to '/my/page_layout'
assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme')
end
def test_add_invalid_block_should_redirect
post :add_block, :block => 'invalid'
assert_redirected_to '/my/page_layout'
end
def test_remove_block
post :remove_block, :block => 'issuesassignedtome'
assert_redirected_to '/my/page_layout'
assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome')
end
def test_order_blocks
xhr :post, :order_blocks, :group => 'left', 'blocks' => ['documents', 'calendar', 'latestnews']
assert_response :success
assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left']
end
def test_reset_rss_key_with_existing_key
@previous_token_value = User.find(2).rss_key # Will generate one if it's missing
post :reset_rss_key
assert_not_equal @previous_token_value, User.find(2).rss_key
assert User.find(2).rss_token
assert_match /reset/, flash[:notice]
assert_redirected_to '/my/account'
end
def test_reset_rss_key_without_existing_key
assert_nil User.find(2).rss_token
post :reset_rss_key
assert User.find(2).rss_token
assert_match /reset/, flash[:notice]
assert_redirected_to '/my/account'
end
def test_reset_api_key_with_existing_key
@previous_token_value = User.find(2).api_key # Will generate one if it's missing
post :reset_api_key
assert_not_equal @previous_token_value, User.find(2).api_key
assert User.find(2).api_token
assert_match /reset/, flash[:notice]
assert_redirected_to '/my/account'
end
def test_reset_api_key_without_existing_key
assert_nil User.find(2).api_token
post :reset_api_key
assert User.find(2).api_token
assert_match /reset/, flash[:notice]
assert_redirected_to '/my/account'
end
end

@ -0,0 +1,165 @@
# Redmine - project management software
# Copyright (C) 2006-2013 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.expand_path('../../test_helper', __FILE__)
class NewsControllerTest < ActionController::TestCase
fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :news, :comments
def setup
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_index_with_invalid_project_should_respond_with_404
get :index, :project_id => 999
assert_response 404
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_should_show_attachments
attachment = Attachment.first
attachment.container = News.find(1)
attachment.save!
get :show, :id => 1
assert_response :success
assert_tag 'a', :content => attachment.filename
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_create
ActionMailer::Base.deliveries.clear
@request.session[:user_id] = 2
with_settings :notified_events => %w(news_added) do
post :create, :project_id => 1, :news => { :title => 'NewsControllerTest',
:description => 'This is the description',
:summary => '' }
end
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
assert_equal 1, ActionMailer::Base.deliveries.size
end
def test_post_create_with_attachment
set_tmp_attachments_directory
@request.session[:user_id] = 2
assert_difference 'News.count' do
assert_difference 'Attachment.count' do
post :create, :project_id => 1,
:news => { :title => 'Test', :description => 'This is the description' },
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
end
end
attachment = Attachment.first(:order => 'id DESC')
news = News.first(:order => 'id DESC')
assert_equal news, attachment.container
end
def test_post_create_with_validation_failure
@request.session[:user_id] = 2
post :create, :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_error_tag :content => /title can&#x27;t be blank/i
end
def test_get_edit
@request.session[:user_id] = 2
get :edit, :id => 1
assert_response :success
assert_template 'edit'
end
def test_put_update
@request.session[:user_id] = 2
put :update, :id => 1, :news => { :description => 'Description changed by test_post_edit' }
assert_redirected_to '/news/1'
news = News.find(1)
assert_equal 'Description changed by test_post_edit', news.description
end
def test_put_update_with_attachment
set_tmp_attachments_directory
@request.session[:user_id] = 2
assert_no_difference 'News.count' do
assert_difference 'Attachment.count' do
put :update, :id => 1,
:news => { :description => 'This is the description' },
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
end
end
attachment = Attachment.first(:order => 'id DESC')
assert_equal News.find(1), attachment.container
end
def test_update_with_failure
@request.session[:user_id] = 2
put :update, :id => 1, :news => { :description => '' }
assert_response :success
assert_template 'edit'
assert_error_tag :content => /description can&#x27;t be blank/i
end
def test_destroy
@request.session[:user_id] = 2
delete :destroy, :id => 1
assert_redirected_to '/projects/ecookbook/news'
assert_nil News.find_by_id(1)
end
end

@ -0,0 +1,81 @@
# Redmine - project management software
# Copyright (C) 2006-2013 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.expand_path('../../test_helper', __FILE__)
class PreviewsControllerTest < ActionController::TestCase
fixtures :projects, :trackers, :issue_statuses, :issues,
:enumerations, :users, :issue_categories,
:projects_trackers,
:roles,
:member_roles,
:members,
:enabled_modules,
:journals, :journal_details,
:news
def test_preview_new_issue
@request.session[:user_id] = 2
post :issue, :project_id => '1', :issue => {:description => 'Foo'}
assert_response :success
assert_template 'preview'
assert_not_nil assigns(:description)
end
def test_preview_issue_notes
@request.session[:user_id] = 2
post :issue, :project_id => '1', :id => 1,
:issue => {:description => Issue.find(1).description, :notes => 'Foo'}
assert_response :success
assert_template 'preview'
assert_not_nil assigns(:notes)
end
def test_preview_journal_notes_for_update
@request.session[:user_id] = 2
post :issue, :project_id => '1', :id => 1, :notes => 'Foo'
assert_response :success
assert_template 'preview'
assert_not_nil assigns(:notes)
assert_tag :p, :content => 'Foo'
end
def test_preview_new_news
get :news, :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
def test_existing_new_news
get :news, :project_id => 1, :id => 2,
:news => {:title => '',
:description => 'News description',
:summary => ''}
assert_response :success
assert_template 'common/_preview'
assert_equal News.find(2), assigns(:previewed)
assert_not_nil assigns(:attachments)
assert_tag :tag => 'fieldset', :attributes => { :class => 'preview' },
:content => /News description/
end
end

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save