aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfrancis <francis>2008-08-26 16:03:36 +0000
committerfrancis <francis>2008-08-26 16:03:36 +0000
commit31ee078910973606e05a469e2fdcb795c0403ebc (patch)
treeaca4b8d0dbe305df827ecc1b9baaf0619fd90b26
parent18338f6f9564093521ee0363bf475cc2d0dee040 (diff)
Test code for comments.
-rw-r--r--app/controllers/comment_controller.rb7
-rw-r--r--app/models/info_request.rb4
-rw-r--r--spec/controllers/comment_controller_spec.rb76
-rw-r--r--spec/controllers/request_controller_spec.rb2
-rw-r--r--todo.txt33
5 files changed, 99 insertions, 23 deletions
diff --git a/app/controllers/comment_controller.rb b/app/controllers/comment_controller.rb
index d852ffe17..7192eb84b 100644
--- a/app/controllers/comment_controller.rb
+++ b/app/controllers/comment_controller.rb
@@ -4,7 +4,7 @@
# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: comment_controller.rb,v 1.1 2008-08-13 01:39:41 francis Exp $
+# $Id: comment_controller.rb,v 1.2 2008-08-26 16:03:36 francis Exp $
class CommentController < ApplicationController
@@ -15,7 +15,6 @@ class CommentController < ApplicationController
:comment_type => 'request',
:user => @user
}))
-
else
raise "Unknown type " + params[:type]
end
@@ -40,11 +39,11 @@ class CommentController < ApplicationController
:email => "Then your annotation to " + @info_request.title + " will be posted.",
:email_subject => "Confirm your annotation to " + @info_request.title
)
- @info_request.add_comment(params[:comment][:body], authenticated_user)
+ @comment = @info_request.add_comment(params[:comment][:body], authenticated_user)
# This automatically saves dependent objects in the same transaction
@info_request.save!
flash[:notice] = "Thank you for making an annotation!"
- redirect_to request_url(@info_request)
+ redirect_to comment_url(@comment)
else
# do nothing - as "authenticated?" has done the redirect to signin page for us
end
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index af1d8b38a..8e303eed2 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -23,7 +23,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: info_request.rb,v 1.130 2008-08-21 00:41:44 francis Exp $
+# $Id: info_request.rb,v 1.131 2008-08-26 16:03:36 francis Exp $
require 'digest/sha1'
require File.join(File.dirname(__FILE__),'../../vendor/plugins/acts_as_xapian/lib/acts_as_xapian')
@@ -274,6 +274,8 @@ public
self.log_event("comment", { :comment_id => comment.id })
self.save!
end
+
+ return comment
end
# The "holding pen" is a special request which stores incoming emails whose
diff --git a/spec/controllers/comment_controller_spec.rb b/spec/controllers/comment_controller_spec.rb
new file mode 100644
index 000000000..6e0baf3b7
--- /dev/null
+++ b/spec/controllers/comment_controller_spec.rb
@@ -0,0 +1,76 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe CommentController, "when commenting on a request" do
+ integrate_views
+ fixtures :info_requests, :outgoing_messages, :public_bodies, :users, :comments
+
+ it "should give an error and render 'new' template when body text is just some whitespace" do
+ post :new, :url_title => info_requests(:naughty_chicken_request).url_title,
+ :comment => { :body => " " },
+ :type => 'request', :submitted_comment => 1, :preview => 1
+ assigns[:comment].errors[:body].should_not be_nil
+ response.should render_template('new')
+ end
+
+ it "should show preview when input is good" do
+ post :new, :url_title => info_requests(:naughty_chicken_request).url_title,
+ :comment => { :body => "A good question, but why not also ask about nice chickens?" },
+ :type => 'request', :submitted_comment => 1, :preview => 1
+ response.should render_template('preview')
+ end
+
+ it "should redirect to sign in page when input is good and nobody is logged in" do
+ params = { :url_title => info_requests(:naughty_chicken_request).url_title,
+ :comment => { :body => "A good question, but why not also ask about nice chickens?" },
+ :type => 'request', :submitted_comment => 1, :preview => 0
+ }
+ post :new, params
+ post_redirect = PostRedirect.get_last_post_redirect
+ response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token)
+ # post_redirect.post_params.should == params # XXX get this working. there's a : vs '' problem amongst others
+ end
+
+ it "should create the comment, and redirect to request page when input is good and somebody is logged in" do
+ session[:user_id] = users(:bob_smith_user).id
+ post :new, :url_title => info_requests(:naughty_chicken_request).url_title,
+ :comment => { :body => "A good question, but why not also ask about nice chickens?" },
+ :type => 'request', :submitted_comment => 1, :preview => 0
+
+ comment_array = Comment.find(:all, :conditions => ["body = ?", "A good question, but why not also ask about nice chickens?"])
+ comment_array.size.should == 1
+ comment = comment_array[0]
+
+ ActionMailer::Base.deliveries.size.should == 0
+
+ response.should redirect_to(:controller => 'request', :action => 'show', :url_title => info_requests(:naughty_chicken_request).url_title, :anchor => 'comment-' + comment.id.to_s)
+ end
+
+# it "should give an error if the same request is submitted twice" do
+# session[:user_id] = users(:bob_smith_user).id
+#
+# # We use raw_body here, so white space is the same
+# post :new, :info_request => { :public_body_id => info_requests(:fancy_dog_request).public_body_id,
+# :title => info_requests(:fancy_dog_request).title },
+# :outgoing_message => { :body => info_requests(:fancy_dog_request).outgoing_messages[0].raw_body},
+# :submitted_new_request => 1, :preview => 0, :mouse_house => 1
+# response.should render_template('new')
+# end
+
+# it "should give an error if the same request is submitted twice with extra whitespace in the body" do
+# # This only works for PostgreSQL databases which have regexp_replace -
+# # see model method InfoRequest.find_by_existing_request for more info
+# if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
+# session[:user_id] = users(:bob_smith_user).id
+#
+# post :new, :info_request => { :public_body_id => info_requests(:fancy_dog_request).public_body_id,
+# :title => info_requests(:fancy_dog_request).title },
+# :outgoing_message => { :body => "\n" + info_requests(:fancy_dog_request).outgoing_messages[0].body + " "},
+# :submitted_new_request => 1, :preview => 0, :mouse_house => 1
+# response.should render_template('new')
+# end
+# end
+
+end
+
+
+
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index f7eb2ca01..e5e514c89 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -112,7 +112,7 @@ describe RequestController, "when creating a new request" do
post :new, :info_request => { :public_body_id => public_bodies(:geraldine_public_body).id },
:outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." },
:submitted_new_request => 1, :preview => 1
- # XXX how do I check the error message here?
+ assigns[:info_request].errors[:title].should_not be_nil
response.should render_template('new')
end
diff --git a/todo.txt b/todo.txt
index b92a8af06..a3b9eaf7e 100644
--- a/todo.txt
+++ b/todo.txt
@@ -1,6 +1,3 @@
-XXX
- Fix up that shows last resend as message?
-
Site move:
Install PostgresSQL 8.3
Move database
@@ -13,6 +10,7 @@ Grrr - so here I wanted to clarify my request, but don't want the timer to be re
http://www.whatdotheyknow.com/request/online_petitions_documents_from#incoming-3248
Test: Check where followups are going to now
+Test: Check new .zips are being indexed
"Then you will be emailed whenever 'Martin Stabe' requests something or gets a
response" doesn't word wrap in confirmation email, and no full stop.
@@ -23,23 +21,24 @@ http://www.whatdotheyknow.com/request/4/response/866#show_response_followup
Email subjects badly escaped
Subject: Confirm you want to be emailed about requests to 'HM Revenue &amp; Customs'
-Comments interleaved with body
- - Add basic tests for comment controller
-
- - Test email alerts for comments
- - Email people subscribed to people about new comments that they make
- ... and likewise to requests, public bodies
+VSD files vsdump - example in zip file
+http://www.whatdotheyknow.com/request/dog_control_orders#incoming-3510
+doing file RESPONSE/Internal documents/Briefing with Contact Islington/Contact Islington Flowchart Jul 08.vsd content type
+Search for other extensions that we have now
+Comments interleaved with body
- Email people when comments on their own request
- Email people when responses to their own comment, or warn them they need to sign up
- - Flag bad comments
- - Delete comments from admin interface
-
- - Test spell checker
- - Don't allow double posting
+ - Don't allow double posting (submitting same comment twice, add spec test)
- Check CSS class/id names used in all comment HTML
- Think about the "nonsense" text a lot more
+ - Improve display of preview, is rubbish
+
+ - Test spell checker
+ - List all comments in admin interface? and/or flag bad comments
+ - Delete comments from admin interface
+ - Check annotation email alerts are working (e.g. when subscribed to a request)
http://www.whatdotheyknow.com/request/communications_about_whatdotheyk
Mask all emails from binary attachments
@@ -65,9 +64,9 @@ Clear out all the need admin attention requests
Clear out all the need classifying requests
Admin:
-Have internal links to different parts of request page
-Somehow fold up the enormous pages on many admin pages
-Make it easy to go from pages to admin page
+ Have internal links to different parts of request page
+ Somehow fold up the enormous pages on many admin pages
+ Make it easy to go from pages to admin page (perhaps via link as in PB?)
Later
=====