aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/raw_email.rb10
-rw-r--r--app/views/request/show.rhtml4
-rw-r--r--config/varnish-alaveteli.vcl96
-rw-r--r--db/migrate/100_remove_redundant_raw_email_columns.rb2
-rw-r--r--doc/INSTALL.md3
-rw-r--r--spec/controllers/request_controller_spec.rb51
-rw-r--r--spec/controllers/request_game_controller_spec.rb3
-rw-r--r--spec/controllers/track_controller_spec.rb5
-rw-r--r--spec/controllers/user_controller_spec.rb3
-rw-r--r--spec/fixtures/files/useless_raw_email.email15
-rw-r--r--spec/fixtures/raw_emails.yml17
-rw-r--r--spec/models/incoming_message_spec.rb6
-rw-r--r--spec/models/outgoing_mailer_spec.rb12
-rw-r--r--spec/models/request_mailer_spec.rb3
-rw-r--r--spec/models/xapian_spec.rb18
-rw-r--r--spec/spec_helper.rb27
16 files changed, 217 insertions, 58 deletions
diff --git a/app/models/raw_email.rb b/app/models/raw_email.rb
index 4e1a69456..1d85cc7d9 100644
--- a/app/models/raw_email.rb
+++ b/app/models/raw_email.rb
@@ -29,9 +29,13 @@ class RawEmail < ActiveRecord::Base
def directory
request_id = self.incoming_message.info_request.id.to_s
- File.join(MySociety::Config.get('RAW_EMAILS_LOCATION',
- 'files/raw_emails'),
- request_id[0..2], request_id)
+ if ENV["RAILS_ENV"] = "test"
+ return 'files/raw_email_test'
+ else
+ return File.join(MySociety::Config.get('RAW_EMAILS_LOCATION',
+ 'files/raw_emails'),
+ request_id[0..2], request_id)
+ end
end
def filepath
diff --git a/app/views/request/show.rhtml b/app/views/request/show.rhtml
index 7c3f79368..1993ee6b2 100644
--- a/app/views/request/show.rhtml
+++ b/app/views/request/show.rhtml
@@ -1,4 +1,4 @@
-<% @title = h(@info_request.title) %>
+<% @title = "#{h(@info_request.title)} - a Freedom of Information request to #{h(@info_request.public_body.name)}" %>
<% if @info_request.prominence == 'hidden' %>
<p id="hidden_request">
@@ -23,7 +23,7 @@
<%= render :partial => 'sidebar' %>
<div id="request_main">
- <h1><%=@title%></h1>
+ <h1><%=h(@info_request.title)%></h1>
<% if @info_request.user.profile_photo %>
<p class="user_photo_on_request">
diff --git a/config/varnish-alaveteli.vcl b/config/varnish-alaveteli.vcl
new file mode 100644
index 000000000..3312c381b
--- /dev/null
+++ b/config/varnish-alaveteli.vcl
@@ -0,0 +1,96 @@
+# This is a sample VCL configuration file for varnish running in front
+# of Alaveteli. See the vcl(7) man page for details on VCL syntax and
+# semantics.
+
+#
+# Default backend definition. Set this to point to your content
+# server. In this case, apache + Passenger running on port 80
+#
+
+backend default {
+ .host = "127.0.0.1";
+ .port = "80";
+ .connect_timeout = 600s;
+ .first_byte_timeout = 600s;
+ .between_bytes_timeout = 600s;
+}
+
+sub vcl_recv {
+
+ # Handle IPv6
+ if (req.http.Host ~ "^ipv6.*") {
+ set req.http.host = regsub(req.http.host, "^ipv6\.(.*)","www\.\1");
+ }
+
+
+ # Sanitise X-Forwarded-For...
+ remove req.http.X-Forwarded-For;
+ set req.http.X-Forwarded-For = client.ip;
+
+ # Remove has_js and Google Analytics cookies.
+ set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(__[a-z]+|has_js)=[^;]*", "");
+
+ # Normalize the Accept-Encoding header
+ if (req.http.Accept-Encoding) {
+ if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv|pdf|ico)$") {
+ # No point in compressing these
+ remove req.http.Accept-Encoding;
+ } elsif (req.http.Accept-Encoding ~ "gzip") {
+ set req.http.Accept-Encoding = "gzip";
+ } elsif (req.http.Accept-Encoding ~ "deflate") {
+ set req.http.Accept-Encoding = "deflate";
+ } else {
+ # unknown algorithm
+ remove req.http.Accept-Encoding;
+ }
+ }
+
+ # Ignore empty cookies
+ if (req.http.Cookie ~ "^\s*$") {
+ remove req.http.Cookie;
+ }
+
+ if (req.request != "GET" &&
+ req.request != "HEAD" &&
+ req.request != "POST" &&
+ req.request != "PUT" &&
+ req.request != "DELETE" ) {
+ # We don't allow any other methods.
+ error 405 "Method Not Allowed";
+ }
+
+ if (req.request != "GET" && req.request != "HEAD") {
+ /* We only deal with GET and HEAD by default, the rest get passed direct to backend */
+ return (pass);
+ }
+
+ # Ignore Cookies on images...
+ if (req.url ~ "\.(png|gif|jpg|jpeg|swf|css|js|rdf|ico|txt)(\?.*|)$") {
+ remove req.http.Cookie;
+ return (lookup);
+ }
+
+ if (req.http.Authorization || req.http.Cookie) {
+ return (pass);
+ }
+
+ # Let's have a little grace
+ set req.grace = 30s;
+ return (lookup);
+}
+
+
+sub vcl_fetch {
+
+ if (req.url ~ "\.(png|gif|jpg|jpeg|swf|css|js|rdf|ico|txt)(\?.*|)$") {
+ # Ignore backend headers..
+ remove beresp.http.set-Cookie;
+ set beresp.ttl = 3600s;
+ return (deliver);
+ }
+
+ if (beresp.status == 404 || beresp.status == 301 || beresp.status == 500) {
+ set beresp.ttl = 1m;
+ return (deliver);
+ }
+}
diff --git a/db/migrate/100_remove_redundant_raw_email_columns.rb b/db/migrate/100_remove_redundant_raw_email_columns.rb
index 2ebffba34..edf6006d7 100644
--- a/db/migrate/100_remove_redundant_raw_email_columns.rb
+++ b/db/migrate/100_remove_redundant_raw_email_columns.rb
@@ -1,9 +1,9 @@
class RemoveRedundantRawEmailColumns < ActiveRecord::Migration
def self.up
remove_column :raw_emails, :data_text
+ remove_column :raw_emails, :data_binary
end
def self.down
- add_column :raw_emails, :data_text, :text
end
end
diff --git a/doc/INSTALL.md b/doc/INSTALL.md
index 19f31fc40..e6f7caec7 100644
--- a/doc/INSTALL.md
+++ b/doc/INSTALL.md
@@ -230,6 +230,9 @@ http://rubyonrails.org/deploy
We usually use Passenger / mod_rails.
+Under all but light loads, it is strongly recommended to run the
+server behind an http accelerator like Varnish. A sample varnish VCL
+is supplied in `../conf/varnish-alaveteli.vcl`.
# Troubleshooting
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 33a6d0486..ffb9861f7 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -8,7 +8,7 @@ require 'json'
describe RequestController, "when listing recent requests" do
- before(:all) do
+ before(:each) do
rebuild_xapian_index
end
@@ -35,11 +35,14 @@ describe RequestController, "when listing recent requests" do
end
end
-
describe RequestController, "when showing one request" do
fixtures :info_requests, :info_request_events, :public_bodies, :public_body_translations, :public_body_translations, :users, :incoming_messages, :raw_emails, :outgoing_messages, :comments # all needed as integrating views
-
+
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ end
+
it "should be successful" do
get :show, :url_title => 'why_do_you_have_such_a_fancy_dog'
response.should be_success
@@ -198,6 +201,10 @@ end
describe RequestController, "when changing prominence of a request" do
fixtures :info_requests, :info_request_events, :public_bodies, :public_body_translations, :users, :incoming_messages, :raw_emails, :outgoing_messages # all needed as integrating views
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ end
+
it "should not show hidden requests" do
ir = info_requests(:fancy_dog_request)
ir.prominence = 'hidden'
@@ -365,7 +372,7 @@ describe RequestController, "when creating a new request" do
response.should redirect_to(:action => 'show', :url_title => ir.url_title)
# This test uses an explicit path because it's relied in
# Google Analytics goals:
- response.redirected_to.should == "/en/request/why_is_your_quango_called_gerald/new"
+ response.redirected_to.should =~ /request\/why_is_your_quango_called_gerald\/new$/
end
it "should give an error if the same request is submitted twice" do
@@ -457,7 +464,11 @@ end
describe RequestController, "when viewing an individual response for reply/followup" do
integrate_views
fixtures :info_requests, :info_request_events, :public_bodies, :public_body_translations, :users, :incoming_messages, :raw_emails, :outgoing_messages, :comments # all needed as integrating views
-
+
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ end
+
it "should ask for login if you are logged in as wrong person" do
session[:user_id] = users(:silly_name_user).id
get :show_response, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message)
@@ -489,6 +500,7 @@ describe RequestController, "when classifying an information request" do
@dog_request = info_requests(:fancy_dog_request)
@dog_request.stub!(:is_old_unclassified?).and_return(false)
InfoRequest.stub!(:find).and_return(@dog_request)
+ load_raw_emails_data(raw_emails)
end
def post_status(status)
@@ -898,7 +910,11 @@ end
describe RequestController, "sending overdue request alerts" do
integrate_views
fixtures :info_requests, :info_request_events, :public_bodies, :public_body_translations, :users, :incoming_messages, :raw_emails, :outgoing_messages # all needed as integrating views
-
+
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ end
+
it "should send an overdue alert mail to creators of overdue requests" do
chicken_request = info_requests(:naughty_chicken_request)
chicken_request.outgoing_messages[0].last_sent_at = Time.now() - 30.days
@@ -982,7 +998,11 @@ end
describe RequestController, "sending unclassified new response reminder alerts" do
integrate_views
fixtures :info_requests, :info_request_events, :public_bodies, :public_body_translations, :users, :incoming_messages, :raw_emails, :outgoing_messages, :comments # all needed as integrating views
-
+
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ end
+
it "should send an alert" do
RequestMailer.alert_new_response_reminders
@@ -1009,7 +1029,10 @@ end
describe RequestController, "clarification required alerts" do
integrate_views
fixtures :info_requests, :info_request_events, :public_bodies, :public_body_translations, :users, :incoming_messages, :raw_emails, :outgoing_messages # all needed as integrating views
-
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ end
+
it "should send an alert" do
ir = info_requests(:fancy_dog_request)
ir.set_described_state('waiting_clarification')
@@ -1060,6 +1083,9 @@ end
describe RequestController, "comment alerts" do
integrate_views
fixtures :info_requests, :info_request_events, :public_bodies, :public_body_translations, :users, :incoming_messages, :raw_emails, :outgoing_messages, :comments # all needed as integrating views
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ end
it "should send an alert (once and once only)" do
# delete ficture comment and make new one, so is in last month (as
@@ -1131,7 +1157,10 @@ end
describe RequestController, "when viewing comments" do
integrate_views
- fixtures :users
+ fixtures :users, :raw_emails, :incoming_messages, :info_requests
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ end
it "should link to the user who submitted it" do
session[:user_id] = users(:bob_smith_user).id
@@ -1240,6 +1269,10 @@ describe RequestController, "when showing JSON version for API" do
fixtures :info_requests, :info_request_events, :public_bodies, :public_body_translations, :users, :incoming_messages, :raw_emails, :outgoing_messages, :comments
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ end
+
it "should return data in JSON form" do
get :show, :url_title => 'why_do_you_have_such_a_fancy_dog', :format => 'json'
diff --git a/spec/controllers/request_game_controller_spec.rb b/spec/controllers/request_game_controller_spec.rb
index ce507fad1..4883bfdd6 100644
--- a/spec/controllers/request_game_controller_spec.rb
+++ b/spec/controllers/request_game_controller_spec.rb
@@ -3,6 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe RequestGameController, "when playing the game" do
fixtures :info_requests, :info_request_events, :public_bodies, :public_body_translations, :users, :incoming_messages, :raw_emails, :outgoing_messages # all needed as integrating views
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ end
it "should show the game homepage" do
get :play
diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb
index 0a8919268..f7002a9d4 100644
--- a/spec/controllers/track_controller_spec.rb
+++ b/spec/controllers/track_controller_spec.rb
@@ -37,6 +37,9 @@ describe TrackController, "when sending alerts for a track" do
integrate_views
fixtures :info_requests, :outgoing_messages, :incoming_messages, :raw_emails, :info_request_events, :users, :track_things, :track_things_sent_emails, :public_bodies, :public_body_translations
include LinkToHelper # for main_url
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ end
before do
rebuild_xapian_index
@@ -100,6 +103,7 @@ describe TrackController, "when viewing RSS feed for a track" do
before do
rebuild_xapian_index
+ load_raw_emails_data(raw_emails)
end
it "should get the RSS feed" do
@@ -125,6 +129,7 @@ describe TrackController, "when viewing JSON version of a track feed" do
before do
rebuild_xapian_index
+ load_raw_emails_data(raw_emails)
end
it "should get the feed" do
diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb
index c6817fbc6..0b5e96711 100644
--- a/spec/controllers/user_controller_spec.rb
+++ b/spec/controllers/user_controller_spec.rb
@@ -8,6 +8,9 @@ require 'json'
describe UserController, "when showing a user" do
integrate_views
fixtures :users, :outgoing_messages, :incoming_messages, :raw_emails, :info_requests, :info_request_events, :comments, :public_bodies, :public_body_translations
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ end
it "should be successful" do
get :show, :url_name => "bob_smith"
diff --git a/spec/fixtures/files/useless_raw_email.email b/spec/fixtures/files/useless_raw_email.email
new file mode 100644
index 000000000..2e4585af7
--- /dev/null
+++ b/spec/fixtures/files/useless_raw_email.email
@@ -0,0 +1,15 @@
+From: "FOI Person" <foiperson@localhost>
+To: "Bob Smith" <bob@localhost>
+Date: Tue, 13 Nov 2007 11:39:55 +0000
+Bcc:
+Subject: Geraldine FOI Code AZXB421
+Reply-To:
+In-Reply-To: <471f1eae5d1cb_7347..fdbe67386163@cat.tmail>
+
+No way! I'm not going to tell you that in a month of Thursdays.
+
+The Geraldine Quango
+
+On Wed, Oct 24, 2007 at 11:30:06AM +0100, Bob Smith wrote:
+> Why do you have such a fancy dog?
+
diff --git a/spec/fixtures/raw_emails.yml b/spec/fixtures/raw_emails.yml
index d24b61854..8ef9248a3 100644
--- a/spec/fixtures/raw_emails.yml
+++ b/spec/fixtures/raw_emails.yml
@@ -1,19 +1,2 @@
useless_raw_email:
id: 1
- data_binary: |
- From: "FOI Person" <foiperson@localhost>
- To: "Bob Smith" <bob@localhost>
- Date: Tue, 13 Nov 2007 11:39:55 +0000
- NoCc: foi+request-1-4b571715@cat
- Bcc:
- Subject: Geraldine FOI Code AZXB421
- Reply-To:
- In-Reply-To: <471f1eae5d1cb_7347..fdbe67386163@cat.tmail>
-
- No way! I'm not going to tell you that in a month of Thursdays.
-
- The Geraldine Quango
-
- On Wed, Oct 24, 2007 at 11:30:06AM +0100, Bob Smith wrote:
- > Why do you have such a fancy dog?
-
diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb
index abbe94a47..42ea748fd 100644
--- a/spec/models/incoming_message_spec.rb
+++ b/spec/models/incoming_message_spec.rb
@@ -1,10 +1,11 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe IncomingMessage, " when dealing with incoming mail" do
- fixtures :incoming_messages, :raw_emails
+ fixtures :incoming_messages, :raw_emails, :info_requests
before do
@im = incoming_messages(:useless_incoming_message)
+ load_raw_emails_data(raw_emails)
end
it "should return the mail Date header date for sent at" do
@@ -129,6 +130,8 @@ describe IncomingMessage, " when censoring data" do
@censor_rule_2.last_edit_editor = "unknown"
@censor_rule_2.last_edit_comment = "none"
@im.info_request.censor_rules << @censor_rule_2
+
+ load_raw_emails_data(raw_emails)
end
it "should do nothing to a JPEG" do
@@ -212,6 +215,7 @@ describe IncomingMessage, " when censoring whole users" do
@censor_rule_1.last_edit_editor = "unknown"
@censor_rule_1.last_edit_comment = "none"
@im.info_request.user.censor_rules << @censor_rule_1
+ load_raw_emails_data(raw_emails)
end
it "should apply censor rules to HTML files" do
diff --git a/spec/models/outgoing_mailer_spec.rb b/spec/models/outgoing_mailer_spec.rb
index 24143fc9b..d7587cb41 100644
--- a/spec/models/outgoing_mailer_spec.rb
+++ b/spec/models/outgoing_mailer_spec.rb
@@ -5,6 +5,9 @@ describe OutgoingMailer, " when working out follow up addresses" do
# calls TMail. XXX untangle it and make these tests spread out and using
# mocks. Put parts of the tests in spec/lib/tmail_extensions.rb
fixtures :info_requests, :incoming_messages, :raw_emails, :public_bodies, :public_body_translations
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ end
it "should parse them right" do
ir = info_requests(:fancy_dog_request)
@@ -69,13 +72,8 @@ end
describe OutgoingMailer, "when working out follow up subjects" do
fixtures :info_requests, :incoming_messages, :outgoing_messages, :raw_emails
- before do
- raw_email = raw_emails(:useless_raw_email)
- raw_email.data=raw_email.dbdata
- end
-
- after do
- raw_emails(:useless_raw_email).destroy_file_representation!
+ before(:each) do
+ load_raw_emails_data(raw_emails)
end
it "should prefix the title with 'Freedom of Information request -' for initial requests" do
diff --git a/spec/models/request_mailer_spec.rb b/spec/models/request_mailer_spec.rb
index a8311e8f8..a5f59b9bf 100644
--- a/spec/models/request_mailer_spec.rb
+++ b/spec/models/request_mailer_spec.rb
@@ -2,6 +2,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe RequestMailer, " when receiving incoming mail" do
fixtures :info_requests, :incoming_messages, :raw_emails, :users, :public_bodies, :public_body_translations
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ end
it "should append it to the appropriate request" do
ir = info_requests(:fancy_dog_request)
diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb
index 79ffc4839..37e68b145 100644
--- a/spec/models/xapian_spec.rb
+++ b/spec/models/xapian_spec.rb
@@ -35,6 +35,9 @@ end
describe PublicBody, " when indexing public bodies with Xapian" do
fixtures :public_bodies, :public_body_translations, :incoming_messages, :outgoing_messages, :raw_emails, :comments
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ end
it "should search index the main name field" do
rebuild_xapian_index
@@ -126,6 +129,9 @@ end
describe User, " when indexing requests by user they are from" do
fixtures :users, :info_request_events, :info_requests, :incoming_messages, :outgoing_messages, :raw_emails, :comments
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ end
it "should find requests from the user" do
rebuild_xapian_index
@@ -210,6 +216,9 @@ end
describe User, " when indexing comments by user they are by" do
fixtures :users, :info_request_events, :info_requests, :comments, :incoming_messages, :outgoing_messages, :raw_emails, :comments
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ end
it "should find requests from the user" do
rebuild_xapian_index
@@ -244,6 +253,9 @@ end
describe InfoRequest, " when indexing requests by their title" do
fixtures :info_request_events, :info_requests, :incoming_messages, :raw_emails, :comments
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ end
it "should find events for the request" do
rebuild_xapian_index
@@ -272,6 +284,9 @@ end
describe InfoRequest, " when indexing requests by tag" do
fixtures :info_request_events, :info_requests, :incoming_messages, :raw_emails, :comments
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ end
it "should find request by tag, even when changes" do
rebuild_xapian_index
@@ -291,6 +306,9 @@ end
describe PublicBody, " when indexing authorities by tag" do
fixtures :public_bodies, :public_body_translations, :incoming_messages, :outgoing_messages, :raw_emails, :comments
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ end
it "should find request by tag, even when changes" do
rebuild_xapian_index
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 086def32a..42c5ff6bf 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -13,9 +13,6 @@ config['ADMIN_PASSWORD'] = 'baz'
# tests assume 20 days
config['REPLY_LATE_AFTER_DAYS'] = 20
-# tests assume 20 days
-config['RAW_EMAILS_LOCATION'] = 'files/raw_emails_tests'
-
# Uncomment the next line to use webrat's matchers
#require 'webrat/integrations/rspec-rails'
@@ -31,21 +28,6 @@ Spec::Runner.configure do |config|
config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
- config.before(:each) do
- # XXX this is a hack around the fact that our raw_email model
- # is in transition to something that doesn't actually live in
- # the database at all. The raw_email *fixture* saves to the
- # model, the model then needs to be told to save itself on the
- # filesystem.
- begin
- raw_email = raw_emails(:useless_raw_email)
- raw_email.data=raw_email.dbdata
- rescue NoMethodError
- # only do it in tests with raw_emails fixtures
- end
- end
-
-
# == Fixtures
#
# You can declare fixtures for each example_group like this:
@@ -164,3 +146,12 @@ if $tempfilecount.nil?
puts "WARNING: HTML validation script " + $html_validation_script + " not found"
end
end
+
+def load_raw_emails_data(raw_emails)
+ raw_email = raw_emails(:useless_raw_email)
+ begin
+ raw_email.destroy_file_representation!
+ rescue Errno::ENOENT
+ end
+ raw_email.data = load_file_fixture("useless_raw_email.email")
+end