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