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