aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/application_controller_spec.rb27
-rw-r--r--spec/controllers/general_controller_spec.rb12
-rw-r--r--spec/controllers/request_controller_spec.rb20
-rw-r--r--spec/integration/errors_spec.rb9
-rw-r--r--spec/integration/search_request_spec.rb4
-rw-r--r--spec/spec_helper.rb14
6 files changed, 66 insertions, 20 deletions
diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb
index 875d7d224..1d6802940 100644
--- a/spec/controllers/application_controller_spec.rb
+++ b/spec/controllers/application_controller_spec.rb
@@ -1,10 +1,25 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+require 'fakeweb'
-describe ApplicationController, "when authenticating user" do
- integrate_views
- fixtures :users
-
-# it "blah" do
-# end
+describe ApplicationController, "when accessing third party services" do
+ it "should fail silently if the country_from_ip domain doesn't exist" do
+ config = MySociety::Config.load_default()
+ config['GAZE_URL'] = 'http://12123sdf14qsd.com'
+ country = self.controller.send :country_from_ip
+ country.should == config['ISO_COUNTRY_CODE']
+ end
+ it "should fail silently if the country_from_ip service doesn't exist" do
+ config = MySociety::Config.load_default()
+ config['GAZE_URL'] = 'http://www.google.com'
+ country = self.controller.send :country_from_ip
+ country.should == config['ISO_COUNTRY_CODE']
+ end
+ it "should fail silently if the country_from_ip service returns an error" do
+ FakeWeb.register_uri(:get, %r|.*|, :body => "Error", :status => ["500", "Error"])
+ config = MySociety::Config.load_default()
+ config['GAZE_URL'] = 'http://500.com'
+ country = self.controller.send :country_from_ip
+ country.should == config['ISO_COUNTRY_CODE']
+ end
end
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index 40a676d61..e1539fa68 100644
--- a/spec/controllers/general_controller_spec.rb
+++ b/spec/controllers/general_controller_spec.rb
@@ -1,4 +1,14 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+require 'fakeweb'
+
+describe GeneralController, "when trying to show the blog" do
+ it "should fail silently if the blog is returning an error" do
+ FakeWeb.register_uri(:get, %r|.*|, :body => "Error", :status => ["500", "Error"])
+ get :blog
+ response.status.should == "200 OK"
+ assigns[:blog_items].count.should == 0
+ end
+end
describe GeneralController, "when searching" do
integrate_views
@@ -68,7 +78,7 @@ describe GeneralController, "when searching" do
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", :view => "requests") # URL /search/:query/all
+ response.should redirect_to(:action => 'search', :combined => "mouse", :view => "all") # URL /search/:query/all
end
describe "when using different locale settings" do
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 40cb168f4..86665a793 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -12,12 +12,12 @@ describe RequestController, "when listing recent requests" do
end
it "should be successful" do
- get :list, :view => 'recent'
+ get :list, :view => 'all'
response.should be_success
end
it "should render with 'list' template" do
- get :list, :view => 'recent'
+ get :list, :view => 'all'
response.should render_template('list')
end
@@ -58,7 +58,7 @@ describe RequestController, "when listing recent requests" do
InfoRequest.should_receive(:full_search).
with([InfoRequestEvent]," (variety:sent OR variety:followup_sent OR variety:response OR variety:comment)", "created_at", anything, anything, anything, anything).
and_return(xap_results)
- get :list, :view => 'recent'
+ get :list, :view => 'all'
assigns[:list_results].size.should == 25
end
end
@@ -450,7 +450,9 @@ describe RequestController, "when searching for an authority" do
"Request for communications between DCMS/Ed Vaizey and ICO from Jan 1st 2011 - May ",
"Bellevue Road Ryde Isle of Wight PO33 2AR - what is the",
"NHS Ayrshire & Arran",
- " cardiff"]
+ " cardiff",
+ "Foo * bax",
+ "qux ~ quux"]
lambda {
get :select_authority, :query => phrase
}.should_not raise_error(StandardError)
@@ -1518,12 +1520,20 @@ describe RequestController, "when doing type ahead searches" do
assigns[:xapian_requests].should be_nil
end
+ it "should do partial matches for longer words" do
+ get :search_typeahead, :q => "chick"
+ response.should render_template('request/_search_ahead.rhtml')
+ assigns[:xapian_requests].results.size.should ==1
+ end
+
it "should not give an error when user users unintended search operators" do
for phrase in ["Marketing/PR activities - Aldborough E-Act Free Schoo",
"Request for communications between DCMS/Ed Vaizey and ICO from Jan 1st 2011 - May ",
"Bellevue Road Ryde Isle of Wight PO33 2AR - what is the",
"NHS Ayrshire & Arran",
- "uda ( units of dent"]
+ "uda ( units of dent",
+ "frob * baz",
+ "bar ~ qux"]
lambda {
get :search_typeahead, :q => phrase
}.should_not raise_error(StandardError)
diff --git a/spec/integration/errors_spec.rb b/spec/integration/errors_spec.rb
index 705c1fff8..d03323445 100644
--- a/spec/integration/errors_spec.rb
+++ b/spec/integration/errors_spec.rb
@@ -46,10 +46,13 @@ describe "When rendering errors" do
response.code.should == "500"
end
it "should render a 403 for attempts at directory listing for attachments" do
- get("/request/5/response/4/attach/html/3/" )
- response.code.should == "403"
- get("/request/5/response/4/attach/html" )
+ # make a fake cache
+ foi_cache_path = File.join(File.dirname(__FILE__), '../../cache')
+ FileUtils.mkdir_p(File.join(foi_cache_path, "views/en/request/101/101/response/1/attach/html/1"))
+ get("/request/101/response/1/attach/html/1/" )
response.code.should == "403"
+ get("/request/101/response/1/attach/html" )
+ response.code.should == "403"
end
it "should render a 404 for non-existent 'details' pages for requests" do
get("/details/request/wobble" )
diff --git a/spec/integration/search_request_spec.rb b/spec/integration/search_request_spec.rb
index 07839af32..5733dea22 100644
--- a/spec/integration/search_request_spec.rb
+++ b/spec/integration/search_request_spec.rb
@@ -48,7 +48,7 @@ describe "When searching" do
request_via_redirect("post", "/search",
:query => "bob",
:latest_status => ['successful'])
- response.body.should include("no requests matching your query")
+ response.body.should include("no results matching your query")
end
it "should correctly filter searches for comments" do
@@ -60,7 +60,7 @@ describe "When searching" do
request_via_redirect("post", "/search",
:query => "daftest",
:request_variety => ['response','sent'])
- response.body.should include("no requests matching your query")
+ response.body.should include("no results matching your query")
end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 6c3a947ba..e58c3890a 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -121,16 +121,24 @@ def validate_as_body(html)
end
def basic_auth_login(request, username = nil, password = nil)
- username = MySociety::Config.get('ADMIN_USERNAME') if username.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
# Monkeypatch! Validate HTML in tests.
-$html_validation_script = "/usr/bin/validate" # from Debian package wdg-html-validator
+utility_search_path = MySociety::Config.get("UTILITY_SEARCH_PATH", ["/usr/bin", "/usr/local/bin"])
+$html_validation_script_found = false
+utility_search_path.each do |d|
+ $html_validation_script = File.join(d, "validate")
+ if File.file? $html_validation_script and File.executable? $html_validation_script
+ $html_validation_script_found = true
+ break
+ end
+end
if $tempfilecount.nil?
$tempfilecount = 0
- if File.exist?($html_validation_script)
+ if $html_validation_script_found
module ActionController
module TestProcess
# Hook into the process function, so can automatically get HTML after each request