annotate .svn/pristine/d1/d17414b1dfdce0231596e6df806c393321b9c1d6.svn-base @ 1327:287f201c2802 redmine-2.2-integration

Add italic
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 19 Jun 2013 20:56:22 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 require File.expand_path('../../test_helper', __FILE__)
Chris@909 19
Chris@909 20 class IssuesTest < ActionController::IntegrationTest
Chris@909 21 fixtures :projects,
Chris@909 22 :users,
Chris@909 23 :roles,
Chris@909 24 :members,
Chris@909 25 :trackers,
Chris@909 26 :projects_trackers,
Chris@909 27 :enabled_modules,
Chris@909 28 :issue_statuses,
Chris@909 29 :issues,
Chris@909 30 :enumerations,
Chris@909 31 :custom_fields,
Chris@909 32 :custom_values,
Chris@909 33 :custom_fields_trackers
Chris@909 34
Chris@909 35 # create an issue
Chris@909 36 def test_add_issue
Chris@909 37 log_user('jsmith', 'jsmith')
Chris@909 38 get 'projects/1/issues/new', :tracker_id => '1'
Chris@909 39 assert_response :success
Chris@909 40 assert_template 'issues/new'
Chris@909 41
Chris@909 42 post 'projects/1/issues', :tracker_id => "1",
Chris@909 43 :issue => { :start_date => "2006-12-26",
Chris@909 44 :priority_id => "4",
Chris@909 45 :subject => "new test issue",
Chris@909 46 :category_id => "",
Chris@909 47 :description => "new issue",
Chris@909 48 :done_ratio => "0",
Chris@909 49 :due_date => "",
Chris@909 50 :assigned_to_id => "" },
Chris@909 51 :custom_fields => {'2' => 'Value for field 2'}
Chris@909 52 # find created issue
Chris@909 53 issue = Issue.find_by_subject("new test issue")
Chris@909 54 assert_kind_of Issue, issue
Chris@909 55
Chris@909 56 # check redirection
Chris@909 57 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
Chris@909 58 follow_redirect!
Chris@909 59 assert_equal issue, assigns(:issue)
Chris@909 60
Chris@909 61 # check issue attributes
Chris@909 62 assert_equal 'jsmith', issue.author.login
Chris@909 63 assert_equal 1, issue.project.id
Chris@909 64 assert_equal 1, issue.status.id
Chris@909 65 end
Chris@909 66
Chris@909 67 # add then remove 2 attachments to an issue
Chris@909 68 def test_issue_attachments
Chris@909 69 log_user('jsmith', 'jsmith')
Chris@909 70 set_tmp_attachments_directory
Chris@909 71
Chris@909 72 put 'issues/1',
Chris@909 73 :notes => 'Some notes',
Chris@909 74 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}}
Chris@909 75 assert_redirected_to "/issues/1"
Chris@909 76
Chris@909 77 # make sure attachment was saved
Chris@909 78 attachment = Issue.find(1).attachments.find_by_filename("testfile.txt")
Chris@909 79 assert_kind_of Attachment, attachment
Chris@909 80 assert_equal Issue.find(1), attachment.container
Chris@909 81 assert_equal 'This is an attachment', attachment.description
Chris@909 82 # verify the size of the attachment stored in db
Chris@909 83 #assert_equal file_data_1.length, attachment.filesize
Chris@909 84 # verify that the attachment was written to disk
Chris@909 85 assert File.exist?(attachment.diskfile)
Chris@909 86
Chris@909 87 # remove the attachments
Chris@909 88 Issue.find(1).attachments.each(&:destroy)
Chris@909 89 assert_equal 0, Issue.find(1).attachments.length
Chris@909 90 end
Chris@909 91
Chris@909 92 def test_other_formats_links_on_get_index
Chris@909 93 get '/projects/ecookbook/issues'
Chris@909 94
Chris@909 95 %w(Atom PDF CSV).each do |format|
Chris@909 96 assert_tag :a, :content => format,
Chris@909 97 :attributes => { :href => "/projects/ecookbook/issues.#{format.downcase}",
Chris@909 98 :rel => 'nofollow' }
Chris@909 99 end
Chris@909 100 end
Chris@909 101
Chris@909 102 def test_other_formats_links_on_post_index_without_project_id_in_url
Chris@909 103 post '/issues', :project_id => 'ecookbook'
Chris@909 104
Chris@909 105 %w(Atom PDF CSV).each do |format|
Chris@909 106 assert_tag :a, :content => format,
Chris@909 107 :attributes => { :href => "/projects/ecookbook/issues.#{format.downcase}",
Chris@909 108 :rel => 'nofollow' }
Chris@909 109 end
Chris@909 110 end
Chris@909 111
Chris@909 112 def test_pagination_links_on_get_index
Chris@909 113 Setting.per_page_options = '2'
Chris@909 114 get '/projects/ecookbook/issues'
Chris@909 115
Chris@909 116 assert_tag :a, :content => '2',
Chris@909 117 :attributes => { :href => '/projects/ecookbook/issues?page=2' }
Chris@909 118
Chris@909 119 end
Chris@909 120
Chris@909 121 def test_pagination_links_on_post_index_without_project_id_in_url
Chris@909 122 Setting.per_page_options = '2'
Chris@909 123 post '/issues', :project_id => 'ecookbook'
Chris@909 124
Chris@909 125 assert_tag :a, :content => '2',
Chris@909 126 :attributes => { :href => '/projects/ecookbook/issues?page=2' }
Chris@909 127
Chris@909 128 end
Chris@909 129
Chris@909 130 def test_issue_with_user_custom_field
Chris@909 131 @field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true, :trackers => Tracker.all)
Chris@909 132 Role.anonymous.add_permission! :add_issues, :edit_issues
Chris@909 133 users = Project.find(1).users
Chris@909 134 tester = users.first
Chris@909 135
Chris@909 136 # Issue form
Chris@909 137 get '/projects/ecookbook/issues/new'
Chris@909 138 assert_response :success
Chris@909 139 assert_tag :select,
Chris@909 140 :attributes => {:name => "issue[custom_field_values][#{@field.id}]"},
Chris@909 141 :children => {:count => (users.size + 1)}, # +1 for blank value
Chris@909 142 :child => {
Chris@909 143 :tag => 'option',
Chris@909 144 :attributes => {:value => tester.id.to_s},
Chris@909 145 :content => tester.name
Chris@909 146 }
Chris@909 147
Chris@909 148 # Create issue
Chris@909 149 assert_difference 'Issue.count' do
Chris@909 150 post '/projects/ecookbook/issues',
Chris@909 151 :issue => {
Chris@909 152 :tracker_id => '1',
Chris@909 153 :priority_id => '4',
Chris@909 154 :subject => 'Issue with user custom field',
Chris@909 155 :custom_field_values => {@field.id.to_s => users.first.id.to_s}
Chris@909 156 }
Chris@909 157 end
Chris@909 158 issue = Issue.first(:order => 'id DESC')
Chris@909 159 assert_response 302
Chris@909 160
Chris@909 161 # Issue view
Chris@909 162 follow_redirect!
Chris@909 163 assert_tag :th,
Chris@909 164 :content => /Tester/,
Chris@909 165 :sibling => {
Chris@909 166 :tag => 'td',
Chris@909 167 :content => tester.name
Chris@909 168 }
Chris@909 169 assert_tag :select,
Chris@909 170 :attributes => {:name => "issue[custom_field_values][#{@field.id}]"},
Chris@909 171 :children => {:count => (users.size + 1)}, # +1 for blank value
Chris@909 172 :child => {
Chris@909 173 :tag => 'option',
Chris@909 174 :attributes => {:value => tester.id.to_s, :selected => 'selected'},
Chris@909 175 :content => tester.name
Chris@909 176 }
Chris@909 177
Chris@909 178 # Update issue
Chris@909 179 new_tester = users[1]
Chris@909 180 assert_difference 'Journal.count' do
Chris@909 181 put "/issues/#{issue.id}",
Chris@909 182 :notes => 'Updating custom field',
Chris@909 183 :issue => {
Chris@909 184 :custom_field_values => {@field.id.to_s => new_tester.id.to_s}
Chris@909 185 }
Chris@909 186 end
Chris@909 187 assert_response 302
Chris@909 188
Chris@909 189 # Issue view
Chris@909 190 follow_redirect!
Chris@909 191 assert_tag :content => 'Tester',
Chris@909 192 :ancestor => {:tag => 'ul', :attributes => {:class => /details/}},
Chris@909 193 :sibling => {
Chris@909 194 :content => tester.name,
Chris@909 195 :sibling => {
Chris@909 196 :content => new_tester.name
Chris@909 197 }
Chris@909 198 }
Chris@909 199 end
Chris@909 200 end