comparison test/functional/journals_controller_test.rb @ 1115:433d4f72a19b redmine-2.2

Update to Redmine SVN revision 11137 on 2.2-stable branch
author Chris Cannam
date Mon, 07 Jan 2013 12:01:42 +0000
parents cbce1fd3b1b7
children 622f24f53b42
comparison
equal deleted inserted replaced
929:5f33065ddc4b 1115:433d4f72a19b
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
37 assert_response :success 37 assert_response :success
38 assert_not_nil assigns(:journals) 38 assert_not_nil assigns(:journals)
39 assert_equal 'application/atom+xml', @response.content_type 39 assert_equal 'application/atom+xml', @response.content_type
40 end 40 end
41 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
42 def test_diff 56 def test_diff
43 get :diff, :id => 3, :detail_id => 4 57 get :diff, :id => 3, :detail_id => 4
44 assert_response :success 58 assert_response :success
45 assert_template 'diff' 59 assert_template 'diff'
46 60
52 :content => /added/ 66 :content => /added/
53 end 67 end
54 68
55 def test_reply_to_issue 69 def test_reply_to_issue
56 @request.session[:user_id] = 2 70 @request.session[:user_id] = 2
57 get :new, :id => 6 71 xhr :get, :new, :id => 6
58 assert_response :success 72 assert_response :success
59 assert_select_rjs :show, "update" 73 assert_template 'new'
74 assert_equal 'text/javascript', response.content_type
75 assert_include '> This is an issue', response.body
60 end 76 end
61 77
62 def test_reply_to_issue_without_permission 78 def test_reply_to_issue_without_permission
63 @request.session[:user_id] = 7 79 @request.session[:user_id] = 7
64 get :new, :id => 6 80 xhr :get, :new, :id => 6
65 assert_response 403 81 assert_response 403
66 end 82 end
67 83
68 def test_reply_to_note 84 def test_reply_to_note
69 @request.session[:user_id] = 2 85 @request.session[:user_id] = 2
70 get :new, :id => 6, :journal_id => 4 86 xhr :get, :new, :id => 6, :journal_id => 4
71 assert_response :success 87 assert_response :success
72 assert_select_rjs :show, "update" 88 assert_template 'new'
89 assert_equal 'text/javascript', response.content_type
90 assert_include '> A comment with a private version', response.body
73 end 91 end
74 92
75 def test_get_edit 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
76 @request.session[:user_id] = 1 109 @request.session[:user_id] = 1
77 xhr :get, :edit, :id => 2 110 xhr :get, :edit, :id => 2
78 assert_response :success 111 assert_response :success
79 assert_select_rjs :insert, :after, 'journal-2-notes' do 112 assert_template 'edit'
80 assert_select 'form[id=journal-2-form]' 113 assert_equal 'text/javascript', response.content_type
81 assert_select 'textarea' 114 assert_include 'textarea', response.body
82 end
83 end 115 end
84 116
85 def test_post_edit 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
86 @request.session[:user_id] = 1 134 @request.session[:user_id] = 1
87 xhr :post, :edit, :id => 2, :notes => 'Updated notes' 135 xhr :post, :edit, :id => 2, :notes => 'Updated notes'
88 assert_response :success 136 assert_response :success
89 assert_select_rjs :replace, 'journal-2-notes' 137 assert_template 'update'
138 assert_equal 'text/javascript', response.content_type
90 assert_equal 'Updated notes', Journal.find(2).notes 139 assert_equal 'Updated notes', Journal.find(2).notes
140 assert_include 'journal-2-notes', response.body
91 end 141 end
92 142
93 def test_post_edit_with_empty_notes 143 def test_update_xhr_with_empty_notes_should_delete_the_journal
94 @request.session[:user_id] = 1 144 @request.session[:user_id] = 1
95 xhr :post, :edit, :id => 2, :notes => '' 145 assert_difference 'Journal.count', -1 do
96 assert_response :success 146 xhr :post, :edit, :id => 2, :notes => ''
97 assert_select_rjs :remove, 'change-2' 147 assert_response :success
148 assert_template 'update'
149 assert_equal 'text/javascript', response.content_type
150 end
98 assert_nil Journal.find_by_id(2) 151 assert_nil Journal.find_by_id(2)
152 assert_include 'change-2', response.body
99 end 153 end
100 end 154 end