aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/info_requests.rb2
-rw-r--r--spec/integration/download_request_spec.rb3
-rw-r--r--spec/mailers/request_mailer_spec.rb21
-rw-r--r--spec/models/censor_rule_spec.rb36
-rw-r--r--spec/models/incoming_message_spec.rb12
-rw-r--r--spec/models/info_request_spec.rb29
-rw-r--r--spec/models/outgoing_message_spec.rb109
7 files changed, 177 insertions, 35 deletions
diff --git a/spec/factories/info_requests.rb b/spec/factories/info_requests.rb
index 45485c435..084712243 100644
--- a/spec/factories/info_requests.rb
+++ b/spec/factories/info_requests.rb
@@ -2,7 +2,7 @@
FactoryGirl.define do
factory :info_request do
- title "Example Title"
+ sequence(:title) { |n| "Example Title #{n}" }
public_body
user
diff --git a/spec/integration/download_request_spec.rb b/spec/integration/download_request_spec.rb
index 4b3d11d13..1050e6792 100644
--- a/spec/integration/download_request_spec.rb
+++ b/spec/integration/download_request_spec.rb
@@ -144,7 +144,8 @@ describe 'when making a zipfile available' do
it "should update the contents of the zipfile when the request changes" do
- info_request = FactoryGirl.create(:info_request_with_incoming)
+ info_request = FactoryGirl.create(:info_request_with_incoming,
+ :title => 'Example Title')
request_owner = login(info_request.user)
inspect_zip_download(request_owner, info_request) do |zip|
zip.count.should == 1 # just the message
diff --git a/spec/mailers/request_mailer_spec.rb b/spec/mailers/request_mailer_spec.rb
index 7dcb47b50..5c8b8a3de 100644
--- a/spec/mailers/request_mailer_spec.rb
+++ b/spec/mailers/request_mailer_spec.rb
@@ -40,6 +40,12 @@ describe RequestMailer, " when receiving incoming mail" do
deliveries.clear
end
+ it "puts messages with a malformed To: in the holding pen" do
+ request = FactoryGirl.create(:info_request)
+ receive_incoming_mail('incoming-request-plain.email', 'asdfg')
+ expect(InfoRequest.holding_pen_request.incoming_messages).to have(1).item
+ end
+
it "should parse attachments from mails sent with apple mail" do
ir = info_requests(:fancy_dog_request)
ir.incoming_messages.size.should == 1
@@ -180,6 +186,21 @@ describe RequestMailer, " when receiving incoming mail" do
deliveries.clear
end
+ it "discards rejected responses with a malformed From: when set to bounce" do
+ ir = info_requests(:fancy_dog_request)
+ ir.allow_new_responses_from = 'nobody'
+ ir.handle_rejected_responses = 'bounce'
+ ir.save!
+ ir.incoming_messages.size.should == 1
+
+ receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "")
+ ir.incoming_messages.size.should == 1
+
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 0
+ deliveries.clear
+ end
+
it "should send all new responses to holding pen if a request is marked to do so" do
# mark request as anti-spam
ir = info_requests(:fancy_dog_request)
diff --git a/spec/models/censor_rule_spec.rb b/spec/models/censor_rule_spec.rb
index 888650a3a..314b060d2 100644
--- a/spec/models/censor_rule_spec.rb
+++ b/spec/models/censor_rule_spec.rb
@@ -18,6 +18,42 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+describe CensorRule do
+
+ describe :apply_to_text do
+
+ it 'applies the rule to the text' do
+ rule = FactoryGirl.build(:censor_rule, :text => 'secret')
+ text = 'Some secret text'
+ expect(rule.apply_to_text(text)).to eq('Some [REDACTED] text')
+ end
+
+ it 'does not mutate the input' do
+ rule = FactoryGirl.build(:censor_rule, :text => 'secret')
+ text = 'Some secret text'
+ rule.apply_to_text(text)
+ expect(text).to eq('Some secret text')
+ end
+
+ it 'returns the text if the rule is unmatched' do
+ rule = FactoryGirl.build(:censor_rule, :text => 'secret')
+ text = 'Some text'
+ expect(rule.apply_to_text(text)).to eq('Some text')
+ end
+ end
+
+ describe :apply_to_text! do
+
+ it 'mutates the input' do
+ rule = FactoryGirl.build(:censor_rule, :text => 'secret')
+ text = 'Some secret text'
+ rule.apply_to_text!(text)
+ expect(text).to eq('Some [REDACTED] text')
+ end
+
+ end
+end
+
describe CensorRule, "substituting things" do
describe 'when using a text rule' do
diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb
index 6651deb61..f4b450370 100644
--- a/spec/models/incoming_message_spec.rb
+++ b/spec/models/incoming_message_spec.rb
@@ -707,3 +707,15 @@ describe IncomingMessage, 'when getting the body of a message for html display'
end
end
+
+describe IncomingMessage, 'when getting clipped attachment text' do
+
+ it 'should clip to characters not bytes' do
+ incoming_message = FactoryGirl.build(:incoming_message)
+ # This character is 2 bytes so the string should get sliced unless
+ # we are handling multibyte chars correctly
+ multibyte_string = "å" * 500002
+ incoming_message.stub!(:_get_attachment_text_internal).and_return(multibyte_string)
+ incoming_message.get_attachment_text_clipped.length.should == 500002
+ end
+end \ No newline at end of file
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index 075bc2607..cddf1f880 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -658,17 +658,22 @@ describe InfoRequest do
before do
Time.stub!(:now).and_return(Time.utc(2007, 11, 9, 23, 59))
- @mock_comment_event = mock_model(InfoRequestEvent, :created_at => Time.now - 23.days,
- :event_type => 'comment',
- :response? => false)
- mock_incoming_message = mock_model(IncomingMessage, :all_can_view? => true)
- @mock_response_event = mock_model(InfoRequestEvent, :created_at => Time.now - 22.days,
- :event_type => 'response',
- :response? => true,
- :incoming_message => mock_incoming_message)
- @info_request = InfoRequest.new(:prominence => 'normal',
- :awaiting_description => true,
- :info_request_events => [@mock_response_event, @mock_comment_event])
+ @info_request = FactoryGirl.create(:info_request,
+ :prominence => 'normal',
+ :awaiting_description => true)
+ @comment_event = FactoryGirl.create(:info_request_event,
+ :created_at => Time.now - 23.days,
+ :event_type => 'comment',
+ :info_request => @info_request)
+ @incoming_message = FactoryGirl.create(:incoming_message,
+ :prominence => 'normal',
+ :info_request => @info_request)
+ @response_event = FactoryGirl.create(:info_request_event,
+ :info_request => @info_request,
+ :created_at => Time.now - 22.days,
+ :event_type => 'response',
+ :incoming_message => @incoming_message)
+ @info_request.update_attribute(:awaiting_description, true)
end
it 'should return false if it is the holding pen' do
@@ -682,7 +687,7 @@ describe InfoRequest do
end
it 'should return false if its last response event occurred less than 21 days ago' do
- @mock_response_event.stub!(:created_at).and_return(Time.now - 20.days)
+ @response_event.update_attribute(:created_at, Time.now - 20.days)
@info_request.is_old_unclassified?.should be_false
end
diff --git a/spec/models/outgoing_message_spec.rb b/spec/models/outgoing_message_spec.rb
index 44644c9d8..336e5a605 100644
--- a/spec/models/outgoing_message_spec.rb
+++ b/spec/models/outgoing_message_spec.rb
@@ -19,6 +19,93 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+describe OutgoingMessage do
+
+ describe :initialize do
+
+ it 'does not censor the #body' do
+ attrs = { :status => 'ready',
+ :message_type => 'initial_request',
+ :body => 'abc',
+ :what_doing => 'normal_sort' }
+
+ message = FactoryGirl.create(:outgoing_message, attrs)
+
+ OutgoingMessage.any_instance.should_not_receive(:body).and_call_original
+ OutgoingMessage.find(message.id)
+ end
+
+ end
+
+ describe :body do
+
+ it 'returns the body attribute' do
+ attrs = { :status => 'ready',
+ :message_type => 'initial_request',
+ :body => 'abc',
+ :what_doing => 'normal_sort' }
+
+ message = FactoryGirl.build(:outgoing_message, attrs)
+ expect(message.body).to eq('abc')
+ end
+
+ it 'strips the body of leading and trailing whitespace' do
+ attrs = { :status => 'ready',
+ :message_type => 'initial_request',
+ :body => ' abc ',
+ :what_doing => 'normal_sort' }
+
+ message = FactoryGirl.build(:outgoing_message, attrs)
+ expect(message.body).to eq('abc')
+ end
+
+ it 'removes excess linebreaks that unnecessarily space it out' do
+ attrs = { :status => 'ready',
+ :message_type => 'initial_request',
+ :body => "ab\n\nc\n\n",
+ :what_doing => 'normal_sort' }
+
+ message = FactoryGirl.build(:outgoing_message, attrs)
+ expect(message.body).to eq("ab\n\nc")
+ end
+
+ it "applies the associated request's censor rules to the text" do
+ attrs = { :status => 'ready',
+ :message_type => 'initial_request',
+ :body => 'This sensitive text contains secret info!',
+ :what_doing => 'normal_sort' }
+ message = FactoryGirl.build(:outgoing_message, attrs)
+
+ rules = [FactoryGirl.build(:censor_rule, :text => 'secret'),
+ FactoryGirl.build(:censor_rule, :text => 'sensitive')]
+ InfoRequest.any_instance.stub(:censor_rules).and_return(rules)
+
+ expected = 'This [REDACTED] text contains [REDACTED] info!'
+ expect(message.body).to eq(expected)
+ end
+
+ it "applies the given censor rules to the text" do
+ attrs = { :status => 'ready',
+ :message_type => 'initial_request',
+ :body => 'This sensitive text contains secret info!',
+ :what_doing => 'normal_sort' }
+ message = FactoryGirl.build(:outgoing_message, attrs)
+
+ request_rules = [FactoryGirl.build(:censor_rule, :text => 'secret'),
+ FactoryGirl.build(:censor_rule, :text => 'sensitive')]
+ InfoRequest.any_instance.stub(:censor_rules).and_return(request_rules)
+
+ censor_rules = [FactoryGirl.build(:censor_rule, :text => 'text'),
+ FactoryGirl.build(:censor_rule, :text => 'contains')]
+
+ expected = 'This sensitive [REDACTED] [REDACTED] secret info!'
+ expect(message.body(:censor_rules => censor_rules)).to eq(expected)
+ end
+
+ end
+
+end
+
describe OutgoingMessage, " when making an outgoing message" do
before do
@@ -58,6 +145,7 @@ describe OutgoingMessage, " when making an outgoing message" do
info_request = mock_model(InfoRequest, :public_body => public_body,
:url_title => 'a_test_title',
:title => 'A test title',
+ :applicable_censor_rules => [],
:apply_censor_rules_to_text! => nil,
:is_batch_request_template? => false)
outgoing_message = OutgoingMessage.new({
@@ -156,27 +244,6 @@ describe OutgoingMessage, " when making an outgoing message" do
end
end
-
-describe OutgoingMessage, " when censoring data" do
-
- before do
- @om = outgoing_messages(:useless_outgoing_message)
-
- @censor_rule = CensorRule.new()
- @censor_rule.text = "dog"
- @censor_rule.replacement = "cat"
- @censor_rule.last_edit_editor = "unknown"
- @censor_rule.last_edit_comment = "none"
-
- @om.info_request.censor_rules << @censor_rule
- end
-
- it "should apply censor rules to outgoing messages" do
- @om.read_attribute(:body).should match(/fancy dog/)
- @om.body.should match(/fancy cat/)
- end
-end
-
describe OutgoingMessage, "when validating the format of the message body" do
it 'should handle a salutation with a bracket in it' do