aboutsummaryrefslogtreecommitdiffstats
path: root/spec/lib
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/ability_spec.rb1
-rw-r--r--spec/lib/alaveteli_external_command_spec.rb1
-rw-r--r--spec/lib/alaveteli_text_masker_spec.rb28
-rw-r--r--spec/lib/attachment_to_html/adapters/could_not_convert_spec.rb1
-rw-r--r--spec/lib/attachment_to_html/adapters/google_docs_viewer_spec.rb1
-rw-r--r--spec/lib/attachment_to_html/adapters/pdf_spec.rb1
-rw-r--r--spec/lib/attachment_to_html/adapters/rtf_spec.rb1
-rw-r--r--spec/lib/attachment_to_html/adapters/text_spec.rb1
-rw-r--r--spec/lib/attachment_to_html/attachment_to_html_spec.rb1
-rw-r--r--spec/lib/attachment_to_html/view_spec.rb1
-rw-r--r--spec/lib/basic_encoding_spec.rb65
-rw-r--r--spec/lib/confidence_intervals_spec.rb1
-rw-r--r--spec/lib/date_quarter_spec.rb1
-rw-r--r--spec/lib/health_checks/checks/days_ago_check_spec.rb7
-rw-r--r--spec/lib/health_checks/health_checkable_spec.rb23
-rw-r--r--spec/lib/health_checks/health_checks_spec.rb7
-rw-r--r--spec/lib/i18n_interpolation_spec.rb6
-rw-r--r--spec/lib/languages_spec.rb22
-rw-r--r--spec/lib/mail_handler/backends/mail_backend_spec.rb11
-rw-r--r--spec/lib/mail_handler/mail_handler_spec.rb6
-rw-r--r--spec/lib/public_body_csv_spec.rb1
-rw-r--r--spec/lib/theme_spec.rb1
-rw-r--r--spec/lib/timezone_fixes_spec.rb1
-rw-r--r--spec/lib/whatdotheyknow/strip_empty_sessions_spec.rb1
24 files changed, 153 insertions, 37 deletions
diff --git a/spec/lib/ability_spec.rb b/spec/lib/ability_spec.rb
index f075d0f32..4c5d50990 100644
--- a/spec/lib/ability_spec.rb
+++ b/spec/lib/ability_spec.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe Ability do
diff --git a/spec/lib/alaveteli_external_command_spec.rb b/spec/lib/alaveteli_external_command_spec.rb
index 18afeda33..f76e26152 100644
--- a/spec/lib/alaveteli_external_command_spec.rb
+++ b/spec/lib/alaveteli_external_command_spec.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'alaveteli_external_command'
diff --git a/spec/lib/alaveteli_text_masker_spec.rb b/spec/lib/alaveteli_text_masker_spec.rb
index 1a4782a83..f8c22a849 100644
--- a/spec/lib/alaveteli_text_masker_spec.rb
+++ b/spec/lib/alaveteli_text_masker_spec.rb
@@ -1,4 +1,4 @@
-# -*- coding: utf-8 -*-
+# -*- encoding : utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe AlaveteliTextMasker do
@@ -31,10 +31,13 @@ describe AlaveteliTextMasker do
data.should == "There was a xxxxx called xxxxxxx, he wished that he was xxxx."
end
- it 'should handle multibyte characters correctly' do
+ it 'should handle multibyte characters in binary file types as binary data' do
data = 'á mouse'
+ if String.method_defined?(:encode)
+ data = data.force_encoding("ASCII-8BIT")
+ end
@regex_censor_rule.text = 'á'
- apply_masks!(data, "application/octet-stream", :censor_rules => @censor_rules).should == 'x mouse'
+ apply_masks!(data, "application/octet-stream", :censor_rules => @censor_rules).should == 'xx mouse'
end
it "should apply censor rules to HTML files" do
@@ -60,7 +63,7 @@ describe AlaveteliTextMasker do
end
def pdf_replacement_test(use_ghostscript_compression)
- config = MySociety::Config.load_default()
+ config = MySociety::Config.load_default
previous = config['USE_GHOSTSCRIPT_COMPRESSION']
config['USE_GHOSTSCRIPT_COMPRESSION'] = use_ghostscript_compression
orig_pdf = load_file_fixture('tfl.pdf')
@@ -92,6 +95,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/attachment_to_html/adapters/could_not_convert_spec.rb b/spec/lib/attachment_to_html/adapters/could_not_convert_spec.rb
index afdc5c552..040f02bae 100644
--- a/spec/lib/attachment_to_html/adapters/could_not_convert_spec.rb
+++ b/spec/lib/attachment_to_html/adapters/could_not_convert_spec.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe AttachmentToHTML::Adapters::CouldNotConvert do
diff --git a/spec/lib/attachment_to_html/adapters/google_docs_viewer_spec.rb b/spec/lib/attachment_to_html/adapters/google_docs_viewer_spec.rb
index e7aafb40d..b1a97ea9b 100644
--- a/spec/lib/attachment_to_html/adapters/google_docs_viewer_spec.rb
+++ b/spec/lib/attachment_to_html/adapters/google_docs_viewer_spec.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe AttachmentToHTML::Adapters::GoogleDocsViewer do
diff --git a/spec/lib/attachment_to_html/adapters/pdf_spec.rb b/spec/lib/attachment_to_html/adapters/pdf_spec.rb
index ceb438be8..f4b60fb93 100644
--- a/spec/lib/attachment_to_html/adapters/pdf_spec.rb
+++ b/spec/lib/attachment_to_html/adapters/pdf_spec.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe AttachmentToHTML::Adapters::PDF do
diff --git a/spec/lib/attachment_to_html/adapters/rtf_spec.rb b/spec/lib/attachment_to_html/adapters/rtf_spec.rb
index 2c53b5272..59aef69d1 100644
--- a/spec/lib/attachment_to_html/adapters/rtf_spec.rb
+++ b/spec/lib/attachment_to_html/adapters/rtf_spec.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe AttachmentToHTML::Adapters::RTF do
diff --git a/spec/lib/attachment_to_html/adapters/text_spec.rb b/spec/lib/attachment_to_html/adapters/text_spec.rb
index b2e8141e0..0eddacb05 100644
--- a/spec/lib/attachment_to_html/adapters/text_spec.rb
+++ b/spec/lib/attachment_to_html/adapters/text_spec.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe AttachmentToHTML::Adapters::Text do
diff --git a/spec/lib/attachment_to_html/attachment_to_html_spec.rb b/spec/lib/attachment_to_html/attachment_to_html_spec.rb
index 1cf7debb7..59c13f501 100644
--- a/spec/lib/attachment_to_html/attachment_to_html_spec.rb
+++ b/spec/lib/attachment_to_html/attachment_to_html_spec.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
describe AttachmentToHTML do
diff --git a/spec/lib/attachment_to_html/view_spec.rb b/spec/lib/attachment_to_html/view_spec.rb
index 50179b0f7..ffe2c0d2d 100644
--- a/spec/lib/attachment_to_html/view_spec.rb
+++ b/spec/lib/attachment_to_html/view_spec.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
describe AttachmentToHTML::View do
diff --git a/spec/lib/basic_encoding_spec.rb b/spec/lib/basic_encoding_spec.rb
index 43a65eab9..6758d60a3 100644
--- a/spec/lib/basic_encoding_spec.rb
+++ b/spec/lib/basic_encoding_spec.rb
@@ -1,4 +1,4 @@
-# -*- coding: utf-8 -*-
+# -*- encoding : utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
def bytes_to_binary_string( bytes, claimed_encoding = nil )
@@ -103,7 +103,7 @@ end
describe "convert_string_to_utf8_or_binary" do
- describe "when passed uniterpretable character data" do
+ describe "when passed uninterpretable character data" do
it "should return it as a binary string" do
@@ -155,3 +155,64 @@ describe "convert_string_to_utf8_or_binary" do
end
end
+
+describe "convert_string_to_utf8" do
+
+ describe "when passed uninterpretable character data" do
+
+ it "should return it as a valid utf8 string with non-utf8 characters removed
+ and mark it as scrubbed" do
+
+ converted = convert_string_to_utf8 random_string
+
+ if String.method_defined?(:encode)
+ converted.string.encoding.to_s.should == 'UTF-8'
+ converted.string.valid_encoding?.should == true
+ end
+ converted.scrubbed?.should == true
+
+ converted = convert_string_to_utf8 random_string,'UTF-8'
+
+ if String.method_defined?(:encode)
+ converted.string.encoding.to_s.should == 'UTF-8'
+ converted.string.valid_encoding?.should == true
+ end
+ converted.scrubbed?.should == true
+
+ end
+ end
+
+ describe "when passed unlabelled Windows 1252 data" do
+
+ it "should correctly convert it to UTF-8" do
+
+ converted = convert_string_to_utf8 windows_1252_string
+
+ converted.string.should == "DASH – DASH"
+
+ if String.method_defined?(:encode)
+ converted.string.encoding.to_s.should == 'UTF-8'
+ end
+ converted.scrubbed?.should == false
+
+ end
+
+ end
+
+ describe "when passed GB 18030 data" do
+
+ it "should correctly convert it to UTF-8 if unlabelled" do
+
+ converted = convert_string_to_utf8 gb_18030_spam_string
+
+ converted.string.should start_with("贵公司负责人")
+
+ if String.method_defined?(:encode)
+ converted.string.encoding.to_s.should == 'UTF-8'
+ end
+ converted.scrubbed?.should == false
+ end
+
+ end
+
+end \ No newline at end of file
diff --git a/spec/lib/confidence_intervals_spec.rb b/spec/lib/confidence_intervals_spec.rb
index cb8717f3d..58f1f3d79 100644
--- a/spec/lib/confidence_intervals_spec.rb
+++ b/spec/lib/confidence_intervals_spec.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
require 'confidence_intervals'
describe "ci_bounds" do
diff --git a/spec/lib/date_quarter_spec.rb b/spec/lib/date_quarter_spec.rb
index 5af6fa334..02d2c2551 100644
--- a/spec/lib/date_quarter_spec.rb
+++ b/spec/lib/date_quarter_spec.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe DateQuarter do
diff --git a/spec/lib/health_checks/checks/days_ago_check_spec.rb b/spec/lib/health_checks/checks/days_ago_check_spec.rb
index 33b4642cd..4fbc1913b 100644
--- a/spec/lib/health_checks/checks/days_ago_check_spec.rb
+++ b/spec/lib/health_checks/checks/days_ago_check_spec.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe HealthChecks::Checks::DaysAgoCheck do
@@ -15,16 +16,16 @@ describe HealthChecks::Checks::DaysAgoCheck do
expect(check.days).to eq(4)
end
- describe :check do
+ describe :ok? do
it 'is successful if the subject is in the last day' do
check = HealthChecks::Checks::DaysAgoCheck.new { Time.now }
- expect(check.check).to be_true
+ expect(check.ok?).to be_true
end
it 'fails if the subject is over a day ago' do
check = HealthChecks::Checks::DaysAgoCheck.new { 2.days.ago }
- expect(check.check).to be_false
+ expect(check.ok?).to be_false
end
end
diff --git a/spec/lib/health_checks/health_checkable_spec.rb b/spec/lib/health_checks/health_checkable_spec.rb
index abfeb5c21..59d76c337 100644
--- a/spec/lib/health_checks/health_checkable_spec.rb
+++ b/spec/lib/health_checks/health_checkable_spec.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
describe HealthChecks::HealthCheckable do
@@ -31,24 +32,10 @@ describe HealthChecks::HealthCheckable do
end
- describe :check do
-
- it 'is intended to be overridden by the includer' do
- expect{ @subject.check }.to raise_error(NotImplementedError)
- end
-
- end
-
describe :ok? do
- it 'returns true if the check was successful' do
- @subject.stub(:check => true)
- expect(@subject.ok?).to be_true
- end
-
- it 'returns false if the check failed' do
- @subject.stub(:check => false)
- expect(@subject.ok?).to be_false
+ it 'is intended to be overridden by the includer' do
+ expect{ @subject.ok? }.to raise_error(NotImplementedError)
end
end
@@ -92,7 +79,7 @@ describe HealthChecks::HealthCheckable do
context 'if the check succeeds' do
before(:each) do
- @subject.stub(:check => true)
+ @subject.stub(:ok? => true)
end
it 'returns the default success message' do
@@ -109,7 +96,7 @@ describe HealthChecks::HealthCheckable do
context 'if the check fails' do
before(:each) do
- @subject.stub(:check => false)
+ @subject.stub(:ok? => false)
end
it 'returns the default failure message' do
diff --git a/spec/lib/health_checks/health_checks_spec.rb b/spec/lib/health_checks/health_checks_spec.rb
index c7037b813..0b97725db 100644
--- a/spec/lib/health_checks/health_checks_spec.rb
+++ b/spec/lib/health_checks/health_checks_spec.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
describe HealthChecks do
@@ -6,7 +7,7 @@ describe HealthChecks do
describe :add do
it 'adds a check to the collection and returns the check' do
- check = double('MockCheck', :check => true)
+ check = double('MockCheck', :ok? => true)
expect(add(check)).to eq(check)
end
@@ -20,8 +21,8 @@ describe HealthChecks do
describe :all do
it 'returns all the checks' do
- check1 = double('MockCheck', :check => true)
- check2 = double('AnotherCheck', :check => false)
+ check1 = double('MockCheck', :ok? => true)
+ check2 = double('AnotherCheck', :ok? => false)
add(check1)
add(check2)
expect(all).to include(check1, check2)
diff --git a/spec/lib/i18n_interpolation_spec.rb b/spec/lib/i18n_interpolation_spec.rb
index 47037ecdb..8c5b8d1b5 100644
--- a/spec/lib/i18n_interpolation_spec.rb
+++ b/spec/lib/i18n_interpolation_spec.rb
@@ -1,4 +1,4 @@
-# -*- coding: utf-8 -*-
+# -*- encoding : utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe "when using i18n" do
@@ -58,7 +58,7 @@ describe "gettext_interpolate" do
result = gettext_interpolate(string, :a => "foo".html_safe)
result.should == "Hello foo"
result.should_not be_html_safe
- end
+ end
end
context "html safe string" do
@@ -74,6 +74,6 @@ describe "gettext_interpolate" do
result = gettext_interpolate(string, :a => "foo&".html_safe)
result.should == "Hello foo&"
result.should be_html_safe
- end
+ end
end
end
diff --git a/spec/lib/languages_spec.rb b/spec/lib/languages_spec.rb
new file mode 100644
index 000000000..38f611087
--- /dev/null
+++ b/spec/lib/languages_spec.rb
@@ -0,0 +1,22 @@
+# -*- encoding : utf-8 -*-
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe LanguageNames do
+
+ describe :get_language_name do
+
+ it 'should return the name assigned to the language' do
+ LanguageNames.get_language_name('en').should == 'English'
+ end
+
+ it 'should return the name assigned to the language when there is no specific location' do
+ LanguageNames.get_language_name('pt_BR').should == 'Português'
+ end
+
+ it 'should return the name assigned to the language/location combination' do
+ LanguageNames.get_language_name('zh_HK').should == '中文(香港)'
+ end
+
+ end
+
+end
diff --git a/spec/lib/mail_handler/backends/mail_backend_spec.rb b/spec/lib/mail_handler/backends/mail_backend_spec.rb
index eb1d4b167..91d9e1b5a 100644
--- a/spec/lib/mail_handler/backends/mail_backend_spec.rb
+++ b/spec/lib/mail_handler/backends/mail_backend_spec.rb
@@ -1,4 +1,4 @@
-# coding: utf-8
+# -*- encoding : utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '../../../../spec_helper')
describe MailHandler::Backends::MailBackend do
@@ -37,6 +37,15 @@ describe MailHandler::Backends::MailBackend do
get_part_file_name(part).should be_nil
end
+ it 'turns an invalid UTF-8 name into a valid one' do
+ mail = get_fixture_mail('non-utf8-filename.email')
+ part = mail.attachments.first
+ filename = get_part_file_name(part)
+ if filename.respond_to?(:valid_encoding)
+ filename.valid_encoding?.should == true
+ end
+ end
+
end
describe :get_part_body do
diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb
index be6da5c4f..27a7a3db4 100644
--- a/spec/lib/mail_handler/mail_handler_spec.rb
+++ b/spec/lib/mail_handler/mail_handler_spec.rb
@@ -1,4 +1,4 @@
-# coding: utf-8
+# -*- encoding : utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
def create_message_from(from_field)
@@ -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/lib/public_body_csv_spec.rb b/spec/lib/public_body_csv_spec.rb
index e3cc4be6e..5c57c9533 100644
--- a/spec/lib/public_body_csv_spec.rb
+++ b/spec/lib/public_body_csv_spec.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe PublicBodyCSV do
diff --git a/spec/lib/theme_spec.rb b/spec/lib/theme_spec.rb
index 829c1a269..b7259078f 100644
--- a/spec/lib/theme_spec.rb
+++ b/spec/lib/theme_spec.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe "theme_url_to_theme_name" do
diff --git a/spec/lib/timezone_fixes_spec.rb b/spec/lib/timezone_fixes_spec.rb
index 8a9a3bf31..c44479fd7 100644
--- a/spec/lib/timezone_fixes_spec.rb
+++ b/spec/lib/timezone_fixes_spec.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
# This is a test of the monkey patches in timezone_fixes.rb
# We use MailServerLogDone here just as a totally random model that has a datetime type.
diff --git a/spec/lib/whatdotheyknow/strip_empty_sessions_spec.rb b/spec/lib/whatdotheyknow/strip_empty_sessions_spec.rb
index fcd729b48..d4f668671 100644
--- a/spec/lib/whatdotheyknow/strip_empty_sessions_spec.rb
+++ b/spec/lib/whatdotheyknow/strip_empty_sessions_spec.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
describe WhatDoTheyKnow::StripEmptySessions do