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