annotate .svn/pristine/fb/fb0370610c36e942e95f18248151b66c8bb1d28d.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
rev   line source
Chris@1295 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
Chris@1295 3 #
Chris@1295 4 # This program is free software; you can redistribute it and/or
Chris@1295 5 # modify it under the terms of the GNU General Public License
Chris@1295 6 # as published by the Free Software Foundation; either version 2
Chris@1295 7 # of the License, or (at your option) any later version.
Chris@1295 8 #
Chris@1295 9 # This program is distributed in the hope that it will be useful,
Chris@1295 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1295 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1295 12 # GNU General Public License for more details.
Chris@1295 13 #
Chris@1295 14 # You should have received a copy of the GNU General Public License
Chris@1295 15 # along with this program; if not, write to the Free Software
Chris@1295 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1295 17
Chris@1295 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1295 19
Chris@1295 20 class JournalsControllerTest < ActionController::TestCase
Chris@1295 21 fixtures :projects, :users, :members, :member_roles, :roles, :issues, :journals, :journal_details, :enabled_modules,
Chris@1295 22 :trackers, :issue_statuses, :enumerations, :custom_fields, :custom_values, :custom_fields_projects
Chris@1295 23
Chris@1295 24 def setup
Chris@1295 25 User.current = nil
Chris@1295 26 end
Chris@1295 27
Chris@1295 28 def test_index
Chris@1295 29 get :index, :project_id => 1
Chris@1295 30 assert_response :success
Chris@1295 31 assert_not_nil assigns(:journals)
Chris@1295 32 assert_equal 'application/atom+xml', @response.content_type
Chris@1295 33 end
Chris@1295 34
Chris@1295 35 def test_index_should_return_privates_notes_with_permission_only
Chris@1295 36 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
Chris@1295 37 @request.session[:user_id] = 2
Chris@1295 38
Chris@1295 39 get :index, :project_id => 1
Chris@1295 40 assert_response :success
Chris@1295 41 assert_include journal, assigns(:journals)
Chris@1295 42
Chris@1295 43 Role.find(1).remove_permission! :view_private_notes
Chris@1295 44 get :index, :project_id => 1
Chris@1295 45 assert_response :success
Chris@1295 46 assert_not_include journal, assigns(:journals)
Chris@1295 47 end
Chris@1295 48
Chris@1295 49 def test_diff
Chris@1295 50 get :diff, :id => 3, :detail_id => 4
Chris@1295 51 assert_response :success
Chris@1295 52 assert_template 'diff'
Chris@1295 53
Chris@1295 54 assert_tag 'span',
Chris@1295 55 :attributes => {:class => 'diff_out'},
Chris@1295 56 :content => /removed/
Chris@1295 57 assert_tag 'span',
Chris@1295 58 :attributes => {:class => 'diff_in'},
Chris@1295 59 :content => /added/
Chris@1295 60 end
Chris@1295 61
Chris@1295 62 def test_reply_to_issue
Chris@1295 63 @request.session[:user_id] = 2
Chris@1295 64 xhr :get, :new, :id => 6
Chris@1295 65 assert_response :success
Chris@1295 66 assert_template 'new'
Chris@1295 67 assert_equal 'text/javascript', response.content_type
Chris@1295 68 assert_include '> This is an issue', response.body
Chris@1295 69 end
Chris@1295 70
Chris@1295 71 def test_reply_to_issue_without_permission
Chris@1295 72 @request.session[:user_id] = 7
Chris@1295 73 xhr :get, :new, :id => 6
Chris@1295 74 assert_response 403
Chris@1295 75 end
Chris@1295 76
Chris@1295 77 def test_reply_to_note
Chris@1295 78 @request.session[:user_id] = 2
Chris@1295 79 xhr :get, :new, :id => 6, :journal_id => 4
Chris@1295 80 assert_response :success
Chris@1295 81 assert_template 'new'
Chris@1295 82 assert_equal 'text/javascript', response.content_type
Chris@1295 83 assert_include '> A comment with a private version', response.body
Chris@1295 84 end
Chris@1295 85
Chris@1295 86 def test_reply_to_private_note_should_fail_without_permission
Chris@1295 87 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true)
Chris@1295 88 @request.session[:user_id] = 2
Chris@1295 89
Chris@1295 90 xhr :get, :new, :id => 2, :journal_id => journal.id
Chris@1295 91 assert_response :success
Chris@1295 92 assert_template 'new'
Chris@1295 93 assert_equal 'text/javascript', response.content_type
Chris@1295 94 assert_include '> Privates notes', response.body
Chris@1295 95
Chris@1295 96 Role.find(1).remove_permission! :view_private_notes
Chris@1295 97 xhr :get, :new, :id => 2, :journal_id => journal.id
Chris@1295 98 assert_response 404
Chris@1295 99 end
Chris@1295 100
Chris@1295 101 def test_edit_xhr
Chris@1295 102 @request.session[:user_id] = 1
Chris@1295 103 xhr :get, :edit, :id => 2
Chris@1295 104 assert_response :success
Chris@1295 105 assert_template 'edit'
Chris@1295 106 assert_equal 'text/javascript', response.content_type
Chris@1295 107 assert_include 'textarea', response.body
Chris@1295 108 end
Chris@1295 109
Chris@1295 110 def test_edit_private_note_should_fail_without_permission
Chris@1295 111 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true)
Chris@1295 112 @request.session[:user_id] = 2
Chris@1295 113 Role.find(1).add_permission! :edit_issue_notes
Chris@1295 114
Chris@1295 115 xhr :get, :edit, :id => journal.id
Chris@1295 116 assert_response :success
Chris@1295 117 assert_template 'edit'
Chris@1295 118 assert_equal 'text/javascript', response.content_type
Chris@1295 119 assert_include 'textarea', response.body
Chris@1295 120
Chris@1295 121 Role.find(1).remove_permission! :view_private_notes
Chris@1295 122 xhr :get, :edit, :id => journal.id
Chris@1295 123 assert_response 404
Chris@1295 124 end
Chris@1295 125
Chris@1295 126 def test_update_xhr
Chris@1295 127 @request.session[:user_id] = 1
Chris@1295 128 xhr :post, :edit, :id => 2, :notes => 'Updated notes'
Chris@1295 129 assert_response :success
Chris@1295 130 assert_template 'update'
Chris@1295 131 assert_equal 'text/javascript', response.content_type
Chris@1295 132 assert_equal 'Updated notes', Journal.find(2).notes
Chris@1295 133 assert_include 'journal-2-notes', response.body
Chris@1295 134 end
Chris@1295 135
Chris@1295 136 def test_update_xhr_with_empty_notes_should_delete_the_journal
Chris@1295 137 @request.session[:user_id] = 1
Chris@1295 138 assert_difference 'Journal.count', -1 do
Chris@1295 139 xhr :post, :edit, :id => 2, :notes => ''
Chris@1295 140 assert_response :success
Chris@1295 141 assert_template 'update'
Chris@1295 142 assert_equal 'text/javascript', response.content_type
Chris@1295 143 end
Chris@1295 144 assert_nil Journal.find_by_id(2)
Chris@1295 145 assert_include 'change-2', response.body
Chris@1295 146 end
Chris@1295 147 end