aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/comment_controller.rb10
-rw-r--r--spec/controllers/comment_controller_spec.rb19
2 files changed, 16 insertions, 13 deletions
diff --git a/app/controllers/comment_controller.rb b/app/controllers/comment_controller.rb
index cda56a211..4904463b5 100644
--- a/app/controllers/comment_controller.rb
+++ b/app/controllers/comment_controller.rb
@@ -21,13 +21,15 @@ class CommentController < ApplicationController
else
raise "Unknown type " + params[:type]
end
-
+
# Are comments disabled on this request?
#
# There is no “add comment” link when comments are disabled, so users should
- # not usually hit this unless they are explicitly attempting to avoid the comment
- # block, so we just raise an exception.
- raise "Comments are not allowed on this request" if !@info_request.comments_allowed?
+ # not usually hit this unless they are explicitly attempting to avoid the comment block
+ unless @info_request.comments_allowed?
+ redirect_to request_url(@info_request), :notice => "Comments are not allowed on this request"
+ return
+ end
# Banned from adding comments?
if !authenticated_user.nil? && !authenticated_user.can_make_comments?
diff --git a/spec/controllers/comment_controller_spec.rb b/spec/controllers/comment_controller_spec.rb
index c03615ce2..3ad334ab1 100644
--- a/spec/controllers/comment_controller_spec.rb
+++ b/spec/controllers/comment_controller_spec.rb
@@ -53,16 +53,17 @@ describe CommentController, "when commenting on a request" do
response.should render_template('new')
end
-
+
it "should not allow comments if comments are not allowed" do
- session[:user_id] = users(:silly_name_user).id
-
- expect {
- post :new, :url_title => info_requests(:spam_1_request).url_title,
- :comment => { :body => "I demand to be heard!" },
- :type => 'request', :submitted_comment => 1, :preview => 0
- }.to raise_error("Comments are not allowed on this request")
-
+ session[:user_id] = users(:silly_name_user).id
+ info_request = info_requests(:spam_1_request)
+
+ post :new, :url_title => info_request.url_title,
+ :comment => { :body => "I demand to be heard!" },
+ :type => 'request', :submitted_comment => 1, :preview => 0
+
+ response.should redirect_to(show_request_path(info_request.url_title))
+ flash[:notice].should == 'Comments are not allowed on this request'
end
describe 'when commenting on an external request' do