@@ -1,141 +1,142 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2013 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 | class MessagesController < ApplicationController |
|
18 | class MessagesController < ApplicationController | |
19 | menu_item :boards |
|
19 | menu_item :boards | |
20 | default_search_scope :messages |
|
20 | default_search_scope :messages | |
21 | before_filter :find_board, :only => [:new, :preview] |
|
21 | before_filter :find_board, :only => [:new, :preview] | |
22 | before_filter :find_attachments, :only => [:preview] |
|
22 | before_filter :find_attachments, :only => [:preview] | |
23 | before_filter :find_message, :except => [:new, :preview] |
|
23 | before_filter :find_message, :except => [:new, :preview] | |
24 | before_filter :authorize, :except => [:preview, :edit, :destroy] |
|
24 | before_filter :authorize, :except => [:preview, :edit, :destroy] | |
25 |
|
25 | |||
26 | helper :boards |
|
26 | helper :boards | |
27 | helper :watchers |
|
27 | helper :watchers | |
28 | helper :attachments |
|
28 | helper :attachments | |
29 | include AttachmentsHelper |
|
29 | include AttachmentsHelper | |
30 |
|
30 | |||
31 | REPLIES_PER_PAGE = 25 unless const_defined?(:REPLIES_PER_PAGE) |
|
31 | REPLIES_PER_PAGE = 25 unless const_defined?(:REPLIES_PER_PAGE) | |
32 |
|
32 | |||
33 | # Show a topic and its replies |
|
33 | # Show a topic and its replies | |
34 | def show |
|
34 | def show | |
35 | page = params[:page] |
|
35 | page = params[:page] | |
36 | # Find the page of the requested reply |
|
36 | # Find the page of the requested reply | |
37 | if params[:r] && page.nil? |
|
37 | if params[:r] && page.nil? | |
38 | offset = @topic.children.count(:conditions => ["#{Message.table_name}.id < ?", params[:r].to_i]) |
|
38 | offset = @topic.children.count(:conditions => ["#{Message.table_name}.id < ?", params[:r].to_i]) | |
39 | page = 1 + offset / REPLIES_PER_PAGE |
|
39 | page = 1 + offset / REPLIES_PER_PAGE | |
40 | end |
|
40 | end | |
41 |
|
41 | |||
42 | @reply_count = @topic.children.count |
|
42 | @reply_count = @topic.children.count | |
43 | @reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page |
|
43 | @reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page | |
44 | @replies = @topic.children. |
|
44 | @replies = @topic.children. | |
45 | includes(:author, :attachments, {:board => :project}). |
|
45 | includes(:author, :attachments, {:board => :project}). | |
46 | reorder("#{Message.table_name}.created_on ASC"). |
|
46 | reorder("#{Message.table_name}.created_on ASC"). | |
47 | limit(@reply_pages.per_page). |
|
47 | limit(@reply_pages.per_page). | |
48 | offset(@reply_pages.offset). |
|
48 | offset(@reply_pages.offset). | |
49 | all |
|
49 | all | |
50 |
|
50 | |||
51 | @reply = Message.new(:subject => "RE: #{@message.subject}") |
|
51 | @reply = Message.new(:subject => "RE: #{@message.subject}") | |
52 | render :action => "show", :layout => false if request.xhr? |
|
52 | render :action => "show", :layout => false if request.xhr? | |
53 | end |
|
53 | end | |
54 |
|
54 | |||
55 | # Create a new topic |
|
55 | # Create a new topic | |
56 | def new |
|
56 | def new | |
57 | @message = Message.new |
|
57 | @message = Message.new | |
58 | @message.author = User.current |
|
58 | @message.author = User.current | |
59 | @message.board = @board |
|
59 | @message.board = @board | |
60 | @message.safe_attributes = params[:message] |
|
60 | @message.safe_attributes = params[:message] | |
61 | if request.post? |
|
61 | if request.post? | |
62 | @message.save_attachments(params[:attachments]) |
|
62 | @message.save_attachments(params[:attachments]) | |
63 | if @message.save |
|
63 | if @message.save | |
64 | call_hook(:controller_messages_new_after_save, { :params => params, :message => @message}) |
|
64 | call_hook(:controller_messages_new_after_save, { :params => params, :message => @message}) | |
65 | render_attachment_warning_if_needed(@message) |
|
65 | render_attachment_warning_if_needed(@message) | |
66 | redirect_to board_message_path(@board, @message) |
|
66 | redirect_to board_message_path(@board, @message) | |
67 | end |
|
67 | end | |
68 | end |
|
68 | end | |
69 | end |
|
69 | end | |
70 |
|
70 | |||
71 | # Reply to a topic |
|
71 | # Reply to a topic | |
72 | def reply |
|
72 | def reply | |
73 | @reply = Message.new |
|
73 | @reply = Message.new | |
74 | @reply.author = User.current |
|
74 | @reply.author = User.current | |
75 | @reply.board = @board |
|
75 | @reply.board = @board | |
76 | @reply.safe_attributes = params[:reply] |
|
76 | @reply.safe_attributes = params[:reply] | |
77 | @topic.children << @reply |
|
77 | @topic.children << @reply | |
78 | if !@reply.new_record? |
|
78 | if !@reply.new_record? | |
79 | call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply}) |
|
79 | call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply}) | |
80 | attachments = Attachment.attach_files(@reply, params[:attachments]) |
|
80 | attachments = Attachment.attach_files(@reply, params[:attachments]) | |
81 | render_attachment_warning_if_needed(@reply) |
|
81 | render_attachment_warning_if_needed(@reply) | |
82 | end |
|
82 | end | |
83 | redirect_to board_message_path(@board, @topic, :r => @reply) |
|
83 | redirect_to board_message_path(@board, @topic, :r => @reply) | |
84 | end |
|
84 | end | |
85 |
|
85 | |||
86 | # Edit a message |
|
86 | # Edit a message | |
87 | def edit |
|
87 | def edit | |
88 | (render_403; return false) unless @message.editable_by?(User.current) |
|
88 | (render_403; return false) unless @message.editable_by?(User.current) | |
89 | @message.safe_attributes = params[:message] |
|
89 | @message.safe_attributes = params[:message] | |
90 | if request.post? && @message.save |
|
90 | if request.post? && @message.save | |
91 | attachments = Attachment.attach_files(@message, params[:attachments]) |
|
91 | attachments = Attachment.attach_files(@message, params[:attachments]) | |
92 | render_attachment_warning_if_needed(@message) |
|
92 | render_attachment_warning_if_needed(@message) | |
93 | flash[:notice] = l(:notice_successful_update) |
|
93 | flash[:notice] = l(:notice_successful_update) | |
94 | @message.reload |
|
94 | @message.reload | |
95 | redirect_to board_message_path(@message.board, @message.root, :r => (@message.parent_id && @message.id)) |
|
95 | redirect_to board_message_path(@message.board, @message.root, :r => (@message.parent_id && @message.id)) | |
96 | end |
|
96 | end | |
97 | end |
|
97 | end | |
98 |
|
98 | |||
99 | # Delete a messages |
|
99 | # Delete a messages | |
100 | def destroy |
|
100 | def destroy | |
101 | (render_403; return false) unless @message.destroyable_by?(User.current) |
|
101 | (render_403; return false) unless @message.destroyable_by?(User.current) | |
102 | r = @message.to_param |
|
102 | r = @message.to_param | |
103 | @message.destroy |
|
103 | @message.destroy | |
104 | if @message.parent |
|
104 | if @message.parent | |
105 | redirect_to board_message_path(@board, @message.parent, :r => r) |
|
105 | redirect_to board_message_path(@board, @message.parent, :r => r) | |
106 | else |
|
106 | else | |
107 | redirect_to project_board_path(@project, @board) |
|
107 | redirect_to project_board_path(@project, @board) | |
108 | end |
|
108 | end | |
109 | end |
|
109 | end | |
110 |
|
110 | |||
111 | def quote |
|
111 | def quote | |
112 | @subject = @message.subject |
|
112 | @subject = @message.subject | |
113 | @subject = "RE: #{@subject}" unless @subject.starts_with?('RE:') |
|
113 | @subject = "RE: #{@subject}" unless @subject.starts_with?('RE:') | |
114 |
|
114 | |||
115 | @content = "#{ll(Setting.default_language, :text_user_wrote, @message.author)}\n> " |
|
115 | @content = "#{ll(Setting.default_language, :text_user_wrote, @message.author)}\n> " | |
116 | @content << @message.content.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n" |
|
116 | @content << @message.content.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n" | |
117 | end |
|
117 | end | |
118 |
|
118 | |||
119 | def preview |
|
119 | def preview | |
120 | message = @board.messages.find_by_id(params[:id]) |
|
120 | message = @board.messages.find_by_id(params[:id]) | |
121 | @text = (params[:message] || params[:reply])[:content] |
|
121 | @text = (params[:message] || params[:reply])[:content] | |
122 | @previewed = message |
|
122 | @previewed = message | |
123 | render :partial => 'common/preview' |
|
123 | render :partial => 'common/preview' | |
124 | end |
|
124 | end | |
125 |
|
125 | |||
126 | private |
|
126 | private | |
127 | def find_message |
|
127 | def find_message | |
128 | find_board |
|
128 | return unless find_board | |
129 | @message = @board.messages.find(params[:id], :include => :parent) |
|
129 | @message = @board.messages.find(params[:id], :include => :parent) | |
130 | @topic = @message.root |
|
130 | @topic = @message.root | |
131 | rescue ActiveRecord::RecordNotFound |
|
131 | rescue ActiveRecord::RecordNotFound | |
132 | render_404 |
|
132 | render_404 | |
133 | end |
|
133 | end | |
134 |
|
134 | |||
135 | def find_board |
|
135 | def find_board | |
136 | @board = Board.find(params[:board_id], :include => :project) |
|
136 | @board = Board.find(params[:board_id], :include => :project) | |
137 | @project = @board.project |
|
137 | @project = @board.project | |
138 | rescue ActiveRecord::RecordNotFound |
|
138 | rescue ActiveRecord::RecordNotFound | |
139 | render_404 |
|
139 | render_404 | |
|
140 | nil | |||
140 | end |
|
141 | end | |
141 | end |
|
142 | end |
@@ -1,212 +1,217 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2013 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 |
|
19 | |||
20 | class MessagesControllerTest < ActionController::TestCase |
|
20 | class MessagesControllerTest < ActionController::TestCase | |
21 | fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules |
|
21 | fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules | |
22 |
|
22 | |||
23 | def setup |
|
23 | def setup | |
24 | User.current = nil |
|
24 | User.current = nil | |
25 | end |
|
25 | end | |
26 |
|
26 | |||
27 | def test_show |
|
27 | def test_show | |
28 | get :show, :board_id => 1, :id => 1 |
|
28 | get :show, :board_id => 1, :id => 1 | |
29 | assert_response :success |
|
29 | assert_response :success | |
30 | assert_template 'show' |
|
30 | assert_template 'show' | |
31 | assert_not_nil assigns(:board) |
|
31 | assert_not_nil assigns(:board) | |
32 | assert_not_nil assigns(:project) |
|
32 | assert_not_nil assigns(:project) | |
33 | assert_not_nil assigns(:topic) |
|
33 | assert_not_nil assigns(:topic) | |
34 | end |
|
34 | end | |
35 |
|
35 | |||
36 | def test_show_should_contain_reply_field_tags_for_quoting |
|
36 | def test_show_should_contain_reply_field_tags_for_quoting | |
37 | @request.session[:user_id] = 2 |
|
37 | @request.session[:user_id] = 2 | |
38 | get :show, :board_id => 1, :id => 1 |
|
38 | get :show, :board_id => 1, :id => 1 | |
39 | assert_response :success |
|
39 | assert_response :success | |
40 |
|
40 | |||
41 | # tags required by MessagesController#quote |
|
41 | # tags required by MessagesController#quote | |
42 | assert_tag 'input', :attributes => {:id => 'message_subject'} |
|
42 | assert_tag 'input', :attributes => {:id => 'message_subject'} | |
43 | assert_tag 'textarea', :attributes => {:id => 'message_content'} |
|
43 | assert_tag 'textarea', :attributes => {:id => 'message_content'} | |
44 | assert_tag 'div', :attributes => {:id => 'reply'} |
|
44 | assert_tag 'div', :attributes => {:id => 'reply'} | |
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | def test_show_with_pagination |
|
47 | def test_show_with_pagination | |
48 | message = Message.find(1) |
|
48 | message = Message.find(1) | |
49 | assert_difference 'Message.count', 30 do |
|
49 | assert_difference 'Message.count', 30 do | |
50 | 30.times do |
|
50 | 30.times do | |
51 | message.children << Message.new(:subject => 'Reply', :content => 'Reply body', :author_id => 2, :board_id => 1) |
|
51 | message.children << Message.new(:subject => 'Reply', :content => 'Reply body', :author_id => 2, :board_id => 1) | |
52 | end |
|
52 | end | |
53 | end |
|
53 | end | |
54 | get :show, :board_id => 1, :id => 1, :r => message.children.last(:order => 'id').id |
|
54 | get :show, :board_id => 1, :id => 1, :r => message.children.last(:order => 'id').id | |
55 | assert_response :success |
|
55 | assert_response :success | |
56 | assert_template 'show' |
|
56 | assert_template 'show' | |
57 | replies = assigns(:replies) |
|
57 | replies = assigns(:replies) | |
58 | assert_not_nil replies |
|
58 | assert_not_nil replies | |
59 | assert !replies.include?(message.children.first(:order => 'id')) |
|
59 | assert !replies.include?(message.children.first(:order => 'id')) | |
60 | assert replies.include?(message.children.last(:order => 'id')) |
|
60 | assert replies.include?(message.children.last(:order => 'id')) | |
61 | end |
|
61 | end | |
62 |
|
62 | |||
63 | def test_show_with_reply_permission |
|
63 | def test_show_with_reply_permission | |
64 | @request.session[:user_id] = 2 |
|
64 | @request.session[:user_id] = 2 | |
65 | get :show, :board_id => 1, :id => 1 |
|
65 | get :show, :board_id => 1, :id => 1 | |
66 | assert_response :success |
|
66 | assert_response :success | |
67 | assert_template 'show' |
|
67 | assert_template 'show' | |
68 | assert_tag :div, :attributes => { :id => 'reply' }, |
|
68 | assert_tag :div, :attributes => { :id => 'reply' }, | |
69 | :descendant => { :tag => 'textarea', :attributes => { :id => 'message_content' } } |
|
69 | :descendant => { :tag => 'textarea', :attributes => { :id => 'message_content' } } | |
70 | end |
|
70 | end | |
71 |
|
71 | |||
72 | def test_show_message_not_found |
|
72 | def test_show_message_not_found | |
73 | get :show, :board_id => 1, :id => 99999 |
|
73 | get :show, :board_id => 1, :id => 99999 | |
74 | assert_response 404 |
|
74 | assert_response 404 | |
75 | end |
|
75 | end | |
76 |
|
76 | |||
|
77 | def test_show_message_from_invalid_board_should_respond_with_404 | |||
|
78 | get :show, :board_id => 999, :id => 1 | |||
|
79 | assert_response 404 | |||
|
80 | end | |||
|
81 | ||||
77 | def test_get_new |
|
82 | def test_get_new | |
78 | @request.session[:user_id] = 2 |
|
83 | @request.session[:user_id] = 2 | |
79 | get :new, :board_id => 1 |
|
84 | get :new, :board_id => 1 | |
80 | assert_response :success |
|
85 | assert_response :success | |
81 | assert_template 'new' |
|
86 | assert_template 'new' | |
82 | end |
|
87 | end | |
83 |
|
88 | |||
84 | def test_get_new_with_invalid_board |
|
89 | def test_get_new_with_invalid_board | |
85 | @request.session[:user_id] = 2 |
|
90 | @request.session[:user_id] = 2 | |
86 | get :new, :board_id => 99 |
|
91 | get :new, :board_id => 99 | |
87 | assert_response 404 |
|
92 | assert_response 404 | |
88 | end |
|
93 | end | |
89 |
|
94 | |||
90 | def test_post_new |
|
95 | def test_post_new | |
91 | @request.session[:user_id] = 2 |
|
96 | @request.session[:user_id] = 2 | |
92 | ActionMailer::Base.deliveries.clear |
|
97 | ActionMailer::Base.deliveries.clear | |
93 |
|
98 | |||
94 | with_settings :notified_events => %w(message_posted) do |
|
99 | with_settings :notified_events => %w(message_posted) do | |
95 | post :new, :board_id => 1, |
|
100 | post :new, :board_id => 1, | |
96 | :message => { :subject => 'Test created message', |
|
101 | :message => { :subject => 'Test created message', | |
97 | :content => 'Message body'} |
|
102 | :content => 'Message body'} | |
98 | end |
|
103 | end | |
99 | message = Message.find_by_subject('Test created message') |
|
104 | message = Message.find_by_subject('Test created message') | |
100 | assert_not_nil message |
|
105 | assert_not_nil message | |
101 | assert_redirected_to "/boards/1/topics/#{message.to_param}" |
|
106 | assert_redirected_to "/boards/1/topics/#{message.to_param}" | |
102 | assert_equal 'Message body', message.content |
|
107 | assert_equal 'Message body', message.content | |
103 | assert_equal 2, message.author_id |
|
108 | assert_equal 2, message.author_id | |
104 | assert_equal 1, message.board_id |
|
109 | assert_equal 1, message.board_id | |
105 |
|
110 | |||
106 | mail = ActionMailer::Base.deliveries.last |
|
111 | mail = ActionMailer::Base.deliveries.last | |
107 | assert_not_nil mail |
|
112 | assert_not_nil mail | |
108 | assert_equal "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] Test created message", mail.subject |
|
113 | assert_equal "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] Test created message", mail.subject | |
109 | assert_mail_body_match 'Message body', mail |
|
114 | assert_mail_body_match 'Message body', mail | |
110 | # author |
|
115 | # author | |
111 | assert mail.bcc.include?('jsmith@somenet.foo') |
|
116 | assert mail.bcc.include?('jsmith@somenet.foo') | |
112 | # project member |
|
117 | # project member | |
113 | assert mail.bcc.include?('dlopper@somenet.foo') |
|
118 | assert mail.bcc.include?('dlopper@somenet.foo') | |
114 | end |
|
119 | end | |
115 |
|
120 | |||
116 | def test_get_edit |
|
121 | def test_get_edit | |
117 | @request.session[:user_id] = 2 |
|
122 | @request.session[:user_id] = 2 | |
118 | get :edit, :board_id => 1, :id => 1 |
|
123 | get :edit, :board_id => 1, :id => 1 | |
119 | assert_response :success |
|
124 | assert_response :success | |
120 | assert_template 'edit' |
|
125 | assert_template 'edit' | |
121 | end |
|
126 | end | |
122 |
|
127 | |||
123 | def test_post_edit |
|
128 | def test_post_edit | |
124 | @request.session[:user_id] = 2 |
|
129 | @request.session[:user_id] = 2 | |
125 | post :edit, :board_id => 1, :id => 1, |
|
130 | post :edit, :board_id => 1, :id => 1, | |
126 | :message => { :subject => 'New subject', |
|
131 | :message => { :subject => 'New subject', | |
127 | :content => 'New body'} |
|
132 | :content => 'New body'} | |
128 | assert_redirected_to '/boards/1/topics/1' |
|
133 | assert_redirected_to '/boards/1/topics/1' | |
129 | message = Message.find(1) |
|
134 | message = Message.find(1) | |
130 | assert_equal 'New subject', message.subject |
|
135 | assert_equal 'New subject', message.subject | |
131 | assert_equal 'New body', message.content |
|
136 | assert_equal 'New body', message.content | |
132 | end |
|
137 | end | |
133 |
|
138 | |||
134 | def test_post_edit_sticky_and_locked |
|
139 | def test_post_edit_sticky_and_locked | |
135 | @request.session[:user_id] = 2 |
|
140 | @request.session[:user_id] = 2 | |
136 | post :edit, :board_id => 1, :id => 1, |
|
141 | post :edit, :board_id => 1, :id => 1, | |
137 | :message => { :subject => 'New subject', |
|
142 | :message => { :subject => 'New subject', | |
138 | :content => 'New body', |
|
143 | :content => 'New body', | |
139 | :locked => '1', |
|
144 | :locked => '1', | |
140 | :sticky => '1'} |
|
145 | :sticky => '1'} | |
141 | assert_redirected_to '/boards/1/topics/1' |
|
146 | assert_redirected_to '/boards/1/topics/1' | |
142 | message = Message.find(1) |
|
147 | message = Message.find(1) | |
143 | assert_equal true, message.sticky? |
|
148 | assert_equal true, message.sticky? | |
144 | assert_equal true, message.locked? |
|
149 | assert_equal true, message.locked? | |
145 | end |
|
150 | end | |
146 |
|
151 | |||
147 | def test_post_edit_should_allow_to_change_board |
|
152 | def test_post_edit_should_allow_to_change_board | |
148 | @request.session[:user_id] = 2 |
|
153 | @request.session[:user_id] = 2 | |
149 | post :edit, :board_id => 1, :id => 1, |
|
154 | post :edit, :board_id => 1, :id => 1, | |
150 | :message => { :subject => 'New subject', |
|
155 | :message => { :subject => 'New subject', | |
151 | :content => 'New body', |
|
156 | :content => 'New body', | |
152 | :board_id => 2} |
|
157 | :board_id => 2} | |
153 | assert_redirected_to '/boards/2/topics/1' |
|
158 | assert_redirected_to '/boards/2/topics/1' | |
154 | message = Message.find(1) |
|
159 | message = Message.find(1) | |
155 | assert_equal Board.find(2), message.board |
|
160 | assert_equal Board.find(2), message.board | |
156 | end |
|
161 | end | |
157 |
|
162 | |||
158 | def test_reply |
|
163 | def test_reply | |
159 | @request.session[:user_id] = 2 |
|
164 | @request.session[:user_id] = 2 | |
160 | post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' } |
|
165 | post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' } | |
161 | reply = Message.order('id DESC').first |
|
166 | reply = Message.order('id DESC').first | |
162 | assert_redirected_to "/boards/1/topics/1?r=#{reply.id}" |
|
167 | assert_redirected_to "/boards/1/topics/1?r=#{reply.id}" | |
163 | assert Message.find_by_subject('Test reply') |
|
168 | assert Message.find_by_subject('Test reply') | |
164 | end |
|
169 | end | |
165 |
|
170 | |||
166 | def test_destroy_topic |
|
171 | def test_destroy_topic | |
167 | @request.session[:user_id] = 2 |
|
172 | @request.session[:user_id] = 2 | |
168 | assert_difference 'Message.count', -3 do |
|
173 | assert_difference 'Message.count', -3 do | |
169 | post :destroy, :board_id => 1, :id => 1 |
|
174 | post :destroy, :board_id => 1, :id => 1 | |
170 | end |
|
175 | end | |
171 | assert_redirected_to '/projects/ecookbook/boards/1' |
|
176 | assert_redirected_to '/projects/ecookbook/boards/1' | |
172 | assert_nil Message.find_by_id(1) |
|
177 | assert_nil Message.find_by_id(1) | |
173 | end |
|
178 | end | |
174 |
|
179 | |||
175 | def test_destroy_reply |
|
180 | def test_destroy_reply | |
176 | @request.session[:user_id] = 2 |
|
181 | @request.session[:user_id] = 2 | |
177 | assert_difference 'Message.count', -1 do |
|
182 | assert_difference 'Message.count', -1 do | |
178 | post :destroy, :board_id => 1, :id => 2 |
|
183 | post :destroy, :board_id => 1, :id => 2 | |
179 | end |
|
184 | end | |
180 | assert_redirected_to '/boards/1/topics/1?r=2' |
|
185 | assert_redirected_to '/boards/1/topics/1?r=2' | |
181 | assert_nil Message.find_by_id(2) |
|
186 | assert_nil Message.find_by_id(2) | |
182 | end |
|
187 | end | |
183 |
|
188 | |||
184 | def test_quote |
|
189 | def test_quote | |
185 | @request.session[:user_id] = 2 |
|
190 | @request.session[:user_id] = 2 | |
186 | xhr :get, :quote, :board_id => 1, :id => 3 |
|
191 | xhr :get, :quote, :board_id => 1, :id => 3 | |
187 | assert_response :success |
|
192 | assert_response :success | |
188 | assert_equal 'text/javascript', response.content_type |
|
193 | assert_equal 'text/javascript', response.content_type | |
189 | assert_template 'quote' |
|
194 | assert_template 'quote' | |
190 | assert_include 'RE: First post', response.body |
|
195 | assert_include 'RE: First post', response.body | |
191 | assert_include '> An other reply', response.body |
|
196 | assert_include '> An other reply', response.body | |
192 | end |
|
197 | end | |
193 |
|
198 | |||
194 | def test_preview_new |
|
199 | def test_preview_new | |
195 | @request.session[:user_id] = 2 |
|
200 | @request.session[:user_id] = 2 | |
196 | post :preview, |
|
201 | post :preview, | |
197 | :board_id => 1, |
|
202 | :board_id => 1, | |
198 | :message => {:subject => "", :content => "Previewed text"} |
|
203 | :message => {:subject => "", :content => "Previewed text"} | |
199 | assert_response :success |
|
204 | assert_response :success | |
200 | assert_template 'common/_preview' |
|
205 | assert_template 'common/_preview' | |
201 | end |
|
206 | end | |
202 |
|
207 | |||
203 | def test_preview_edit |
|
208 | def test_preview_edit | |
204 | @request.session[:user_id] = 2 |
|
209 | @request.session[:user_id] = 2 | |
205 | post :preview, |
|
210 | post :preview, | |
206 | :id => 4, |
|
211 | :id => 4, | |
207 | :board_id => 1, |
|
212 | :board_id => 1, | |
208 | :message => {:subject => "", :content => "Previewed text"} |
|
213 | :message => {:subject => "", :content => "Previewed text"} | |
209 | assert_response :success |
|
214 | assert_response :success | |
210 | assert_template 'common/_preview' |
|
215 | assert_template 'common/_preview' | |
211 | end |
|
216 | end | |
212 | end |
|
217 | end |
General Comments 0
You need to be logged in to leave comments.
Login now