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