annotate test/functional/journals_controller_test.rb @ 1516:b450a9d58aed redmine-2.4

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