Merged trunk r1773.
git-svn-id: http://redmine.rubyforge.org/svn/branches/work@1774 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -44,6 +44,17 @@ class AccountControllerTest < Test::Unit::TestCase
|
||||
assert_nil assigns(:user)
|
||||
end
|
||||
|
||||
def test_login_should_redirect_to_back_url_param
|
||||
# request.uri is "test.host" in test environment
|
||||
post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http://test.host/issues/show/1'
|
||||
assert_redirected_to '/issues/show/1'
|
||||
end
|
||||
|
||||
def test_login_should_not_redirect_to_another_host
|
||||
post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http://test.foo/fake'
|
||||
assert_redirected_to '/my/page'
|
||||
end
|
||||
|
||||
def test_login_with_wrong_password
|
||||
post :login, :username => 'admin', :password => 'bad'
|
||||
assert_response :success
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
# 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 'attachments_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class AttachmentsController; def rescue_action(e) raise e end; end
|
||||
|
||||
|
||||
class AttachmentsControllerTest < Test::Unit::TestCase
|
||||
fixtures :users, :projects, :issues, :attachments
|
||||
|
||||
def setup
|
||||
@controller = AttachmentsController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
Attachment.storage_path = "#{RAILS_ROOT}/test/fixtures/files"
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_routing
|
||||
assert_routing('/attachments/1', :controller => 'attachments', :action => 'show', :id => '1')
|
||||
assert_routing('/attachments/1/filename.ext', :controller => 'attachments', :action => 'show', :id => '1', :filename => 'filename.ext')
|
||||
assert_routing('/attachments/download/1', :controller => 'attachments', :action => 'download', :id => '1')
|
||||
assert_routing('/attachments/download/1/filename.ext', :controller => 'attachments', :action => 'download', :id => '1', :filename => 'filename.ext')
|
||||
end
|
||||
|
||||
def test_recognizes
|
||||
assert_recognizes({:controller => 'attachments', :action => 'show', :id => '1'}, '/attachments/1')
|
||||
assert_recognizes({:controller => 'attachments', :action => 'show', :id => '1'}, '/attachments/show/1')
|
||||
assert_recognizes({:controller => 'attachments', :action => 'show', :id => '1', :filename => 'filename.ext'}, '/attachments/1/filename.ext')
|
||||
assert_recognizes({:controller => 'attachments', :action => 'download', :id => '1'}, '/attachments/download/1')
|
||||
assert_recognizes({:controller => 'attachments', :action => 'download', :id => '1', :filename => 'filename.ext'},'/attachments/download/1/filename.ext')
|
||||
end
|
||||
|
||||
def test_show_diff
|
||||
get :show, :id => 5
|
||||
assert_response :success
|
||||
assert_template 'diff'
|
||||
end
|
||||
|
||||
def test_show_text_file
|
||||
get :show, :id => 4
|
||||
assert_response :success
|
||||
assert_template 'file'
|
||||
end
|
||||
|
||||
def test_show_other
|
||||
get :show, :id => 6
|
||||
assert_response :success
|
||||
assert_equal 'application/octet-stream', @response.content_type
|
||||
end
|
||||
|
||||
def test_download_text_file
|
||||
get :download, :id => 4
|
||||
assert_response :success
|
||||
assert_equal 'application/x-ruby', @response.content_type
|
||||
end
|
||||
|
||||
def test_anonymous_on_private_private
|
||||
get :download, :id => 7
|
||||
assert_redirected_to 'account/login'
|
||||
end
|
||||
end
|
||||
@@ -40,6 +40,8 @@ class DocumentsControllerTest < Test::Unit::TestCase
|
||||
|
||||
def test_new_with_one_attachment
|
||||
@request.session[:user_id] = 2
|
||||
set_tmp_attachments_directory
|
||||
|
||||
post :new, :project_id => 'ecookbook',
|
||||
:document => { :title => 'DocumentsControllerTest#test_post_new',
|
||||
:description => 'This is a new document',
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
# 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 'enumerations_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class EnumerationsController; def rescue_action(e) raise e end; end
|
||||
|
||||
class EnumerationsControllerTest < Test::Unit::TestCase
|
||||
fixtures :enumerations, :issues, :users
|
||||
|
||||
def setup
|
||||
@controller = EnumerationsController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
@request.session[:user_id] = 1 # admin
|
||||
end
|
||||
|
||||
def test_index
|
||||
get :index
|
||||
assert_response :success
|
||||
assert_template 'list'
|
||||
end
|
||||
|
||||
def test_destroy_enumeration_not_in_use
|
||||
post :destroy, :id => 7
|
||||
assert_redirected_to :controller => 'enumerations', :action => 'index'
|
||||
assert_nil Enumeration.find_by_id(7)
|
||||
end
|
||||
|
||||
def test_destroy_enumeration_in_use
|
||||
post :destroy, :id => 4
|
||||
assert_response :success
|
||||
assert_template 'destroy'
|
||||
assert_not_nil Enumeration.find_by_id(4)
|
||||
end
|
||||
|
||||
def test_destroy_enumeration_in_use_with_reassignment
|
||||
issue = Issue.find(:first, :conditions => {:priority_id => 4})
|
||||
post :destroy, :id => 4, :reassign_to_id => 6
|
||||
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
|
||||
end
|
||||
@@ -38,7 +38,9 @@ class IssuesControllerTest < Test::Unit::TestCase
|
||||
:custom_fields,
|
||||
:custom_values,
|
||||
:custom_fields_trackers,
|
||||
:time_entries
|
||||
:time_entries,
|
||||
:journals,
|
||||
:journal_details
|
||||
|
||||
def setup
|
||||
@controller = IssuesController.new
|
||||
@@ -53,13 +55,44 @@ class IssuesControllerTest < Test::Unit::TestCase
|
||||
assert_template 'index.rhtml'
|
||||
assert_not_nil assigns(:issues)
|
||||
assert_nil assigns(:project)
|
||||
assert_tag :tag => 'a', :content => /Can't print recipes/
|
||||
assert_tag :tag => 'a', :content => /Subproject issue/
|
||||
# private projects hidden
|
||||
assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
|
||||
assert_no_tag :tag => 'a', :content => /Issue on project 2/
|
||||
end
|
||||
|
||||
def test_index_with_project
|
||||
Setting.display_subprojects_issues = 0
|
||||
get :index, :project_id => 1
|
||||
assert_response :success
|
||||
assert_template 'index.rhtml'
|
||||
assert_not_nil assigns(:issues)
|
||||
assert_tag :tag => 'a', :content => /Can't print recipes/
|
||||
assert_no_tag :tag => 'a', :content => /Subproject issue/
|
||||
end
|
||||
|
||||
def test_index_with_project_and_subprojects
|
||||
Setting.display_subprojects_issues = 1
|
||||
get :index, :project_id => 1
|
||||
assert_response :success
|
||||
assert_template 'index.rhtml'
|
||||
assert_not_nil assigns(:issues)
|
||||
assert_tag :tag => 'a', :content => /Can't print recipes/
|
||||
assert_tag :tag => 'a', :content => /Subproject issue/
|
||||
assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
|
||||
end
|
||||
|
||||
def test_index_with_project_and_subprojects_should_show_private_subprojects
|
||||
@request.session[:user_id] = 2
|
||||
Setting.display_subprojects_issues = 1
|
||||
get :index, :project_id => 1
|
||||
assert_response :success
|
||||
assert_template 'index.rhtml'
|
||||
assert_not_nil assigns(:issues)
|
||||
assert_tag :tag => 'a', :content => /Can't print recipes/
|
||||
assert_tag :tag => 'a', :content => /Subproject issue/
|
||||
assert_tag :tag => 'a', :content => /Issue of a private subproject/
|
||||
end
|
||||
|
||||
def test_index_with_project_and_filter
|
||||
@@ -137,7 +170,7 @@ class IssuesControllerTest < Test::Unit::TestCase
|
||||
assert_response :success
|
||||
assert_template 'new'
|
||||
|
||||
assert_tag :tag => 'input', :attributes => { :name => 'custom_fields[2]',
|
||||
assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
|
||||
:value => 'Default string' }
|
||||
end
|
||||
|
||||
@@ -166,17 +199,20 @@ class IssuesControllerTest < Test::Unit::TestCase
|
||||
def test_post_new
|
||||
@request.session[:user_id] = 2
|
||||
post :new, :project_id => 1,
|
||||
:issue => {:tracker_id => 1,
|
||||
:issue => {:tracker_id => 3,
|
||||
:subject => 'This is the test_new issue',
|
||||
:description => 'This is the description',
|
||||
:priority_id => 5},
|
||||
:custom_fields => {'2' => 'Value for field 2'}
|
||||
:priority_id => 5,
|
||||
:estimated_hours => '',
|
||||
:custom_field_values => {'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_equal 3, issue.tracker_id
|
||||
assert_nil issue.estimated_hours
|
||||
v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
|
||||
assert_not_nil v
|
||||
assert_equal 'Value for field 2', v.value
|
||||
end
|
||||
@@ -191,6 +227,50 @@ class IssuesControllerTest < Test::Unit::TestCase
|
||||
assert_redirected_to 'issues/show'
|
||||
end
|
||||
|
||||
def test_post_new_with_required_custom_field_and_without_custom_fields_param
|
||||
field = IssueCustomField.find_by_name('Database')
|
||||
field.update_attribute(:is_required, true)
|
||||
|
||||
@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_response :success
|
||||
assert_template 'new'
|
||||
issue = assigns(:issue)
|
||||
assert_not_nil issue
|
||||
assert_equal 'activerecord_error_invalid', issue.errors.on(:custom_values)
|
||||
end
|
||||
|
||||
def test_post_should_preserve_fields_values_on_validation_failure
|
||||
@request.session[:user_id] = 2
|
||||
post :new, :project_id => 1,
|
||||
:issue => {:tracker_id => 1,
|
||||
:subject => 'This is the test_new issue',
|
||||
# empty description
|
||||
:description => '',
|
||||
:priority_id => 6,
|
||||
:custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
|
||||
assert_response :success
|
||||
assert_template 'new'
|
||||
|
||||
assert_tag :input, :attributes => { :name => 'issue[subject]',
|
||||
:value => 'This is the test_new issue' }
|
||||
assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
|
||||
:child => { :tag => 'option', :attributes => { :selected => 'selected',
|
||||
:value => '6' },
|
||||
:content => 'High' }
|
||||
# Custom fields
|
||||
assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
|
||||
:child => { :tag => 'option', :attributes => { :selected => 'selected',
|
||||
:value => 'Oracle' },
|
||||
:content => 'Oracle' }
|
||||
assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
|
||||
:value => 'Value for field 2'}
|
||||
end
|
||||
|
||||
def test_copy_issue
|
||||
@request.session[:user_id] = 2
|
||||
get :new, :project_id => 1, :copy_from => 1
|
||||
@@ -230,19 +310,43 @@ class IssuesControllerTest < Test::Unit::TestCase
|
||||
:content => 'Urgent',
|
||||
:attributes => { :selected => 'selected' } }
|
||||
end
|
||||
|
||||
def test_reply_to_issue
|
||||
@request.session[:user_id] = 2
|
||||
get :reply, :id => 1
|
||||
assert_response :success
|
||||
assert_select_rjs :show, "update"
|
||||
end
|
||||
|
||||
def test_post_edit
|
||||
def test_reply_to_note
|
||||
@request.session[:user_id] = 2
|
||||
get :reply, :id => 1, :journal_id => 2
|
||||
assert_response :success
|
||||
assert_select_rjs :show, "update"
|
||||
end
|
||||
|
||||
def test_post_edit_without_custom_fields_param
|
||||
@request.session[:user_id] = 2
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
issue = Issue.find(1)
|
||||
assert_equal '125', issue.custom_value_for(2).value
|
||||
old_subject = issue.subject
|
||||
new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
|
||||
|
||||
post :edit, :id => 1, :issue => {:subject => new_subject}
|
||||
assert_difference('Journal.count') do
|
||||
assert_difference('JournalDetail.count', 2) do
|
||||
post :edit, :id => 1, :issue => {:subject => new_subject,
|
||||
:priority_id => '6',
|
||||
:category_id => '1' # no change
|
||||
}
|
||||
end
|
||||
end
|
||||
assert_redirected_to 'issues/show/1'
|
||||
issue.reload
|
||||
assert_equal new_subject, issue.subject
|
||||
# Make sure custom fields were not cleared
|
||||
assert_equal '125', issue.custom_value_for(2).value
|
||||
|
||||
mail = ActionMailer::Base.deliveries.last
|
||||
assert_kind_of TMail::Mail, mail
|
||||
@@ -250,14 +354,40 @@ class IssuesControllerTest < Test::Unit::TestCase
|
||||
assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
|
||||
end
|
||||
|
||||
def test_post_edit_with_custom_field_change
|
||||
@request.session[:user_id] = 2
|
||||
issue = Issue.find(1)
|
||||
assert_equal '125', issue.custom_value_for(2).value
|
||||
|
||||
assert_difference('Journal.count') do
|
||||
assert_difference('JournalDetail.count', 3) do
|
||||
post :edit, :id => 1, :issue => {:subject => 'Custom field change',
|
||||
:priority_id => '6',
|
||||
:category_id => '1', # no change
|
||||
:custom_field_values => { '2' => 'New custom value' }
|
||||
}
|
||||
end
|
||||
end
|
||||
assert_redirected_to 'issues/show/1'
|
||||
issue.reload
|
||||
assert_equal 'New custom value', issue.custom_value_for(2).value
|
||||
|
||||
mail = ActionMailer::Base.deliveries.last
|
||||
assert_kind_of TMail::Mail, mail
|
||||
assert mail.body.include?("Searchable field changed from 125 to New custom value")
|
||||
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_difference('TimeEntry.count', 0) do
|
||||
post :edit,
|
||||
:id => 1,
|
||||
:issue => { :status_id => 2, :assigned_to_id => 3 },
|
||||
:notes => 'Assigned to dlopper',
|
||||
:time_entry => { :hours => '', :comments => '', :activity_id => Enumeration.get_values('ACTI').first }
|
||||
end
|
||||
assert_redirected_to 'issues/show/1'
|
||||
issue.reload
|
||||
assert_equal 2, issue.status_id
|
||||
@@ -288,10 +418,12 @@ class IssuesControllerTest < Test::Unit::TestCase
|
||||
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_difference('TimeEntry.count') do
|
||||
post :edit,
|
||||
:id => 1,
|
||||
:notes => '2.5 hours added',
|
||||
:time_entry => { :hours => '2.5', :comments => '', :activity_id => Enumeration.get_values('ACTI').first }
|
||||
end
|
||||
assert_redirected_to 'issues/show/1'
|
||||
|
||||
issue = Issue.find(1)
|
||||
@@ -307,6 +439,8 @@ class IssuesControllerTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_post_edit_with_attachment_only
|
||||
set_tmp_attachments_directory
|
||||
|
||||
# anonymous user
|
||||
post :edit,
|
||||
:id => 1,
|
||||
@@ -398,10 +532,10 @@ class IssuesControllerTest < Test::Unit::TestCase
|
||||
: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',
|
||||
:attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&priority_id=8',
|
||||
:class => '' }
|
||||
assert_tag :tag => 'a', :content => 'Dave Lopper',
|
||||
:attributes => { :href => '/issues/edit/1?issue%5Bassigned_to_id%5D=3',
|
||||
:attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&ids%5B%5D=1',
|
||||
:class => '' }
|
||||
assert_tag :tag => 'a', :content => 'Copy',
|
||||
:attributes => { :href => '/projects/ecookbook/issues/new?copy_from=1',
|
||||
@@ -431,6 +565,12 @@ class IssuesControllerTest < Test::Unit::TestCase
|
||||
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 => 'Immediate',
|
||||
:attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&ids%5B%5D=2&priority_id=8',
|
||||
:class => '' }
|
||||
assert_tag :tag => 'a', :content => 'Dave Lopper',
|
||||
:attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&ids%5B%5D=1&ids%5B%5D=2',
|
||||
:class => '' }
|
||||
assert_tag :tag => 'a', :content => 'Move',
|
||||
:attributes => { :href => '/issues/move?ids%5B%5D=1&ids%5B%5D=2',
|
||||
:class => 'icon-move' }
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
# 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 'mail_handler_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class MailHandlerController; def rescue_action(e) raise e end; end
|
||||
|
||||
class MailHandlerControllerTest < Test::Unit::TestCase
|
||||
fixtures :users, :projects, :enabled_modules, :roles, :members, :issues, :issue_statuses, :trackers, :enumerations
|
||||
|
||||
FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler'
|
||||
|
||||
def setup
|
||||
@controller = MailHandlerController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
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'
|
||||
|
||||
post :index, :key => 'secret', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
|
||||
assert_response 201
|
||||
end
|
||||
|
||||
def test_should_not_allow
|
||||
# Disable API
|
||||
Setting.mail_handler_api_enabled = 0
|
||||
Setting.mail_handler_api_key = 'secret'
|
||||
|
||||
post :index, :key => 'secret', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
|
||||
assert_response 403
|
||||
end
|
||||
end
|
||||
@@ -40,6 +40,15 @@ class MessagesControllerTest < Test::Unit::TestCase
|
||||
assert_not_nil assigns(:topic)
|
||||
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
|
||||
@@ -108,4 +117,11 @@ class MessagesControllerTest < Test::Unit::TestCase
|
||||
assert_redirected_to 'boards/show'
|
||||
assert_nil Message.find_by_id(1)
|
||||
end
|
||||
|
||||
def test_quote
|
||||
@request.session[:user_id] = 2
|
||||
xhr :get, :quote, :board_id => 1, :id => 3
|
||||
assert_response :success
|
||||
assert_select_rjs :show, 'reply'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -29,24 +29,27 @@ class ProjectsControllerTest < Test::Unit::TestCase
|
||||
@controller = ProjectsController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
@request.session[:user_id] = nil
|
||||
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_template 'index'
|
||||
assert_not_nil assigns(:project_tree)
|
||||
# Root project as hash key
|
||||
assert assigns(:project_tree).has_key?(Project.find(1))
|
||||
assert assigns(:project_tree).keys.include?(Project.find(1))
|
||||
# Subproject in corresponding value
|
||||
assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3))
|
||||
end
|
||||
|
||||
def test_index_atom
|
||||
get :index, :format => 'atom'
|
||||
assert_response :success
|
||||
assert_template 'common/feed.atom.rxml'
|
||||
assert_select 'feed>title', :text => 'Redmine: Latest projects'
|
||||
assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_by(User.current))
|
||||
end
|
||||
|
||||
def test_show_by_id
|
||||
get :show, :id => 1
|
||||
@@ -63,6 +66,21 @@ class ProjectsControllerTest < Test::Unit::TestCase
|
||||
assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
|
||||
end
|
||||
|
||||
def test_private_subprojects_hidden
|
||||
get :show, :id => 'ecookbook'
|
||||
assert_response :success
|
||||
assert_template 'show'
|
||||
assert_no_tag :tag => 'a', :content => /Private child/
|
||||
end
|
||||
|
||||
def test_private_subprojects_visible
|
||||
@request.session[:user_id] = 2 # manager who is a member of the private subproject
|
||||
get :show, :id => 'ecookbook'
|
||||
assert_response :success
|
||||
assert_template 'show'
|
||||
assert_tag :tag => 'a', :content => /Private child/
|
||||
end
|
||||
|
||||
def test_settings
|
||||
@request.session[:user_id] = 2 # manager
|
||||
get :settings, :id => 1
|
||||
@@ -73,7 +91,7 @@ class ProjectsControllerTest < Test::Unit::TestCase
|
||||
def test_edit
|
||||
@request.session[:user_id] = 2 # manager
|
||||
post :edit, :id => 1, :project => {:name => 'Test changed name',
|
||||
:custom_field_ids => ['']}
|
||||
:issue_custom_field_ids => ['']}
|
||||
assert_redirected_to 'projects/settings/ecookbook'
|
||||
project = Project.find(1)
|
||||
assert_equal 'Test changed name', project.name
|
||||
@@ -135,22 +153,20 @@ class ProjectsControllerTest < Test::Unit::TestCase
|
||||
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' },
|
||||
:attributes => { :class => /issue-edit/ },
|
||||
:child => { :tag => "a",
|
||||
:content => /(#{IssueStatus.find(2).name})/,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
def test_previous_project_activity
|
||||
get :activity, :id => 1, :from => 3.days.ago.to_date
|
||||
assert_response :success
|
||||
assert_template 'activity'
|
||||
@@ -160,7 +176,7 @@ class ProjectsControllerTest < Test::Unit::TestCase
|
||||
:content => /#{3.day.ago.to_date.day}/,
|
||||
:sibling => { :tag => "dl",
|
||||
:child => { :tag => "dt",
|
||||
:attributes => { :class => 'issue' },
|
||||
:attributes => { :class => /issue/ },
|
||||
:child => { :tag => "a",
|
||||
:content => /#{Issue.find(1).subject}/,
|
||||
}
|
||||
@@ -168,53 +184,30 @@ class ProjectsControllerTest < Test::Unit::TestCase
|
||||
}
|
||||
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
|
||||
def test_global_activity
|
||||
get :activity
|
||||
assert_response :success
|
||||
assert_template 'activity'
|
||||
assert_not_nil assigns(:events)
|
||||
assert_not_nil assigns(:events_by_day)
|
||||
|
||||
assert assigns(:events).include?(Issue.find(1))
|
||||
# Issue of a private project
|
||||
assert !assigns(:events).include?(Issue.find(4))
|
||||
assert_tag :tag => "h3",
|
||||
:content => /#{5.day.ago.to_date.day}/,
|
||||
:sibling => { :tag => "dl",
|
||||
:child => { :tag => "dt",
|
||||
:attributes => { :class => /issue/ },
|
||||
:child => { :tag => "a",
|
||||
:content => /#{Issue.find(5).subject}/,
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_global_activity_logged_user
|
||||
@request.session[:user_id] = 2 # manager
|
||||
get :activity
|
||||
def test_activity_atom_feed
|
||||
get :activity, :format => 'atom'
|
||||
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))
|
||||
assert_template 'common/feed.atom.rxml'
|
||||
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
|
||||
@@ -222,27 +215,56 @@ class ProjectsControllerTest < Test::Unit::TestCase
|
||||
assert_not_nil assigns(:calendar)
|
||||
end
|
||||
|
||||
def test_calendar_with_subprojects
|
||||
def test_calendar_with_subprojects_should_not_show_private_subprojects
|
||||
get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
|
||||
assert_response :success
|
||||
assert_template 'calendar'
|
||||
assert_not_nil assigns(:calendar)
|
||||
assert_no_tag :tag => 'a', :content => /#6/
|
||||
end
|
||||
|
||||
def test_calendar_with_subprojects_should_show_private_subprojects
|
||||
@request.session[:user_id] = 2
|
||||
get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
|
||||
assert_response :success
|
||||
assert_template 'calendar'
|
||||
assert_not_nil assigns(:calendar)
|
||||
assert_tag :tag => 'a', :content => /#6/
|
||||
end
|
||||
|
||||
def test_gantt
|
||||
get :gantt, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'gantt.rhtml'
|
||||
assert_not_nil assigns(:events)
|
||||
events = assigns(:events)
|
||||
assert_not_nil events
|
||||
# Issue with start and due dates
|
||||
i = Issue.find(1)
|
||||
assert_not_nil i.due_date
|
||||
assert events.include?(Issue.find(1))
|
||||
# Issue with without due date but targeted to a version with date
|
||||
i = Issue.find(2)
|
||||
assert_nil i.due_date
|
||||
assert events.include?(i)
|
||||
end
|
||||
|
||||
def test_gantt_with_subprojects
|
||||
def test_gantt_with_subprojects_should_not_show_private_subprojects
|
||||
get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
|
||||
assert_response :success
|
||||
assert_template 'gantt.rhtml'
|
||||
assert_not_nil assigns(:events)
|
||||
assert_no_tag :tag => 'a', :content => /#6/
|
||||
end
|
||||
|
||||
def test_gantt_with_subprojects_should_show_private_subprojects
|
||||
@request.session[:user_id] = 2
|
||||
get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
|
||||
assert_response :success
|
||||
assert_template 'gantt.rhtml'
|
||||
assert_not_nil assigns(:events)
|
||||
assert_tag :tag => 'a', :content => /#6/
|
||||
end
|
||||
|
||||
def test_gantt_export_to_pdf
|
||||
get :gantt, :id => 1, :format => 'pdf'
|
||||
assert_response :success
|
||||
@@ -265,4 +287,33 @@ class ProjectsControllerTest < Test::Unit::TestCase
|
||||
assert_redirected_to 'admin/projects'
|
||||
assert Project.find(1).active?
|
||||
end
|
||||
|
||||
def test_project_menu
|
||||
assert_no_difference 'Redmine::MenuManager.items(:project_menu).size' do
|
||||
Redmine::MenuManager.map :project_menu do |menu|
|
||||
menu.push :foo, { :controller => 'projects', :action => 'show' }, :cation => 'Foo'
|
||||
menu.push :bar, { :controller => 'projects', :action => 'show' }, :before => :activity
|
||||
menu.push :hello, { :controller => 'projects', :action => 'show' }, :caption => Proc.new {|p| p.name.upcase }, :after => :bar
|
||||
end
|
||||
|
||||
get :show, :id => 1
|
||||
assert_tag :div, :attributes => { :id => 'main-menu' },
|
||||
:descendant => { :tag => 'li', :child => { :tag => 'a', :content => 'Foo' } }
|
||||
|
||||
assert_tag :div, :attributes => { :id => 'main-menu' },
|
||||
:descendant => { :tag => 'li', :child => { :tag => 'a', :content => 'Bar' },
|
||||
:before => { :tag => 'li', :child => { :tag => 'a', :content => 'ECOOKBOOK' } } }
|
||||
|
||||
assert_tag :div, :attributes => { :id => 'main-menu' },
|
||||
:descendant => { :tag => 'li', :child => { :tag => 'a', :content => 'ECOOKBOOK' },
|
||||
:before => { :tag => 'li', :child => { :tag => 'a', :content => 'Activity' } } }
|
||||
|
||||
# Remove the menu items
|
||||
Redmine::MenuManager.map :project_menu do |menu|
|
||||
menu.delete :foo
|
||||
menu.delete :bar
|
||||
menu.delete :hello
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -43,10 +43,10 @@ class RepositoriesControllerTest < Test::Unit::TestCase
|
||||
assert_response :success
|
||||
assert_template 'revision'
|
||||
assert_no_tag :tag => "div", :attributes => { :class => "contextual" },
|
||||
:child => { :tag => "a", :attributes => { :href => '/repositories/revision/ecookbook?rev=0'}
|
||||
:child => { :tag => "a", :attributes => { :href => '/repositories/revision/ecookbook/0'}
|
||||
}
|
||||
assert_tag :tag => "div", :attributes => { :class => "contextual" },
|
||||
:child => { :tag => "a", :attributes => { :href => '/repositories/revision/ecookbook?rev=2'}
|
||||
:child => { :tag => "a", :attributes => { :href => '/repositories/revision/ecookbook/2'}
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ 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/
|
||||
REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
|
||||
# CVS module
|
||||
MODULE_NAME = 'test'
|
||||
|
||||
@@ -89,6 +89,19 @@ class RepositoriesCvsControllerTest < Test::Unit::TestCase
|
||||
get :entry, :id => 1, :path => ['sources', 'watchers_controller.rb']
|
||||
assert_response :success
|
||||
assert_template 'entry'
|
||||
assert_no_tag :tag => 'td', :attributes => { :class => /line-code/},
|
||||
:content => /before_filter/
|
||||
end
|
||||
|
||||
def test_entry_at_given_revision
|
||||
# changesets must be loaded
|
||||
Project.find(1).repository.fetch_changesets
|
||||
get :entry, :id => 1, :path => ['sources', 'watchers_controller.rb'], :rev => 2
|
||||
assert_response :success
|
||||
assert_template 'entry'
|
||||
# this line was removed in r3
|
||||
assert_tag :tag => 'td', :attributes => { :class => /line-code/},
|
||||
:content => /before_filter/
|
||||
end
|
||||
|
||||
def test_entry_not_found
|
||||
|
||||
@@ -26,7 +26,7 @@ class RepositoriesGitControllerTest < Test::Unit::TestCase
|
||||
|
||||
# No '..' in the repository path
|
||||
REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
|
||||
REPOSITORY_PATH.gsub!(/\//, "\\") if RUBY_PLATFORM =~ /mswin/
|
||||
REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
|
||||
|
||||
def setup
|
||||
@controller = RepositoriesController.new
|
||||
|
||||
@@ -71,6 +71,19 @@ class RepositoriesSubversionControllerTest < Test::Unit::TestCase
|
||||
assert_not_nil assigns(:entries)
|
||||
assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'], assigns(:entries).collect(&:name)
|
||||
end
|
||||
|
||||
def test_changes
|
||||
get :changes, :id => 1, :path => ['subversion_test', 'folder', 'helloworld.rb' ]
|
||||
assert_response :success
|
||||
assert_template 'changes'
|
||||
# svn properties
|
||||
assert_not_nil assigns(:properties)
|
||||
assert_equal 'native', assigns(:properties)['svn:eol-style']
|
||||
assert_tag :ul,
|
||||
:child => { :tag => 'li',
|
||||
:child => { :tag => 'b', :content => 'svn:eol-style' },
|
||||
:child => { :tag => 'span', :content => 'native' } }
|
||||
end
|
||||
|
||||
def test_entry
|
||||
get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c']
|
||||
@@ -78,6 +91,15 @@ class RepositoriesSubversionControllerTest < Test::Unit::TestCase
|
||||
assert_template 'entry'
|
||||
end
|
||||
|
||||
def test_entry_at_given_revision
|
||||
get :entry, :id => 1, :path => ['subversion_test', 'helloworld.rb'], :rev => 2
|
||||
assert_response :success
|
||||
assert_template 'entry'
|
||||
# this line was removed in r3 and file was moved in r6
|
||||
assert_tag :tag => 'td', :attributes => { :class => /line-code/},
|
||||
:content => /Here's the code/
|
||||
end
|
||||
|
||||
def test_entry_not_found
|
||||
get :entry, :id => 1, :path => ['subversion_test', 'zzz.c']
|
||||
assert_tag :tag => 'div', :attributes => { :class => /error/ },
|
||||
@@ -97,6 +119,37 @@ class RepositoriesSubversionControllerTest < Test::Unit::TestCase
|
||||
assert_equal 'folder', assigns(:entry).name
|
||||
end
|
||||
|
||||
def test_revision
|
||||
get :revision, :id => 1, :rev => 2
|
||||
assert_response :success
|
||||
assert_template 'revision'
|
||||
assert_tag :tag => 'tr',
|
||||
:child => { :tag => 'td',
|
||||
# link to the entry at rev 2
|
||||
:child => { :tag => 'a', :attributes => {:href => 'repositories/entry/ecookbook/test/some/path/in/the/repo?rev=2'},
|
||||
:content => %r{/test/some/path/in/the/repo} }
|
||||
},
|
||||
:child => { :tag => 'td',
|
||||
# link to partial diff
|
||||
:child => { :tag => 'a', :attributes => { :href => '/repositories/diff/ecookbook/test/some/path/in/the/repo?rev=2' } }
|
||||
}
|
||||
end
|
||||
|
||||
def test_revision_with_repository_pointing_to_a_subdirectory
|
||||
r = Project.find(1).repository
|
||||
# Changes repository url to a subdirectory
|
||||
r.update_attribute :url, (r.url + '/test/some')
|
||||
|
||||
get :revision, :id => 1, :rev => 2
|
||||
assert_response :success
|
||||
assert_template 'revision'
|
||||
assert_tag :tag => 'tr',
|
||||
:child => { :tag => 'td', :content => %r{/test/some/path/in/the/repo} },
|
||||
:child => { :tag => 'td',
|
||||
:child => { :tag => 'a', :attributes => { :href => '/repositories/diff/ecookbook/path/in/the/repo?rev=2' } }
|
||||
}
|
||||
end
|
||||
|
||||
def test_diff
|
||||
get :diff, :id => 1, :rev => 3
|
||||
assert_response :success
|
||||
|
||||
@@ -5,7 +5,10 @@ require 'search_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
|
||||
fixtures :projects, :enabled_modules, :roles, :users,
|
||||
:issues, :trackers, :issue_statuses,
|
||||
:custom_fields, :custom_values,
|
||||
:repositories, :changesets
|
||||
|
||||
def setup
|
||||
@controller = SearchController.new
|
||||
@@ -25,6 +28,31 @@ class SearchControllerTest < Test::Unit::TestCase
|
||||
assert assigns(:results).include?(Project.find(1))
|
||||
end
|
||||
|
||||
def test_search_all_projects
|
||||
get :index, :q => 'recipe subproject commit', :submit => 'Search'
|
||||
assert_response :success
|
||||
assert_template 'index'
|
||||
|
||||
assert assigns(:results).include?(Issue.find(2))
|
||||
assert assigns(:results).include?(Issue.find(5))
|
||||
assert assigns(:results).include?(Changeset.find(101))
|
||||
assert_tag :dt, :attributes => { :class => /issue/ },
|
||||
:child => { :tag => 'a', :content => /Add ingredients categories/ },
|
||||
:sibling => { :tag => 'dd', :content => /should be classified by categories/ }
|
||||
|
||||
assert assigns(:results_by_type).is_a?(Hash)
|
||||
assert_equal 4, assigns(:results_by_type)['changesets']
|
||||
assert_tag :a, :content => 'Changesets (4)'
|
||||
end
|
||||
|
||||
def test_search_project_and_subprojects
|
||||
get :index, :id => 1, :q => 'recipe subproject', :scope => 'subprojects', :submit => 'Search'
|
||||
assert_response :success
|
||||
assert_template 'index'
|
||||
assert assigns(:results).include?(Issue.find(1))
|
||||
assert assigns(:results).include?(Issue.find(5))
|
||||
end
|
||||
|
||||
def test_search_without_searchable_custom_fields
|
||||
CustomField.update_all "searchable = #{ActiveRecord::Base.connection.quoted_false}"
|
||||
|
||||
|
||||
@@ -30,11 +30,22 @@ class TimelogControllerTest < Test::Unit::TestCase
|
||||
@response = ActionController::TestResponse.new
|
||||
end
|
||||
|
||||
def test_create
|
||||
def test_get_edit
|
||||
@request.session[:user_id] = 3
|
||||
get :edit, :project_id => 1
|
||||
assert_response :success
|
||||
assert_template 'edit'
|
||||
# Default activity selected
|
||||
assert_tag :tag => 'option', :attributes => { :selected => 'selected' },
|
||||
:content => 'Development'
|
||||
end
|
||||
|
||||
def test_post_edit
|
||||
@request.session[:user_id] = 3
|
||||
post :edit, :project_id => 1,
|
||||
:time_entry => {:comments => 'Some work on TimelogControllerTest',
|
||||
:activity_id => '10',
|
||||
# Not the default activity
|
||||
:activity_id => '11',
|
||||
:spent_on => '2008-03-14',
|
||||
:issue_id => '1',
|
||||
:hours => '7.3'}
|
||||
@@ -43,6 +54,7 @@ class TimelogControllerTest < Test::Unit::TestCase
|
||||
i = Issue.find(1)
|
||||
t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
|
||||
assert_not_nil t
|
||||
assert_equal 11, t.activity_id
|
||||
assert_equal 7.3, t.hours
|
||||
assert_equal 3, t.user_id
|
||||
assert_equal i, t.issue
|
||||
@@ -198,6 +210,14 @@ class TimelogControllerTest < Test::Unit::TestCase
|
||||
assert_equal '2007-04-22'.to_date, assigns(:to)
|
||||
end
|
||||
|
||||
def test_details_atom_feed
|
||||
get :details, :project_id => 1, :format => 'atom'
|
||||
assert_response :success
|
||||
assert_equal 'application/atom+xml', @response.content_type
|
||||
assert_not_nil assigns(:items)
|
||||
assert assigns(:items).first.is_a?(TimeEntry)
|
||||
end
|
||||
|
||||
def test_details_csv_export
|
||||
get :details, :project_id => 1, :format => 'csv'
|
||||
assert_response :success
|
||||
|
||||
@@ -22,7 +22,7 @@ require 'versions_controller'
|
||||
class VersionsController; def rescue_action(e) raise e end; end
|
||||
|
||||
class VersionsControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :versions, :users, :roles, :members, :enabled_modules
|
||||
fixtures :projects, :versions, :issues, :users, :roles, :members, :enabled_modules
|
||||
|
||||
def setup
|
||||
@controller = VersionsController.new
|
||||
@@ -60,9 +60,9 @@ class VersionsControllerTest < Test::Unit::TestCase
|
||||
|
||||
def test_destroy
|
||||
@request.session[:user_id] = 2
|
||||
post :destroy, :id => 2
|
||||
post :destroy, :id => 3
|
||||
assert_redirected_to 'projects/settings/ecookbook'
|
||||
assert_nil Version.find_by_id(2)
|
||||
assert_nil Version.find_by_id(3)
|
||||
end
|
||||
|
||||
def test_issue_status_by
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
# 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 'watchers_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class WatchersController; def rescue_action(e) raise e end; end
|
||||
|
||||
class WatchersControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :users, :roles, :members, :enabled_modules,
|
||||
:issues, :trackers, :projects_trackers, :issue_statuses, :enumerations, :watchers
|
||||
|
||||
def setup
|
||||
@controller = WatchersController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_get_watch_should_be_invalid
|
||||
@request.session[:user_id] = 3
|
||||
get :watch, :object_type => 'issue', :object_id => '1'
|
||||
assert_response 405
|
||||
end
|
||||
|
||||
def test_watch
|
||||
@request.session[:user_id] = 3
|
||||
assert_difference('Watcher.count') do
|
||||
xhr :post, :watch, :object_type => 'issue', :object_id => '1'
|
||||
assert_response :success
|
||||
assert_select_rjs :replace_html, 'watcher'
|
||||
end
|
||||
assert Issue.find(1).watched_by?(User.find(3))
|
||||
end
|
||||
|
||||
def test_unwatch
|
||||
@request.session[:user_id] = 3
|
||||
assert_difference('Watcher.count', -1) do
|
||||
xhr :post, :unwatch, :object_type => 'issue', :object_id => '2'
|
||||
assert_response :success
|
||||
assert_select_rjs :replace_html, 'watcher'
|
||||
end
|
||||
assert !Issue.find(1).watched_by?(User.find(3))
|
||||
end
|
||||
|
||||
def test_new_watcher
|
||||
@request.session[:user_id] = 2
|
||||
assert_difference('Watcher.count') do
|
||||
xhr :post, :new, :object_type => 'issue', :object_id => '2', :watcher => {:user_id => '4'}
|
||||
assert_response :success
|
||||
assert_select_rjs :replace_html, 'watchers'
|
||||
end
|
||||
assert Issue.find(2).watched_by?(User.find(4))
|
||||
end
|
||||
end
|
||||
@@ -46,4 +46,18 @@ class WelcomeControllerTest < Test::Unit::TestCase
|
||||
get :index
|
||||
assert_equal :fr, @controller.current_language
|
||||
end
|
||||
|
||||
def test_browser_language_alternate
|
||||
Setting.default_language = 'en'
|
||||
@request.env['HTTP_ACCEPT_LANGUAGE'] = 'zh-TW'
|
||||
get :index
|
||||
assert_equal :"zh-tw", @controller.current_language
|
||||
end
|
||||
|
||||
def test_browser_language_alternate_not_valid
|
||||
Setting.default_language = 'en'
|
||||
@request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr-CA'
|
||||
get :index
|
||||
assert_equal :fr, @controller.current_language
|
||||
end
|
||||
end
|
||||
|
||||
@@ -32,10 +32,16 @@ class WikiControllerTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_show_start_page
|
||||
get :index, :id => 1
|
||||
get :index, :id => 'ecookbook'
|
||||
assert_response :success
|
||||
assert_template 'show'
|
||||
assert_tag :tag => 'h1', :content => /CookBook documentation/
|
||||
|
||||
# child_pages macro
|
||||
assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
|
||||
:child => { :tag => 'li',
|
||||
:child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/Page_with_an_inline_image' },
|
||||
:content => 'Page with an inline image' } }
|
||||
end
|
||||
|
||||
def test_show_page_with_name
|
||||
@@ -86,14 +92,35 @@ class WikiControllerTest < Test::Unit::TestCase
|
||||
assert_tag :tag => 'strong', :content => /previewed text/
|
||||
end
|
||||
|
||||
def test_preview_new_page
|
||||
@request.session[:user_id] = 2
|
||||
xhr :post, :preview, :id => 1, :page => 'New page',
|
||||
:content => { :text => 'h1. New page',
|
||||
:comments => '',
|
||||
:version => 0 }
|
||||
assert_response :success
|
||||
assert_template 'common/_preview'
|
||||
assert_tag :tag => 'h1', :content => /New page/
|
||||
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
|
||||
assert_select "input[type=submit][name=commit]"
|
||||
end
|
||||
|
||||
|
||||
def test_history_with_one_version
|
||||
get :history, :id => 1, :page => 'Another_page'
|
||||
assert_response :success
|
||||
assert_template 'history'
|
||||
assert_not_nil assigns(:versions)
|
||||
assert_equal 1, assigns(:versions).size
|
||||
assert_select "input[type=submit][name=commit]", false
|
||||
end
|
||||
|
||||
def test_diff
|
||||
get :diff, :id => 1, :page => 'CookBook_documentation', :version => 2, :version_from => 1
|
||||
assert_response :success
|
||||
@@ -152,12 +179,76 @@ class WikiControllerTest < Test::Unit::TestCase
|
||||
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/
|
||||
|
||||
assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
|
||||
:child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/CookBook_documentation' },
|
||||
:content => 'CookBook documentation' },
|
||||
:child => { :tag => 'ul',
|
||||
:child => { :tag => 'li',
|
||||
:child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/Page_with_an_inline_image' },
|
||||
:content => 'Page with an inline image' } } } },
|
||||
:child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/Another_page' },
|
||||
:content => 'Another page' } }
|
||||
end
|
||||
|
||||
def test_not_found
|
||||
get :index, :id => 999
|
||||
assert_response 404
|
||||
end
|
||||
|
||||
def test_protect_page
|
||||
page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
|
||||
assert !page.protected?
|
||||
@request.session[:user_id] = 2
|
||||
post :protect, :id => 1, :page => page.title, :protected => '1'
|
||||
assert_redirected_to 'wiki/ecookbook/Another_page'
|
||||
assert page.reload.protected?
|
||||
end
|
||||
|
||||
def test_unprotect_page
|
||||
page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
|
||||
assert page.protected?
|
||||
@request.session[:user_id] = 2
|
||||
post :protect, :id => 1, :page => page.title, :protected => '0'
|
||||
assert_redirected_to 'wiki/ecookbook'
|
||||
assert !page.reload.protected?
|
||||
end
|
||||
|
||||
def test_show_page_with_edit_link
|
||||
@request.session[:user_id] = 2
|
||||
get :index, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'show'
|
||||
assert_tag :tag => 'a', :attributes => { :href => '/wiki/1/CookBook_documentation/edit' }
|
||||
end
|
||||
|
||||
def test_show_page_without_edit_link
|
||||
@request.session[:user_id] = 4
|
||||
get :index, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'show'
|
||||
assert_no_tag :tag => 'a', :attributes => { :href => '/wiki/1/CookBook_documentation/edit' }
|
||||
end
|
||||
|
||||
def test_edit_unprotected_page
|
||||
# Non members can edit unprotected wiki pages
|
||||
@request.session[:user_id] = 4
|
||||
get :edit, :id => 1, :page => 'Another_page'
|
||||
assert_response :success
|
||||
assert_template 'edit'
|
||||
end
|
||||
|
||||
def test_edit_protected_page_by_nonmember
|
||||
# Non members can't edit protected wiki pages
|
||||
@request.session[:user_id] = 4
|
||||
get :edit, :id => 1, :page => 'CookBook_documentation'
|
||||
assert_response 403
|
||||
end
|
||||
|
||||
def test_edit_protected_page_by_member
|
||||
@request.session[:user_id] = 2
|
||||
get :edit, :id => 1, :page => 'CookBook_documentation'
|
||||
assert_response :success
|
||||
assert_template 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user