annotate .svn/pristine/78/78164ab7a78d6e246acf0f645b14e7909fe8c662.svn-base @ 1613:90bed4e10cc8 deploy

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