annotate .svn/pristine/59/598bfbe3334b3cbbbae9cfeaf77c5e20e935d3f1.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

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