aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/admin_request_controller_spec.rb11
-rw-r--r--spec/fixtures/info_requests.yml6
-rw-r--r--spec/models/info_request_spec.rb34
3 files changed, 48 insertions, 3 deletions
diff --git a/spec/controllers/admin_request_controller_spec.rb b/spec/controllers/admin_request_controller_spec.rb
index 0b12fa97a..04e412e76 100644
--- a/spec/controllers/admin_request_controller_spec.rb
+++ b/spec/controllers/admin_request_controller_spec.rb
@@ -57,4 +57,15 @@ describe AdminRequestController, "when administering the holding pen" do
response.should have_text(/Only the authority can reply to this request/)
end
+ it "guesses a misdirected request" do
+ ir = info_requests(:fancy_dog_request)
+ ir.handle_rejected_responses = 'holding_pen'
+ ir.save!
+ mail_to = "request-#{ir.id}-asdfg@example.com"
+ receive_incoming_mail('incoming-request-plain.email', mail_to)
+ get :show_raw_email, :id => InfoRequest.holding_pen_request.get_last_response.raw_email.id
+ response.should have_text(/Could not identify the request/)
+ assigns[:info_requests][0].should == ir
+ end
+
end
diff --git a/spec/fixtures/info_requests.yml b/spec/fixtures/info_requests.yml
index bdeef4800..c1e3c1910 100644
--- a/spec/fixtures/info_requests.yml
+++ b/spec/fixtures/info_requests.yml
@@ -8,6 +8,7 @@ fancy_dog_request:
user_id: 1
described_state: waiting_response
awaiting_description: true
+ idhash: 50929748
naughty_chicken_request:
id: 103
title: How much public money is wasted on breeding naughty chickens?
@@ -17,6 +18,5 @@ naughty_chicken_request:
public_body_id: 2
user_id: 1
described_state: waiting_response
- awaiting_description: false
-
-
+ awaiting_description: false
+ idhash: e8d18c84
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index d0b0e0e32..ba80256ab 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -2,6 +2,40 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe InfoRequest do
+ describe "guessing a request from an email" do
+ fixtures :info_requests, :public_bodies, :incoming_messages, :raw_emails
+
+ before do
+ @im = incoming_messages(:useless_incoming_message)
+ load_raw_emails_data(raw_emails)
+ end
+
+ it 'should compute a hash' do
+ @info_request = InfoRequest.new(:title => "testing",
+ :public_body => public_bodies(:geraldine_public_body),
+ :user_id => 1)
+ @info_request.save!
+ @info_request.idhash.should_not == nil
+ end
+
+ it 'should find a request based on an email with an intact id and a broken hash' do
+ ir = info_requests(:fancy_dog_request)
+ id = ir.id
+ @im.mail.to = "request-#{id}-asdfg@example.com"
+ guessed = InfoRequest.guess_by_incoming_email(@im)
+ guessed[0].idhash.should == ir.idhash
+ end
+
+ it 'should find a request based on an email with a broken id and an intact hash' do
+ ir = info_requests(:fancy_dog_request)
+ idhash = ir.idhash
+ @im.mail.to = "request-123ab-#{idhash}@example.com"
+ guessed = InfoRequest.guess_by_incoming_email(@im)
+ guessed[0].id.should == ir.id
+ end
+
+ end
+
describe "making up the URL title" do
before do
@info_request = InfoRequest.new