annotate test/functional/journals_controller_test.rb @ 1465:ab8bd24eeb65 bug_635

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