##// END OF EJS Templates
Adds test for r7961 fix (#9672)....
Jean-Philippe Lang -
r7842:dfa62334840e
parent child
Show More
@@ -1,144 +1,155
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
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
42 53
43 54 def test_show_with_pagination
44 55 message = Message.find(1)
45 56 assert_difference 'Message.count', 30 do
46 57 30.times do
47 58 message.children << Message.new(:subject => 'Reply', :content => 'Reply body', :author_id => 2, :board_id => 1)
48 59 end
49 60 end
50 61 get :show, :board_id => 1, :id => 1, :r => message.children.last(:order => 'id').id
51 62 assert_response :success
52 63 assert_template 'show'
53 64 replies = assigns(:replies)
54 65 assert_not_nil replies
55 66 assert !replies.include?(message.children.first(:order => 'id'))
56 67 assert replies.include?(message.children.last(:order => 'id'))
57 68 end
58 69
59 70 def test_show_with_reply_permission
60 71 @request.session[:user_id] = 2
61 72 get :show, :board_id => 1, :id => 1
62 73 assert_response :success
63 74 assert_template 'show'
64 75 assert_tag :div, :attributes => { :id => 'reply' },
65 76 :descendant => { :tag => 'textarea', :attributes => { :id => 'message_content' } }
66 77 end
67 78
68 79 def test_show_message_not_found
69 80 get :show, :board_id => 1, :id => 99999
70 81 assert_response 404
71 82 end
72 83
73 84 def test_get_new
74 85 @request.session[:user_id] = 2
75 86 get :new, :board_id => 1
76 87 assert_response :success
77 88 assert_template 'new'
78 89 end
79 90
80 91 def test_post_new
81 92 @request.session[:user_id] = 2
82 93 ActionMailer::Base.deliveries.clear
83 94 Setting.notified_events = ['message_posted']
84 95
85 96 post :new, :board_id => 1,
86 97 :message => { :subject => 'Test created message',
87 98 :content => 'Message body'}
88 99 message = Message.find_by_subject('Test created message')
89 100 assert_not_nil message
90 101 assert_redirected_to "/boards/1/topics/#{message.to_param}"
91 102 assert_equal 'Message body', message.content
92 103 assert_equal 2, message.author_id
93 104 assert_equal 1, message.board_id
94 105
95 106 mail = ActionMailer::Base.deliveries.last
96 107 assert_kind_of TMail::Mail, mail
97 108 assert_equal "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] Test created message", mail.subject
98 109 assert mail.body.include?('Message body')
99 110 # author
100 111 assert mail.bcc.include?('jsmith@somenet.foo')
101 112 # project member
102 113 assert mail.bcc.include?('dlopper@somenet.foo')
103 114 end
104 115
105 116 def test_get_edit
106 117 @request.session[:user_id] = 2
107 118 get :edit, :board_id => 1, :id => 1
108 119 assert_response :success
109 120 assert_template 'edit'
110 121 end
111 122
112 123 def test_post_edit
113 124 @request.session[:user_id] = 2
114 125 post :edit, :board_id => 1, :id => 1,
115 126 :message => { :subject => 'New subject',
116 127 :content => 'New body'}
117 128 assert_redirected_to '/boards/1/topics/1'
118 129 message = Message.find(1)
119 130 assert_equal 'New subject', message.subject
120 131 assert_equal 'New body', message.content
121 132 end
122 133
123 134 def test_reply
124 135 @request.session[:user_id] = 2
125 136 post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' }
126 137 reply = Message.find(:first, :order => 'id DESC')
127 138 assert_redirected_to "/boards/1/topics/1?r=#{reply.id}"
128 139 assert Message.find_by_subject('Test reply')
129 140 end
130 141
131 142 def test_destroy_topic
132 143 @request.session[:user_id] = 2
133 144 post :destroy, :board_id => 1, :id => 1
134 145 assert_redirected_to '/projects/ecookbook/boards/1'
135 146 assert_nil Message.find_by_id(1)
136 147 end
137 148
138 149 def test_quote
139 150 @request.session[:user_id] = 2
140 151 xhr :get, :quote, :board_id => 1, :id => 3
141 152 assert_response :success
142 153 assert_select_rjs :show, 'reply'
143 154 end
144 155 end
General Comments 0
You need to be logged in to leave comments. Login now