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