##// END OF EJS Templates
More function tests for MessagesController....
Jean-Philippe Lang -
r9048:2de9e782ad2e
parent child
Show More
@@ -1,155 +1,185
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19 require 'messages_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class MessagesController; def rescue_action(e) raise e end; end
23 23
24 24 class MessagesControllerTest < ActionController::TestCase
25 25 fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
26 26
27 27 def setup
28 28 @controller = MessagesController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 31 User.current = nil
32 32 end
33 33
34 34 def test_show
35 35 get :show, :board_id => 1, :id => 1
36 36 assert_response :success
37 37 assert_template 'show'
38 38 assert_not_nil assigns(:board)
39 39 assert_not_nil assigns(:project)
40 40 assert_not_nil assigns(:topic)
41 41 end
42 42
43 43 def test_show_should_contain_reply_field_tags_for_quoting
44 44 @request.session[:user_id] = 2
45 45 get :show, :board_id => 1, :id => 1
46 46 assert_response :success
47 47
48 48 # tags required by MessagesController#quote
49 49 assert_tag 'input', :attributes => {:id => 'message_subject'}
50 50 assert_tag 'textarea', :attributes => {:id => 'message_content'}
51 51 assert_tag 'div', :attributes => {:id => 'reply'}
52 52 end
53 53
54 54 def test_show_with_pagination
55 55 message = Message.find(1)
56 56 assert_difference 'Message.count', 30 do
57 57 30.times do
58 58 message.children << Message.new(:subject => 'Reply', :content => 'Reply body', :author_id => 2, :board_id => 1)
59 59 end
60 60 end
61 61 get :show, :board_id => 1, :id => 1, :r => message.children.last(:order => 'id').id
62 62 assert_response :success
63 63 assert_template 'show'
64 64 replies = assigns(:replies)
65 65 assert_not_nil replies
66 66 assert !replies.include?(message.children.first(:order => 'id'))
67 67 assert replies.include?(message.children.last(:order => 'id'))
68 68 end
69 69
70 70 def test_show_with_reply_permission
71 71 @request.session[:user_id] = 2
72 72 get :show, :board_id => 1, :id => 1
73 73 assert_response :success
74 74 assert_template 'show'
75 75 assert_tag :div, :attributes => { :id => 'reply' },
76 76 :descendant => { :tag => 'textarea', :attributes => { :id => 'message_content' } }
77 77 end
78 78
79 79 def test_show_message_not_found
80 80 get :show, :board_id => 1, :id => 99999
81 81 assert_response 404
82 82 end
83 83
84 84 def test_get_new
85 85 @request.session[:user_id] = 2
86 86 get :new, :board_id => 1
87 87 assert_response :success
88 88 assert_template 'new'
89 89 end
90 90
91 91 def test_post_new
92 92 @request.session[:user_id] = 2
93 93 ActionMailer::Base.deliveries.clear
94 94 Setting.notified_events = ['message_posted']
95 95
96 96 post :new, :board_id => 1,
97 97 :message => { :subject => 'Test created message',
98 98 :content => 'Message body'}
99 99 message = Message.find_by_subject('Test created message')
100 100 assert_not_nil message
101 101 assert_redirected_to "/boards/1/topics/#{message.to_param}"
102 102 assert_equal 'Message body', message.content
103 103 assert_equal 2, message.author_id
104 104 assert_equal 1, message.board_id
105 105
106 106 mail = ActionMailer::Base.deliveries.last
107 107 assert_not_nil mail
108 108 assert_equal "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] Test created message", mail.subject
109 109 assert_mail_body_match 'Message body', mail
110 110 # author
111 111 assert mail.bcc.include?('jsmith@somenet.foo')
112 112 # project member
113 113 assert mail.bcc.include?('dlopper@somenet.foo')
114 114 end
115 115
116 116 def test_get_edit
117 117 @request.session[:user_id] = 2
118 118 get :edit, :board_id => 1, :id => 1
119 119 assert_response :success
120 120 assert_template 'edit'
121 121 end
122 122
123 123 def test_post_edit
124 124 @request.session[:user_id] = 2
125 125 post :edit, :board_id => 1, :id => 1,
126 126 :message => { :subject => 'New subject',
127 127 :content => 'New body'}
128 128 assert_redirected_to '/boards/1/topics/1'
129 129 message = Message.find(1)
130 130 assert_equal 'New subject', message.subject
131 131 assert_equal 'New body', message.content
132 132 end
133 133
134 134 def test_reply
135 135 @request.session[:user_id] = 2
136 136 post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' }
137 137 reply = Message.find(:first, :order => 'id DESC')
138 138 assert_redirected_to "/boards/1/topics/1?r=#{reply.id}"
139 139 assert Message.find_by_subject('Test reply')
140 140 end
141 141
142 142 def test_destroy_topic
143 143 @request.session[:user_id] = 2
144 post :destroy, :board_id => 1, :id => 1
144 assert_difference 'Message.count', -3 do
145 post :destroy, :board_id => 1, :id => 1
146 end
145 147 assert_redirected_to '/projects/ecookbook/boards/1'
146 148 assert_nil Message.find_by_id(1)
147 149 end
148 150
151 def test_destroy_reply
152 @request.session[:user_id] = 2
153 assert_difference 'Message.count', -1 do
154 post :destroy, :board_id => 1, :id => 2
155 end
156 assert_redirected_to '/boards/1/topics/1?r=2'
157 assert_nil Message.find_by_id(2)
158 end
159
149 160 def test_quote
150 161 @request.session[:user_id] = 2
151 162 xhr :get, :quote, :board_id => 1, :id => 3
152 163 assert_response :success
153 164 assert_select_rjs :show, 'reply'
154 165 end
166
167 def test_preview_new
168 @request.session[:user_id] = 2
169 post :preview,
170 :board_id => 1,
171 :message => {:subject => "", :content => "Previewed text"}
172 assert_response :success
173 assert_template 'common/_preview'
174 end
175
176 def test_preview_edit
177 @request.session[:user_id] = 2
178 post :preview,
179 :id => 4,
180 :board_id => 1,
181 :message => {:subject => "", :content => "Previewed text"}
182 assert_response :success
183 assert_template 'common/_preview'
184 end
155 185 end
General Comments 0
You need to be logged in to leave comments. Login now