aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/foi_attachment_spec.rb2
-rw-r--r--spec/models/incoming_message_spec.rb65
-rw-r--r--spec/models/outgoing_message_spec.rb19
-rw-r--r--spec/models/xapian_spec.rb26
4 files changed, 108 insertions, 4 deletions
diff --git a/spec/models/foi_attachment_spec.rb b/spec/models/foi_attachment_spec.rb
index 537a3363c..9b0115c44 100644
--- a/spec/models/foi_attachment_spec.rb
+++ b/spec/models/foi_attachment_spec.rb
@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-describe FoiAttachment, " when calculating due date" do
+describe FoiAttachment do
before(:each) do
load_raw_emails_data
diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb
index e22235298..03152f5ff 100644
--- a/spec/models/incoming_message_spec.rb
+++ b/spec/models/incoming_message_spec.rb
@@ -59,12 +59,19 @@ describe IncomingMessage, " when dealing with incoming mail" do
message.subject.should == "Câmara Responde: Banco de ideias"
end
- it 'should not error on display of a message which has no charset set on the body part and
- is not good utf-8' do
+ it 'should deal with GB18030 text even if the charset is missing' do
ir = info_requests(:fancy_dog_request)
receive_incoming_mail('no-part-charset-bad-utf8.email', ir.incoming_email)
message = ir.incoming_messages[1]
message.parse_raw_email!
+ message.get_main_body_text_internal.should include("贵公司负责人")
+ end
+
+ it 'should not error on display of a message which has no charset set on the body part and is not good UTF-8' do
+ ir = info_requests(:fancy_dog_request)
+ receive_incoming_mail('no-part-charset-random-data.email', ir.incoming_email)
+ message = ir.incoming_messages[1]
+ message.parse_raw_email!
message.get_main_body_text_internal.should include("The above text was badly encoded")
end
@@ -412,6 +419,17 @@ describe IncomingMessage, " when uudecoding bad messages" do
im.get_attachments_for_display.size.should == 1
end
+ it "should still work when parsed from the raw email" do
+ raw_email = load_file_fixture 'inline-uuencode.email'
+ mail = MailHandler.mail_from_raw_email(raw_email)
+ im = incoming_messages :useless_incoming_message
+ im.stub!(:raw_email).and_return(raw_email)
+ im.stub!(:mail).and_return(mail)
+ im.parse_raw_email!
+ attachments = im.foi_attachments
+ attachments.size.should == 2
+ end
+
it "should apply censor rules" do
mail = get_fixture_mail('incoming-request-bad-uuencoding.email')
@@ -524,3 +542,46 @@ describe IncomingMessage, "when TNEF attachments are attached to messages" do
end
end
+describe IncomingMessage, "when extracting attachments" do
+
+ it 'handles the case where reparsing changes the body of the main part
+ and the cached attachment has been deleted' do
+ # original set of attachment attributes
+ attachment_attributes = { :url_part_number => 1,
+ :within_rfc822_subject => nil,
+ :content_type => "text/plain",
+ :charset => nil,
+ :body => "No way!\n",
+ :hexdigest => "0c8b1b0f5cb9c94ed15a180e73b5c7d1",
+ :filename => nil }
+
+ # Make a small change in the body returned for the attachment
+ new_attachment_attributes = attachment_attributes.merge(:body => "No way!",
+ :hexdigest => "74d2c0a41e074f9cebe49324d5b47414")
+
+
+ # Simulate parsing with the original attachments
+ MailHandler.stub!(:get_attachment_attributes).and_return([attachment_attributes])
+ incoming_message = incoming_messages(:useless_incoming_message)
+
+ # Extract the attachments
+ incoming_message.extract_attachments!
+
+ # delete the cached file for the main body part
+ main = incoming_message.get_main_body_text_part
+ main.delete_cached_file!
+
+ # Simulate reparsing with the slightly changed body
+ MailHandler.stub!(:get_attachment_attributes).and_return([new_attachment_attributes])
+
+ # Re-extract the attachments
+ incoming_message.extract_attachments!
+
+ attachments = incoming_message.foi_attachments
+ attachments.size.should == 1
+ attachments.first.hexdigest.should == "74d2c0a41e074f9cebe49324d5b47414"
+ attachments.first.body.should == 'No way!'
+ end
+
+end
+
diff --git a/spec/models/outgoing_message_spec.rb b/spec/models/outgoing_message_spec.rb
index 51bb6fdf5..60164fb31 100644
--- a/spec/models/outgoing_message_spec.rb
+++ b/spec/models/outgoing_message_spec.rb
@@ -16,7 +16,7 @@ describe OutgoingMessage, " when making an outgoing message" do
it "should not index the email addresses" do
# also used for track emails
@outgoing_message.get_text_for_indexing.should_not include("foo@bar.com")
- end
+ end
it "should not display email addresses on page" do
@outgoing_message.get_body_for_html_display.should_not include("foo@bar.com")
@@ -33,6 +33,23 @@ describe OutgoingMessage, " when making an outgoing message" do
it "should work out a salutation" do
@om.get_salutation.should == "Dear Geraldine Quango,"
end
+
+ it 'should produce the expected text for an internal review request' do
+ public_body = mock_model(PublicBody, :name => 'A test public body')
+ info_request = mock_model(InfoRequest, :public_body => public_body,
+ :url_title => 'a_test_title',
+ :title => 'A test title',
+ :apply_censor_rules_to_text! => nil)
+ outgoing_message = OutgoingMessage.new({
+ :status => 'ready',
+ :message_type => 'followup',
+ :what_doing => 'internal_review',
+ :info_request => info_request
+ })
+ expected_text = "I am writing to request an internal review of A test public body's handling of my FOI request 'A test title'."
+ outgoing_message.body.should include(expected_text)
+ end
+
end
diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb
index b7c8b4dbe..c40334142 100644
--- a/spec/models/xapian_spec.rb
+++ b/spec/models/xapian_spec.rb
@@ -1,3 +1,4 @@
+# encoding: utf-8
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe User, " when indexing users with Xapian" do
@@ -369,3 +370,28 @@ describe PublicBody, " when only indexing selected things on a rebuild" do
end
end
+# I would expect ActsAsXapian to have some tests under vendor/plugins/acts_as_xapian, but
+# it looks like this is not the case. Putting a test here instead.
+describe ActsAsXapian::Search, "#words_to_highlight" do
+ it "should return a list of words used in the search" do
+ s = ActsAsXapian::Search.new([PublicBody], "albatross words", :limit => 100)
+ s.words_to_highlight.should == ["albatross", "words"]
+ end
+
+ it "should remove any operators" do
+ s = ActsAsXapian::Search.new([PublicBody], "albatross words tag:mice", :limit => 100)
+ s.words_to_highlight.should == ["albatross", "words"]
+ end
+
+ # This is the current behaviour but it seems a little simplistic to me
+ it "should separate punctuation" do
+ s = ActsAsXapian::Search.new([PublicBody], "The doctor's patient", :limit => 100)
+ s.words_to_highlight.should == ["The", "doctor", "s", "patient"]
+ end
+
+ it "should handle non-ascii characters" do
+ s = ActsAsXapian::Search.new([PublicBody], "adatigénylés words tag:mice", :limit => 100)
+ s.words_to_highlight.should == ["adatigénylés", "words"]
+ end
+
+end