aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers')
-rw-r--r--spec/controllers/admin_general_controller_spec.rb8
-rw-r--r--spec/controllers/admin_public_body_controller_spec.rb12
-rw-r--r--spec/controllers/admin_request_controller_spec.rb62
-rw-r--r--spec/controllers/general_controller_spec.rb46
-rw-r--r--spec/controllers/public_body_controller_spec.rb4
-rw-r--r--spec/controllers/request_controller_spec.rb12
-rw-r--r--spec/controllers/track_controller_spec.rb14
-rw-r--r--spec/controllers/user_controller_spec.rb4
8 files changed, 139 insertions, 23 deletions
diff --git a/spec/controllers/admin_general_controller_spec.rb b/spec/controllers/admin_general_controller_spec.rb
index 4c3708268..820d1e7f3 100644
--- a/spec/controllers/admin_general_controller_spec.rb
+++ b/spec/controllers/admin_general_controller_spec.rb
@@ -5,8 +5,14 @@ describe AdminGeneralController, "when viewing front page of admin interface" do
before { basic_auth_login @request }
it "should render the front page" do
- get :index
+ get :index, :suppress_redirect => 1
response.should render_template('index')
end
+ it "should redirect to include trailing slash" do
+ get :index
+ response.should redirect_to(:controller => 'admin_general',
+ :action => 'index')
+ end
+
end
diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb
index 6b88fe39d..357564211 100644
--- a/spec/controllers/admin_public_body_controller_spec.rb
+++ b/spec/controllers/admin_public_body_controller_spec.rb
@@ -110,27 +110,27 @@ describe AdminPublicBodyController, "when administering public bodies with i18n"
end
it "creates a new public body" do
- I18n.locale = :es
+ 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.locale = :en
+ I18n.default_locale = :en
end
it "edits a public body" do
- I18n.locale = :es
+ I18n.default_locale = :es
get :edit, {:id => 3, :locale => :es}
response.body.should include('Baguette')
- I18n.locale = :en
+ I18n.default_locale = :en
end
it "saves edits to a public body" do
- I18n.locale = :es
+ 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.locale = :en
+ I18n.default_locale = :en
pb = PublicBody.find(public_bodies(:humpadink_public_body).id)
PublicBody.with_locale(:es) do
diff --git a/spec/controllers/admin_request_controller_spec.rb b/spec/controllers/admin_request_controller_spec.rb
index d82e4a49c..423c2fb49 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
+ fixtures :info_requests, :outgoing_messages, :users, :info_request_events, :public_bodies, :public_body_translations
before { basic_auth_login @request }
it "shows the index/list page" do
@@ -39,3 +39,63 @@ describe AdminRequestController, "when administering requests" do
end
+describe AdminRequestController, "when administering the holding pen" do
+ integrate_views
+ fixtures :info_requests, :incoming_messages, :raw_emails, :users, :public_bodies, :public_body_translations
+ before(:each) do
+ basic_auth_login @request
+ load_raw_emails_data(raw_emails)
+ end
+
+ it "shows a rejection reason for an incoming message from an invalid address" do
+ ir = info_requests(:fancy_dog_request)
+ ir.allow_new_responses_from = 'authority_only'
+ ir.handle_rejected_responses = 'holding_pen'
+ ir.save!
+ receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "frob@nowhere.com")
+ get :show_raw_email, :id => InfoRequest.holding_pen_request.get_last_response.raw_email.id
+ response.should have_text(/Only the authority can reply to this request/)
+ end
+
+ it "allows redelivery even to a closed request" do
+ ir = info_requests(:fancy_dog_request)
+ ir.allow_new_responses_from = 'nobody'
+ ir.handle_rejected_responses = 'holding_pen'
+ ir.save!
+ InfoRequest.holding_pen_request.incoming_messages.length.should == 0
+ ir.incoming_messages.length.should == 1
+ receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "frob@nowhere.com")
+ InfoRequest.holding_pen_request.incoming_messages.length.should == 1
+ new_im = InfoRequest.holding_pen_request.incoming_messages[0]
+ ir.incoming_messages.length.should == 1
+ 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')
+ InfoRequest.holding_pen_request.incoming_messages.length.should == 0
+ end
+
+ it "guesses a misdirected request" do
+ ir = info_requests(:fancy_dog_request)
+ ir.handle_rejected_responses = 'holding_pen'
+ ir.allow_new_responses_from = 'authority_only'
+ ir.save!
+ mail_to = "request-#{ir.id}-asdfg@example.com"
+ receive_incoming_mail('incoming-request-plain.email', mail_to)
+ interesting_email = InfoRequest.holding_pen_request.get_last_response.raw_email.id
+ # now we add another message to the queue, which we're not interested in
+ receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "")
+ InfoRequest.holding_pen_request.incoming_messages.length.should == 2
+ get :show_raw_email, :id => interesting_email
+ response.should have_text(/Could not identify the request/)
+ assigns[:info_requests][0].should == ir
+ end
+
+ it "destroys an incoming message" do
+ im = incoming_messages(:useless_incoming_message)
+ raw_email = im.raw_email.filepath
+ post :destroy_incoming, :incoming_message_id => im.id
+ assert_equal File.exists?(raw_email), false
+ end
+
+end
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index 7807a5541..76e1bb5e6 100644
--- a/spec/controllers/general_controller_spec.rb
+++ b/spec/controllers/general_controller_spec.rb
@@ -12,11 +12,57 @@ describe GeneralController, "when searching" do
:incoming_messages,
:comments ]
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ end
+
it "should render the front page successfully" do
get :frontpage
response.should be_success
end
+ it "should render the front page with default language" do
+ get :frontpage
+ response.should have_tag('html[lang="en"]')
+ end
+
+ it "should render the front page with default language" do
+ old_default_locale = I18n.default_locale
+ I18n.default_locale = "es"
+ get :frontpage
+ response.should have_tag('html[lang="es"]')
+ I18n.default_locale = old_default_locale
+ end
+
+ it "should render the front page with default language and ignore the browser setting" do
+ config = MySociety::Config.load_default()
+ config['USE_DEFAULT_BROWSER_LANGUAGE'] = false
+ accept_language = "en-GB,en-US;q=0.8,en;q=0.6"
+ request.env['HTTP_ACCEPT_LANGUAGE'] = accept_language
+ old_default_locale = I18n.default_locale
+ I18n.default_locale = "es"
+ get :frontpage
+ response.should have_tag('html[lang="es"]')
+ I18n.default_locale = old_default_locale
+ end
+
+ it "should render the front page with browser-selected language when there's no default set" do
+ config = MySociety::Config.load_default()
+ config['USE_DEFAULT_BROWSER_LANGUAGE'] = true
+ accept_language = "es-ES,en-GB,en-US;q=0.8,en;q=0.6"
+ request.env['HTTP_ACCEPT_LANGUAGE'] = accept_language
+ get :frontpage
+ response.should have_tag('html[lang="es"]')
+ request.env['HTTP_ACCEPT_LANGUAGE'] = nil
+ end
+
+ it "doesn't raise an error when there's no user matching the one in the session" do
+ session[:user_id] = 999
+ get :frontpage
+ 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
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb
index f157d4ac4..dd5fbb8bd 100644
--- a/spec/controllers/public_body_controller_spec.rb
+++ b/spec/controllers/public_body_controller_spec.rb
@@ -72,13 +72,13 @@ describe PublicBodyController, "when listing bodies" do
end
it "should list bodies in alphabetical order with different locale" do
- I18n.locale = :es
+ I18n.default_locale = :es
get :list
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"
- I18n.locale = :en
+ I18n.default_locale = :en
end
it "should list a tagged thing on the appropriate list page, and others on the other page, and all still on the all page" do
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index ffb9861f7..516aa602f 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -7,8 +7,10 @@ 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
+
before(:each) do
+ load_raw_emails_data(raw_emails)
rebuild_xapian_index
end
@@ -496,7 +498,7 @@ 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
- before do
+ before(:each) do
@dog_request = info_requests(:fancy_dog_request)
@dog_request.stub!(:is_old_unclassified?).and_return(false)
InfoRequest.stub!(:find).and_return(@dog_request)
@@ -831,7 +833,11 @@ 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
-
+
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ end
+
it "should require login" do
post :show_response, :outgoing_message => { :body => "What a useless response! You suck.", :what_doing => 'normal_sort' }, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :submitted_followup => 1
post_redirect = PostRedirect.get_last_post_redirect
diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb
index f7002a9d4..2f3f903f9 100644
--- a/spec/controllers/track_controller_spec.rb
+++ b/spec/controllers/track_controller_spec.rb
@@ -37,14 +37,12 @@ describe TrackController, "when sending alerts for a track" do
integrate_views
fixtures :info_requests, :outgoing_messages, :incoming_messages, :raw_emails, :info_request_events, :users, :track_things, :track_things_sent_emails, :public_bodies, :public_body_translations
include LinkToHelper # for main_url
+
before(:each) do
load_raw_emails_data(raw_emails)
- end
-
- before do
rebuild_xapian_index
end
-
+
it "should send alerts" do
# Don't do clever locale-insertion-unto-URL stuff
ActionController::Routing::Routes.filters.clear
@@ -101,9 +99,9 @@ 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
- before do
- rebuild_xapian_index
+ before(:each) do
load_raw_emails_data(raw_emails)
+ rebuild_xapian_index
end
it "should get the RSS feed" do
@@ -127,9 +125,9 @@ 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
- before do
- rebuild_xapian_index
+ before(:each) do
load_raw_emails_data(raw_emails)
+ rebuild_xapian_index
end
it "should get the feed" do
diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb
index 0b5e96711..c974c8a0d 100644
--- a/spec/controllers/user_controller_spec.rb
+++ b/spec/controllers/user_controller_spec.rb
@@ -179,7 +179,7 @@ describe UserController, "when signing up" do
deliveries = ActionMailer::Base.deliveries
deliveries.size.should == 1
- deliveries[0].body.should include("have an account")
+ deliveries[0].body.should include("when you already have an")
end
# XXX need to do bob@localhost signup and check that sends different email
@@ -236,7 +236,7 @@ describe UserController, "when sending another user a message" do
deliveries = ActionMailer::Base.deliveries
deliveries.size.should == 1
mail = deliveries[0]
- mail.body.should include("Bob Smith has used WhatDoTheyKnow to send you the message below")
+ mail.body.should include("Bob Smith has used #{MySociety::Config.get('SITE_NAME')} to send you the message below")
mail.body.should include("Just a test!")
#mail.to_addrs.to_s.should == users(:silly_name_user).name_and_email # XXX fix some nastiness with quoting name_and_email
mail.from_addrs.to_s.should == users(:bob_smith_user).name_and_email