To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / 0e / 0e59eac074a412c3150c3135d0a1eec08baa4fba.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (8.99 KB)
| 1 | 1296:038ba2d95de8 | Chris | # Redmine - project management software |
|---|---|---|---|
| 2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
||
| 3 | # |
||
| 4 | # This program is free software; you can redistribute it and/or |
||
| 5 | # modify it under the terms of the GNU General Public License |
||
| 6 | # as published by the Free Software Foundation; either version 2 |
||
| 7 | # of the License, or (at your option) any later version. |
||
| 8 | # |
||
| 9 | # This program is distributed in the hope that it will be useful, |
||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 12 | # GNU General Public License for more details. |
||
| 13 | # |
||
| 14 | # You should have received a copy of the GNU General Public License |
||
| 15 | # along with this program; if not, write to the Free Software |
||
| 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||
| 17 | |||
| 18 | require File.expand_path('../../test_helper', __FILE__)
|
||
| 19 | require 'issues_controller' |
||
| 20 | |||
| 21 | class IssuesControllerTransactionTest < ActionController::TestCase |
||
| 22 | fixtures :projects, |
||
| 23 | :users, |
||
| 24 | :roles, |
||
| 25 | :members, |
||
| 26 | :member_roles, |
||
| 27 | :issues, |
||
| 28 | :issue_statuses, |
||
| 29 | :versions, |
||
| 30 | :trackers, |
||
| 31 | :projects_trackers, |
||
| 32 | :issue_categories, |
||
| 33 | :enabled_modules, |
||
| 34 | :enumerations, |
||
| 35 | :attachments, |
||
| 36 | :workflows, |
||
| 37 | :custom_fields, |
||
| 38 | :custom_values, |
||
| 39 | :custom_fields_projects, |
||
| 40 | :custom_fields_trackers, |
||
| 41 | :time_entries, |
||
| 42 | :journals, |
||
| 43 | :journal_details, |
||
| 44 | :queries |
||
| 45 | |||
| 46 | self.use_transactional_fixtures = false |
||
| 47 | |||
| 48 | def setup |
||
| 49 | @controller = IssuesController.new |
||
| 50 | @request = ActionController::TestRequest.new |
||
| 51 | @response = ActionController::TestResponse.new |
||
| 52 | User.current = nil |
||
| 53 | end |
||
| 54 | |||
| 55 | def test_update_stale_issue_should_not_update_the_issue |
||
| 56 | issue = Issue.find(2) |
||
| 57 | @request.session[:user_id] = 2 |
||
| 58 | |||
| 59 | assert_no_difference 'Journal.count' do |
||
| 60 | assert_no_difference 'TimeEntry.count' do |
||
| 61 | put :update, |
||
| 62 | :id => issue.id, |
||
| 63 | :issue => {
|
||
| 64 | :fixed_version_id => 4, |
||
| 65 | :notes => 'My notes', |
||
| 66 | :lock_version => (issue.lock_version - 1) |
||
| 67 | }, |
||
| 68 | :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id }
|
||
| 69 | end |
||
| 70 | end |
||
| 71 | |||
| 72 | assert_response :success |
||
| 73 | assert_template 'edit' |
||
| 74 | |||
| 75 | assert_select 'div.conflict' |
||
| 76 | assert_select 'input[name=?][value=?]', 'conflict_resolution', 'overwrite' |
||
| 77 | assert_select 'input[name=?][value=?]', 'conflict_resolution', 'add_notes' |
||
| 78 | assert_select 'label' do |
||
| 79 | assert_select 'input[name=?][value=?]', 'conflict_resolution', 'cancel' |
||
| 80 | assert_select 'a[href=/issues/2]' |
||
| 81 | end |
||
| 82 | end |
||
| 83 | |||
| 84 | def test_update_stale_issue_should_save_attachments |
||
| 85 | set_tmp_attachments_directory |
||
| 86 | issue = Issue.find(2) |
||
| 87 | @request.session[:user_id] = 2 |
||
| 88 | |||
| 89 | assert_no_difference 'Journal.count' do |
||
| 90 | assert_no_difference 'TimeEntry.count' do |
||
| 91 | assert_difference 'Attachment.count' do |
||
| 92 | put :update, |
||
| 93 | :id => issue.id, |
||
| 94 | :issue => {
|
||
| 95 | :fixed_version_id => 4, |
||
| 96 | :notes => 'My notes', |
||
| 97 | :lock_version => (issue.lock_version - 1) |
||
| 98 | }, |
||
| 99 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}},
|
||
| 100 | :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id }
|
||
| 101 | end |
||
| 102 | end |
||
| 103 | end |
||
| 104 | |||
| 105 | assert_response :success |
||
| 106 | assert_template 'edit' |
||
| 107 | attachment = Attachment.first(:order => 'id DESC') |
||
| 108 | assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
|
||
| 109 | assert_tag 'span', :content => /testfile.txt/ |
||
| 110 | end |
||
| 111 | |||
| 112 | def test_update_stale_issue_without_notes_should_not_show_add_notes_option |
||
| 113 | issue = Issue.find(2) |
||
| 114 | @request.session[:user_id] = 2 |
||
| 115 | |||
| 116 | put :update, :id => issue.id, |
||
| 117 | :issue => {
|
||
| 118 | :fixed_version_id => 4, |
||
| 119 | :notes => '', |
||
| 120 | :lock_version => (issue.lock_version - 1) |
||
| 121 | } |
||
| 122 | |||
| 123 | assert_tag 'div', :attributes => {:class => 'conflict'}
|
||
| 124 | assert_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'overwrite'}
|
||
| 125 | assert_no_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'add_notes'}
|
||
| 126 | assert_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'cancel'}
|
||
| 127 | end |
||
| 128 | |||
| 129 | def test_update_stale_issue_should_show_conflicting_journals |
||
| 130 | @request.session[:user_id] = 2 |
||
| 131 | |||
| 132 | put :update, :id => 1, |
||
| 133 | :issue => {
|
||
| 134 | :fixed_version_id => 4, |
||
| 135 | :notes => '', |
||
| 136 | :lock_version => 2 |
||
| 137 | }, |
||
| 138 | :last_journal_id => 1 |
||
| 139 | |||
| 140 | assert_not_nil assigns(:conflict_journals) |
||
| 141 | assert_equal 1, assigns(:conflict_journals).size |
||
| 142 | assert_equal 2, assigns(:conflict_journals).first.id |
||
| 143 | assert_tag 'div', :attributes => {:class => 'conflict'},
|
||
| 144 | :descendant => {:content => /Some notes with Redmine links/}
|
||
| 145 | end |
||
| 146 | |||
| 147 | def test_update_stale_issue_without_previous_journal_should_show_all_journals |
||
| 148 | @request.session[:user_id] = 2 |
||
| 149 | |||
| 150 | put :update, :id => 1, |
||
| 151 | :issue => {
|
||
| 152 | :fixed_version_id => 4, |
||
| 153 | :notes => '', |
||
| 154 | :lock_version => 2 |
||
| 155 | }, |
||
| 156 | :last_journal_id => '' |
||
| 157 | |||
| 158 | assert_not_nil assigns(:conflict_journals) |
||
| 159 | assert_equal 2, assigns(:conflict_journals).size |
||
| 160 | assert_tag 'div', :attributes => {:class => 'conflict'},
|
||
| 161 | :descendant => {:content => /Some notes with Redmine links/}
|
||
| 162 | assert_tag 'div', :attributes => {:class => 'conflict'},
|
||
| 163 | :descendant => {:content => /Journal notes/}
|
||
| 164 | end |
||
| 165 | |||
| 166 | def test_update_stale_issue_should_show_private_journals_with_permission_only |
||
| 167 | journal = Journal.create!(:journalized => Issue.find(1), :notes => 'Privates notes', :private_notes => true, :user_id => 1) |
||
| 168 | |||
| 169 | @request.session[:user_id] = 2 |
||
| 170 | put :update, :id => 1, :issue => {:fixed_version_id => 4, :lock_version => 2}, :last_journal_id => ''
|
||
| 171 | assert_include journal, assigns(:conflict_journals) |
||
| 172 | |||
| 173 | Role.find(1).remove_permission! :view_private_notes |
||
| 174 | put :update, :id => 1, :issue => {:fixed_version_id => 4, :lock_version => 2}, :last_journal_id => ''
|
||
| 175 | assert_not_include journal, assigns(:conflict_journals) |
||
| 176 | end |
||
| 177 | |||
| 178 | def test_update_stale_issue_with_overwrite_conflict_resolution_should_update |
||
| 179 | @request.session[:user_id] = 2 |
||
| 180 | |||
| 181 | assert_difference 'Journal.count' do |
||
| 182 | put :update, :id => 1, |
||
| 183 | :issue => {
|
||
| 184 | :fixed_version_id => 4, |
||
| 185 | :notes => 'overwrite_conflict_resolution', |
||
| 186 | :lock_version => 2 |
||
| 187 | }, |
||
| 188 | :conflict_resolution => 'overwrite' |
||
| 189 | end |
||
| 190 | |||
| 191 | assert_response 302 |
||
| 192 | issue = Issue.find(1) |
||
| 193 | assert_equal 4, issue.fixed_version_id |
||
| 194 | journal = Journal.first(:order => 'id DESC') |
||
| 195 | assert_equal 'overwrite_conflict_resolution', journal.notes |
||
| 196 | assert journal.details.any? |
||
| 197 | end |
||
| 198 | |||
| 199 | def test_update_stale_issue_with_add_notes_conflict_resolution_should_update |
||
| 200 | @request.session[:user_id] = 2 |
||
| 201 | |||
| 202 | assert_difference 'Journal.count' do |
||
| 203 | put :update, :id => 1, |
||
| 204 | :issue => {
|
||
| 205 | :fixed_version_id => 4, |
||
| 206 | :notes => 'add_notes_conflict_resolution', |
||
| 207 | :lock_version => 2 |
||
| 208 | }, |
||
| 209 | :conflict_resolution => 'add_notes' |
||
| 210 | end |
||
| 211 | |||
| 212 | assert_response 302 |
||
| 213 | issue = Issue.find(1) |
||
| 214 | assert_nil issue.fixed_version_id |
||
| 215 | journal = Journal.first(:order => 'id DESC') |
||
| 216 | assert_equal 'add_notes_conflict_resolution', journal.notes |
||
| 217 | assert journal.details.empty? |
||
| 218 | end |
||
| 219 | |||
| 220 | def test_update_stale_issue_with_cancel_conflict_resolution_should_redirect_without_updating |
||
| 221 | @request.session[:user_id] = 2 |
||
| 222 | |||
| 223 | assert_no_difference 'Journal.count' do |
||
| 224 | put :update, :id => 1, |
||
| 225 | :issue => {
|
||
| 226 | :fixed_version_id => 4, |
||
| 227 | :notes => 'add_notes_conflict_resolution', |
||
| 228 | :lock_version => 2 |
||
| 229 | }, |
||
| 230 | :conflict_resolution => 'cancel' |
||
| 231 | end |
||
| 232 | |||
| 233 | assert_redirected_to '/issues/1' |
||
| 234 | issue = Issue.find(1) |
||
| 235 | assert_nil issue.fixed_version_id |
||
| 236 | end |
||
| 237 | |||
| 238 | def test_put_update_with_spent_time_and_failure_should_not_add_spent_time |
||
| 239 | @request.session[:user_id] = 2 |
||
| 240 | |||
| 241 | assert_no_difference('TimeEntry.count') do
|
||
| 242 | put :update, |
||
| 243 | :id => 1, |
||
| 244 | :issue => { :subject => '' },
|
||
| 245 | :time_entry => { :hours => '2.5', :comments => 'should not be added', :activity_id => TimeEntryActivity.first.id }
|
||
| 246 | assert_response :success |
||
| 247 | end |
||
| 248 | |||
| 249 | assert_select 'input[name=?][value=?]', 'time_entry[hours]', '2.5' |
||
| 250 | assert_select 'input[name=?][value=?]', 'time_entry[comments]', 'should not be added' |
||
| 251 | assert_select 'select[name=?]', 'time_entry[activity_id]' do |
||
| 252 | assert_select 'option[value=?][selected=selected]', TimeEntryActivity.first.id |
||
| 253 | end |
||
| 254 | end |
||
| 255 | |||
| 256 | def test_index_should_rescue_invalid_sql_query |
||
| 257 | Query.any_instance.stubs(:statement).returns("INVALID STATEMENT")
|
||
| 258 | |||
| 259 | get :index |
||
| 260 | assert_response 500 |
||
| 261 | assert_tag 'p', :content => /An error occurred/ |
||
| 262 | assert_nil session[:query] |
||
| 263 | assert_nil session[:issues_index_sort] |
||
| 264 | end |
||
| 265 | end |