aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/admin_public_body_categories_controller_spec.rb2
-rw-r--r--spec/helpers/health_checks_helper_spec.rb5
-rw-r--r--spec/integration/admin_public_body_edit_spec.rb2
-rw-r--r--spec/integration/xapian_search_highlighting_spec.rb15
-rw-r--r--spec/lib/alaveteli_text_masker_spec.rb17
-rw-r--r--spec/lib/mail_handler/mail_handler_spec.rb4
-rw-r--r--spec/mailers/request_mailer_spec.rb46
-rw-r--r--spec/models/info_request_batch_spec.rb2
-rw-r--r--spec/models/info_request_spec.rb17
-rw-r--r--spec/models/public_body_spec.rb27
-rw-r--r--spec/spec_helper.rb7
-rw-r--r--spec/views/public_body/show.html.erb_spec.rb1
12 files changed, 131 insertions, 14 deletions
diff --git a/spec/controllers/admin_public_body_categories_controller_spec.rb b/spec/controllers/admin_public_body_categories_controller_spec.rb
index 1131b3c0b..c15ee77f1 100644
--- a/spec/controllers/admin_public_body_categories_controller_spec.rb
+++ b/spec/controllers/admin_public_body_categories_controller_spec.rb
@@ -310,7 +310,7 @@ describe AdminPublicBodyCategoriesController do
post :update, :id => category.id,
:public_body_category => category.serializable_hash.except(:title, :description)
- expect(assigns(:tagged_public_bodies)).to eq(expected_bodies)
+ expect(assigns(:tagged_public_bodies)).to match_array(expected_bodies)
end
it "saves edits to a public body category's heading associations" do
diff --git a/spec/helpers/health_checks_helper_spec.rb b/spec/helpers/health_checks_helper_spec.rb
index 7d4083da5..7dbfaf06e 100644
--- a/spec/helpers/health_checks_helper_spec.rb
+++ b/spec/helpers/health_checks_helper_spec.rb
@@ -10,6 +10,11 @@ describe HealthChecksHelper do
expect(check_status(check)).to include('red')
end
+ it 'sets style to a blank string if ok' do
+ check = double(:message => '', :ok? => true)
+ expect(check_status(check)).to include('style=""')
+ end
+
end
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/xapian_search_highlighting_spec.rb b/spec/integration/xapian_search_highlighting_spec.rb
index 65a34cf91..a91df341f 100644
--- a/spec/integration/xapian_search_highlighting_spec.rb
+++ b/spec/integration/xapian_search_highlighting_spec.rb
@@ -1,8 +1,14 @@
+# encoding: utf-8
+
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)
@@ -36,4 +42,13 @@ describe 'highlighting search results' do
highlight_matches(phrase, matches).should == '<mark>boring</mark>'
end
+ it 'handles macrons correctly' do
+ phrase = 'Māori'
+
+ search = ActsAsXapian::Search.new([PublicBody], phrase, :limit => 1)
+ matches = search.words_to_highlight(:regex => true, :include_original => true)
+
+ highlight_matches(phrase, matches).should == '<mark>Māori</mark>'
+ end
+
end
diff --git a/spec/lib/alaveteli_text_masker_spec.rb b/spec/lib/alaveteli_text_masker_spec.rb
index 1a4782a83..102d2582e 100644
--- a/spec/lib/alaveteli_text_masker_spec.rb
+++ b/spec/lib/alaveteli_text_masker_spec.rb
@@ -92,6 +92,23 @@ describe AlaveteliTextMasker do
pdf.should_not == ""
end
+ it 'should keep the uncensored original if uncompression of a PDF fails' do
+ orig_pdf = load_file_fixture('tfl.pdf')
+ pdf = orig_pdf.dup
+ stub!(:uncompress_pdf).and_return nil
+ apply_masks!(pdf, "application/pdf")
+ pdf.should == orig_pdf
+ end
+
+ it 'should use the uncompressed PDF text if re-compression of a compressed PDF fails' do
+ orig_pdf = load_file_fixture('tfl.pdf')
+ pdf = orig_pdf.dup
+ stub!(:uncompress_pdf).and_return "something about foi@tfl.gov.uk"
+ stub!(:compress_pdf).and_return nil
+ apply_masks!(pdf, "application/pdf")
+ pdf.should match "something about xxx@xxx.xxx.xx"
+ end
+
it "should apply hard-coded privacy rules to HTML files" do
data = "http://test.host/c/cheese"
apply_masks!(data, 'text/html')
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/mailers/request_mailer_spec.rb b/spec/mailers/request_mailer_spec.rb
index 9e98dbc00..6b54c25d2 100644
--- a/spec/mailers/request_mailer_spec.rb
+++ b/spec/mailers/request_mailer_spec.rb
@@ -1,6 +1,8 @@
# encoding: utf-8
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+# TODO: Combine all these separate "describe" blocks to tidy things up
+
describe RequestMailer, " when receiving incoming mail" do
before(:each) do
load_raw_emails_data
@@ -411,6 +413,10 @@ describe RequestMailer, 'when sending a new response email' do
@mail = RequestMailer.new_response(@info_request, @incoming_message)
end
+ it 'should not create HTML entities in the subject line' do
+ mail = RequestMailer.new_response(FactoryGirl.create(:info_request, :title => "Here's a request"), FactoryGirl.create(:incoming_message))
+ expect(mail.subject).to eq "New response to your FOI request - Here's a request"
+ end
end
describe RequestMailer, 'requires_admin' do
@@ -419,7 +425,7 @@ describe RequestMailer, 'requires_admin' do
:name => 'Bruce Jones')
@info_request = mock_model(InfoRequest, :user => user,
:described_state => 'error_message',
- :title => 'Test request',
+ :title => "It's a Test request",
:url_title => 'test_request',
:law_used_short => 'FOI',
:id => 123)
@@ -435,4 +441,42 @@ describe RequestMailer, 'requires_admin' do
mail.body.should include 'Something has gone wrong'
end
+ it 'should not create HTML entities in the subject line' do
+ expect(RequestMailer.requires_admin(@info_request).subject).to eq "FOI response requires admin (error_message) - It's a Test request"
+ end
+end
+
+describe RequestMailer, "overdue_alert" do
+ it 'should not create HTML entities in the subject line' do
+ mail = RequestMailer.overdue_alert(FactoryGirl.create(:info_request, :title => "Here's a request"), FactoryGirl.create(:user))
+ expect(mail.subject).to eq "Delayed response to your FOI request - Here's a request"
+ end
+end
+
+describe RequestMailer, "very_overdue_alert" do
+ it 'should not create HTML entities in the subject line' do
+ mail = RequestMailer.very_overdue_alert(FactoryGirl.create(:info_request, :title => "Here's a request"), FactoryGirl.create(:user))
+ expect(mail.subject).to eq "You're long overdue a response to your FOI request - Here's a request"
+ end
+end
+
+describe RequestMailer, "not_clarified_alert" do
+ it 'should not create HTML entities in the subject line' do
+ mail = RequestMailer.not_clarified_alert(FactoryGirl.create(:info_request, :title => "Here's a request"), FactoryGirl.create(:incoming_message))
+ expect(mail.subject).to eq "Clarify your FOI request - Here's a request"
+ end
+end
+
+describe RequestMailer, "comment_on_alert" do
+ it 'should not create HTML entities in the subject line' do
+ mail = RequestMailer.comment_on_alert(FactoryGirl.create(:info_request, :title => "Here's a request"), FactoryGirl.create(:comment))
+ expect(mail.subject).to eq "Somebody added a note to your FOI request - Here's a request"
+ end
+end
+
+describe RequestMailer, "comment_on_alert_plural" do
+ it 'should not create HTML entities in the subject line' do
+ mail = RequestMailer.comment_on_alert_plural(FactoryGirl.create(:info_request, :title => "Here's a request"), 2, FactoryGirl.create(:comment))
+ expect(mail.subject).to eq "Some notes have been added to your FOI request - Here's a request"
+ end
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/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index 70947584b..d8c0c59b1 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -1221,6 +1221,7 @@ describe InfoRequest do
describe InfoRequest, "when constructing a list of requests by query" do
before(:each) do
+ load_raw_emails_data
get_fixtures_xapian_index
end
@@ -1313,4 +1314,20 @@ describe InfoRequest do
end
+
+ describe 'when destroying a message' do
+
+ it 'can destroy a request with comments and censor rules' do
+ info_request = FactoryGirl.create(:info_request)
+ censor_rule = FactoryGirl.create(:censor_rule, :info_request => info_request)
+ comment = FactoryGirl.create(:comment, :info_request => info_request)
+ info_request.reload
+ info_request.fully_destroy
+
+ InfoRequest.where(:id => info_request.id).should be_empty
+ CensorRule.where(:id => censor_rule.id).should be_empty
+ Comment.where(:id => comment.id).should be_empty
+ end
+
+ end
end
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index 7b55efda1..cce017424 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -1237,6 +1237,33 @@ describe PublicBody do
end
+ describe :request_email do
+ context "when the email is set" do
+ subject(:public_body) { FactoryGirl.create(:public_body, :request_email => "request@example.com") }
+
+ it "should return the set email address" do
+ expect(public_body.request_email).to eq("request@example.com")
+ end
+
+ it "should return a different email address when overridden in configuration" do
+ AlaveteliConfiguration.stub!(:override_all_public_body_request_emails).and_return("tester@example.com")
+ expect(public_body.request_email).to eq("tester@example.com")
+ end
+ end
+
+ context "when no email is set" do
+ subject(:public_body) { FactoryGirl.create(:public_body, :request_email => "") }
+
+ it "should return a blank email address" do
+ expect(public_body.request_email).to be_blank
+ end
+
+ it "should still return a blank email address when overridden in configuration" do
+ AlaveteliConfiguration.stub!(:override_all_public_body_request_emails).and_return("tester@example.com")
+ expect(public_body.request_email).to be_blank
+ end
+ end
+ end
end
describe PublicBody::Translation do
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:
diff --git a/spec/views/public_body/show.html.erb_spec.rb b/spec/views/public_body/show.html.erb_spec.rb
index 6ebc39caa..2a4c21d04 100644
--- a/spec/views/public_body/show.html.erb_spec.rb
+++ b/spec/views/public_body/show.html.erb_spec.rb
@@ -13,7 +13,6 @@ describe "public_body/show" do
:publication_scheme => '',
:disclosure_log => '',
:calculated_home_page => '')
- @pb.stub!(:override_request_email).and_return(nil)
@pb.stub!(:is_requestable?).and_return(true)
@pb.stub!(:special_not_requestable_reason?).and_return(false)
@pb.stub!(:has_notes?).and_return(false)