diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/public_body_controller_spec.rb | 7 | ||||
-rw-r--r-- | spec/helpers/public_body_helper_spec.rb | 2 | ||||
-rw-r--r-- | spec/integration/admin_public_body_edit_spec.rb | 2 | ||||
-rw-r--r-- | spec/integration/alaveteli_dsl.rb | 9 | ||||
-rw-r--r-- | spec/integration/search_request_spec.rb | 28 | ||||
-rw-r--r-- | spec/integration/xapian_search_highlighting_spec.rb | 4 | ||||
-rw-r--r-- | spec/lib/mail_handler/mail_handler_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/info_request_batch_spec.rb | 2 | ||||
-rw-r--r-- | spec/spec_helper.rb | 7 |
9 files changed, 45 insertions, 20 deletions
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index 130631ef6..ff0a70a6f 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -82,6 +82,13 @@ describe PublicBodyController, "when showing a body" do expect(flash[:search_params]).to eq(search_params) end + + it 'should not show high page offsets as these are extremely slow to generate' do + lambda { + get :show, { :url_name => 'dfh', :view => 'all', :page => 25 } + }.should raise_error(ActiveRecord::RecordNotFound) + end + end describe PublicBodyController, "when listing bodies" do diff --git a/spec/helpers/public_body_helper_spec.rb b/spec/helpers/public_body_helper_spec.rb index 0bf55abb4..d4f3acf78 100644 --- a/spec/helpers/public_body_helper_spec.rb +++ b/spec/helpers/public_body_helper_spec.rb @@ -74,7 +74,7 @@ describe PublicBodyHelper do :description => "spec category #{i}") heading.add_category(category) end - public_body = FactoryGirl.create(:public_body, :tag_string => 'spec_0 spec_2 unknown') + public_body = FactoryGirl.create(:public_body, :tag_string => 'unknown spec_0 spec_2') expected = '<a href="/body/list/spec_0">Spec category 0</a> and <a href="/body/list/spec_2">spec category 2</a>' expect(type_of_authority(public_body)).to eq(expected) end diff --git a/spec/integration/admin_public_body_edit_spec.rb b/spec/integration/admin_public_body_edit_spec.rb index aeec3e65a..21011b172 100644 --- a/spec/integration/admin_public_body_edit_spec.rb +++ b/spec/integration/admin_public_body_edit_spec.rb @@ -39,7 +39,7 @@ describe 'Editing a Public Body' do end end - it 'can add a translation for multiple locales', :focus => true do + it 'can add a translation for multiple locales' do @admin.visit edit_admin_body_path(@body) @admin.fill_in 'public_body_name__en', :with => 'New Quango EN' @admin.click_button 'Save' diff --git a/spec/integration/alaveteli_dsl.rb b/spec/integration/alaveteli_dsl.rb index 370628d98..d7485a094 100644 --- a/spec/integration/alaveteli_dsl.rb +++ b/spec/integration/alaveteli_dsl.rb @@ -74,5 +74,14 @@ def cache_directories_exist?(request) paths.any?{ |path| File.exist?(path) } end +def with_forgery_protection + orig = ActionController::Base.allow_forgery_protection + begin + ActionController::Base.allow_forgery_protection = true + yield if block_given? + ensure + ActionController::Base.allow_forgery_protection = orig + end +end diff --git a/spec/integration/search_request_spec.rb b/spec/integration/search_request_spec.rb index 23a62e97b..699eb2c6c 100644 --- a/spec/integration/search_request_spec.rb +++ b/spec/integration/search_request_spec.rb @@ -1,4 +1,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl') describe "When searching" do @@ -8,24 +9,35 @@ describe "When searching" do end it "should not strip quotes from quoted query" do - request_via_redirect("post", "/search", :query => '"mouse stilton"') + request_via_redirect("get", "/search", :query => '"mouse stilton"') response.body.should include(""mouse stilton"") end it "should redirect requests with search in query string to URL-based page" do - post '/search/all?query=bob' + get '/search/all?query=bob' response.should redirect_to "/en/search/bob/all" end it "should correctly execute simple search" do - request_via_redirect("post", "/search", + request_via_redirect("get", "/search", :query => 'bob' ) response.body.should include("FOI requests") end + it "should not log a logged-in user out" do + with_forgery_protection do + user = FactoryGirl.create(:user) + user_session = login(user) + user_session.visit frontpage_path + user_session.fill_in "query", :with => 'test' + user_session.click_button "Search" + user_session.response.body.should include(user.name) + end + end + it "should correctly filter searches for requests" do - request_via_redirect("post", "/search/bob/requests") + request_via_redirect("get", "/search/bob/requests") response.body.should_not include("One person found") n = 4 # The number of requests that contain the word "bob" somewhere # in the email text. At present this is: @@ -39,13 +51,13 @@ describe "When searching" do response.body.should include("FOI requests 1 to #{n} of #{n}") end it "should correctly filter searches for users" do - request_via_redirect("post", "/search/bob/users") + request_via_redirect("get", "/search/bob/users") response.body.should include("One person found") response.body.should_not include("FOI requests 1 to") end it "should correctly filter searches for successful requests" do - request_via_redirect("post", "/search/requests", + request_via_redirect("get", "/search/requests", :query => "bob", :latest_status => ['successful']) n = 2 # The number of *successful* requests that contain the word "bob" somewhere @@ -56,12 +68,12 @@ describe "When searching" do end it "should correctly filter searches for comments" do - request_via_redirect("post", "/search/requests", + request_via_redirect("get", "/search/requests", :query => "daftest", :request_variety => ['comments']) response.body.should include("One FOI request found") - request_via_redirect("post", "/search/requests", + request_via_redirect("get", "/search/requests", :query => "daftest", :request_variety => ['response','sent']) response.body.should include("no results matching your query") diff --git a/spec/integration/xapian_search_highlighting_spec.rb b/spec/integration/xapian_search_highlighting_spec.rb index 65a34cf91..b2994eb31 100644 --- a/spec/integration/xapian_search_highlighting_spec.rb +++ b/spec/integration/xapian_search_highlighting_spec.rb @@ -3,6 +3,10 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe 'highlighting search results' do include HighlightHelper + before do + get_fixtures_xapian_index + end + it 'ignores stopwords' do phrase = 'department of humpadinking' search = ActsAsXapian::Search.new([PublicBody], phrase, :limit => 1) diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index e7ad93300..ea7a99b05 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -9,7 +9,7 @@ end describe 'when creating a mail object from raw data' do - it "should be able to parse a large email without raising an exception", :focus => true do + it "should be able to parse a large email without raising an exception" do m = Mail.new m.add_file(:filename => "attachment.data", :content => "a" * (8 * 1024 * 1024)) raw_email = "From jamis_buck@byu.edu Mon May 2 16:07:05 2005\r\n#{m.to_s}" @@ -22,7 +22,7 @@ describe 'when creating a mail object from raw data' do mail.multipart?.should == true end - it "should not fail on invalid byte sequence in content-disposition header", :focus => true do + it "should not fail on invalid byte sequence in content-disposition header" do part = Mail::Part.new("Content-Disposition: inline; filename=a\xB8z\r\n\r\nThis is the body text.") lambda { part.inline? }.should_not raise_error end diff --git a/spec/models/info_request_batch_spec.rb b/spec/models/info_request_batch_spec.rb index 2881e7745..701422037 100644 --- a/spec/models/info_request_batch_spec.rb +++ b/spec/models/info_request_batch_spec.rb @@ -80,7 +80,7 @@ describe InfoRequestBatch, "when finding an existing batch" do end end -describe InfoRequestBatch, "when creating a batch", :focus => true do +describe InfoRequestBatch, "when creating a batch" do before do @title = 'A test title' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 93bcfa1ba..4df1b5649 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -124,13 +124,6 @@ Spork.prefork do end end - # TODO: No idea what namespace/class/module to put this in - # Create a clean xapian index based on the fixture files and the raw_email data. - def create_fixtures_xapian_index - load_raw_emails_data - rebuild_xapian_index - end - # Use the before create job hook to simulate a race condition with # another process by creating an acts_as_xapian_job record for the # same model: |