diff options
Diffstat (limited to 'spec')
65 files changed, 1987 insertions, 280 deletions
diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index 357564211..0a90cd64b 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -52,6 +52,12 @@ describe AdminPublicBodyController, "when administering public bodies" do get :show, :id => 2 session[:using_admin].should == 1 end +end + +describe AdminPublicBodyController, "when administering public bodies and paying attention to authentication" do + + integrate_views + fixtures :public_bodies, :public_body_translations it "disallows non-authenticated users to do anything" do @request.env["HTTP_AUTHORIZATION"] = "" @@ -82,6 +88,19 @@ describe AdminPublicBodyController, "when administering public bodies" do PublicBody.count.should == 1 session[:using_admin].should == 1 end + it "forces authorisation when password and username set" do + config = MySociety::Config.load_default() + config['ADMIN_USERNAME'] = 'biz' + config['ADMIN_PASSWORD'] = 'fuz' + @request.env["HTTP_AUTHORIZATION"] = "" + PublicBody.count.should == 2 + basic_auth_login(@request, "baduser", "badpassword") + post :destroy, { :id => 3 } + response.code.should == "401" + PublicBody.count.should == 2 + session[:using_admin].should == nil + end + end @@ -109,28 +128,34 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" get :show, {:id => 2, :locale => "es" } end - it "creates a new public body" do - I18n.default_locale = :es - PublicBody.count.should == 2 - post :create, { :public_body => { :name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' } } - PublicBody.count.should == 3 - I18n.default_locale = :en - end - it "edits a public body" do - I18n.default_locale = :es - get :edit, {:id => 3, :locale => :es} - response.body.should include('Baguette') - I18n.default_locale = :en + get :edit, {:id => 3, :locale => :en} + + # When editing a body, the controller returns all available translations + assigns[:public_body].translation("es").name.should == 'El Department for Humpadinking' + assigns[:public_body].name.should == 'Department for Humpadinking' + response.should render_template('edit') end it "saves edits to a public body" do - I18n.default_locale = :es - pb = PublicBody.find(id=3) - pb.name.should == "El Department for Humpadinking" - post :update, { :id => 3, :public_body => { :name => "Renamed", :short_name => "", :tag_string => "some tags", :request_email => 'edited@localhost', :last_edit_comment => 'From test code' }} - response.flash[:notice].should include('successful') - I18n.default_locale = :en + PublicBody.with_locale(:es) do + pb = PublicBody.find(id=3) + pb.name.should == "El Department for Humpadinking" + post :update, { + :id => 3, + :public_body => { + :name => "Department for Humpadinking", + :short_name => "", + :tag_string => "some tags", + :request_email => 'edited@localhost', + :last_edit_comment => 'From test code', + :translated_versions => { + 3 => {:locale => "es", :name => "Renamed",:short_name => "", :request_email => 'edited@localhost'} + } + } + } + response.flash[:notice].should include('successful') + end pb = PublicBody.find(public_bodies(:humpadink_public_body).id) PublicBody.with_locale(:es) do @@ -148,3 +173,51 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" end end + +describe AdminPublicBodyController, "when creating public bodies with i18n" do + integrate_views + fixtures :public_bodies, :public_body_translations + + before do + username = MySociety::Config.get('ADMIN_USERNAME', '') + password = MySociety::Config.get('ADMIN_PASSWORD', '') + basic_auth_login @request + + ActionController::Routing::Routes.filters.clear # don't auto-insert locale, complicates assertions + end + + it "creates a new public body in one locale" do + PublicBody.count.should == 2 + post :create, { :public_body => { :name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' } } + PublicBody.count.should == 3 + + body = PublicBody.find_by_name("New Quango") + response.should redirect_to(:controller=>'admin_public_body', :action=>'show', :id=>body.id) + end + + it "creates a new public body with multiple locales" do + PublicBody.count.should == 2 + post :create, { + :public_body => { + :name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code', + :translated_versions => [{ :locale => "es", :name => "Mi Nuevo Quango", :short_name => "", :request_email => 'newquango@localhost' }] + } + } + PublicBody.count.should == 3 + + body = PublicBody.find_by_name("New Quango") + body.translations.map {|t| t.locale.to_s}.sort.should == ["en", "es"] + PublicBody.with_locale(:en) do + body.name.should == "New Quango" + body.url_name.should == "new_quango" + body.first_letter.should == "N" + end + PublicBody.with_locale(:es) do + body.name.should == "Mi Nuevo Quango" + body.url_name.should == "mi_nuevo_quango" + body.first_letter.should == "M" + end + + response.should redirect_to(:controller=>'admin_public_body', :action=>'show', :id=>body.id) + end +end diff --git a/spec/controllers/admin_request_controller_spec.rb b/spec/controllers/admin_request_controller_spec.rb index 423c2fb49..441b1b91d 100644 --- a/spec/controllers/admin_request_controller_spec.rb +++ b/spec/controllers/admin_request_controller_spec.rb @@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminRequestController, "when administering requests" do integrate_views - fixtures :info_requests, :outgoing_messages, :users, :info_request_events, :public_bodies, :public_body_translations + fixtures :users, :public_bodies, :public_body_translations, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events before { basic_auth_login @request } it "shows the index/list page" do @@ -41,7 +41,7 @@ end describe AdminRequestController, "when administering the holding pen" do integrate_views - fixtures :info_requests, :incoming_messages, :raw_emails, :users, :public_bodies, :public_body_translations + fixtures :users, :public_bodies, :public_body_translations, :info_requests, :raw_emails, :incoming_messages before(:each) do basic_auth_login @request load_raw_emails_data(raw_emails) @@ -71,7 +71,7 @@ describe AdminRequestController, "when administering the holding pen" do post :redeliver_incoming, :redeliver_incoming_message_id => new_im.id, :url_title => ir.url_title ir = InfoRequest.find_by_url_title(ir.url_title) ir.incoming_messages.length.should == 2 - response.should redirect_to('http://test.host/admin/request/show/101') + response.should redirect_to(:controller=>'admin_request', :action=>'show', :id=>101) InfoRequest.holding_pen_request.incoming_messages.length.should == 0 end diff --git a/spec/controllers/admin_track_controller_spec.rb b/spec/controllers/admin_track_controller_spec.rb index 4d5b0ac5e..3db242f73 100644 --- a/spec/controllers/admin_track_controller_spec.rb +++ b/spec/controllers/admin_track_controller_spec.rb @@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminTrackController, "when administering tracks" do integrate_views - fixtures :track_things, :users + fixtures :users, :track_things it "shows the list page" do get :list diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index 76e1bb5e6..054b9881f 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -2,12 +2,12 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe GeneralController, "when searching" do integrate_views - fixtures [ :info_requests, - :info_request_events, - :public_bodies, + fixtures [ :public_bodies, :public_body_translations, :users, :raw_emails, + :info_requests, + :info_request_events, :outgoing_messages, :incoming_messages, :comments ] @@ -62,10 +62,9 @@ describe GeneralController, "when searching" do response.should be_success end - it "should redirect from search query URL to pretty URL" do post :search_redirect, :query => "mouse" # query hidden in POST parameters - response.should redirect_to(:action => 'search', :combined => "mouse") # URL /search/:query + response.should redirect_to(:action => 'search', :combined => "mouse", :view => "requests") # URL /search/:query/all end describe "when using different locale settings" do @@ -123,6 +122,34 @@ describe GeneralController, "when searching" do end + it "should filter results based on end of URL being 'all'" do + get :search, :combined => ['"bob"', "all"] + assigns[:xapian_requests].results.size.should == 2 + assigns[:xapian_users].results.size.should == 1 + assigns[:xapian_bodies].results.size.should == 0 + end + + it "should filter results based on end of URL being 'users'" do + get :search, :combined => ['"bob"', "users"] + assigns[:xapian_requests].should == nil + assigns[:xapian_users].results.size.should == 1 + assigns[:xapian_bodies].should == nil + end + + it "should filter results based on end of URL being 'requests'" do + get :search, :combined => ['"bob"', "requests"] + assigns[:xapian_requests].results.size.should == 2 + assigns[:xapian_users].should == nil + assigns[:xapian_bodies].should == nil + end + + it "should filter results based on end of URL being 'bodies'" do + get :search, :combined => ['"quango"', "bodies"] + assigns[:xapian_requests].should == nil + assigns[:xapian_users].should == nil + assigns[:xapian_bodies].results.size.should == 1 + end + it "should show help when searching for nothing" do get :search_redirect, :query => nil response.should render_template('search') diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index 0050678d2..efcbc7d57 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -7,47 +7,54 @@ describe PublicBodyController, "when showing a body" do fixtures :public_bodies, :public_body_translations, :public_body_versions it "should be successful" do - get :show, :url_name => "dfh" + get :show, :url_name => "dfh", :view => 'all' response.should be_success end it "should render with 'show' template" do - get :show, :url_name => "dfh" + get :show, :url_name => "dfh", :view => 'all' response.should render_template('show') end it "should assign the body" do - get :show, :url_name => "dfh" + get :show, :url_name => "dfh", :view => 'all' assigns[:public_body].should == public_bodies(:humpadink_public_body) end + it "should assign the requests" do + get :show, :url_name => "tgq", :view => 'all' + assigns[:xapian_requests].results.count.should == 2 + get :show, :url_name => "tgq", :view => 'successful' + assigns[:xapian_requests].results.count.should == 0 + end + it "should assign the body using different locale from that used for url_name" do PublicBody.with_locale(:es) do - get :show, {:url_name => "dfh"} + get :show, {:url_name => "dfh", :view => 'all'} assigns[:public_body].notes.should == "Baguette" end end it "should assign the body using same locale as that used in url_name" do PublicBody.with_locale(:es) do - get :show, {:url_name => "edfh"} + get :show, {:url_name => "edfh", :view => 'all'} assigns[:public_body].notes.should == "Baguette" end end it "should redirect use to the relevant locale even when url_name is for a different locale" do ActionController::Routing::Routes.filters.clear - get :show, {:url_name => "edfh"} + get :show, {:url_name => "edfh", :view => 'all'} response.should redirect_to "http://test.host/body/dfh" end it "should redirect to newest name if you use historic name of public body in URL" do - get :show, :url_name => "hdink" + get :show, :url_name => "hdink", :view => 'all' response.should redirect_to(:controller => 'public_body', :action => 'show', :url_name => "dfh") end it "should redirect to lower case name if you use mixed case name in URL" do - get :show, :url_name => "dFh" + get :show, :url_name => "dFh", :view => 'all' response.should redirect_to(:controller => 'public_body', :action => 'show', :url_name => "dfh") end end @@ -68,7 +75,17 @@ describe PublicBodyController, "when listing bodies" do assigns[:public_bodies].should == [ public_bodies(:humpadink_public_body), public_bodies(:geraldine_public_body) ] assigns[:tag].should == "all" - assigns[:description].should == "all" + assigns[:description].should == "" + end + + it "should support simple searching of bodies by title" do + get :list, :public_body_query => 'quango' + assigns[:public_bodies].should == [ public_bodies(:geraldine_public_body) ] + end + + it "should support simple searching of bodies by notes" do + get :list, :public_body_query => 'Albatross' + assigns[:public_bodies].should == [ public_bodies(:humpadink_public_body) ] end it "should list bodies in alphabetical order with different locale" do @@ -77,7 +94,7 @@ describe PublicBodyController, "when listing bodies" do response.should render_template('list') assigns[:public_bodies].should == [ public_bodies(:geraldine_public_body), public_bodies(:humpadink_public_body) ] assigns[:tag].should == "all" - assigns[:description].should == "all" + assigns[:description].should == "" I18n.default_locale = :en end @@ -96,7 +113,7 @@ describe PublicBodyController, "when listing bodies" do get :list response.should render_template('list') - assigns[:public_bodies].should == [ public_bodies(:humpadink_public_body), public_bodies(:geraldine_public_body) ] + assigns[:public_bodies].count.should == 2 end @@ -128,7 +145,7 @@ describe PublicBodyController, "when showing JSON version for API" do fixtures :public_bodies, :public_body_translations it "should be successful" do - get :show, :url_name => "dfh", :format => "json" + get :show, :url_name => "dfh", :format => "json", :view => 'all' pb = JSON.parse(response.body) pb.class.to_s.should == 'Hash' @@ -139,6 +156,41 @@ describe PublicBodyController, "when showing JSON version for API" do end +describe PublicBodyController, "when doing type ahead searches" do + fixtures :public_bodies, :public_body_translations, :users, :raw_emails, :info_requests, :incoming_messages, :outgoing_messages, :comments, :info_request_events + + it "should return nothing for the empty query string" do + get :search_typeahead, :q => "" + response.should render_template('public_body/_search_ahead') + assigns[:xapian_requests].results.size.should == 0 + end + + it "should return a body matching the given keyword, but not users with a matching description" do + get :search_typeahead, :q => "Geraldine" + response.should render_template('public_body/_search_ahead') + assigns[:xapian_requests].results.size.should == 1 + assigns[:xapian_requests].results[0][:model].name.should == public_bodies(:geraldine_public_body).name + end + it "should return all requests matching any of the given keywords" do + get :search_typeahead, :q => "Geraldine Humpadinking" + response.should render_template('public_body/_search_ahead') + assigns[:xapian_requests].results.size.should == 2 + assigns[:xapian_requests].results[0][:model].name.should == public_bodies(:humpadink_public_body).name + assigns[:xapian_requests].results[1][:model].name.should == public_bodies(:geraldine_public_body).name + end + it "should return requests matching the given keywords in any of their locales" do + get :search_typeahead, :q => "baguette" # part of the spanish notes + response.should render_template('public_body/_search_ahead') + assigns[:xapian_requests].results.size.should == 1 + assigns[:xapian_requests].results[0][:model].name.should == public_bodies(:humpadink_public_body).name + end + it "should return partial matches" do + get :search_typeahead, :q => "geral" # 'geral' for 'Geraldine' + response.should render_template('public_body/_search_ahead') + assigns[:xapian_requests].results.size.should == 1 + assigns[:xapian_requests].results[0][:model].name.should == public_bodies(:geraldine_public_body).name + end +end diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index dcd33d279..fe9a6a99e 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1,13 +1,10 @@ -# £2k p/a -# talk about margins -# - +# -*- coding: utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require 'json' describe RequestController, "when listing recent requests" do - fixtures :info_requests, :outgoing_messages, :users, :info_request_events, :public_bodies, :public_body_translations, :incoming_messages, :raw_emails, :comments + fixtures :users, :public_bodies, :public_body_translations, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events before(:each) do load_raw_emails_data(raw_emails) @@ -24,13 +21,29 @@ describe RequestController, "when listing recent requests" do response.should render_template('list') end + it "should filter requests" do + get :list, :view => 'all' + assigns[:list_results].size.should == 2 + get :list, :view => 'successful' + assigns[:list_results].size.should == 0 + end + + it "should filter requests by date" do + get :list, :view => 'all', :request_date_before => '13/10/2007' + assigns[:list_results].size.should == 1 + get :list, :view => 'all', :request_date_after => '13/10/2007' + assigns[:list_results].size.should == 1 + get :list, :view => 'all', :request_date_after => '10/10/2007', :request_date_before => '01/01/2010' + assigns[:list_results].size.should == 2 + end + it "should assign the first page of results" do xap_results = mock_model(ActsAsXapian::Search, :results => (1..25).to_a.map { |m| { :model => m } }, :matches_estimated => 103) InfoRequest.should_receive(:full_search). - with([InfoRequestEvent],"variety:sent", "created_at", anything, anything, anything, anything). + with([InfoRequestEvent]," variety:sent", "created_at", anything, anything, anything, anything). and_return(xap_results) get :list, :view => 'recent' assigns[:list_results].size.should == 25 @@ -39,7 +52,7 @@ 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 + fixtures :public_bodies, :public_body_translations, :public_body_translations, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events # all needed as integrating views before(:each) do load_raw_emails_data(raw_emails) @@ -125,6 +138,21 @@ describe RequestController, "when showing one request" do response.should have_text(/First hello/) end + it "should convert message body to UTF8" do + ir = info_requests(:fancy_dog_request) + receive_incoming_mail('iso8859_2_raw_email.email', ir.incoming_email) + get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' + response.should have_text(/tënde/u) + end + + it "should generate valid HTML verson of plain text attachments " do + ir = info_requests(:fancy_dog_request) + receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt.html'], :skip_cache => 1 + response.content_type.should == "text/html" + response.should have_text(/Second hello/) + end + it "should treat attachments with unknown extensions as binary" do ir = info_requests(:fancy_dog_request) receive_incoming_mail('incoming-request-attachment-unknown-extension.email', ir.incoming_email) @@ -141,7 +169,7 @@ describe RequestController, "when showing one request" do lambda { get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['http://trying.to.hack'] - }.should raise_error(RuntimeError) + }.should raise_error(ActiveRecord::RecordNotFound) end it "should censor attachments downloaded as binary" do @@ -196,12 +224,32 @@ describe RequestController, "when showing one request" do response.body.should have_tag("p.attachment strong", /goodbye.txt/m) end - + it "should make a zipfile available, which has a different URL when it changes" do + ir = info_requests(:fancy_dog_request) + session[:user_id] = ir.user.id # bob_smith_user + receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) + title = 'why_do_you_have_such_a_fancy_dog' + get :download_entire_request, :url_title => title + assigns[:url_path].should have_text(/#{title}.zip$/) + old_path = assigns[:url_path] + response.location.should have_text(/#{assigns[:url_path]}$/) + zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", old_path)) { |zipfile| + zipfile.count.should == 2 + } + receive_incoming_mail('incoming-request-attachment-unknown-extension.email', ir.incoming_email) + get :download_entire_request, :url_title => title + assigns[:url_path].should have_text(/#{title}.zip$/) + response.location.should have_text(/#{assigns[:url_path]}/) + zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", assigns[:url_path])) { |zipfile| + zipfile.count.should == 4 + } + assigns[:url_path].should_not == old_path + end end 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 + fixtures :public_bodies, :public_body_translations, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :info_request_events # all needed as integrating views before(:each) do load_raw_emails_data(raw_emails) @@ -288,9 +336,36 @@ end # response.headers["Status"].should == "404 Not Found" # end +describe RequestController, "when searching for an authority" do + fixtures :public_bodies, :users + + # Whether or not sign-in is required for this step is configurable, + # so we make sure we're logged in, just in case + before do + @user = users(:bob_smith_user) + end + + it "should return nothing for the empty query string" do + session[:user_id] = @user.id + get :select_authority, :query => "" + + response.should render_template('select_authority') + assigns[:xapian_requests].results.size == 0 + end + + it "should return matching bodies" do + session[:user_id] = @user.id + get :select_authority, :query => "Quango" + + response.should render_template('select_authority') + assigns[:xapian_requests].results.size == 1 + assigns[:xapian_requests].results[0][:model].name.should == public_bodies(:geraldine_public_body).name + end +end + describe RequestController, "when creating a new request" do integrate_views - fixtures :info_requests, :outgoing_messages, :public_bodies, :public_body_translations, :users + fixtures :public_bodies, :public_body_translations, :users, :info_requests, :outgoing_messages before do @user = users(:bob_smith_user) @@ -308,6 +383,13 @@ describe RequestController, "when creating a new request" do response.should redirect_to(:controller => 'general', :action => 'frontpage') end + it "should redirect 'bad request' page when a body has no email address" do + @body.request_email = "" + @body.save! + get :new, :public_body_id => @body.id + response.should render_template('new_bad_contact') + end + it "should accept a public body parameter" do get :new, :public_body_id => @body.id assigns[:info_request].public_body.should == @body @@ -322,7 +404,20 @@ describe RequestController, "when creating a new request" do response.should render_template('new') end + it "should redirect to sign in page when input is good and nobody is logged in" do + params = { :info_request => { :public_body_id => @body.id, + :title => "Why is your quango called Geraldine?", :tag_string => "" }, + :outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." }, + :submitted_new_request => 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 show preview when input is good" do + session[:user_id] = @user.id post :new, { :info_request => { :public_body_id => @body.id, :title => "Why is your quango called Geraldine?", :tag_string => "" }, :outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." }, @@ -340,18 +435,6 @@ describe RequestController, "when creating a new request" do response.should render_template('new') end - it "should redirect to sign in page when input is good and nobody is logged in" do - params = { :info_request => { :public_body_id => @body.id, - :title => "Why is your quango called Geraldine?", :tag_string => "" }, - :outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." }, - :submitted_new_request => 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 request and outgoing message, and send the outgoing message by email, and redirect to request page when input is good and somebody is logged in" do session[:user_id] = @user.id post :new, :info_request => { :public_body_id => @body.id, @@ -423,6 +506,7 @@ describe RequestController, "when making a new request" do @user.stub!(:get_undescribed_requests).and_return([]) @user.stub!(:can_leave_requests_undescribed?).and_return(false) @user.stub!(:can_file_requests?).and_return(true) + @user.stub!(:locale).and_return("en") User.stub!(:find).and_return(@user) @body = mock_model(PublicBody, :id => 314, :eir_only? => false, :is_requestable? => true, :name => "Test Quango") @@ -465,7 +549,7 @@ 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 + fixtures :public_bodies, :public_body_translations, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events # all needed as integrating views before(:each) do load_raw_emails_data(raw_emails) @@ -483,6 +567,22 @@ describe RequestController, "when viewing an individual response for reply/follo response.should render_template('show_response') end + it "should offer the opportunity to reply to the main address" do + session[:user_id] = users(:bob_smith_user).id + get :show_response, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message) + response.body.should have_tag("div#other_recipients ul li", /the main FOI contact address for/) + end + + it "should offer an opportunity to reply to another address" do + session[:user_id] = users(:bob_smith_user).id + ir = info_requests(:fancy_dog_request) + ir.allow_new_responses_from = "anybody" + ir.save! + receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "Frob <frob@bonce.com>") + get :show_response, :id => ir.id, :incoming_message_id => incoming_messages(:useless_incoming_message) + response.body.should have_tag("div#other_recipients ul li", /Frob/) + end + it "should not show individual responses if request hidden, even if request owner" do ir = info_requests(:fancy_dog_request) ir.prominence = 'hidden' @@ -496,7 +596,7 @@ end describe RequestController, "when classifying an information request" do - fixtures :info_requests, :info_request_events, :public_bodies, :public_body_translations, :users, :incoming_messages, :raw_emails, :outgoing_messages, :comments # all needed as integrating views + fixtures :public_bodies, :public_body_translations, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events # all needed as integrating views before(:each) do @dog_request = info_requests(:fancy_dog_request) @@ -720,18 +820,16 @@ describe RequestController, "when classifying an information request" do response.should redirect_to(:controller => 'help', :action => 'unhappy', :url_title => @dog_request.url_title) end - describe "when using custom statuses from the theme" do + it "knows about extended states" do InfoRequest.send(:require, File.expand_path(File.join(File.dirname(__FILE__), '..', 'models', 'customstates'))) InfoRequest.send(:include, InfoRequestCustomStates) InfoRequest.class_eval('@@custom_states_loaded = true') RequestController.send(:require, File.expand_path(File.join(File.dirname(__FILE__), '..', 'models', 'customstates'))) RequestController.send(:include, RequestControllerCustomStates) RequestController.class_eval('@@custom_states_loaded = true') - it "knows about extended states" do - Time.stub!(:now).and_return(Time.utc(2007, 11, 10, 00, 01)) - post_status('deadline_extended') - flash[:notice].should == 'Authority has requested extension of the deadline.' - end + Time.stub!(:now).and_return(Time.utc(2007, 11, 10, 00, 01)) + post_status('deadline_extended') + flash[:notice].should == 'Authority has requested extension of the deadline.' end end @@ -834,7 +932,7 @@ end describe RequestController, "when sending a followup message" 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 + fixtures :public_bodies, :public_body_translations, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :info_request_events # all needed as integrating views before(:each) do load_raw_emails_data(raw_emails) @@ -917,7 +1015,7 @@ 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 + fixtures :public_bodies, :public_body_translations, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :info_request_events # all needed as integrating views before(:each) do load_raw_emails_data(raw_emails) @@ -1005,7 +1103,7 @@ 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 + fixtures :public_bodies, :public_body_translations, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events # all needed as integrating views before(:each) do load_raw_emails_data(raw_emails) @@ -1036,7 +1134,7 @@ 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 + fixtures :public_bodies, :public_body_translations, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :info_request_events # all needed as integrating views before(:each) do load_raw_emails_data(raw_emails) end @@ -1090,7 +1188,7 @@ 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 + fixtures :public_bodies, :public_body_translations, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events # all needed as integrating views before(:each) do load_raw_emails_data(raw_emails) end @@ -1165,7 +1263,7 @@ end describe RequestController, "when viewing comments" do integrate_views - fixtures :users, :raw_emails, :incoming_messages, :info_requests + fixtures :users, :info_requests, :raw_emails, :incoming_messages before(:each) do load_raw_emails_data(raw_emails) end @@ -1188,7 +1286,7 @@ end describe RequestController, "authority uploads a response from the web interface" do - fixtures :info_requests, :info_request_events, :public_bodies, :public_body_translations, :users + fixtures :public_bodies, :public_body_translations, :users, :info_requests, :info_request_events before(:all) do # domain after the @ is used for authentication of FOI officers, so to test it @@ -1275,7 +1373,7 @@ end 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 + fixtures :public_bodies, :public_body_translations, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events before(:each) do load_raw_emails_data(raw_emails) @@ -1294,5 +1392,36 @@ describe RequestController, "when showing JSON version for API" do end +describe RequestController, "when doing type ahead searches" do + fixtures :public_bodies, :public_body_translations, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events + + it "should return nothing for the empty query string" do + get :search_typeahead, :q => "" + response.should render_template('request/_search_ahead.rhtml') + assigns[:xapian_requests].results.size.should == 0 + end + + it "should return a request matching the given keyword, but not users with a matching description" do + get :search_typeahead, :q => "chicken" + response.should render_template('request/_search_ahead.rhtml') + assigns[:xapian_requests].results.size.should == 1 + assigns[:xapian_requests].results[0][:model].title.should == info_requests(:naughty_chicken_request).title + end + + it "should return all requests matching any of the given keywords" do + get :search_typeahead, :q => "money dog" + response.should render_template('request/_search_ahead.rhtml') + assigns[:xapian_requests].results.size.should == 2 + assigns[:xapian_requests].results[0][:model].title.should == info_requests(:fancy_dog_request).title + assigns[:xapian_requests].results[1][:model].title.should == info_requests(:naughty_chicken_request).title + end + + it "should return partial matches" do + get :search_typeahead, :q => "chick" # 'chick' for 'chicken' + response.should render_template('request/_search_ahead.rhtml') + assigns[:xapian_requests].results.size.should == 1 + assigns[:xapian_requests].results[0][:model].title.should == info_requests(:naughty_chicken_request).title + end +end diff --git a/spec/controllers/request_game_controller_spec.rb b/spec/controllers/request_game_controller_spec.rb index 4883bfdd6..0b8f5751c 100644 --- a/spec/controllers/request_game_controller_spec.rb +++ b/spec/controllers/request_game_controller_spec.rb @@ -2,7 +2,7 @@ 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 + fixtures :public_bodies, :public_body_translations, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :info_request_events # all needed as integrating views before(:each) do load_raw_emails_data(raw_emails) end diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb new file mode 100644 index 000000000..1bafd0c8f --- /dev/null +++ b/spec/controllers/services_controller_spec.rb @@ -0,0 +1,31 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe ServicesController, "when using web services" do + integrate_views + + it "should show no alaveteli message when in the deployed country" do + config = MySociety::Config.load_default() + config['ISO_COUNTRY_CODE'] = "DE" + controller.stub!(:country_from_ip).and_return('DE') + get :other_country_message + response.body.should == "" + end + + it "should show an alaveteli message when not in the deployed country and in a country with no FOI website" do + config = MySociety::Config.load_default() + config['ISO_COUNTRY_CODE'] = "DE" + controller.stub!(:country_from_ip).and_return('ZZ') + get :other_country_message + response.body.should match(/outside Germany/) + end + + it "should show link to other FOI website when not in the deployed country" do + config = MySociety::Config.load_default() + config['ISO_COUNTRY_CODE'] = "ZZ" + controller.stub!(:country_from_ip).and_return('DE') + get :other_country_message + response.body.should match(/within Germany/) + end + + +end diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb index 2f3f903f9..617e36213 100644 --- a/spec/controllers/track_controller_spec.rb +++ b/spec/controllers/track_controller_spec.rb @@ -16,6 +16,7 @@ describe TrackController, "when making a new track on a request" do @user = mock_model(User) User.stub!(:find).and_return(@user) + @user.stub!(:locale).and_return("en") end it "should require login when making new track" do @@ -35,7 +36,7 @@ end 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 + fixtures :public_bodies, :public_body_translations, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things, :track_things_sent_emails include LinkToHelper # for main_url before(:each) do @@ -69,7 +70,6 @@ describe TrackController, "when sending alerts for a track" do mail.body.should include('added an annotation') # comment included mail.body.should =~ /This a the daftest comment the world has ever seen/ # comment text included - # Check subscription managing link # XXX We can't do this, as it is redirecting to another controller. I'm # apparently meant to be writing controller unit tests here, not functional @@ -93,11 +93,24 @@ describe TrackController, "when sending alerts for a track" do deliveries.size.should == 0 end + it "should send localised alerts" do + # set the time the comment event happened at to within the last week + ire = info_request_events(:silly_comment_event) + ire.created_at = Time.now - 3.days + ire.save! + user = users(:silly_name_user) + user.locale = "es" + user.save! + TrackMailer.alert_tracks + deliveries = ActionMailer::Base.deliveries + mail = deliveries[0] + mail.body.should include('el equipo de ') + end end describe TrackController, "when viewing RSS feed for a track" do integrate_views - fixtures :info_requests, :outgoing_messages, :incoming_messages, :raw_emails, :info_request_events, :users, :track_things, :comments, :public_bodies, :public_body_translations + fixtures :public_bodies, :public_body_translations, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things before(:each) do load_raw_emails_data(raw_emails) @@ -123,7 +136,7 @@ end describe TrackController, "when viewing JSON version of a track feed" do integrate_views - fixtures :info_requests, :outgoing_messages, :incoming_messages, :raw_emails, :info_request_events, :users, :track_things, :comments, :public_bodies, :public_body_translations + fixtures :public_bodies, :public_body_translations, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things before(:each) do load_raw_emails_data(raw_emails) diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index c974c8a0d..ae771da04 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -7,7 +7,7 @@ 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 + fixtures :users, :public_bodies, :public_body_translations, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :info_request_events, :comments before(:each) do load_raw_emails_data(raw_emails) end @@ -32,6 +32,13 @@ describe UserController, "when showing a user" do assigns[:display_user].should == users(:bob_smith_user) end + it "should search the user's contributions" do + get :show, :url_name => "bob_smith" + assigns[:xapian_requests].results.count.should == 2 + get :show, :url_name => "bob_smith", :user_query => "money" + assigns[:xapian_requests].results.count.should == 1 + end + # Error handling not quite good enough for this yet # it "should not show unconfirmed users" do # get :show, :url_name => "silly_emnameem" @@ -104,7 +111,7 @@ describe UserController, "when signing in" do get :signin, :r => "/list" response.should render_template('sign') post_redirect = get_last_postredirect - post :signin, { :user_signin => { :email => 'silly@localhost', :password => 'jonespassword' }, + post :signin, { :user_signin => { :email => 'unconfirmed@localhost', :password => 'jonespassword' }, :token => post_redirect.token } response.should render_template('confirm') @@ -116,7 +123,7 @@ describe UserController, "when signing in" do get :signin, :r => "/list" post_redirect = get_last_postredirect - post :signin, { :user_signin => { :email => 'silly@localhost', :password => 'jonespassword' }, + post :signin, { :user_signin => { :email => 'unconfirmed@localhost', :password => 'jonespassword' }, :token => post_redirect.token } response.should send_email @@ -136,7 +143,7 @@ describe UserController, "when signing in" do # check confirmation URL works session[:user_id].should be_nil get :confirm, :email_token => post_redirect.email_token - session[:user_id].should == users(:silly_name_user).id + session[:user_id].should == users(:unconfirmed_user).id response.should redirect_to(:controller => 'request', :action => 'list', :post_redirect => 1) end @@ -171,6 +178,19 @@ describe UserController, "when signing up" do deliveries[0].body.should include("not reveal your email") end + it "should send confirmation mail in other languages or different locales" do + session[:locale] = "es" + post :signup, {:user_signup => { :email => 'new@localhost', :name => 'New Person', + :password => 'sillypassword', :password_confirmation => 'sillypassword', + } + } + response.should render_template('confirm') + + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + deliveries[0].body.should include("No revelaremos su dirección de correo") + end + it "should send special 'already signed up' mail if you fill the form in with existing registered email " do post :signup, { :user_signup => { :email => 'silly@localhost', :name => 'New Person', :password => 'sillypassword', :password_confirmation => 'sillypassword' } @@ -179,7 +199,9 @@ describe UserController, "when signing up" do deliveries = ActionMailer::Base.deliveries deliveries.size.should == 1 - deliveries[0].body.should include("when you already have an") + + # This text may span a line break, depending on the length of the SITE_NAME + deliveries[0].body.should match(/when\s+you\s+already\s+have\s+an/) end # XXX need to do bob@localhost signup and check that sends different email diff --git a/spec/fixtures/files/autoresponse-header.email b/spec/fixtures/files/autoresponse-header.email new file mode 100644 index 000000000..ecd292961 --- /dev/null +++ b/spec/fixtures/files/autoresponse-header.email @@ -0,0 +1,22 @@ +From: EMAIL_FROM +To: FOI Person <EMAIL_TO> +Delivery-date: Fri, 01 Aug 2008 14:35:58 +0100 +Return-path: <me@cheese.com> +X-Failed-Recipients: enquiries@cheese.com +Auto-Submitted: auto-replied +From: Mail Delivery System <Mailer-Daemon@sandwich.com> +Subject: Mail delivery failed: returning message to sender +Message-Id: <E1KOunW-000dXv-C6@sandwich.com> +Date: Fri, 01 Aug 2008 14:35:58 +0100 + +This message was created automatically by mail delivery software. + +A message that you sent could not be delivered to one or more of its +recipients. This is a permanent error. The following address(es) failed: + + enquiries@cheese.com + Unrouteable address + +------ This is a copy of the message, including all the headers. ------ + +Hello
\ No newline at end of file diff --git a/spec/fixtures/files/email-folding-example-1.txt b/spec/fixtures/files/email-folding-example-1.txt new file mode 100644 index 000000000..9d0810a36 --- /dev/null +++ b/spec/fixtures/files/email-folding-example-1.txt @@ -0,0 +1,32 @@ +Dear Mr Pollard, + +Thank you for your email of 26 February. Please find a response attached. + +Yours faithfully, + +On behalf of James Hall, Chief Executive +Identity and Passport Service + +<<9032 C Pollard final response.doc>> + +********************************************************************** + +This email and any files transmitted with it are confidential and + +intended solely for the use of the individual or entity to whom they + +are addressed. If you have received this email in error please notify + +the system manager. + +This footnote also confirms that this email message has been swept for the +presence of computer viruses. + +********************************************************************** + +The original of this email was scanned for viruses by the Government +Secure Intranet virus scanning service supplied by Cable&Wireless in +partnership with MessageLabs. (CCTM Certificate Number 2007/11/0032.) On +leaving the GSi this email was certified virus free. +Communications via the GSi may be automatically logged, monitored and/or +recorded for legal purposes. diff --git a/spec/fixtures/files/email-folding-example-1.txt.expected b/spec/fixtures/files/email-folding-example-1.txt.expected new file mode 100644 index 000000000..801542288 --- /dev/null +++ b/spec/fixtures/files/email-folding-example-1.txt.expected @@ -0,0 +1,10 @@ +Dear Mr Pollard, + +Thank you for your email of 26 February. Please find a response attached. + +Yours faithfully, + +On behalf of James Hall, Chief Executive +Identity and Passport Service + +<<9032 C Pollard final response.doc>> diff --git a/spec/fixtures/files/email-folding-example-10.txt b/spec/fixtures/files/email-folding-example-10.txt new file mode 100644 index 000000000..0fabb7f9c --- /dev/null +++ b/spec/fixtures/files/email-folding-example-10.txt @@ -0,0 +1,52 @@ +Please note: it is not possible to reply to this email. To contact the +Department of Health, please visit the 'Contact us' page on the +Department’s website. + +----------------------------------------------------------------------------------------- + + Apologies that you were not able to read our previous response of 4 + October. Please find the text of that email below. + +Our ref: DE00000642471 + +Dear Ms Peters Rock, + +You requested your correspondence to be treated under the Freedom of +Information Act. However, as your correspondence asked for general +information, rather than requesting recorded information or documentation, +I should advise you that on this occasion we have not considered your +correspondence under the provisions of the Act. + +I am sorry I cannot be more helpful. + +Yours sincerely, +Simon Dove +Customer Service Centre +Department of Health + + + + +------------------------------------------------------------------------------------------------------------------------- + + +Please do not reply to this email. To contact the Department of Health, +please visit the 'Contact us' page on the Department’s website, where you +can also view our performance against quarterly service targets. + + +- - Disclaimer - - +This e-mail and any files transmitted with it are confidential. If you are +not the intended recipient, any reading, printing, storage, disclosure, +copying or any other action taken in respect of this e-mail is prohibited +and may be unlawful. If you are not the intended recipient, please notify +the sender immediately by using the reply function and then permanently +delete what you have received. + +Incoming and outgoing e-mail messages are routinely monitored for +compliance with the Department of Health's policy on the use of electronic +communications. For more information on the Department of Health's e-mail +policy click here http://www.dh.gov.uk/terms + +The original of this email was scanned for viruses by the Government Secure Intranet virus scanning service supplied by Cable&Wireless Worldwide in partnership with MessageLabs. (CCTM Certificate Number 2009/09/0052.) On leaving the GSi this email was certified virus free. +Communications via the GSi may be automatically logged, monitored and/or recorded for legal purposes. diff --git a/spec/fixtures/files/email-folding-example-10.txt.expected b/spec/fixtures/files/email-folding-example-10.txt.expected new file mode 100644 index 000000000..e4f704c0e --- /dev/null +++ b/spec/fixtures/files/email-folding-example-10.txt.expected @@ -0,0 +1,25 @@ +Please note: it is not possible to reply to this email. To contact the +Department of Health, please visit the 'Contact us' page on the +Department’s website. + +----------------------------------------------------------------------------------------- + + Apologies that you were not able to read our previous response of 4 + October. Please find the text of that email below. + +Our ref: DE00000642471 + +Dear Ms Peters Rock, + +You requested your correspondence to be treated under the Freedom of +Information Act. However, as your correspondence asked for general +information, rather than requesting recorded information or documentation, +I should advise you that on this occasion we have not considered your +correspondence under the provisions of the Act. + +I am sorry I cannot be more helpful. + +Yours sincerely, +Simon Dove +Customer Service Centre +Department of Health diff --git a/spec/fixtures/files/email-folding-example-2.txt b/spec/fixtures/files/email-folding-example-2.txt new file mode 100644 index 000000000..13dd39a69 --- /dev/null +++ b/spec/fixtures/files/email-folding-example-2.txt @@ -0,0 +1,7 @@ +Preface to the message which we are not interested in + +----------------------------------------------------------------------------------------- +Important message about cheese +----------------------------------------------------------------------------------------- + +Actual footer that contains the word confidential diff --git a/spec/fixtures/files/email-folding-example-2.txt.expected b/spec/fixtures/files/email-folding-example-2.txt.expected new file mode 100644 index 000000000..e52fbe443 --- /dev/null +++ b/spec/fixtures/files/email-folding-example-2.txt.expected @@ -0,0 +1,4 @@ +Preface to the message which we are not interested in + +----------------------------------------------------------------------------------------- +Important message about cheese diff --git a/spec/fixtures/files/email-folding-example-3.txt b/spec/fixtures/files/email-folding-example-3.txt new file mode 100644 index 000000000..28a3861f6 --- /dev/null +++ b/spec/fixtures/files/email-folding-example-3.txt @@ -0,0 +1,18 @@ +Reference : T3241/8 + +Thank you for your e-mail enquiry of 12th February. + +A reply is attached. + +********************************************************************** +This email and any files transmitted with it are private and intended +solely for the use of the individual or entity to whom they are addressed. +If you have received this email in error please return it to the address +it came from telling them it is not for you and then delete it from your system. + +This email message has been swept for computer viruses. + +********************************************************************** + +The original of this email was scanned for viruses by the Government Secure Intranet virus scanning service supplied by Cable&Wireless in partnership with MessageLabs. (CCTM Certificate Number 2007/11/0032.) On leaving the GSi this email was certified virus free. +Communications via the GSi may be automatically logged, monitored and/or recorded for legal purposes. diff --git a/spec/fixtures/files/email-folding-example-3.txt.expected b/spec/fixtures/files/email-folding-example-3.txt.expected new file mode 100644 index 000000000..e2cca4933 --- /dev/null +++ b/spec/fixtures/files/email-folding-example-3.txt.expected @@ -0,0 +1,5 @@ +Reference : T3241/8 + +Thank you for your e-mail enquiry of 12th February. + +A reply is attached. diff --git a/spec/fixtures/files/email-folding-example-4.txt b/spec/fixtures/files/email-folding-example-4.txt new file mode 100644 index 000000000..63b94a35c --- /dev/null +++ b/spec/fixtures/files/email-folding-example-4.txt @@ -0,0 +1,37 @@ +<<Freedom of Information request - Contracts or options with Kimberley +Developments or Waitrose>> + +Arthur Pritchard +Property & Assets Manager +Tel: 01625 504234 +Fax: 01625 504268 +e-mail: [1][email address] + +*********************************************************************************** +The information in this Email and any attachments is personal to the +sender and the views of the author may not necessarily reflect those +of Macclesfield Borough Council. The information is strictly confidential +and is intended only for the named person or organisation to whom it is +addressed as it may contain privileged and confidential information. If +you are not the intended recipient do not copy, distribute or use this +Email, and please notify the sender. Please note that we cannot +guarantee that this message or any attachment is virus free or has not +been intercepted and amended. +*********************************************************************************** + +Disclaimer + +-------------------------------------------------------------------------- + +This email message has been scanned for viruses by Mimecast. +Mimecast delivers a complete managed email solution from a single web +based platform. +For more information please visit [2]http://www.mimecast.com + +-------------------------------------------------------------------------- + +References + +Visible links +1. mailto:[email address] +2. http://www.mimecast.com/ diff --git a/spec/fixtures/files/email-folding-example-4.txt.expected b/spec/fixtures/files/email-folding-example-4.txt.expected new file mode 100644 index 000000000..42334a290 --- /dev/null +++ b/spec/fixtures/files/email-folding-example-4.txt.expected @@ -0,0 +1,15 @@ +<<Freedom of Information request - Contracts or options with Kimberley +Developments or Waitrose>> + +Arthur Pritchard +Property & Assets Manager +Tel: 01625 504234 +Fax: 01625 504268 +e-mail: [1][email address] +FOLDED_QUOTED_SECTION +FOLDED_QUOTED_SECTION +References + +Visible links +1. mailto:[email address] +2. http://www.mimecast.com/ diff --git a/spec/fixtures/files/email-folding-example-5.txt b/spec/fixtures/files/email-folding-example-5.txt new file mode 100644 index 000000000..3d0964722 --- /dev/null +++ b/spec/fixtures/files/email-folding-example-5.txt @@ -0,0 +1,35 @@ +Hi Simon + +My apologies for timescale of response. The data forwarded is a public +register, and is updated on a frequent and regular basis; your request +unfortunately coincided with annual leave and a monthly update of the +spreadsheet. As the definition of an HMO under the Housing Act 2004 +differs to that under planning legislation, I have forwarded this and +your original request on to Andy England, Development Control Manager to +respond independantly. + +If I can be of further assistance please contact me + +Barry Turnbull +Environmental Health Co-ordinator (Housing) +Housing, Health and Community Safety + +-- + +**************************************************************** +Any opinions expressed are not necessarily those of Penwith +District Council. This e-mail and any attachments, replies +and forwarded copies are confidential and are strictly for +the use of named recipient(s) only. If you have received +it in error you may not make use of it. Please e-mail us, +including a copy of the message to, [email address]. +Then delete the e-mail and any copies. +**************************************************************** + +********************************************************************** +This footnote confirms that this message, and any +attachments, have been screened by McAffee +Webshield for the presence of virus code. + +Penwith District Council +********************************************************************** diff --git a/spec/fixtures/files/email-folding-example-5.txt.expected b/spec/fixtures/files/email-folding-example-5.txt.expected new file mode 100644 index 000000000..fbb0f0f50 --- /dev/null +++ b/spec/fixtures/files/email-folding-example-5.txt.expected @@ -0,0 +1,24 @@ +Hi Simon + +My apologies for timescale of response. The data forwarded is a public +register, and is updated on a frequent and regular basis; your request +unfortunately coincided with annual leave and a monthly update of the +spreadsheet. As the definition of an HMO under the Housing Act 2004 +differs to that under planning legislation, I have forwarded this and +your original request on to Andy England, Development Control Manager to +respond independantly. + +If I can be of further assistance please contact me + +Barry Turnbull +Environmental Health Co-ordinator (Housing) +Housing, Health and Community Safety + +-- +FOLDED_QUOTED_SECTION +This footnote confirms that this message, and any +attachments, have been screened by McAffee +Webshield for the presence of virus code. + +Penwith District Council +********************************************************************** diff --git a/spec/fixtures/files/email-folding-example-6.txt b/spec/fixtures/files/email-folding-example-6.txt new file mode 100644 index 000000000..272d6c9da --- /dev/null +++ b/spec/fixtures/files/email-folding-example-6.txt @@ -0,0 +1,30 @@ +Dear Mr. Brown, + +Please find attached a reply to your FOI request. + +Yours ever, + +Adetokunbo Ighodaro + +<<FOI 0169-08 final.doc>> + +*********************************************************************************** +Visit [1]http://www.fco.gov.uk for British foreign policy news and travel +advice; and [2]http://www.i-uk.com - the essential guide to the UK. + +We keep and use information in line with the Data Protection Act 1998. We +may release this personal information to other UK government departments +and public authorities. + +Please note that all messages sent and received by members of the Foreign +& Commonwealth Office and its +missions overseas may be monitored centrally. This is done to ensure the +integrity of the system. + +*********************************************************************************** + +References + +Visible links +1. http://www.fco.gov.uk/ +2. http://www.i-uk.com/ diff --git a/spec/fixtures/files/email-folding-example-6.txt.expected b/spec/fixtures/files/email-folding-example-6.txt.expected new file mode 100644 index 000000000..58021ce12 --- /dev/null +++ b/spec/fixtures/files/email-folding-example-6.txt.expected @@ -0,0 +1,15 @@ +Dear Mr. Brown, + +Please find attached a reply to your FOI request. + +Yours ever, + +Adetokunbo Ighodaro + +<<FOI 0169-08 final.doc>> +FOLDED_QUOTED_SECTION +References + +Visible links +1. http://www.fco.gov.uk/ +2. http://www.i-uk.com/
\ No newline at end of file diff --git a/spec/fixtures/files/email-folding-example-7.txt b/spec/fixtures/files/email-folding-example-7.txt new file mode 100644 index 000000000..e10fe4657 --- /dev/null +++ b/spec/fixtures/files/email-folding-example-7.txt @@ -0,0 +1,30 @@ +Mr Hearne, +Please see attached our response to your request dated 06 March 2008. +Kind Regards, +Linda Dempsey + +Information Assistant DP/FOI +Data Protection/Information Security +Professional Standards +Leicestershire Constabulary +http://www.leics.police.uk +mailto [Leicestershire Constabulary request email] +Telephone +44 (0) 116 2222222 +Extn 5221 VM No. 8035 +Fax + 44 (0) 116 2485217 + +<<0001_00035908_Resp_12RESPONSE LETTER_20080408_112311_01.TIF>> + +********** + +Internet email is not to be treated as a secure means of communication. + +Leicestershire Constabulary monitors all internet email activity and content. + +This communication is intended for the addressee(s) only. Please notify the sender if received in error. Unauthorised use or disclosure of the content may be unlawful. Opinions expressed in this document may not be official policy. + +Thank you for your co-operation. + +© Leicestershire Constabulary + +********** diff --git a/spec/fixtures/files/email-folding-example-7.txt.expected b/spec/fixtures/files/email-folding-example-7.txt.expected new file mode 100644 index 000000000..0ef8fd82b --- /dev/null +++ b/spec/fixtures/files/email-folding-example-7.txt.expected @@ -0,0 +1,16 @@ +Mr Hearne, +Please see attached our response to your request dated 06 March 2008. +Kind Regards, +Linda Dempsey + +Information Assistant DP/FOI +Data Protection/Information Security +Professional Standards +Leicestershire Constabulary +http://www.leics.police.uk +mailto [Leicestershire Constabulary request email] +Telephone +44 (0) 116 2222222 +Extn 5221 VM No. 8035 +Fax + 44 (0) 116 2485217 + +<<0001_00035908_Resp_12RESPONSE LETTER_20080408_112311_01.TIF>>
\ No newline at end of file diff --git a/spec/fixtures/files/email-folding-example-8.txt b/spec/fixtures/files/email-folding-example-8.txt new file mode 100644 index 000000000..c1899e7c8 --- /dev/null +++ b/spec/fixtures/files/email-folding-example-8.txt @@ -0,0 +1,18 @@ +I will be out of the office starting 11/04/2008 and will not return until +22/04/2008. + +I will respond to your message when I return. If you have any urgent +queries please ring 02085419088 for Legal Business Support queries or +contact Eileen Perren for FOI or DP queries + +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +This email and any attachments with it are intended for the addressee only. +It may be confidential and may be the subject of legal and/or professional privilege. +If you have received this email in error please notify the sender or [email address] +The content may be personal or contain personal opinions and cannot be taken as an expression of the County Council's position. +Surrey County Council reserves the right to monitor all incoming and outgoing mail. +Whilst every care has been taken to check this outgoing e-mail for viruses, it is your responsibility to carry out any checks upon receipt. + +Visit the Surrey County Council website - http://www.surreycc.gov.uk + +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * diff --git a/spec/fixtures/files/email-folding-example-8.txt.expected b/spec/fixtures/files/email-folding-example-8.txt.expected new file mode 100644 index 000000000..b5dc10c0d --- /dev/null +++ b/spec/fixtures/files/email-folding-example-8.txt.expected @@ -0,0 +1,6 @@ +I will be out of the office starting 11/04/2008 and will not return until +22/04/2008. + +I will respond to your message when I return. If you have any urgent +queries please ring 02085419088 for Legal Business Support queries or +contact Eileen Perren for FOI or DP queries
\ No newline at end of file diff --git a/spec/fixtures/files/email-folding-example-9.txt b/spec/fixtures/files/email-folding-example-9.txt new file mode 100644 index 000000000..1f3d4c34a --- /dev/null +++ b/spec/fixtures/files/email-folding-example-9.txt @@ -0,0 +1,29 @@ +Dear Mr Cross + +Freedom of Information Request Reference No: 2008040590 + +Yours sincerely + +MICHAEL HEGARTY + +FOI Officer + +********************************************************************************************** +Please Note: Incoming and Outgoing E-mail messages are routinely monitored +for compliance with our policy on the use of electronic communications. + +Interested in Occupational Health & Safety information? +Please visit the HSE website at the following address to keep yourself up +to date + +www.hse.gov.uk + +Or contact HSE Infoline on 0845 345 0055 or email [HSE request email] + +********************************************************************************************** +The original of this email was scanned for viruses by the Government +Secure Intranet virus scanning service supplied by Cable&Wireless in +partnership with MessageLabs. (CCTM Certificate Number 2007/11/0032.) On +leaving the GSi this email was certified virus free. +Communications via the GSi may be automatically logged, monitored and/or +recorded for legal purposes. diff --git a/spec/fixtures/files/email-folding-example-9.txt.expected b/spec/fixtures/files/email-folding-example-9.txt.expected new file mode 100644 index 000000000..2d2381a34 --- /dev/null +++ b/spec/fixtures/files/email-folding-example-9.txt.expected @@ -0,0 +1,9 @@ +Dear Mr Cross + +Freedom of Information Request Reference No: 2008040590 + +Yours sincerely + +MICHAEL HEGARTY + +FOI Officer diff --git a/spec/fixtures/files/empty-return-path.email b/spec/fixtures/files/empty-return-path.email new file mode 100644 index 000000000..b01e96de8 --- /dev/null +++ b/spec/fixtures/files/empty-return-path.email @@ -0,0 +1,21 @@ +From: EMAIL_FROM +To: FOI Person <EMAIL_TO> +Return-path: <> +Delivery-date: Fri, 01 Aug 2008 14:35:58 +0100 +X-Failed-Recipients: enquiries@cheese.com +From: Mail Delivery System <Mailer-Daemon@sandwich.com> +Subject: Mail delivery failed: returning message to sender +Message-Id: <E1KOunW-000dXv-C6@sandwich.com> +Date: Fri, 01 Aug 2008 14:35:58 +0100 + +This message was created automatically by mail delivery software. + +A message that you sent could not be delivered to one or more of its +recipients. This is a permanent error. The following address(es) failed: + + enquiries@cheese.com + Unrouteable address + +------ This is a copy of the message, including all the headers. ------ + +Hello
\ No newline at end of file diff --git a/spec/fixtures/files/fake-authority-add-tags.rb b/spec/fixtures/files/fake-authority-add-tags.rb new file mode 100644 index 000000000..a5612d87f --- /dev/null +++ b/spec/fixtures/files/fake-authority-add-tags.rb @@ -0,0 +1,4 @@ +#id,request_email,name,tag_string +,north_west_foi@localhost,North West Fake Authority,aTag +,scottish_foi@localhost,Scottish Fake Authority,aTag +,ni_foi@localhost,Fake Authority of Northern Ireland,fake aTag diff --git a/spec/fixtures/files/fake-authority-type-with-field-names.csv b/spec/fixtures/files/fake-authority-type-with-field-names.csv index 93ce00a25..a4247dced 100644 --- a/spec/fixtures/files/fake-authority-type-with-field-names.csv +++ b/spec/fixtures/files/fake-authority-type-with-field-names.csv @@ -1,4 +1,4 @@ -#id,email,name,name.es -,north_west_foi@localhost,North West Fake Authority,Autoridad del Nordeste -,scottish_foi@localhost,Scottish Fake Authority,Autoridad Escocesa -,ni_foi@localhost,Fake Authority of Northern Ireland,Autoridad Irlandesa +#id,request_email,name,name.es,tag_string,home_page +,north_west_foi@localhost,North West Fake Authority,Autoridad del Nordeste,,http://northwest.org +,scottish_foi@localhost,Scottish Fake Authority,Autoridad Escocesa,scottish,http://scottish.org +,ni_foi@localhost,Fake Authority of Northern Ireland,Autoridad Irlandesa,fake aTag diff --git a/spec/fixtures/files/iso8859_2_email.html b/spec/fixtures/files/iso8859_2_email.html new file mode 100644 index 000000000..c7384a831 --- /dev/null +++ b/spec/fixtures/files/iso8859_2_email.html @@ -0,0 +1,18 @@ +<html> +<head> +<style><!-- +.hmmessage P +{ +margin:0px; +padding:0px +} +body.hmmessage +{ +font-size: 10pt; +font-family:Tahoma +} +--></style> +</head> +<body class='hmmessage'><div dir='ltr'> +<div>Faleminderit per kerkesen tënde.</div> </div></body> +</html> diff --git a/spec/fixtures/files/iso8859_2_raw_email.email b/spec/fixtures/files/iso8859_2_raw_email.email new file mode 100644 index 000000000..2ac3b2533 --- /dev/null +++ b/spec/fixtures/files/iso8859_2_raw_email.email @@ -0,0 +1,50 @@ +From: EMAIL_FROM +To: FOI Person <EMAIL_TO> +Bcc: +Reply-To: +In-Reply-To: <471f1eae5d1cb_7347..fdbe67386163@cat.tmail> +Content-Type: multipart/alternative; + boundary="_d47fc84f-c9cd-4fb3-ab16-15de158c8eef_" +Subject: =?iso-8859-2?Q?RE:_Freedo?= =?iso-8859-2?Q?m_of_Infor?= + =?iso-8859-2?Q?mation_req?= =?iso-8859-2?Q?uest_-_Sas?= + =?iso-8859-2?Q?ia_e_pulav?= =?iso-8859-2?Q?e_t=EB_impor?= + =?iso-8859-2?Q?tuara_gjat?= =?iso-8859-2?Q?=EB_vitit_20?= =?iso-8859-2?Q?10?= +Date: Fri, 30 Sep 2011 11:06:39 +0200 + +--_d47fc84f-c9cd-4fb3-ab16-15de158c8eef_ +Content-Type: text/plain; charset="iso-8859-2" +Content-Transfer-Encoding: quoted-printable + + +I nderuari Besnik=2C=20 +Faleminderit per kerkesen t=EBnde.Numri i puleve te importuara ne vitin 201= +0 ka qene 5 milion e treqind mije sosh (me numra 3=2C500=2C000) + + +--_d47fc84f-c9cd-4fb3-ab16-15de158c8eef_ +Content-Type: text/html; charset="iso-8859-2" +Content-Transfer-Encoding: quoted-printable + +<html> +<head> +<style><!-- +.hmmessage P +{ +margin:0px=3B +padding:0px +} +body.hmmessage +{ +font-size: 10pt=3B +font-family:Tahoma +} +--></style> +</head> +<body class=3D'hmmessage'><div dir=3D'ltr'> +<div>I nderuari Besnik=2C =3B</div><div><br></div><div>Faleminderit per= + kerkesen t=EBnde.</div>Numri i puleve te importuara ne vitin 2010 ka qene = +5 milion e treqind mije sosh (me numra 3=2C500=2C000)<br><br></body> +</html>= + +--_d47fc84f-c9cd-4fb3-ab16-15de158c8eef_-- + diff --git a/spec/fixtures/files/track-response-exchange-oof-1.email b/spec/fixtures/files/track-response-exchange-oof-1.email new file mode 100644 index 000000000..6bb696119 --- /dev/null +++ b/spec/fixtures/files/track-response-exchange-oof-1.email @@ -0,0 +1,102 @@ +Delivered-To: mysociety.robin@gmail.com +Received: by 10.216.187.197 with SMTP id y47cs73028wem; + Tue, 6 Sep 2011 00:02:08 -0700 (PDT) +Received: by 10.216.229.167 with SMTP id h39mr1763951weq.57.1315292527401; + Tue, 06 Sep 2011 00:02:07 -0700 (PDT) +Return-Path: <Firstname.Surname@example.com> +Received: from wildfire.ukcod.org.uk (wildfire.ukcod.org.uk [89.238.145.74]) + by mx.google.com with ESMTPS id i56si7850683wed.12.2011.09.06.00.02.05 + (version=TLSv1/SSLv3 cipher=OTHER); + Tue, 06 Sep 2011 00:02:06 -0700 (PDT) +Received-SPF: neutral (google.com: 89.238.145.74 is neither permitted nor denied by domain of Firstname.Surname@example.com) client-ip=89.238.145.74; +Authentication-Results: mx.google.com; spf=neutral (google.com: 89.238.145.74 is neither permitted nor denied by domain of Firstname.Surname@example.com) smtp.mail=Firstname.Surname@example.com +Received: from gweuoutb1.linde.com ([94.100.245.173]:15826) + by wildfire.ukcod.org.uk with esmtp (Exim 4.69) + (envelope-from <Firstname.Surname@example.com>) + id 1R0pfT-00074Q-Bb + for team@whatdotheyknow.com; Tue, 06 Sep 2011 08:01:59 +0100 +X-IronPort-AV: E=Sophos;i="4.68,337,1312149600"; + d="scan'208,217";a="16336258" +X-Header: No Trailer +Received: from unknown (HELO mlgmuc00mail099.boc.com) ([10.138.224.206]) + by gweub1.linde.grp with ESMTP; 06 Sep 2011 09:01:48 +0200 +Received: from mlgmuc00mail096.boc.com ([10.138.224.203]) by mlgmuc00mail099.boc.com with Microsoft SMTPSVC(6.0.3790.4675); + Tue, 6 Sep 2011 09:02:24 +0200 +Received: from VSUK4EX01.eu.boc.com ([172.18.77.27]) by mlgmuc00mail096.boc.com with Microsoft SMTPSVC(6.0.3790.4675); + Tue, 6 Sep 2011 09:01:32 +0200 +Content-class: urn:content-classes:message +MIME-Version: 1.0 +Content-Type: multipart/alternative; + boundary="----_=_NextPart_001_01CC6C62.CEC3EF3C" +Subject: Out of Office AutoReply: Was the response you got to your FOI request any good? +X-MimeOLE: Produced By Microsoft Exchange V6.5 +Date: Tue, 6 Sep 2011 08:01:31 +0100 +Message-ID: <E75A6D7A72D76346A4BF6A27672C39AB11BFF525@VSUK4EX01.eu.boc.com> +X-MS-Has-Attach: +X-MS-TNEF-Correlator: +Thread-Topic: Was the response you got to your FOI request any good? +Thread-Index: AcxsYs6PUz9cAAJDScO38LEWgNj/CQAAAA2I +From: "Surname,Firstname" <Firstname.Surname@example.com> +To: "WhatDoTheyKnow" <team@whatdotheyknow.com> +X-OriginalArrivalTime: 06 Sep 2011 07:01:32.0883 (UTC) FILETIME=[CF626A30:01CC6C62] +List-Id: Admin Team for What Do They Know <team@whatdotheyknow.com> + +This is a multi-part message in MIME format. + +------_=_NextPart_001_01CC6C62.CEC3EF3C +Content-Type: text/plain; charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable + +I am out of the office and have limited access to my emails until Thursday = +nth Bartember. If you have an urgent query the please telephone me on 1234= +5678. + + +The information contained in this email and any attachments may be confiden= +tial and is provided solely for the use of the intended recipient(s). If yo= +u are not the intended recipient, you are hereby notified that any disclosu= +re, distribution, or use of this e-mail, its attachments or any information= + contained therein is unauthorized and prohibited. If you have received thi= +s in error, please contact the sender immediately and delete this e-mail an= +d any attachments. + +No responsibility is accepted for any virus or defect that might arise from= + opening this e-mail or attachments, whether or not it has been checked by = +anti-virus software. + +------_=_NextPart_001_01CC6C62.CEC3EF3C +Content-Type: text/html; charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable + +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> +<HTML> +<HEAD> +<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; charset=3Diso-8859-= +1"> +<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version 6.5.7654.12"> +<TITLE>Out of Office AutoReply: Was the response you got to your FOI reques= +t any good?</TITLE> +</HEAD> +<BODY> +<!-- Converted from text/plain format --> + +<P><FONT SIZE=3D2>I am out of the office and have limited access to my emai= +ls until Thursday 8th September. If you have an urgent query the plea= +se telephone me on 12345678.</FONT></P> + +<font face=3D"monospace"><br> +<br> +The information contained in this email and any attachments may be confiden= +tial and is provided solely for the use of the intended recipient(s). If yo= +u are not the intended recipient, you are hereby notified that any disclosu= +re, distribution, or use of this e-mail, its attachments or any information= + contained therein is unauthorized and prohibited. If you have received thi= +s in error, please contact the sender immediately and delete this e-mail an= +d any attachments.<br> +<br> +No responsibility is accepted for any virus or defect that might arise from= + opening this e-mail or attachments, whether or not it has been checked by = +anti-virus software.</font></BODY> +</HTML> +------_=_NextPart_001_01CC6C62.CEC3EF3C-- + diff --git a/spec/fixtures/files/track-response-exim-bounce.email b/spec/fixtures/files/track-response-exim-bounce.email new file mode 100644 index 000000000..8d40380b1 --- /dev/null +++ b/spec/fixtures/files/track-response-exim-bounce.email @@ -0,0 +1,67 @@ +Delivered-To: mysociety.robin@gmail.com +Received: by 10.216.187.197 with SMTP id y47cs98510wem; + Tue, 6 Sep 2011 14:22:44 -0700 (PDT) +Received: by 10.216.203.79 with SMTP id e57mr78207weo.42.1315344164092; + Tue, 06 Sep 2011 14:22:44 -0700 (PDT) +Return-Path: <> +Received: from wildfire.ukcod.org.uk (wildfire.ukcod.org.uk [89.238.145.74]) + by mx.google.com with ESMTPS id n64si9483505weq.102.2011.09.06.14.22.42 + (version=TLSv1/SSLv3 cipher=OTHER); + Tue, 06 Sep 2011 14:22:43 -0700 (PDT) +Received-SPF: pass (google.com: best guess record for domain of wildfire.ukcod.org.uk designates 89.238.145.74 as permitted sender) client-ip=89.238.145.74; +Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of wildfire.ukcod.org.uk designates 89.238.145.74 as permitted sender) smtp.mail= +Received: from Debian-exim by wildfire.ukcod.org.uk with local (Exim 4.69) + id 1R136L-0003xr-1Q + for team@whatdotheyknow.com; Tue, 06 Sep 2011 22:22:37 +0100 +X-Failed-Recipients: user@example.com +Auto-Submitted: auto-replied +From: Mail Delivery System <Mailer-Daemon@wildfire.ukcod.org.uk> +To: team@whatdotheyknow.com +Subject: Mail delivery failed: returning message to sender +Message-Id: <E1R136L-0003xr-1Q@wildfire.ukcod.org.uk> +Date: Tue, 06 Sep 2011 22:22:37 +0100 +List-Id: Admin Team for What Do They Know <team@whatdotheyknow.com> + +This message was created automatically by mail delivery software. + +A message that you sent could not be delivered to one or more of its +recipients. This is a permanent error. The following address(es) failed: + + user@example.com + Unrouteable address + +------ This is a copy of the message, including all the headers. ------ + +Return-path: <team@whatdotheyknow.com> +Received: from foi by wildfire.ukcod.org.uk with local (Exim 4.69) + (envelope-from <team@whatdotheyknow.com>) + id 1R136J-0003xp-Td + for user@example.com; Tue, 06 Sep 2011 22:22:36 +0100 +Date: Tue, 6 Sep 2011 22:22:35 +0100 +From: WhatDoTheyKnow <team@whatdotheyknow.com> +To: Nonexistent User <user@example.com> +Subject: Your WhatDoTheyKnow email alert +Mime-Version: 1.0 +Content-Type: text/plain; charset=utf-8 +Precedence: bulk +Auto-Submitted: auto-generated +Message-Id: <E1R136J-0003xp-Td@wildfire.ukcod.org.uk> + +FOI requests to 'Maritime and Coastguard Agency' +================================================ + +-- MCA & HM Coastguard Official Vehicles -- +Maritime and Coastguard Agency sent a response to Peter Smith (12 August 2011) + "Peter In response (reference F0000881) to your FOI questions the + MCA answer is:- 1. All MCA vehicles are purchased outright. 2. Yes + there is a volu..." +http://www.whatdotheyknow.com/request/mca_hm_coastguard_official_vehic#incoming-201529 + + +Alter your subscription +======================= + +Please click on the link below to cancel or alter these emails. +http://www.whatdotheyknow.com/c/ie4pkpy70dl4b8flsig + +-- the WhatDoTheyKnow team diff --git a/spec/fixtures/files/track-response-generic-oof.email b/spec/fixtures/files/track-response-generic-oof.email new file mode 100644 index 000000000..bf1e3e8fe --- /dev/null +++ b/spec/fixtures/files/track-response-generic-oof.email @@ -0,0 +1,8 @@ +From: Someone <someone@example.com> +Subject: Out of Office: Notification blah blah blah +To: track@whatdotheyknow.com +Return-Path: <> +Content-Type: text/plain; charset=utf-8 + +I am out of the office till the 12th of February, hunting lions in Africa. + diff --git a/spec/fixtures/files/track-response-lotus-oof-1.email b/spec/fixtures/files/track-response-lotus-oof-1.email new file mode 100644 index 000000000..dbe63714d --- /dev/null +++ b/spec/fixtures/files/track-response-lotus-oof-1.email @@ -0,0 +1,58 @@ +Delivered-To: mysociety.robin@gmail.com +Received: by 10.216.187.197 with SMTP id y47cs137414wem; + Wed, 7 Sep 2011 14:02:45 -0700 (PDT) +Received: by 10.227.179.14 with SMTP id bo14mr1666492wbb.90.1315429363348; + Wed, 07 Sep 2011 14:02:43 -0700 (PDT) +Return-Path: <Arnos.Grove@example.net> +Received: from wildfire.ukcod.org.uk (wildfire.ukcod.org.uk [89.238.145.74]) + by mx.google.com with ESMTPS id 2si1547851wbx.79.2011.09.07.14.02.41 + (version=TLSv1/SSLv3 cipher=OTHER); + Wed, 07 Sep 2011 14:02:42 -0700 (PDT) +Received-SPF: neutral (google.com: 89.238.145.74 is neither permitted nor denied by best guess record for domain of Arnos.Grove@example.net) client-ip=89.238.145.74; +Authentication-Results: mx.google.com; spf=neutral (google.com: 89.238.145.74 is neither permitted nor denied by best guess record for domain of Arnos.Grove@example.net) smtp.mail=Arnos.Grove@example.net +Received: from foi by wildfire.ukcod.org.uk with local (Exim 4.69) + (envelope-from <Arnos.Grove@example.net>) + id 1R1PGV-0008Gu-GX + for team@whatdotheyknow.com; Wed, 07 Sep 2011 22:02:35 +0100 +Received: from eu1sys200aog108.obsmtp.com ([207.126.144.125]:54514) + by wildfire.ukcod.org.uk with smtp (Exim 4.69) + (envelope-from <Arnos.Grove@example.net>) + id 1R1PGS-0008Go-Ih + for track@whatdotheyknow.com; Wed, 07 Sep 2011 22:02:32 +0100 +Received: from DomG5P.tm-gnet.com ([80.195.120.125]) by eu1sys200aob108.postini.com ([207.126.147.11]) with SMTP + ID DSNKTmfb6CEGJQfujkX1ZzzGzMsn6uoI+AGs@postini.com; Wed, 07 Sep 2011 21:02:32 UTC +Received: from dc3-email-02.tm-gnet.com ([10.145.42.2]) + by DomG5P.tm-gnet.com (Lotus Domino Release 7.0.3) + with ESMTP id 2011090722024075-323511 ; + Wed, 7 Sep 2011 22:02:40 +0100 +Subject: Emma McKinney/MAIL/BIR/MG_REG is out of the office +Auto-Submitted: auto-generated +From: Arnos.Grove@example.net +To: track@whatdotheyknow.com +Message-ID: <OF82EB79DF.C2563724-ON80257904.00739633-80257904.00739633@TrinityMirror.com> +Date: Wed, 7 Sep 2011 22:02:30 +0100 +MIME-Version: 1.0 +X-MIMETrack: Serialize by Router on DC3-Email-02/GMH(Release 8.5.1FP4|July 25, 2010) at + 07/09/2011 22:02:31, + Itemize by SMTP Server on DomG5P/GMH(Release 7.0.3|September 26, 2007) at + 09/07/2011 22:02:40, + Serialize by Router on DomG5P/GMH(Release 7.0.3|September 26, 2007) at 09/07/2011 + 22:02:41, + Serialize complete at 09/07/2011 22:02:41 +Content-type: text/plain; charset=US-ASCII +List-Id: Admin Team for What Do They Know <team@whatdotheyknow.com> + + +I will be out of the office starting dd/mm/yyyy and will not return until +dd/mm/yyyy. + +If you need to contact anyone urgently while I'm out of the office call +aaaa bbb cccc or aaaa bbb dddd. + +******************** +IMPORTANT NOTICE This email (including any attachments) is meant only for the intended recipient. It may also contain confidential and privileged information. If you are not the intended recipient, any reliance on, use, disclosure, distribution or copying of this email or attachments is strictly prohibited. Please notify the sender immediately by email if you have received this message by mistake and delete the email and all attachments. + +Any views or opinions in this email are solely those of the author and do not necessarily represent those of Brickbat Industries PLC or its associated group companies (hereinafter referred to as "BI Group"). BI Group accept no liability for the content of this email, or for the consequences of any actions taken on the basis of the information provided, unless that information is subsequently confirmed in writing. Although every reasonable effort is made to keep its network free from viruses, BI Group accept no liability for any virus transmitted by this email or any attachments and the recipient should use up-to-date virus checking software. Email to or from this address may be subject to interception or monitoring for operational reasons or for lawful business practices. + +Brickbat PLC is the parent company of the Brickbat group of companies and is registered in England No 99999, with its address at Nine Made-up Lane, Arnos Grove. +******************** diff --git a/spec/fixtures/files/track-response-messageclass-oof.email b/spec/fixtures/files/track-response-messageclass-oof.email new file mode 100644 index 000000000..ce82b6df0 --- /dev/null +++ b/spec/fixtures/files/track-response-messageclass-oof.email @@ -0,0 +1,63 @@ +Delivered-To: mysociety.robin@gmail.com +Received: by 10.216.187.197 with SMTP id y47cs177522wem; + Thu, 8 Sep 2011 14:01:27 -0700 (PDT) +Received: by 10.216.220.168 with SMTP id o40mr1165141wep.75.1315515686762; + Thu, 08 Sep 2011 14:01:26 -0700 (PDT) +Return-Path: <MAILER-DAEMON@wildfire.ukcod.org.uk> +Received: from wildfire.ukcod.org.uk (wildfire.ukcod.org.uk [89.238.145.74]) + by mx.google.com with ESMTPS id k18si4719546wed.16.2011.09.08.14.01.25 + (version=TLSv1/SSLv3 cipher=OTHER); + Thu, 08 Sep 2011 14:01:25 -0700 (PDT) +Received-SPF: pass (google.com: best guess record for domain of MAILER-DAEMON@wildfire.ukcod.org.uk designates 89.238.145.74 as permitted sender) client-ip=89.238.145.74; +Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of MAILER-DAEMON@wildfire.ukcod.org.uk designates 89.238.145.74 as permitted sender) smtp.mail=MAILER-DAEMON@wildfire.ukcod.org.uk +Received: from foi by wildfire.ukcod.org.uk with local (Exim 4.69) + (envelope-from <MAILER-DAEMON@wildfire.ukcod.org.uk>) + id 1R1lio-0004zB-Fv + for team_delivery@whatdotheyknow.com; Thu, 08 Sep 2011 22:01:18 +0100 +Received: from mailproxy2.newsquest.co.uk ([93.174.8.201]:2528) + by wildfire.ukcod.org.uk with esmtp (Exim 4.69) + id 1R1lin-0004z2-Lk + for track@whatdotheyknow.com; Thu, 08 Sep 2011 22:01:17 +0100 +X-IronPort-AV: E=Sophos;i="4.68,352,1312153200"; + d="scan'208";a="450582625" +Content-Type: multipart/mixed; boundary="===============1667734580==" +MIME-Version: 1.0 +Received: from sx-mailtraq.se.ad.newsquest.co.uk (sx-mailtraq.se.ad.newsquest.co.uk [10.50.6.12]) + by nqsussex.co.uk with ESMTP (Mailtraq/2.12.0.2278) id NQSSF0865193 + for track@whatdotheyknow.com; Thu, 08 Sep 2011 22:01:04 +0100 +From: "bjarne.stroustrup" <bjarne.stroustrup@example.co.uk> +To: track@whatdotheyknow.com +Date: Thu, 08 Sep 2011 22:01:01 +0100 +Message-ID: <THRGF086ADB9@example.co.uk> +Subject: Automatic Response +X-Hops: 1 +X-POST-MessageClass: 9; Autoresponder + +--===============1667734580== +MIME-Version: 1.0 +Content-Type: text/plain; charset="" + +I am out of the office until Tuesday, January 20. If your email is +urgent please resend it to news@example.co.uk. +Thanks very much +Boris + +--===============1667734580== +Content-Type: text/plain; charset="utf-8" +MIME-Version: 1.0 +Content-Transfer-Encoding: quoted-printable +Content-Disposition: inline + +This email has been scanned for viruses and other threats using Newsquest's= + Ironport email filters. + +This document is private and confidential. +All property, copyright and other rights in it and its contents belong to +ewsquest Media Group Limited. +It must not be read, copied, disclosed or otherwise used without Newsquest= +=E2=80=99s authorisation. Newsquest may exercise its legal rights and remed= +ies in the event of any such unauthorised use. + + +--===============1667734580==-- + diff --git a/spec/fixtures/files/track-response-messagelabs-oof-1.email b/spec/fixtures/files/track-response-messagelabs-oof-1.email new file mode 100644 index 000000000..7cd5d6b8d --- /dev/null +++ b/spec/fixtures/files/track-response-messagelabs-oof-1.email @@ -0,0 +1,62 @@ +Delivered-To: mysociety.robin@gmail.com +Received: by 10.216.187.197 with SMTP id y47cs96363wem; + Tue, 6 Sep 2011 13:24:49 -0700 (PDT) +Received: by 10.216.229.200 with SMTP id h50mr234738weq.32.1315340689299; + Tue, 06 Sep 2011 13:24:49 -0700 (PDT) +Return-Path: <rick.rollington@parliament.uk> +Received: from majestic.ukcod.org.uk (majestic.ukcod.org.uk [89.238.145.68]) + by mx.google.com with ESMTPS id j13si9391756wed.109.2011.09.06.13.24.48 + (version=TLSv1/SSLv3 cipher=OTHER); + Tue, 06 Sep 2011 13:24:49 -0700 (PDT) +Received-SPF: pass (google.com: domain of rick.rollington@parliament.uk designates 89.238.145.68 as permitted sender) client-ip=89.238.145.68; +Authentication-Results: mx.google.com; spf=pass (google.com: domain of rick.rollington@parliament.uk designates 89.238.145.68 as permitted sender) smtp.mail=rick.rollington@parliament.uk +Received: from mail82.messagelabs.com ([195.245.231.67]:4996) + by majestic.ukcod.org.uk with esmtp (Exim 4.72) + (envelope-from <rick.rollington@parliament.uk>) + id 1R12CI-000465-Gx + for team@whatdotheyknow.com; Tue, 06 Sep 2011 21:24:42 +0100 +X-Env-Sender: rick.rollington@parliament.uk +X-Msg-Ref: server-4.tower-82.messagelabs.com!1315340670!59450288!1 +X-Originating-IP: [194.60.38.7] +X-StarScan-Version: 6.3.6; banners=-,-,- +X-VirusChecked: Checked +Received: (qmail 4246 invoked from network); 6 Sep 2011 20:24:31 -0000 +Received: from hpux13x.parliament.uk (HELO hpux13x.parliament.uk) (194.60.38.7) + by server-4.tower-82.messagelabs.com with DHE-RSA-AES256-SHA encrypted SMTP; 6 Sep 2011 20:24:31 -0000 +Received: from MMEH001.parliament.uk (mmeh001.parliament.uk [10.100.70.11]) + by hpux13x.parliament.uk with ESMTP id p86KOKNw039771 + for <team@whatdotheyknow.com>; Tue, 6 Sep 2011 21:24:20 +0100 (BST) +Received: from MMEM001.parliament.uk ([169.254.1.45]) by MMEH001.parliament.uk + ([10.100.70.11]) with mapi; Tue, 6 Sep 2011 21:24:20 +0100 +From: "ROLLINGTON, Rick" <rick.rollington@parliament.uk> +To: WhatDoTheyKnow <team@whatdotheyknow.com> +Date: Tue, 6 Sep 2011 21:24:20 +0100 +Subject: Out of Office +Thread-Topic: Out of Office +Thread-Index: Acxs0vWVKlHifbrXTBmxr7r0Rh9bhwAAAAGd +Message-ID: <93A0DC80C8953B4B88DB2726AE921E264E8DE93980@MMEM001.parliament.uk> +Accept-Language: en-US, en-GB +Content-Language: en-US +X-MS-Has-Attach: +X-MS-TNEF-Correlator: +acceptlanguage: en-US, en-GB +Content-Type: text/plain; charset="us-ascii" +Content-Transfer-Encoding: quoted-printable +MIME-Version: 1.0 +List-Id: Admin Team for What Do They Know <team@whatdotheyknow.com> + +Thank you for your email. + +I will be out of the office between xnd August and yth September. + +For urgent enquiries please email Paul the Pony at, paul.the.pony@parliame= +nt.uk + + +________________________________ +UK Parliament Disclaimer: +This e-mail is confidential to the intended recipient. If you have received= + it in error, please notify the sender and delete it from your system. Any = +unauthorised use, disclosure, or copying is not permitted. This e-mail has = +been checked for viruses, but no liability is accepted for any damage cause= +d by any virus transmitted by this e-mail.
\ No newline at end of file diff --git a/spec/fixtures/files/track-response-multipart-report.email b/spec/fixtures/files/track-response-multipart-report.email new file mode 100644 index 000000000..4f8e6d86b --- /dev/null +++ b/spec/fixtures/files/track-response-multipart-report.email @@ -0,0 +1,113 @@ +Delivered-To: mysociety.robin@gmail.com +Received: by 10.216.187.197 with SMTP id y47cs96752wem; + Tue, 6 Sep 2011 13:37:26 -0700 (PDT) +Received: by 10.216.212.37 with SMTP id x37mr3361871weo.35.1315341445852; + Tue, 06 Sep 2011 13:37:25 -0700 (PDT) +Return-Path: <> +Received: from wildfire.ukcod.org.uk (wildfire.ukcod.org.uk [89.238.145.74]) + by mx.google.com with ESMTPS id h49si1800318wed.40.2011.09.06.13.37.25 + (version=TLSv1/SSLv3 cipher=OTHER); + Tue, 06 Sep 2011 13:37:25 -0700 (PDT) +Received-SPF: pass (google.com: best guess record for domain of wildfire.ukcod.org.uk designates 89.238.145.74 as permitted sender) client-ip=89.238.145.74; +Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of wildfire.ukcod.org.uk designates 89.238.145.74 as permitted sender) smtp.mail= +Received: from cluster-a.mailcontrol.com ([85.115.52.190]:43258) + by wildfire.ukcod.org.uk with esmtp (Exim 4.69) + id 1R12OV-0003KQ-9c + for team@whatdotheyknow.com; Tue, 06 Sep 2011 21:37:19 +0100 +Received: from mail.example.com ([62.6.240.178]) + by rly22a.srv.mailcontrol.com (MailControl) with ESMTP id p86KbIZV025877 + (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) + for <team@whatdotheyknow.com>; Tue, 6 Sep 2011 21:37:18 +0100 +Received: from MX05.example.com (10.100.14.57) by GCEX534.PHSGROUP.local + (10.100.21.78) with Microsoft SMTP Server id 14.1.270.1; Tue, 6 Sep 2011 + 21:38:52 +0100 +From: <postmaster@xyz.local> +To: <team@whatdotheyknow.com> +Date: Tue, 6 Sep 2011 21:37:13 +0100 +MIME-Version: 1.0 +Content-Type: multipart/report; report-type=delivery-status; + boundary="9B095B5ADSN=_01CC68D9CD29F1E300015B60MX05.example.com" +X-DSNContext: 7ce717b1 - 1148 - 00000002 - 00000000 +Message-ID: <DEU8FnRwh00000d1b@MX05.example.com> +Subject: Delivery Status Notification (Failure) +X-Scanned-By: MailControl A-12-01-02 (www.mailcontrol.com) on 10.65.0.132 +List-Id: Admin Team for What Do They Know <team@whatdotheyknow.com> + +--9B095B5ADSN=_01CC68D9CD29F1E300015B60MX05.example.com +Content-Type: text/plain; charset="unicode-1-1-utf-7" + +This is an automatically generated Delivery Status Notification. + +Delivery to the following recipients failed. + + FailedUser@example.com + + + + +--9B095B5ADSN=_01CC68D9CD29F1E300015B60MX05.example.com +Content-Type: message/delivery-status + +Reporting-MTA: dns;MX05.example.com +Received-From-MTA: dns;MX04.example.com +Arrival-Date: Tue, 6 Sep 2011 21:37:13 +0100 + +Final-Recipient: rfc822;FailedUser@example.com +Action: failed +Status: 5.2.2 +X-Display-Name: Failed User + + +--9B095B5ADSN=_01CC68D9CD29F1E300015B60MX05.example.com +Content-Type: message/rfc822 + +Received: from MX04.example.com ([10.100.14.56]) by MX05.example.com with + Microsoft SMTPSVC(5.0.2195.6713); Tue, 6 Sep 2011 21:37:13 +0100 +Received: from DCEX553.example.com ([10.211.10.27]) by MX04.example.com with + Microsoft SMTPSVC(5.0.2195.6713); Tue, 6 Sep 2011 21:37:13 +0100 +Received: from cluster-a.mailcontrol.com (85.115.52.190) by mail.example.com + (10.211.10.27) with Microsoft SMTP Server id 14.1.270.1; Tue, 6 Sep 2011 + 20:36:49 +0100 +Received: from wildfire.ukcod.org.uk (wildfire.ukcod.org.uk [89.238.145.74]) + by rly01a.srv.mailcontrol.com (MailControl) with ESMTP id p86KbAZN016792 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for + <faileduser@example.com>; Tue, 6 Sep 2011 21:37:11 +0100 +Received: from foi by wildfire.ukcod.org.uk with local (Exim 4.69) + (envelope-from <team@whatdotheyknow.com>) id 1R12OL-0003K9-UE for + faileduser@example.com; Tue, 06 Sep 2011 21:37:10 +0100 +Date: Tue, 6 Sep 2011 21:37:09 +0100 +From: WhatDoTheyKnow <team@whatdotheyknow.com> +To: Failed <faileduser@example.com> +Subject: Your WhatDoTheyKnow email alert +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Precedence: bulk +Auto-Submitted: auto-generated +Message-ID: <E1R12OL-0003K9-UE@wildfire.ukcod.org.uk> +X-Mailcontrol-Inbound: 7DN0MnCsYCrl5jj2!rZ4BuxxWQ2q0l7t3Lrex4V7ScCE2eoC2RNzHw== +X-Spam-Score: -0.857 +X-Scanned-By: MailControl A-12-01-02 (www.mailcontrol.com) on 10.65.0.111 +Return-Path: team@whatdotheyknow.com +X-OriginalArrivalTime: 06 Sep 2011 20:37:13.0070 (UTC) FILETIME=[C20250E0:01CC6CD4] + +Requests or responses matching 'bottled water cooler' +===================================================== + +-- HS2 meetings - Agendas and Minutes -- +Warwickshire County Council sent a response to Richard Jones (21 July 2011) + "Dear Mr Jones FREEDOM OF INFORMATION ACT 2000 - INFORMATION + REQUEST Your request for information has now been considered. The + information you have..." +http://www.whatdotheyknow.com/request/hs2_meetings_agendas_and_minutes_2#incoming-195748 + + +Alter your subscription +======================= + +Please click on the link below to cancel or alter these emails. +http://www.whatdotheyknow.com/c/f76ffwifzlo5sk4egr3 + +-- the WhatDoTheyKnow team + + +--9B095B5ADSN=_01CC68D9CD29F1E300015B60MX05.example.com--
\ No newline at end of file diff --git a/spec/fixtures/users.yml b/spec/fixtures/users.yml index 2485c95a0..16ffec034 100644 --- a/spec/fixtures/users.yml +++ b/spec/fixtures/users.yml @@ -10,6 +10,7 @@ bob_smith_user: email_confirmed: true admin_level: 'none' ban_text: '' + locale: 'en' about_me: 'I like making requests about fancy dogs and naughty chickens and stuff.' silly_name_user: id: "2" @@ -20,9 +21,10 @@ silly_name_user: hashed_password: 6b7cd45a5f35fd83febc0452a799530398bfb6e8 # jonespassword updated_at: 2007-11-01 10:39:15.491593 created_at: 2007-11-01 10:39:15.491593 - email_confirmed: false + email_confirmed: true admin_level: 'none' ban_text: '' + locale: 'en' about_me: '' admin_user: id: "3" @@ -36,4 +38,18 @@ admin_user: email_confirmed: false admin_level: 'super' ban_text: '' + locale: '' + about_me: '' +unconfirmed_user: + id: "4" + name: "Unconfirmed" + url_name: unconfirmed + email: unconfirmed@localhost + salt: "-6116981980.392287733335677" + hashed_password: 6b7cd45a5f35fd83febc0452a799530398bfb6e8 # jonespassword + updated_at: 2007-11-01 10:39:15.491593 + created_at: 2007-11-01 10:39:15.491593 + email_confirmed: false + admin_level: 'none' + ban_text: '' about_me: '' diff --git a/spec/integration/errors_spec.rb b/spec/integration/errors_spec.rb new file mode 100644 index 000000000..c64ca79e8 --- /dev/null +++ b/spec/integration/errors_spec.rb @@ -0,0 +1,45 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe "When rendering errors" do + + fixtures [ :info_requests, + :info_request_events, + :public_bodies, + :public_body_translations, + :users, + :raw_emails, + :outgoing_messages, + :incoming_messages, + :comments ] + + before(:each) do + load_raw_emails_data(raw_emails) + ActionController::Base.consider_all_requests_local = false + end + + after(:each) do + ActionController::Base.consider_all_requests_local = true + end + + it "should render a 404 for unrouteable URLs" do + get("/frobsnasm") + response.code.should == "404" + response.body.should include("The page doesn't exist") + end + it "should render a 404 for users that don't exist" do + get("/user/wobsnasm") + response.code.should == "404" + end + it "should render a 404 for bodies that don't exist" do + get("/body/wobsnasm") + response.code.should == "404" + end + it "should render a 500 for general errors" do + ir = info_requests(:naughty_chicken_request) + # Set an invalid state for the request. Note that update_attribute doesn't run the validations + ir.update_attribute(:described_state, "crotchety") + get("/request/#{ir.url_title}") + response.code.should == "500" + end +end + diff --git a/spec/integration/search_request_spec.rb b/spec/integration/search_request_spec.rb new file mode 100644 index 000000000..dcd20c7bd --- /dev/null +++ b/spec/integration/search_request_spec.rb @@ -0,0 +1,63 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe "When searching" do + + fixtures [ :info_requests, + :info_request_events, + :public_bodies, + :public_body_translations, + :users, + :raw_emails, + :outgoing_messages, + :incoming_messages, + :comments ] + + before(:each) do + emails = raw_emails.clone + load_raw_emails_data(emails) + end + + it "should not strip quotes from quoted query" do + request_via_redirect("post", "/search", :query => '"mouse stilton"') + response.body.should include(""mouse stilton"") + end + + it "should correctly execute simple search" do + request_via_redirect("post", "/search", + :query => 'bob' + ) + response.body.should include("FOI requests") + end + + it "should correctly filter searches for requests" do + request_via_redirect("post", "/search/bob/requests") + response.body.should_not include("One person found") + response.body.should include("FOI requests 1 to 2 of 2") + end + it "should correctly filter searches for users" do + request_via_redirect("post", "/search/bob/users") + response.body.should include("One person found") + response.body.should_not include("FOI requests 1 to 2 of 2") + end + + it "should correctly filter searches for successful requests" do + request_via_redirect("post", "/search", + :query => "bob", + :latest_status => ['successful']) + response.body.should include("no requests matching your query") + end + + it "should correctly filter searches for comments" do + request_via_redirect("post", "/search", + :query => "daftest", + :request_variety => ['comments']) + response.body.should include("One FOI request found") + + request_via_redirect("post", "/search", + :query => "daftest", + :request_variety => ['response','sent']) + response.body.should include("no requests matching your query") + end + +end + diff --git a/spec/lib/external_command_scripts/output.sh b/spec/lib/external_command_scripts/output.sh deleted file mode 100755 index 0472c89a3..000000000 --- a/spec/lib/external_command_scripts/output.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -out_msg=${1:-out} -err_msg=${2:-} -repeats=${3:-10} -exit_status=${4:-0} - -n=0 -while [ "$n" -lt "$repeats" ] -do - if [ -n "$out_msg" ] - then - echo "$out_msg $n" - fi - if [ -n "$err_msg" ] - then - echo >&2 "$err_msg $n" - fi - n=$[$n + 1] -done - -exit "$exit_status" diff --git a/spec/lib/external_command_spec.rb b/spec/lib/external_command_spec.rb deleted file mode 100644 index 0ff1a9c0a..000000000 --- a/spec/lib/external_command_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -# This is a test of the external_command library - -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') -script_dir = File.join(File.dirname(__FILE__), 'external_command_scripts') -output_script = File.join(script_dir, "output.sh") - -require 'external_command' - -describe "when running ExternalCommand" do - - it "should get correct status code for /bin/true" do - t = ExternalCommand.new("/bin/true").run() - t.status.should == 0 - t.out.should == "" - t.err.should == "" - end - - it "should get correct status code for /bin/false" do - f = ExternalCommand.new("/bin/false").run() - f.status.should == 1 - f.out.should == "" - f.err.should == "" - end - - it "should get stdout and stderr" do - f = ExternalCommand.new(output_script, "out", "err", "10", "23").run() - f.status.should == 23 - f.out.should == (0..9).map {|i| "out #{i}\n"}.join("") - f.err.should == (0..9).map {|i| "err #{i}\n"}.join("") - end - - it "should work with large amounts of data" do - f = ExternalCommand.new(output_script, "a longer output line", "a longer error line", "10000", "5").run() - f.status.should == 5 - f.out.should == (0..9999).map {|i| "a longer output line #{i}\n"}.join("") - f.err.should == (0..9999).map {|i| "a longer error line #{i}\n"}.join("") - end - -end - diff --git a/spec/lib/i18n_interpolation.rb b/spec/lib/i18n_interpolation.rb new file mode 100644 index 000000000..8c86413ad --- /dev/null +++ b/spec/lib/i18n_interpolation.rb @@ -0,0 +1,15 @@ +# This is a test of the set_content_type monkey patch in +# lib/tmail_extensions.rb + +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe "when using i18n" do + + it "should not complain if we're missing variables from the string" do + result = _('Hello', :dip => 'hummus') + result.should == 'Hello' + result = _('Hello {{dip}}', :dip => 'hummus') + result.should == 'Hello hummus' + end +end + diff --git a/spec/lib/tmail_extensions_spec.rb b/spec/lib/tmail_extensions_spec.rb index c647fe522..ffb8cb178 100644 --- a/spec/lib/tmail_extensions_spec.rb +++ b/spec/lib/tmail_extensions_spec.rb @@ -27,5 +27,14 @@ describe "when using TMail" do mail.to.should == ["request-66666-caa77777@whatdotheyknow.com", "foi@example.com"] end + it 'should convert to utf8' do + # NB this isn't actually a TMail extension, but is core TMail; + # this was just a convenient place to assert the UTF8 + # conversion is working + mail = TMail::Mail.parse(load_file_fixture('iso8859_2_raw_email.email')) + mail.subject.should have_text(/gjatë/u) + mail.body.is_utf8?.should == true + end + end diff --git a/spec/models/customstates.rb b/spec/models/customstates.rb index 406d4ead9..3488e6730 100644 --- a/spec/models/customstates.rb +++ b/spec/models/customstates.rb @@ -5,16 +5,6 @@ module InfoRequestCustomStates end # Mixin methods for InfoRequest - def theme_display_status(status) - if status == 'deadline_extended' - _("Deadline extended.") - elsif status == 'wrong_response' - _("Wrong Response.") - else - raise _("unknown status ") + status - end - end - def theme_calculate_status return 'waiting_classification' if self.awaiting_description waiting_response = self.described_state == "waiting_response" || self.described_state == "deadline_extended" @@ -41,6 +31,16 @@ module InfoRequestCustomStates end module ClassMethods + def theme_display_status(status) + if status == 'deadline_extended' + _("Deadline extended.") + elsif status == 'wrong_response' + _("Wrong Response.") + else + raise _("unknown status ") + status + end + end + def theme_extra_states return ['deadline_extended', 'wrong_response'] diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index 183a258af..a8411bc34 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -1,7 +1,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe IncomingMessage, " when dealing with incoming mail" do - fixtures :incoming_messages, :raw_emails, :info_requests + fixtures :users, :raw_emails, :public_bodies, :public_body_translations, :info_requests, :incoming_messages before(:each) do @im = incoming_messages(:useless_incoming_message) @@ -17,6 +17,27 @@ describe IncomingMessage, " when dealing with incoming mail" do TMail::Address.parse(em) end + it "should correctly fold various types of footer" do + Dir.glob(File.join(Spec::Runner.configuration.fixture_path, "files", "email-folding-example-*.txt")).each do |file| + message = File.read(file) + parsed = IncomingMessage.remove_quoted_sections(message) + expected = File.read("#{file}.expected") + parsed.should include(expected) + end + end + + it "should fold multiline sections" do + { + "foo\n--------\nconfidential" => "foo\nFOLDED_QUOTED_SECTION\n", # basic test + "foo\n--------\nbar - confidential" => "foo\nFOLDED_QUOTED_SECTION\n", # allow scorechar inside folded section + "foo\n--------\nbar\n--------\nconfidential" => "foo\n--------\nbar\nFOLDED_QUOTED_SECTION\n", # don't assume that anything after a score is a folded section + "foo\n--------\nbar\n--------\nconfidential\n--------\nrest" => "foo\n--------\nbar\nFOLDED_QUOTED_SECTION\nrest", # don't assume that a folded section continues to the end of the message + "foo\n--------\nbar\n- - - - - - - -\nconfidential\n--------\nrest" => "foo\n--------\nbar\nFOLDED_QUOTED_SECTION\nrest", # allow spaces in the score + }.each do |input,output| + IncomingMessage.remove_quoted_sections(input).should == output + end + end + end describe IncomingMessage, "when parsing HTML mail" do @@ -79,11 +100,21 @@ describe IncomingMessage, " folding quoted parts of emails" do end describe IncomingMessage, " checking validity to reply to" do - def test_email(email, result) + def test_email(result, email, return_path, autosubmitted) @address = mock(TMail::Address) @address.stub!(:spec).and_return(email) + + @return_path = mock(TMail::ReturnPathHeader) + @return_path.stub!(:addr).and_return(return_path) + + @autosubmitted = mock(TMail::KeywordsHeader) + @autosubmitted.stub!(:keys).and_return(autosubmitted) + @mail = mock(TMail::Mail) @mail.stub!(:from_addrs).and_return( [ @address ] ) + @mail.stub!(:[]).with("return-path").and_return(@return_path) + @mail.stub!(:[]).with("auto-submitted").and_return(@autosubmitted) + @incoming_message = IncomingMessage.new() @incoming_message.stub!(:mail).and_return(@mail) @@ -91,33 +122,69 @@ describe IncomingMessage, " checking validity to reply to" do end it "says a valid email is fine" do - test_email("team@mysociety.org", true) + test_email(true, "team@mysociety.org", nil, []) end it "says postmaster email is bad" do - test_email("postmaster@mysociety.org", false) + test_email(false, "postmaster@mysociety.org", nil, []) end it "says Mailer-Daemon email is bad" do - test_email("Mailer-Daemon@mysociety.org", false) + test_email(false, "Mailer-Daemon@mysociety.org", nil, []) end it "says case mangled MaIler-DaemOn email is bad" do - test_email("MaIler-DaemOn@mysociety.org", false) + test_email(false, "MaIler-DaemOn@mysociety.org", nil, []) end it "says Auto_Reply email is bad" do - test_email("Auto_Reply@mysociety.org", false) + test_email(false, "Auto_Reply@mysociety.org", nil, []) end it "says DoNotReply email is bad" do - test_email("DoNotReply@tube.tfl.gov.uk", false) + test_email(false, "DoNotReply@tube.tfl.gov.uk", nil, []) + end + + it "says a filled-out return-path is fine" do + test_email(true, "team@mysociety.org", "Return-path: <foo@baz.com>", []) + end + + it "says an empty return-path is bad" do + test_email(false, "team@mysociety.org", "<>", []) + end + + it "says an auto-submitted keyword is bad" do + test_email(false, "team@mysociety.org", nil, ["auto-replied"]) + end + +end + +describe IncomingMessage, " checking validity to reply to with real emails" do + fixtures :users, :raw_emails, :public_bodies, :public_body_translations, :info_requests, :incoming_messages + + after(:all) do + ActionMailer::Base.deliveries.clear + end + it "should allow a reply to plain emails" do + ir = info_requests(:fancy_dog_request) + receive_incoming_mail('incoming-request-plain.email', ir.incoming_email) + ir.incoming_messages[1].valid_to_reply_to?.should == true + end + it "should not allow a reply to emails with empty return-paths" do + ir = info_requests(:fancy_dog_request) + receive_incoming_mail('empty-return-path.email', ir.incoming_email) + ir.incoming_messages[1].valid_to_reply_to?.should == false + end + it "should not allow a reply to emails with autoresponse headers" do + ir = info_requests(:fancy_dog_request) + receive_incoming_mail('autoresponse-header.email', ir.incoming_email) + ir.incoming_messages[1].valid_to_reply_to?.should == false end end describe IncomingMessage, " when censoring data" do - fixtures :incoming_messages, :raw_emails, :public_bodies, :public_body_translations, :info_requests, :users + fixtures :users, :raw_emails, :public_bodies, :public_body_translations, :info_requests, :incoming_messages before(:each) do @test_data = "There was a mouse called Stilton, he wished that he was blue." @@ -227,7 +294,7 @@ describe IncomingMessage, " when censoring data" do end describe IncomingMessage, " when censoring whole users" do - fixtures :incoming_messages, :raw_emails, :public_bodies, :public_body_translations, :info_requests, :users + fixtures :users, :raw_emails, :public_bodies, :public_body_translations, :info_requests, :incoming_messages before(:each) do @test_data = "There was a mouse called Stilton, he wished that he was blue." diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index b82052a0f..d50d6dace 100644 --- a/spec/models/info_request_spec.rb +++ b/spec/models/info_request_spec.rb @@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe InfoRequest do describe "guessing a request from an email" do - fixtures :info_requests, :public_bodies, :incoming_messages, :raw_emails + fixtures :public_bodies, :info_requests, :raw_emails, :incoming_messages before(:each) do @im = incoming_messages(:useless_incoming_message) @@ -74,7 +74,7 @@ describe InfoRequest do describe " when emailing" do - fixtures :info_requests, :info_request_events, :outgoing_messages, :public_bodies, :public_body_translations, :users, :comments + fixtures :public_bodies, :public_body_translations, :users, :info_requests, :outgoing_messages, :info_request_events, :comments before do @info_request = info_requests(:fancy_dog_request) @@ -154,7 +154,7 @@ describe InfoRequest do end describe "when calculating the status" do - fixtures :info_requests, :info_request_events, :holidays, :public_bodies, :public_body_translations, :outgoing_messages + fixtures :holidays, :public_bodies, :public_body_translations, :info_requests, :outgoing_messages, :info_request_events before do @ir = info_requests(:naughty_chicken_request) @@ -231,7 +231,7 @@ describe InfoRequest do describe "when calculating the status for a school" do - fixtures :info_requests, :info_request_events, :holidays, :public_bodies, :public_body_translations + fixtures :holidays, :public_bodies, :public_body_translations, :info_requests, :info_request_events before do @ir = info_requests(:naughty_chicken_request) diff --git a/spec/models/outgoing_mailer_spec.rb b/spec/models/outgoing_mailer_spec.rb index d7587cb41..c96a3fb74 100644 --- a/spec/models/outgoing_mailer_spec.rb +++ b/spec/models/outgoing_mailer_spec.rb @@ -112,7 +112,6 @@ describe OutgoingMailer, "when working out follow up subjects" do it "should not add Re: prefix if there already is a lower case re: prefix" do ir = info_requests(:fancy_dog_request) im = ir.incoming_messages[0] - puts im.raw_email.data om = outgoing_messages(:useless_outgoing_message) om.incoming_message_followup = im diff --git a/spec/models/outgoing_message_spec.rb b/spec/models/outgoing_message_spec.rb index a9ef57b4f..1956c4d73 100644 --- a/spec/models/outgoing_message_spec.rb +++ b/spec/models/outgoing_message_spec.rb @@ -1,7 +1,10 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe OutgoingMessage, " when making an outgoing message" do + fixtures :outgoing_messages, :info_requests, :incoming_messages, :public_bodies, :public_body_translations + before do + @om = outgoing_messages(:useless_outgoing_message) @outgoing_message = OutgoingMessage.new({ :status => 'ready', :message_type => 'initial_request', @@ -27,6 +30,10 @@ describe OutgoingMessage, " when making an outgoing message" do it "should include email addresses in outgoing messages" do @outgoing_message.body.should include("foo@bar.com") end + + it "should work out a salutation" do + @om.get_salutation.should == "Dear Geraldine Quango," + end end diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index ec84cbe65..33ab8ffdb 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -210,19 +210,52 @@ describe PublicBody, "when searching" do body.id.should == 3 body.class.to_s.should == 'PublicBody' end + + it "should cope with same url_name across multiple locales" do + PublicBody.with_locale(:es) do + # use the unique spanish name to retrieve and edit + body = PublicBody.find_by_url_name_with_historic('etgq') + body.short_name = 'tgq' # Same as english version + body.save! + + # now try to retrieve it + body = PublicBody.find_by_url_name_with_historic('tgq') + body.id.should == public_bodies(:geraldine_public_body).id + body.name.should == "El A Geraldine Quango" + end + end end describe PublicBody, " when loading CSV files" do + before(:each) do + # InternalBody is created the first time it's accessed, which happens sometimes during imports, + # depending on the tag used. By accessing it here before every test, it doesn't disturb our checks later on + PublicBody.internal_admin_body + end + + it "should import even if no email is provided" do + errors, notes = PublicBody.import_csv("1,aBody", '', 'replace', true, 'someadmin') # true means dry run + errors.should == [] + notes.size.should == 2 + notes.should == [ + "line 1: creating new authority 'aBody' (locale: en):\n\t{\"name\":\"aBody\"}", + "Notes: Some bodies are in database, but not in CSV file:\n Department for Humpadinking\n Geraldine Quango\nYou may want to delete them manually.\n" + ] + end + it "should do a dry run successfully" do original_count = PublicBody.count csv_contents = load_file_fixture("fake-authority-type.csv") - errors, notes = PublicBody.import_csv(csv_contents, 'fake', true, 'someadmin') # true means dry run + errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', true, 'someadmin') # true means dry run errors.should == [] - notes.size.should == 3 - notes.should == ["line 1: new authority 'North West Fake Authority' with email north_west_foi@localhost", - "line 2: new authority 'Scottish Fake Authority' with email scottish_foi@localhost", - "line 3: new authority 'Fake Authority of Northern Ireland' with email ni_foi@localhost"] + notes.size.should == 4 + notes.should == [ + "line 1: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\"\}", + "line 2: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\"\}", + "line 3: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\"\}", + "Notes: Some bodies are in database, but not in CSV file:\n Department for Humpadinking\n Geraldine Quango\nYou may want to delete them manually.\n" + ] PublicBody.count.should == original_count end @@ -231,44 +264,105 @@ describe PublicBody, " when loading CSV files" do original_count = PublicBody.count csv_contents = load_file_fixture("fake-authority-type.csv") - errors, notes = PublicBody.import_csv(csv_contents, 'fake', false, 'someadmin') # false means real run + errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', false, 'someadmin') # false means real run errors.should == [] - notes.size.should == 3 - notes.should == ["line 1: new authority 'North West Fake Authority' with email north_west_foi@localhost", - "line 2: new authority 'Scottish Fake Authority' with email scottish_foi@localhost", - "line 3: new authority 'Fake Authority of Northern Ireland' with email ni_foi@localhost"] + notes.size.should == 4 + notes.should == [ + "line 1: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\"\}", + "line 2: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\"\}", + "line 3: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\"\}", + "Notes: Some bodies are in database, but not in CSV file:\n Department for Humpadinking\n Geraldine Quango\nYou may want to delete them manually.\n" + ] PublicBody.count.should == original_count + 3 end + it "should do imports without a tag successfully" do + original_count = PublicBody.count + + csv_contents = load_file_fixture("fake-authority-type.csv") + errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', false, 'someadmin') # false means real run + errors.should == [] + notes.size.should == 4 + notes.should == [ + "line 1: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\"\}", + "line 2: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\"\}", + "line 3: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\"\}", + "Notes: Some bodies are in database, but not in CSV file:\n Department for Humpadinking\n Geraldine Quango\nYou may want to delete them manually.\n" + ] + PublicBody.count.should == original_count + 3 + end + it "should handle a field list and fields out of order" do original_count = PublicBody.count csv_contents = load_file_fixture("fake-authority-type-with-field-names.csv") - errors, notes = PublicBody.import_csv(csv_contents, 'fake', true, 'someadmin') # true means dry run + errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', true, 'someadmin') # true means dry run errors.should == [] - notes.size.should == 3 - notes.should == ["line 2: new authority 'North West Fake Authority' with email north_west_foi@localhost", - "line 3: new authority 'Scottish Fake Authority' with email scottish_foi@localhost", - "line 4: new authority 'Fake Authority of Northern Ireland' with email ni_foi@localhost"] + notes.size.should == 4 + notes.should == [ + "line 2: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\",\"home_page\":\"http://northwest.org\"\}", + "line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"tag_string\":\"scottish\",\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\"\}", + "line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"tag_string\":\"fake aTag\",\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\"\}", + "Notes: Some bodies are in database, but not in CSV file:\n Department for Humpadinking\n Geraldine Quango\nYou may want to delete them manually.\n" + ] PublicBody.count.should == original_count end + + it "should import tags successfully when the import tag is not set" do + csv_contents = load_file_fixture("fake-authority-type-with-field-names.csv") + errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', false, 'someadmin') # false means real run + + PublicBody.find_by_name('North West Fake Authority').tag_array_for_search.should == [] + PublicBody.find_by_name('Scottish Fake Authority').tag_array_for_search.should == ['scottish'] + PublicBody.find_by_name('Fake Authority of Northern Ireland').tag_array_for_search.should == ['fake', 'aTag'] + + # Import again to check the 'add' tag functionality works + new_tags_file = load_file_fixture('fake-authority-add-tags.rb') + errors, notes = PublicBody.import_csv(new_tags_file, '', 'add', false, 'someadmin') # false means real run + + # Check tags were added successfully + PublicBody.find_by_name('North West Fake Authority').tag_array_for_search.should == ['aTag'] + PublicBody.find_by_name('Scottish Fake Authority').tag_array_for_search.should == ['scottish', 'aTag'] + PublicBody.find_by_name('Fake Authority of Northern Ireland').tag_array_for_search.should == ['fake', 'aTag'] + end + + it "should import tags successfully when the import tag is set" do + csv_contents = load_file_fixture("fake-authority-type-with-field-names.csv") + errors, notes = PublicBody.import_csv(csv_contents, 'fake', 'add', false, 'someadmin') # false means real run + + # Check new bodies were imported successfully + PublicBody.find_by_name('North West Fake Authority').tag_array_for_search.should == ['fake'] + PublicBody.find_by_name('Scottish Fake Authority').tag_array_for_search.should == ['scottish', 'fake'] + PublicBody.find_by_name('Fake Authority of Northern Ireland').tag_array_for_search.should == ['fake', 'aTag'] + + # Import again to check the 'replace' tag functionality works + new_tags_file = load_file_fixture('fake-authority-add-tags.rb') + errors, notes = PublicBody.import_csv(new_tags_file, 'fake', 'replace', false, 'someadmin') # false means real run + + # Check tags were added successfully + PublicBody.find_by_name('North West Fake Authority').tag_array_for_search.should == ['aTag'] + PublicBody.find_by_name('Scottish Fake Authority').tag_array_for_search.should == ['aTag'] + PublicBody.find_by_name('Fake Authority of Northern Ireland').tag_array_for_search.should == ['fake', 'aTag'] + end it "should create bodies with names in multiple locales" do original_count = PublicBody.count csv_contents = load_file_fixture("fake-authority-type-with-field-names.csv") - errors, notes = PublicBody.import_csv(csv_contents, 'fake', false, 'someadmin', ['es']) + errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', false, 'someadmin', [:en, :es]) errors.should == [] - notes.size.should == 6 + notes.size.should == 7 notes.should == [ - "line 2: new authority 'North West Fake Authority' with email north_west_foi@localhost", - "line 2: (aka 'Autoridad del Nordeste' in locale es)", - "line 3: new authority 'Scottish Fake Authority' with email scottish_foi@localhost", - "line 3: (aka 'Autoridad Escocesa' in locale es)", - "line 4: new authority 'Fake Authority of Northern Ireland' with email ni_foi@localhost", - "line 4: (aka 'Autoridad Irlandesa' in locale es)"] + "line 2: creating new authority 'North West Fake Authority' (locale: en):\n\t{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\",\"home_page\":\"http://northwest.org\"}", + "line 2: creating new authority 'North West Fake Authority' (locale: es):\n\t{\"name\":\"Autoridad del Nordeste\"}", + "line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t{\"tag_string\":\"scottish\",\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\"}", + "line 3: creating new authority 'Scottish Fake Authority' (locale: es):\n\t{\"name\":\"Autoridad Escocesa\"}", + "line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t{\"tag_string\":\"fake aTag\",\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\"}", + "line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: es):\n\t{\"name\":\"Autoridad Irlandesa\"}", + "Notes: Some bodies are in database, but not in CSV file:\n Department for Humpadinking\n Geraldine Quango\nYou may want to delete them manually.\n" + ] PublicBody.count.should == original_count + 3 @@ -283,12 +377,18 @@ describe PublicBody, " when loading CSV files" do original_count = PublicBody.count csv_contents = load_file_fixture("fake-authority-type-with-field-names.csv") - errors, notes = PublicBody.import_csv(csv_contents, 'fake', true, 'someadmin', ['xx']) # true means dry run + # Depending on the runtime environment (Ruby version? OS?) the list of available locales + # is made of strings or symbols, so we use 'en' here as a string to test both scenarios. + # See https://github.com/sebbacon/alaveteli/issues/193 + errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', true, 'someadmin', ['en', :xx]) # true means dry run errors.should == [] - notes.size.should == 3 - notes.should == ["line 2: new authority 'North West Fake Authority' with email north_west_foi@localhost", - "line 3: new authority 'Scottish Fake Authority' with email scottish_foi@localhost", - "line 4: new authority 'Fake Authority of Northern Ireland' with email ni_foi@localhost"] + notes.size.should == 4 + notes.should == [ + "line 2: creating new authority 'North West Fake Authority' (locale: en):\n\t{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\",\"home_page\":\"http://northwest.org\"}", + "line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t{\"tag_string\":\"scottish\",\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\"}", + "line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t{\"tag_string\":\"fake aTag\",\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\"}", + "Notes: Some bodies are in database, but not in CSV file:\n Department for Humpadinking\n Geraldine Quango\nYou may want to delete them manually.\n" + ] PublicBody.count.should == original_count end diff --git a/spec/models/track_mailer_spec.rb b/spec/models/track_mailer_spec.rb index 828904d02..67a64ee10 100644 --- a/spec/models/track_mailer_spec.rb +++ b/spec/models/track_mailer_spec.rb @@ -21,7 +21,9 @@ describe TrackMailer do @user = mock_model(User, :no_xapian_reindex= => false, :last_daily_track_email= => true, :save! => true, - :url_name => 'test-name') + :url_name => 'test-name', + :get_locale => 'en', + :should_be_emailed? => true) User.stub!(:find).and_return([@user]) @user.stub!(:no_xapian_reindex=) end @@ -43,6 +45,9 @@ describe TrackMailer do @user.should_receive(:save!) TrackMailer.alert_tracks end + it 'should return true' do + TrackMailer.alert_tracks.should == true + end describe 'for each tracked thing' do @@ -109,6 +114,39 @@ describe TrackMailer do end + describe 'when a user should not be emailed' do + before do + @user = mock_model(User, :no_xapian_reindex= => false, + :last_daily_track_email= => true, + :save! => true, + :url_name => 'test-name', + :should_be_emailed? => false) + User.stub!(:find).and_return([@user]) + @user.stub!(:no_xapian_reindex=) + end + + it 'should not ask for any daily track things for the user' do + expected_conditions = [ "tracking_user_id = ? and track_medium = ?", @user.id, 'email_daily' ] + TrackThing.should_not_receive(:find).with(:all, :conditions => expected_conditions).and_return([]) + TrackMailer.alert_tracks + end + + + it 'should not set the no_xapian_reindex flag on the user' do + @user.should_not_receive(:no_xapian_reindex=).with(true) + TrackMailer.alert_tracks + end + + it 'should not update the time of the user\'s last daily tracking email' do + @user.should_not_receive(:last_daily_track_email=).with(Time.now) + @user.should_not_receive(:save!) + TrackMailer.alert_tracks + end + it 'should return false' do + TrackMailer.alert_tracks.should == false + end + end + end describe 'delivering the email' do diff --git a/spec/models/track_thing_spec.rb b/spec/models/track_thing_spec.rb index 6b9cd6d4a..1a0324a78 100644 --- a/spec/models/track_thing_spec.rb +++ b/spec/models/track_thing_spec.rb @@ -28,5 +28,15 @@ describe TrackThing, "when tracking changes" do found_track.should == @track_thing end + it "will make some sane descriptions of search-based tracks" do + tests = [['bob variety:user', "users matching text 'bob'"], + ['bob (variety:sent OR variety:followup_sent OR variety:response OR variety:comment) (latest_status:successful OR latest_status:partially_successful OR latest_status:rejected OR latest_status:not_held)', "requests which are successful or unsuccessful or comments matching text 'bob'"], + ['(latest_status:waiting_response OR latest_status:waiting_clarification OR waiting_classification:true)', 'requests which are awaiting a response']] + for query, description in tests + track_thing = TrackThing.create_track_for_search_query(query) + track_thing.track_query_description.should == description + end + end + end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ee6916ffc..751a61060 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -282,3 +282,26 @@ describe User, "when setting a profile photo" do # end end +describe User, "when unconfirmed" do + fixtures :users + + before do + @user = users(:unconfirmed_user) + end + + it "should not be emailed" do + @user.should_be_emailed?.should be_false + end +end + +describe User, "when emails have bounced" do + fixtures :users + + it "should record bounces" do + User.record_bounce_for_email("bob@localhost", "The reason we think the email bounced (e.g. a bounce message)") + + user = User.find_user_by_email("bob@localhost") + user.email_bounced_at.should_not be_nil + user.email_bounce_message.should == "The reason we think the email bounced (e.g. a bounce message)" + end +end diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb index c08b3e5a4..8e8616df5 100644 --- a/spec/models/xapian_spec.rb +++ b/spec/models/xapian_spec.rb @@ -2,12 +2,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe User, " when indexing users with Xapian" do fixtures :users - - before(:all) do - rebuild_xapian_index - end - + it "should search by name" do + rebuild_xapian_index # def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page) xapian_object = InfoRequest.full_search([User], "Silly", 'created_at', true, nil, 100, 1) xapian_object.results.size.should == 1 @@ -37,27 +34,29 @@ end describe PublicBody, " when indexing public bodies with Xapian" do fixtures :public_bodies, :public_body_translations, :incoming_messages, :outgoing_messages, :raw_emails, :comments, :info_requests - - before(:all) do - rebuild_xapian_index - end before(:each) do load_raw_emails_data(raw_emails) end it "should search index the main name field" do + rebuild_xapian_index + xapian_object = InfoRequest.full_search([PublicBody], "humpadinking", 'created_at', true, nil, 100, 1) xapian_object.results.size.should == 1 xapian_object.results[0][:model].should == public_bodies(:humpadink_public_body) end it "should search index the notes field" do + rebuild_xapian_index + xapian_object = InfoRequest.full_search([PublicBody], "albatross", 'created_at', true, nil, 100, 1) xapian_object.results.size.should == 1 xapian_object.results[0][:model].should == public_bodies(:humpadink_public_body) end it "should delete public bodies from the index when they are destroyed" do + rebuild_xapian_index + xapian_object = InfoRequest.full_search([PublicBody], "albatross", 'created_at', true, nil, 100, 1) xapian_object.results.size.should == 1 xapian_object.results[0][:model].should == public_bodies(:humpadink_public_body) @@ -74,20 +73,19 @@ end describe PublicBody, " when indexing requests by body they are to" do fixtures :public_bodies, :public_body_translations, :info_request_events, :info_requests, :raw_emails, :comments - before(:all) do - rebuild_xapian_index - end before(:each) do load_raw_emails_data(raw_emails) end it "should find requests to the body" do + rebuild_xapian_index xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_from:tgq", 'created_at', true, nil, 100, 1) xapian_object.results.size.should == 4 end it "should update index correctly when URL name of body changes" do # initial search + rebuild_xapian_index xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_from:tgq", 'created_at', true, nil, 100, 1) xapian_object.results.size.should == 4 models_found_before = xapian_object.results.map { |x| x[:model] } @@ -112,6 +110,8 @@ describe PublicBody, " when indexing requests by body they are to" do # if you index via the Xapian TermGenerator, it ignores terms of this length, # this checks we're using Document:::add_term() instead it "should work with URL names that are longer than 64 characters" do + rebuild_xapian_index + # change the URL name of the body body = public_bodies(:geraldine_public_body) body.short_name = 'The Uncensored, Complete Name of the Quasi-Autonomous Public Body Also Known As Geraldine' @@ -132,20 +132,18 @@ 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(:all) do - rebuild_xapian_index - end before(:each) do load_raw_emails_data(raw_emails) end it "should find requests from the user" do + rebuild_xapian_index xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith", 'created_at', true, nil, 100, 1) xapian_object.results.size.should == 4 end it "should find just the sent message events from a particular user" do + rebuild_xapian_index # def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page) xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith variety:sent", 'created_at', true, nil, 100, 1) xapian_object.results.size.should == 2 @@ -154,6 +152,7 @@ describe User, " when indexing requests by user they are from" do end it "should not find it when one of the request's users is changed" do + rebuild_xapian_index silly_user = users(:silly_name_user) naughty_chicken_request = info_requests(:naughty_chicken_request) naughty_chicken_request.user = silly_user @@ -168,6 +167,8 @@ describe User, " when indexing requests by user they are from" do end it "should not get confused searching for requests when one user has a name which has same stem as another" do + rebuild_xapian_index + bob_smith_user = users(:bob_smith_user) bob_smith_user.name = "John King" bob_smith_user.url_name.should == 'john_king' @@ -218,21 +219,19 @@ 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(:all) do - rebuild_xapian_index - end before(:each) do load_raw_emails_data(raw_emails) end it "should find requests from the user" do + rebuild_xapian_index xapian_object = InfoRequest.full_search([InfoRequestEvent], "commented_by:silly_emnameem", 'created_at', true, nil, 100, 1) xapian_object.results.size.should == 1 end it "should update index correctly when URL name of user changes" do # initial search + rebuild_xapian_index xapian_object = InfoRequest.full_search([InfoRequestEvent], "commented_by:silly_emnameem", 'created_at', true, nil, 100, 1) xapian_object.results.size.should == 1 models_found_before = xapian_object.results.map { |x| x[:model] } @@ -257,15 +256,12 @@ end describe InfoRequest, " when indexing requests by their title" do fixtures :info_request_events, :info_requests, :incoming_messages, :raw_emails, :comments - - before(:all) do - rebuild_xapian_index - end before(:each) do load_raw_emails_data(raw_emails) end it "should find events for the request" do + rebuild_xapian_index xapian_object = InfoRequest.full_search([InfoRequestEvent], "request:how_much_public_money_is_wasted_o", 'created_at', true, nil, 100, 1) xapian_object.results.size.should == 1 xapian_object.results[0][:model] == info_request_events(:silly_outgoing_message_event) @@ -273,6 +269,7 @@ describe InfoRequest, " when indexing requests by their title" do it "should update index correctly when URL title of request changes" do # change the URL name of the body + rebuild_xapian_index ir = info_requests(:naughty_chicken_request) ir.title = 'Really naughty' ir.save! @@ -290,14 +287,12 @@ end describe InfoRequest, " when indexing requests by tag" do fixtures :info_request_events, :info_requests, :incoming_messages, :raw_emails, :comments - before(:all) do - rebuild_xapian_index - end before(:each) do load_raw_emails_data(raw_emails) end it "should find request by tag, even when changes" do + rebuild_xapian_index ir = info_requests(:naughty_chicken_request) ir.tag_string = 'bunnyrabbit' ir.save! @@ -314,14 +309,12 @@ end describe PublicBody, " when indexing authorities by tag" do fixtures :public_bodies, :public_body_translations, :incoming_messages, :outgoing_messages, :raw_emails, :comments - before(:all) do - rebuild_xapian_index - end before(:each) do load_raw_emails_data(raw_emails) end it "should find request by tag, even when changes" do + rebuild_xapian_index body = public_bodies(:geraldine_public_body) body.tag_string = 'mice:3' body.save! diff --git a/spec/script/handle-mail-replies_spec.rb b/spec/script/handle-mail-replies_spec.rb new file mode 100644 index 000000000..eae0b516b --- /dev/null +++ b/spec/script/handle-mail-replies_spec.rb @@ -0,0 +1,58 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +require "external_command" + +def mail_reply_test(email_filename) + Dir.chdir RAILS_ROOT do + xc = ExternalCommand.new("script/handle-mail-replies", "--test") + xc.run(load_file_fixture(email_filename)) + + xc.err.should == "" + return xc + end +end + +describe "When filtering" do + it "should detect an Exim bounce" do + r = mail_reply_test("track-response-exim-bounce.email") + r.status.should == 1 + r.out.should == "user@example.com\n" + end + + it "should pass on a non-bounce message" do + r = mail_reply_test("incoming-request-bad-uuencoding.email") + r.status.should == 0 + r.out.should == "" + end + + it "should detect a multipart bounce" do + r = mail_reply_test("track-response-multipart-report.email") + r.status.should == 1 + r.out.should == "FailedUser@example.com\n" + end + + it "should detect a generic out-of-office" do + r = mail_reply_test("track-response-generic-oof.email") + r.status.should == 2 + end + + it "should detect an Exchange-style out-of-office" do + r = mail_reply_test("track-response-exchange-oof-1.email") + r.status.should == 2 + end + + it "should detect a Lotus Domino-style out-of-office" do + r = mail_reply_test("track-response-lotus-oof-1.email") + r.status.should == 2 + end + + it "should detect a Messagelabs-style out-of-office" do + r = mail_reply_test("track-response-messagelabs-oof-1.email") + r.status.should == 2 + end + + it "should detect an out-of-office that has an X-POST-MessageClass header" do + r = mail_reply_test("track-response-messageclass-oof.email") + r.status.should == 2 + end +end + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b4471afc1..d1b3083c4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -113,9 +113,9 @@ def validate_as_body(html) "<html><head><title>Test</title></head><body>#{html}</body></html>") end -def basic_auth_login(request) - username = MySociety::Config.get('ADMIN_USERNAME') - password = MySociety::Config.get('ADMIN_PASSWORD') +def basic_auth_login(request, username = nil, password = nil) + username = MySociety::Config.get('ADMIN_USERNAME') if username.nil? + password = MySociety::Config.get('ADMIN_PASSWORD') if password.nil? request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("#{username}:#{password}") end @@ -148,7 +148,7 @@ if $tempfilecount.nil? end def load_raw_emails_data(raw_emails) - raw_email = raw_emails(:useless_raw_email) + raw_email = raw_emails(:useless_raw_email) begin raw_email.destroy_file_representation! rescue Errno::ENOENT diff --git a/spec/views/public_body/show.rhtml_spec.rb b/spec/views/public_body/show.rhtml_spec.rb index 7793b9b38..cd81888eb 100644 --- a/spec/views/public_body/show.rhtml_spec.rb +++ b/spec/views/public_body/show.rhtml_spec.rb @@ -1,7 +1,6 @@ require File.dirname(__FILE__) + '/../../spec_helper' describe "when viewing a body" do - before do @pb = mock_model(PublicBody, :name => 'Test Quango', @@ -28,6 +27,8 @@ describe "when viewing a body" do assigns[:xapian_requests] = @xap assigns[:page] = 1 assigns[:per_page] = 10 + # work round a bug in ActionController::TestRequest; allows request.query_string to work in the template + request.env["REQUEST_URI"] = "" end it "should be successful" do @@ -47,11 +48,11 @@ describe "when viewing a body" do it "should tell total number of requests" do render "public_body/show" - response.should include_text("4 Freedom of Information requests made") + response.should include_text("4 Freedom of Information requests") end it "should cope with no results" do - @xap.stub!(:results).and_return([]) + @pb.stub!(:info_requests).and_return([]) render "public_body/show" response.should have_tag("p", /Nobody has made any Freedom of Information requests/m) end @@ -67,10 +68,10 @@ describe "when viewing a body" do @pb.stub!(:get_tag_values).and_return(['98765', '12345']) render "public_body/show" - response.should have_tag("div#request_sidebar") do + response.should have_tag("div#header_right") do with_tag("a[href*=?]", /charity-commission.gov.uk.*RegisteredCharityNumber=98765$/) end - response.should have_tag("div#request_sidebar") do + response.should have_tag("div#header_right") do with_tag("a[href*=?]", /charity-commission.gov.uk.*RegisteredCharityNumber=12345$/) end end @@ -80,7 +81,7 @@ describe "when viewing a body" do @pb.stub!(:get_tag_values).and_return(['SC1234']) render "public_body/show" - response.should have_tag("div#request_sidebar") do + response.should have_tag("div#header_right") do with_tag("a[href*=?]", /www.oscr.org.uk.*id=SC1234$/) end end @@ -88,7 +89,7 @@ describe "when viewing a body" do it "should not link to Charity Commission site if we don't have number" do render "public_body/show" - response.should have_tag("div#request_sidebar") do + response.should have_tag("div#header_right") do without_tag("a[href*=?]", /charity-commission.gov.uk/) end end diff --git a/spec/views/request/_after_actions.rhtml_spec.rb b/spec/views/request/_after_actions.rhtml_spec.rb index a92ef2dda..c73f35d33 100644 --- a/spec/views/request/_after_actions.rhtml_spec.rb +++ b/spec/views/request/_after_actions.rhtml_spec.rb @@ -79,30 +79,5 @@ describe 'when displaying actions that can be taken with regard to a request' do it 'should display a link for the request owner to request a review' do expect_owner_link('Request an internal review') end - - describe 'when there is no last response' do - - before do - assigns[:last_response] = nil - end - - it 'should display a link for the request owner to send a follow up' do - expect_owner_link('Send follow up to test public body') - end - - end - - describe 'when there is a last response' do - before do - assigns[:last_response] = mock_model(IncomingMessage, - :valid_to_reply_to? => false) - end - - it 'should display a link for the request owner to reply to the last response' do - expect_owner_link('Reply to test public body') - end - - end - -end
\ No newline at end of file +end diff --git a/spec/views/request/list.rhtml_spec.rb b/spec/views/request/list.rhtml_spec.rb index 578bd5cc8..60a28eec5 100644 --- a/spec/views/request/list.rhtml_spec.rb +++ b/spec/views/request/list.rhtml_spec.rb @@ -5,7 +5,8 @@ describe "when listing recent requests" do before do assigns[:page] = 1 assigns[:per_page] = 10 - + # work round a bug in ActionController::TestRequest; allows request.query_string to work in the template + request.env["REQUEST_URI"] = "" # we're not testing the interlock plugin's cache template.stub!(:view_cache).and_yield end @@ -32,9 +33,7 @@ describe "when listing recent requests" do it "should be successful" do assigns[:list_results] = [ make_mock_event, make_mock_event ] assigns[:matches_estimated] = 2 - render "request/list" - response.should have_tag("div.request_listing") response.should_not have_tag("p", /No requests of this sort yet/m) end @@ -42,7 +41,6 @@ describe "when listing recent requests" do it "should cope with no results" do assigns[:list_results] = [ ] assigns[:matches_estimated] = 0 - render "request/list" response.should have_tag("p", /No requests of this sort yet/m) response.should_not have_tag("div.request_listing") |