annotate .svn/pristine/19/1959b21aed080e49e7eb19db5f9d559c39f78f7a.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-2012 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 require 'journals_controller'
Chris@1295 20
Chris@1295 21 # Re-raise errors caught by the controller.
Chris@1295 22 class JournalsController; def rescue_action(e) raise e end; end
Chris@1295 23
Chris@1295 24 class JournalsControllerTest < ActionController::TestCase
Chris@1295 25 fixtures :projects, :users, :members, :member_roles, :roles, :issues, :journals, :journal_details, :enabled_modules,
Chris@1295 26 :trackers, :issue_statuses, :enumerations, :custom_fields, :custom_values, :custom_fields_projects
Chris@1295 27
Chris@1295 28 def setup
Chris@1295 29 @controller = JournalsController.new
Chris@1295 30 @request = ActionController::TestRequest.new
Chris@1295 31 @response = ActionController::TestResponse.new
Chris@1295 32 User.current = nil
Chris@1295 33 end
Chris@1295 34
Chris@1295 35 def test_index
Chris@1295 36 get :index, :project_id => 1
Chris@1295 37 assert_response :success
Chris@1295 38 assert_not_nil assigns(:journals)
Chris@1295 39 assert_equal 'application/atom+xml', @response.content_type
Chris@1295 40 end
Chris@1295 41
Chris@1295 42 def test_index_should_return_privates_notes_with_permission_only
Chris@1295 43 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
Chris@1295 44 @request.session[:user_id] = 2
Chris@1295 45
Chris@1295 46 get :index, :project_id => 1
Chris@1295 47 assert_response :success
Chris@1295 48 assert_include journal, assigns(:journals)
Chris@1295 49
Chris@1295 50 Role.find(1).remove_permission! :view_private_notes
Chris@1295 51 get :index, :project_id => 1
Chris@1295 52 assert_response :success
Chris@1295 53 assert_not_include journal, assigns(:journals)
Chris@1295 54 end
Chris@1295 55
Chris@1295 56 def test_diff
Chris@1295 57 get :diff, :id => 3, :detail_id => 4
Chris@1295 58 assert_response :success
Chris@1295 59 assert_template 'diff'
Chris@1295 60
Chris@1295 61 assert_tag 'span',
Chris@1295 62 :attributes => {:class => 'diff_out'},
Chris@1295 63 :content => /removed/
Chris@1295 64 assert_tag 'span',
Chris@1295 65 :attributes => {:class => 'diff_in'},
Chris@1295 66 :content => /added/
Chris@1295 67 end
Chris@1295 68
Chris@1295 69 def test_reply_to_issue
Chris@1295 70 @request.session[:user_id] = 2
Chris@1295 71 xhr :get, :new, :id => 6
Chris@1295 72 assert_response :success
Chris@1295 73 assert_template 'new'
Chris@1295 74 assert_equal 'text/javascript', response.content_type
Chris@1295 75 assert_include '> This is an issue', response.body
Chris@1295 76 end
Chris@1295 77
Chris@1295 78 def test_reply_to_issue_without_permission
Chris@1295 79 @request.session[:user_id] = 7
Chris@1295 80 xhr :get, :new, :id => 6
Chris@1295 81 assert_response 403
Chris@1295 82 end
Chris@1295 83
Chris@1295 84 def test_reply_to_note
Chris@1295 85 @request.session[:user_id] = 2
Chris@1295 86 xhr :get, :new, :id => 6, :journal_id => 4
Chris@1295 87 assert_response :success
Chris@1295 88 assert_template 'new'
Chris@1295 89 assert_equal 'text/javascript', response.content_type
Chris@1295 90 assert_include '> A comment with a private version', response.body
Chris@1295 91 end
Chris@1295 92
Chris@1295 93 def test_reply_to_private_note_should_fail_without_permission
Chris@1295 94 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true)
Chris@1295 95 @request.session[:user_id] = 2
Chris@1295 96
Chris@1295 97 xhr :get, :new, :id => 2, :journal_id => journal.id
Chris@1295 98 assert_response :success
Chris@1295 99 assert_template 'new'
Chris@1295 100 assert_equal 'text/javascript', response.content_type
Chris@1295 101 assert_include '> Privates notes', response.body
Chris@1295 102
Chris@1295 103 Role.find(1).remove_permission! :view_private_notes
Chris@1295 104 xhr :get, :new, :id => 2, :journal_id => journal.id
Chris@1295 105 assert_response 404
Chris@1295 106 end
Chris@1295 107
Chris@1295 108 def test_edit_xhr
Chris@1295 109 @request.session[:user_id] = 1
Chris@1295 110 xhr :get, :edit, :id => 2
Chris@1295 111 assert_response :success
Chris@1295 112 assert_template 'edit'
Chris@1295 113 assert_equal 'text/javascript', response.content_type
Chris@1295 114 assert_include 'textarea', response.body
Chris@1295 115 end
Chris@1295 116
Chris@1295 117 def test_edit_private_note_should_fail_without_permission
Chris@1295 118 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true)
Chris@1295 119 @request.session[:user_id] = 2
Chris@1295 120 Role.find(1).add_permission! :edit_issue_notes
Chris@1295 121
Chris@1295 122 xhr :get, :edit, :id => journal.id
Chris@1295 123 assert_response :success
Chris@1295 124 assert_template 'edit'
Chris@1295 125 assert_equal 'text/javascript', response.content_type
Chris@1295 126 assert_include 'textarea', response.body
Chris@1295 127
Chris@1295 128 Role.find(1).remove_permission! :view_private_notes
Chris@1295 129 xhr :get, :edit, :id => journal.id
Chris@1295 130 assert_response 404
Chris@1295 131 end
Chris@1295 132
Chris@1295 133 def test_update_xhr
Chris@1295 134 @request.session[:user_id] = 1
Chris@1295 135 xhr :post, :edit, :id => 2, :notes => 'Updated notes'
Chris@1295 136 assert_response :success
Chris@1295 137 assert_template 'update'
Chris@1295 138 assert_equal 'text/javascript', response.content_type
Chris@1295 139 assert_equal 'Updated notes', Journal.find(2).notes
Chris@1295 140 assert_include 'journal-2-notes', response.body
Chris@1295 141 end
Chris@1295 142
Chris@1295 143 def test_update_xhr_with_empty_notes_should_delete_the_journal
Chris@1295 144 @request.session[:user_id] = 1
Chris@1295 145 assert_difference 'Journal.count', -1 do
Chris@1295 146 xhr :post, :edit, :id => 2, :notes => ''
Chris@1295 147 assert_response :success
Chris@1295 148 assert_template 'update'
Chris@1295 149 assert_equal 'text/javascript', response.content_type
Chris@1295 150 end
Chris@1295 151 assert_nil Journal.find_by_id(2)
Chris@1295 152 assert_include 'change-2', response.body
Chris@1295 153 end
Chris@1295 154 end