aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/general_controller_spec.rb30
-rw-r--r--spec/controllers/public_body_controller_spec.rb35
-rw-r--r--spec/controllers/request_controller_spec.rb34
-rw-r--r--spec/integration/errors_spec.rb61
-rw-r--r--spec/integration/search_request_spec.rb48
-rw-r--r--spec/views/public_body/show.rhtml_spec.rb13
-rw-r--r--spec/views/request/list.rhtml_spec.rb6
7 files changed, 195 insertions, 32 deletions
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index 3640a8148..4d7f1831d 100644
--- a/spec/controllers/general_controller_spec.rb
+++ b/spec/controllers/general_controller_spec.rb
@@ -64,7 +64,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") # URL /search/:query
+ response.should redirect_to(:action => 'search', :combined => "mouse", :view => "all") # URL /search/:query/all
end
describe "when using different locale settings" do
@@ -122,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..df3fc10dc 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
@@ -71,6 +78,16 @@ describe PublicBodyController, "when listing bodies" do
assigns[:description].should == "all"
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
I18n.default_locale = :es
get :list
@@ -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'
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index f69cf414c..f3084af12 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -1,7 +1,3 @@
-# £2k p/a
-# talk about margins
-#
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'json'
@@ -24,13 +20,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
@@ -149,7 +161,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
@@ -735,18 +747,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
diff --git a/spec/integration/errors_spec.rb b/spec/integration/errors_spec.rb
new file mode 100644
index 000000000..84a44c9c3
--- /dev/null
+++ b/spec/integration/errors_spec.rb
@@ -0,0 +1,61 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+module TestCustomStates
+ def self.included(base)
+ base.extend(ClassMethods)
+ end
+
+ module ClassMethods
+ def theme_extra_states
+ return ['crotchety']
+ end
+ end
+end
+
+
+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)
+ InfoRequest.send(:include, TestCustomStates)
+ InfoRequest.class_eval('@@custom_states_loaded = true')
+ ir.set_described_state("crotchety")
+ ir.save!
+ InfoRequest.class_eval('@@custom_states_loaded = false')
+ 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
index 9398519b7..84239f7a3 100644
--- a/spec/integration/search_request_spec.rb
+++ b/spec/integration/search_request_spec.rb
@@ -1,9 +1,57 @@
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
+ load_raw_emails_data(raw_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("One person matching")
+ end
+
+ it "should correctly filter searches for requests" do
+ request_via_redirect("post", "/search/bob/requests")
+ response.body.should_not include("One person matching")
+ response.body.should 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 matching your search")
+
+ 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/views/public_body/show.rhtml_spec.rb b/spec/views/public_body/show.rhtml_spec.rb
index 7793b9b38..797923c5d 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
@@ -51,7 +52,7 @@ describe "when viewing a body" do
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/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")