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