aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/request_controller_spec.rb11
-rw-r--r--spec/fixtures/files/unrecognized-encoding-mail.email36
-rw-r--r--spec/lib/mail_handler/mail_handler_spec.rb5
-rw-r--r--spec/models/incoming_message_spec.rb13
-rw-r--r--spec/models/info_request_spec.rb203
5 files changed, 262 insertions, 6 deletions
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index c73576c50..387b040d6 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -1519,8 +1519,8 @@ describe RequestController, "when classifying an information request" do
post_status('rejected')
end
- it 'should not log a status update event' do
- @dog_request.should_not_receive(:log_event)
+ it 'should log a status update event' do
+ @dog_request.should_receive(:log_event)
post_status('rejected')
end
@@ -1573,11 +1573,12 @@ describe RequestController, "when classifying an information request" do
@dog_request.awaiting_description.should == false
@dog_request.described_state.should == 'rejected'
@dog_request.get_last_response_event.should == info_request_events(:useless_incoming_message_event)
- @dog_request.get_last_response_event.calculated_state.should == 'rejected'
+ @dog_request.info_request_events.last.event_type.should == "status_update"
+ @dog_request.info_request_events.last.calculated_state.should == 'rejected'
end
- it 'should not log a status update event' do
- @dog_request.should_not_receive(:log_event)
+ it 'should log a status update event' do
+ @dog_request.should_receive(:log_event)
post_status('rejected')
end
diff --git a/spec/fixtures/files/unrecognized-encoding-mail.email b/spec/fixtures/files/unrecognized-encoding-mail.email
new file mode 100644
index 000000000..266a90fbc
--- /dev/null
+++ b/spec/fixtures/files/unrecognized-encoding-mail.email
@@ -0,0 +1,36 @@
+From xxx@example.com Fri Jun 21 07:50:52 2013
+Return-path: <xxx@example.com>
+Envelope-to: xxx@example.com
+Delivery-date: Fri, 21 Jun 2013 07:50:52 +0100
+Message-ID: <185C0D48380D7AE612DD38A527D5EAF2@tmvbalem>
+From: "cttlqvx" <xxx@example.com>
+To: <xxx@example.com>
+Subject: =?hz-gb-2312?B?fntPck9ISXpWQn59c3J5dW95d3MoQUQpICAgIA==?=
+Date: Fri, 21 Jun 2013 14:48:20 +0800
+MIME-Version: 1.0
+Content-Type: multipart/related;
+ type="multipart/alternative";
+ boundary="----=_NextPart_000_02ED_01A0462A.178683F0"
+X-Priority: 1
+X-MSMail-Priority: High
+X-Mailer: Microsoft Outlook Express 6.00.2900.5512
+X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
+
+This is a multi-part message in MIME format.
+
+------=_NextPart_000_02ED_01A0462A.178683F0
+Content-Type: multipart/alternative;
+ boundary="----=_NextPart_001_09EC_01A0462A.178683F0"
+
+------=_NextPart_001_09EC_01A0462A.178683F0
+Content-Type: text/plain;
+ charset="hz-gb-2312"
+Content-Transfer-Encoding: base64
+
+
+------=_NextPart_001_09EC_01A0462A.178683F0
+Content-Type: text/html;
+ charset="hz-gb-2312"
+Content-Transfer-Encoding: base64
+
+------=_NextPart_001_09EC_01A0462A.178683F0--
diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb
index 3e5176e87..aa351bd94 100644
--- a/spec/lib/mail_handler/mail_handler_spec.rb
+++ b/spec/lib/mail_handler/mail_handler_spec.rb
@@ -67,6 +67,11 @@ describe 'when creating a mail object from raw data' do
body.should match(/ \xe2\x80\x93 /)
end
+ it 'should not error on a subject line with an encoding encoding not recognized by iconv' do
+ mail = get_fixture_mail('unrecognized-encoding-mail.email')
+ lambda{ mail.subject }.should_not raise_error
+ end
+
end
describe 'when asked for the from name' do
diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb
index 3c924dcb3..ff6a8e34e 100644
--- a/spec/models/incoming_message_spec.rb
+++ b/spec/models/incoming_message_spec.rb
@@ -328,7 +328,18 @@ describe IncomingMessage, " when censoring data" do
data.should == "His email was x\000x\000x\000@\000x\000x\000x\000.\000x\000x\000x\000, indeed"
end
-
+ it 'should handle multibyte characters correctly', :focus => true do
+ orig_data = 'á'
+ data = orig_data.dup
+ @regex_censor_rule = CensorRule.new()
+ @regex_censor_rule.text = 'á'
+ @regex_censor_rule.regexp = true
+ @regex_censor_rule.replacement = 'cat'
+ @regex_censor_rule.last_edit_editor = 'unknown'
+ @regex_censor_rule.last_edit_comment = 'none'
+ @im.info_request.censor_rules << @regex_censor_rule
+ lambda{ @im.binary_mask_stuff!(data, "text/plain") }.should_not raise_error
+ end
def pdf_replacement_test(use_ghostscript_compression)
config = MySociety::Config.load_default()
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index f9ca44657..0ba8abd75 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -606,4 +606,207 @@ describe InfoRequest do
@info_request.user_json_for_api.should == {:name => 'Anonymous user'}
end
end
+ describe "#set_described_state and #log_event" do
+ context "a request" do
+ let(:request) { InfoRequest.create!(:title => "my request",
+ :public_body => public_bodies(:geraldine_public_body),
+ :user => users(:bob_smith_user)) }
+
+ context "a series of events on a request" do
+ it "should have sensible events after the initial request has been made" do
+ # An initial request is sent
+ # The logic that changes the status when a message is sent is mixed up
+ # in OutgoingMessage#send_message. So, rather than extract it (or call it)
+ # let's just duplicate what it does here for the time being.
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+
+ events = request.info_request_events
+ events.count.should == 1
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ end
+
+ it "should have sensible events after a response is received to a request" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+ # A response is received
+ # This is normally done in InfoRequest#receive
+ request.awaiting_description = true
+ request.log_event("response", {})
+
+ events = request.info_request_events
+ events.count.should == 2
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ events[1].event_type.should == "response"
+ events[1].described_state.should be_nil
+ # TODO: Should calculated_status in this situation be "waiting_classification"?
+ # This would allow searches like "latest_status: waiting_classification" to be
+ # available to the user in "Advanced search"
+ events[1].calculated_state.should be_nil
+ end
+
+ it "should have sensible events after a request is classified by the requesting user" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+ # A response is received
+ request.awaiting_description = true
+ request.log_event("response", {})
+ # The request is classified by the requesting user
+ # This is normally done in RequestController#describe_state
+ request.log_event("status_update", {})
+ request.set_described_state("waiting_response")
+
+ events = request.info_request_events
+ events.count.should == 3
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ events[1].event_type.should == "response"
+ events[1].described_state.should be_nil
+ events[1].calculated_state.should be_nil
+ events[2].event_type.should == "status_update"
+ events[2].described_state.should == "waiting_response"
+ events[2].calculated_state.should == "waiting_response"
+ end
+
+ it "should have sensible events after a normal followup is sent" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+ # A response is received
+ request.awaiting_description = true
+ request.log_event("response", {})
+ # The request is classified by the requesting user
+ request.log_event("status_update", {})
+ request.set_described_state("waiting_response")
+ # A normal follow up is sent
+ # This is normally done in OutgoingMessage#send_message
+ request.log_event('followup_sent', {})
+ request.set_described_state('waiting_response')
+
+ events = request.info_request_events
+ events.count.should == 4
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ events[1].event_type.should == "response"
+ events[1].described_state.should be_nil
+ events[1].calculated_state.should be_nil
+ events[2].event_type.should == "status_update"
+ events[2].described_state.should == "waiting_response"
+ events[2].calculated_state.should == "waiting_response"
+ events[3].event_type.should == "followup_sent"
+ events[3].described_state.should == "waiting_response"
+ events[3].calculated_state.should == "waiting_response"
+ end
+
+ it "should have sensible events after a user classifies the request after a follow up" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+ # A response is received
+ request.awaiting_description = true
+ request.log_event("response", {})
+ # The request is classified by the requesting user
+ request.log_event("status_update", {})
+ request.set_described_state("waiting_response")
+ # A normal follow up is sent
+ request.log_event('followup_sent', {})
+ request.set_described_state('waiting_response')
+ # The request is classified by the requesting user
+ request.log_event("status_update", {})
+ request.set_described_state("waiting_response")
+
+ events = request.info_request_events
+ events.count.should == 5
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ events[1].event_type.should == "response"
+ events[1].described_state.should be_nil
+ events[1].calculated_state.should be_nil
+ events[2].event_type.should == "status_update"
+ events[2].described_state.should == "waiting_response"
+ events[2].calculated_state.should == "waiting_response"
+ events[3].event_type.should == "followup_sent"
+ events[3].described_state.should == "waiting_response"
+ events[3].calculated_state.should == "waiting_response"
+ events[4].event_type.should == "status_update"
+ events[4].described_state.should == "waiting_response"
+ events[4].calculated_state.should == "waiting_response"
+ end
+ end
+
+ context "another series of events on a request" do
+ it "should have sensible event states" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+ # An internal review is requested
+ request.log_event('followup_sent', {})
+ request.set_described_state('internal_review')
+
+ events = request.info_request_events
+ events.count.should == 2
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ events[1].event_type.should == "followup_sent"
+ events[1].described_state.should == "internal_review"
+ events[1].calculated_state.should == "internal_review"
+ end
+
+ it "should have sensible event states" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+ # An internal review is requested
+ request.log_event('followup_sent', {})
+ request.set_described_state('internal_review')
+ # The user marks the request as rejected
+ request.log_event("status_update", {})
+ request.set_described_state("rejected")
+
+ events = request.info_request_events
+ events.count.should == 3
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ events[1].event_type.should == "followup_sent"
+ events[1].described_state.should == "internal_review"
+ events[1].calculated_state.should == "internal_review"
+ events[2].event_type.should == "status_update"
+ events[2].described_state.should == "rejected"
+ events[2].calculated_state.should == "rejected"
+ end
+ end
+
+ context "another series of events on a request" do
+ it "should have sensible event states" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+ # The user marks the request as successful (I know silly but someone did
+ # this in https://www.whatdotheyknow.com/request/family_support_worker_redundanci)
+ request.log_event("status_update", {})
+ request.set_described_state("successful")
+
+ events = request.info_request_events
+ events.count.should == 2
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ events[1].event_type.should == "status_update"
+ events[1].described_state.should == "successful"
+ events[1].calculated_state.should == "successful"
+ end
+ end
+ end
+ end
end