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