2011-04-01 17:44:58 +04:00
|
|
|
# Redmine - project management software
|
|
|
|
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
2008-06-09 22:40:59 +04:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-08-27 06:10:59 +04:00
|
|
|
#
|
2008-06-09 22:40:59 +04:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2011-08-27 06:10:59 +04:00
|
|
|
#
|
2008-06-09 22:40:59 +04:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
2010-12-13 02:24:34 +03:00
|
|
|
require File.expand_path('../../test_helper', __FILE__)
|
2006-12-26 23:14:03 +03:00
|
|
|
|
|
|
|
class IssuesTest < ActionController::IntegrationTest
|
2011-08-27 06:10:59 +04:00
|
|
|
fixtures :projects,
|
2008-01-21 00:29:51 +03:00
|
|
|
:users,
|
2008-07-04 21:58:14 +04:00
|
|
|
:roles,
|
|
|
|
:members,
|
2008-01-21 00:29:51 +03:00
|
|
|
:trackers,
|
|
|
|
:projects_trackers,
|
2008-07-04 21:58:14 +04:00
|
|
|
:enabled_modules,
|
2008-01-21 00:29:51 +03:00
|
|
|
:issue_statuses,
|
|
|
|
:issues,
|
|
|
|
:enumerations,
|
|
|
|
:custom_fields,
|
|
|
|
:custom_values,
|
|
|
|
:custom_fields_trackers
|
2006-12-26 23:14:03 +03:00
|
|
|
|
|
|
|
# create an issue
|
|
|
|
def test_add_issue
|
|
|
|
log_user('jsmith', 'jsmith')
|
2008-01-20 14:30:57 +03:00
|
|
|
get 'projects/1/issues/new', :tracker_id => '1'
|
2006-12-26 23:14:03 +03:00
|
|
|
assert_response :success
|
2008-01-20 14:30:57 +03:00
|
|
|
assert_template 'issues/new'
|
2011-08-27 06:10:59 +04:00
|
|
|
|
2009-01-26 04:47:51 +03:00
|
|
|
post 'projects/1/issues', :tracker_id => "1",
|
2011-08-27 06:10:59 +04:00
|
|
|
:issue => { :start_date => "2006-12-26",
|
|
|
|
:priority_id => "4",
|
|
|
|
:subject => "new test issue",
|
|
|
|
:category_id => "",
|
|
|
|
:description => "new issue",
|
2006-12-26 23:14:03 +03:00
|
|
|
:done_ratio => "0",
|
|
|
|
:due_date => "",
|
2008-01-21 00:29:51 +03:00
|
|
|
:assigned_to_id => "" },
|
|
|
|
:custom_fields => {'2' => 'Value for field 2'}
|
2006-12-26 23:14:03 +03:00
|
|
|
# find created issue
|
|
|
|
issue = Issue.find_by_subject("new test issue")
|
|
|
|
assert_kind_of Issue, issue
|
|
|
|
|
|
|
|
# check redirection
|
2009-02-21 14:04:50 +03:00
|
|
|
assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
|
2006-12-26 23:14:03 +03:00
|
|
|
follow_redirect!
|
2008-03-15 14:27:46 +03:00
|
|
|
assert_equal issue, assigns(:issue)
|
2006-12-26 23:14:03 +03:00
|
|
|
|
2011-08-27 06:10:59 +04:00
|
|
|
# check issue attributes
|
2006-12-26 23:14:03 +03:00
|
|
|
assert_equal 'jsmith', issue.author.login
|
|
|
|
assert_equal 1, issue.project.id
|
|
|
|
assert_equal 1, issue.status.id
|
|
|
|
end
|
|
|
|
|
2011-12-13 00:43:51 +04:00
|
|
|
def test_update_issue_form
|
|
|
|
log_user('jsmith', 'jsmith')
|
|
|
|
post 'projects/ecookbook/issues/new', :issue => { :tracker_id => "2"}
|
|
|
|
assert_response :success
|
|
|
|
assert_tag 'select',
|
|
|
|
:attributes => {:name => 'issue[tracker_id]'},
|
|
|
|
:child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}}
|
|
|
|
end
|
|
|
|
|
2006-12-26 23:14:03 +03:00
|
|
|
# add then remove 2 attachments to an issue
|
2011-04-02 12:01:06 +04:00
|
|
|
def test_issue_attachments
|
2006-12-26 23:14:03 +03:00
|
|
|
log_user('jsmith', 'jsmith')
|
2008-06-09 22:40:59 +04:00
|
|
|
set_tmp_attachments_directory
|
2006-12-26 23:14:03 +03:00
|
|
|
|
2010-08-26 20:36:59 +04:00
|
|
|
put 'issues/1',
|
2008-01-06 20:06:14 +03:00
|
|
|
:notes => 'Some notes',
|
2009-10-10 18:56:29 +04:00
|
|
|
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}}
|
2010-11-14 19:45:32 +03:00
|
|
|
assert_redirected_to "/issues/1"
|
2011-08-27 06:10:59 +04:00
|
|
|
|
2006-12-26 23:14:03 +03:00
|
|
|
# make sure attachment was saved
|
2007-02-18 14:41:39 +03:00
|
|
|
attachment = Issue.find(1).attachments.find_by_filename("testfile.txt")
|
2006-12-26 23:14:03 +03:00
|
|
|
assert_kind_of Attachment, attachment
|
|
|
|
assert_equal Issue.find(1), attachment.container
|
2008-02-29 22:46:58 +03:00
|
|
|
assert_equal 'This is an attachment', attachment.description
|
2006-12-26 23:14:03 +03:00
|
|
|
# verify the size of the attachment stored in db
|
2007-02-18 14:41:39 +03:00
|
|
|
#assert_equal file_data_1.length, attachment.filesize
|
2006-12-26 23:14:03 +03:00
|
|
|
# verify that the attachment was written to disk
|
|
|
|
assert File.exist?(attachment.diskfile)
|
2011-08-27 06:10:59 +04:00
|
|
|
|
2006-12-26 23:14:03 +03:00
|
|
|
# remove the attachments
|
|
|
|
Issue.find(1).attachments.each(&:destroy)
|
|
|
|
assert_equal 0, Issue.find(1).attachments.length
|
|
|
|
end
|
2011-08-27 06:10:59 +04:00
|
|
|
|
2011-12-01 22:02:21 +04:00
|
|
|
def test_other_formats_links_on_index
|
2009-03-07 01:46:49 +03:00
|
|
|
get '/projects/ecookbook/issues'
|
2011-08-27 06:10:59 +04:00
|
|
|
|
2009-03-07 01:46:49 +03:00
|
|
|
%w(Atom PDF CSV).each do |format|
|
|
|
|
assert_tag :a, :content => format,
|
|
|
|
:attributes => { :href => "/projects/ecookbook/issues.#{format.downcase}",
|
|
|
|
:rel => 'nofollow' }
|
|
|
|
end
|
|
|
|
end
|
2011-08-27 06:10:59 +04:00
|
|
|
|
2011-12-01 22:02:21 +04:00
|
|
|
def test_other_formats_links_on_index_without_project_id_in_url
|
|
|
|
get '/issues', :project_id => 'ecookbook'
|
2011-08-27 06:10:59 +04:00
|
|
|
|
2009-03-07 01:46:49 +03:00
|
|
|
%w(Atom PDF CSV).each do |format|
|
|
|
|
assert_tag :a, :content => format,
|
|
|
|
:attributes => { :href => "/projects/ecookbook/issues.#{format.downcase}",
|
|
|
|
:rel => 'nofollow' }
|
|
|
|
end
|
|
|
|
end
|
2011-08-27 06:10:59 +04:00
|
|
|
|
2011-12-01 22:02:21 +04:00
|
|
|
def test_pagination_links_on_index
|
2009-03-07 01:46:49 +03:00
|
|
|
Setting.per_page_options = '2'
|
|
|
|
get '/projects/ecookbook/issues'
|
2011-08-27 06:10:59 +04:00
|
|
|
|
2009-03-07 01:46:49 +03:00
|
|
|
assert_tag :a, :content => '2',
|
|
|
|
:attributes => { :href => '/projects/ecookbook/issues?page=2' }
|
2011-08-27 06:10:59 +04:00
|
|
|
|
2009-03-07 01:46:49 +03:00
|
|
|
end
|
2011-08-27 06:10:59 +04:00
|
|
|
|
2011-12-01 22:02:21 +04:00
|
|
|
def test_pagination_links_on_index_without_project_id_in_url
|
2009-03-07 01:46:49 +03:00
|
|
|
Setting.per_page_options = '2'
|
2011-12-01 22:02:21 +04:00
|
|
|
get '/issues', :project_id => 'ecookbook'
|
2011-08-27 06:10:59 +04:00
|
|
|
|
2009-03-07 01:46:49 +03:00
|
|
|
assert_tag :a, :content => '2',
|
|
|
|
:attributes => { :href => '/projects/ecookbook/issues?page=2' }
|
2011-08-27 06:10:59 +04:00
|
|
|
|
2009-03-07 01:46:49 +03:00
|
|
|
end
|
2011-08-27 06:10:59 +04:00
|
|
|
|
2011-04-01 17:44:58 +04:00
|
|
|
def test_issue_with_user_custom_field
|
|
|
|
@field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true, :trackers => Tracker.all)
|
|
|
|
Role.anonymous.add_permission! :add_issues, :edit_issues
|
|
|
|
users = Project.find(1).users
|
|
|
|
tester = users.first
|
2011-08-27 06:10:59 +04:00
|
|
|
|
2011-04-01 17:44:58 +04:00
|
|
|
# Issue form
|
|
|
|
get '/projects/ecookbook/issues/new'
|
|
|
|
assert_response :success
|
|
|
|
assert_tag :select,
|
|
|
|
:attributes => {:name => "issue[custom_field_values][#{@field.id}]"},
|
|
|
|
:children => {:count => (users.size + 1)}, # +1 for blank value
|
|
|
|
:child => {
|
|
|
|
:tag => 'option',
|
|
|
|
:attributes => {:value => tester.id.to_s},
|
|
|
|
:content => tester.name
|
|
|
|
}
|
2011-08-27 06:10:59 +04:00
|
|
|
|
2011-04-01 17:44:58 +04:00
|
|
|
# Create issue
|
|
|
|
assert_difference 'Issue.count' do
|
2011-08-27 06:10:59 +04:00
|
|
|
post '/projects/ecookbook/issues',
|
2011-04-01 17:44:58 +04:00
|
|
|
:issue => {
|
|
|
|
:tracker_id => '1',
|
|
|
|
:priority_id => '4',
|
|
|
|
:subject => 'Issue with user custom field',
|
|
|
|
:custom_field_values => {@field.id.to_s => users.first.id.to_s}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
issue = Issue.first(:order => 'id DESC')
|
|
|
|
assert_response 302
|
2011-08-27 06:10:59 +04:00
|
|
|
|
2011-04-01 17:44:58 +04:00
|
|
|
# Issue view
|
|
|
|
follow_redirect!
|
|
|
|
assert_tag :th,
|
|
|
|
:content => /Tester/,
|
|
|
|
:sibling => {
|
|
|
|
:tag => 'td',
|
|
|
|
:content => tester.name
|
|
|
|
}
|
|
|
|
assert_tag :select,
|
|
|
|
:attributes => {:name => "issue[custom_field_values][#{@field.id}]"},
|
|
|
|
:children => {:count => (users.size + 1)}, # +1 for blank value
|
|
|
|
:child => {
|
|
|
|
:tag => 'option',
|
|
|
|
:attributes => {:value => tester.id.to_s, :selected => 'selected'},
|
|
|
|
:content => tester.name
|
|
|
|
}
|
2011-08-27 06:10:59 +04:00
|
|
|
|
2011-04-01 17:44:58 +04:00
|
|
|
# Update issue
|
|
|
|
new_tester = users[1]
|
|
|
|
assert_difference 'Journal.count' do
|
|
|
|
put "/issues/#{issue.id}",
|
|
|
|
:notes => 'Updating custom field',
|
|
|
|
:issue => {
|
|
|
|
:custom_field_values => {@field.id.to_s => new_tester.id.to_s}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
assert_response 302
|
2011-08-27 06:10:59 +04:00
|
|
|
|
2011-04-01 17:44:58 +04:00
|
|
|
# Issue view
|
|
|
|
follow_redirect!
|
|
|
|
assert_tag :content => 'Tester',
|
|
|
|
:ancestor => {:tag => 'ul', :attributes => {:class => /details/}},
|
|
|
|
:sibling => {
|
|
|
|
:content => tester.name,
|
|
|
|
:sibling => {
|
|
|
|
:content => new_tester.name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
2006-12-26 23:14:03 +03:00
|
|
|
end
|