aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/admin_request_controller_spec.rb2
-rw-r--r--spec/fixtures/incoming-request-plain.email2
-rw-r--r--spec/fixtures/incoming-request-two-same-name.email2
-rw-r--r--spec/models/request_mailer_spec.rb81
-rw-r--r--spec/spec_helper.rb3
5 files changed, 84 insertions, 6 deletions
diff --git a/spec/controllers/admin_request_controller_spec.rb b/spec/controllers/admin_request_controller_spec.rb
index ff0f74aed..cb30541b6 100644
--- a/spec/controllers/admin_request_controller_spec.rb
+++ b/spec/controllers/admin_request_controller_spec.rb
@@ -18,7 +18,7 @@ describe AdminRequestController, "when administering requests" do
it "saves edits to a request" do
info_requests(:fancy_dog_request).title.should == "Why do you have & such a fancy dog?"
- post :update, { :id => info_requests(:fancy_dog_request), :info_request => { :title => "Renamed", :prominence => "normal", :described_state => "waiting_response", :awaiting_description => false } }
+ post :update, { :id => info_requests(:fancy_dog_request), :info_request => { :title => "Renamed", :prominence => "normal", :described_state => "waiting_response", :awaiting_description => false, :allow_new_responses_from => 'anybody', :handle_rejected_responses => 'bounce' } }
response.flash[:notice].should include('successful')
ir = InfoRequest.find(info_requests(:fancy_dog_request).id)
ir.title.should == "Renamed"
diff --git a/spec/fixtures/incoming-request-plain.email b/spec/fixtures/incoming-request-plain.email
index 4ee258d2a..8aca7707b 100644
--- a/spec/fixtures/incoming-request-plain.email
+++ b/spec/fixtures/incoming-request-plain.email
@@ -1,4 +1,4 @@
-From: geraldinequango@localhost
+From: EMAIL_FROM
To: FOI Person <EMAIL_TO>
Bcc:
Subject: Re: Freedom of Information Request - Why aren't you leaving the house?
diff --git a/spec/fixtures/incoming-request-two-same-name.email b/spec/fixtures/incoming-request-two-same-name.email
index f0ab9f29c..f1024d607 100644
--- a/spec/fixtures/incoming-request-two-same-name.email
+++ b/spec/fixtures/incoming-request-two-same-name.email
@@ -1,4 +1,4 @@
-From: Francis Irving <francis@flourish.org>
+From: EMAIL_FROM
To: FOI Person <EMAIL_TO>
Subject: Same attachment twice
Content-Type: multipart/mixed; boundary="Q68bSM7Ycu6FN28Q"
diff --git a/spec/models/request_mailer_spec.rb b/spec/models/request_mailer_spec.rb
index 6f765d982..2cc132b50 100644
--- a/spec/models/request_mailer_spec.rb
+++ b/spec/models/request_mailer_spec.rb
@@ -14,6 +14,7 @@ describe RequestMailer, " when receiving incoming mail" do
deliveries = ActionMailer::Base.deliveries
deliveries.size.should == 1
mail = deliveries[0]
+ mail.to.should == [ 'bob@localhost' ] # to the user who sent fancy_dog_request
deliveries.clear
end
@@ -32,10 +33,11 @@ describe RequestMailer, " when receiving incoming mail" do
deliveries.clear
end
- it "should return incoming mail to sender when a request is stopped for spam" do
+ it "should return incoming mail to sender when a request is stopped fully for spam" do
# mark request as anti-spam
ir = info_requests(:fancy_dog_request)
- ir.stop_new_responses = true
+ ir.allow_new_responses_from = 'nobody'
+ ir.handle_rejected_responses = 'bounce'
ir.save!
# test what happens if something arrives
@@ -51,6 +53,81 @@ describe RequestMailer, " when receiving incoming mail" do
deliveries.clear
end
+ it "should return incoming mail to sender if not authority when a request is stopped for non-authority spam" do
+ # mark request as anti-spam
+ ir = info_requests(:fancy_dog_request)
+ ir.allow_new_responses_from = 'authority_only'
+ ir.handle_rejected_responses = 'bounce'
+ ir.save!
+
+ # Test what happens if something arrives from authority domain (@localhost)
+ ir.incoming_messages.size.should == 1 # in the fixture
+ receive_incoming_mail('incoming-request-plain.email', ir.incoming_email)
+ ir.incoming_messages.size.should == 2 # one more arrives
+
+ # ... should get "responses arrived" message for original requester
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ mail = deliveries[0]
+ mail.to.should == [ 'bob@localhost' ] # to the user who sent fancy_dog_request
+ deliveries.clear
+
+ # Test what happens if something arrives from another domain
+ ir.incoming_messages.size.should == 2 # in fixture and above
+ receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "dummy-address@dummy.localhost")
+ ir.incoming_messages.size.should == 2 # nothing should arrive
+
+ # ... should be a bounce message back to sender
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ mail = deliveries[0]
+ mail.to.should == [ 'dummy-address@dummy.localhost' ]
+ 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)
+ ir.allow_new_responses_from = 'nobody'
+ ir.handle_rejected_responses = 'holding_pen'
+ ir.save!
+
+ # test what happens if something arrives
+ ir = info_requests(:fancy_dog_request)
+ ir.incoming_messages.size.should == 1
+ InfoRequest.holding_pen_request.incoming_messages.size.should == 0
+ receive_incoming_mail('incoming-request-plain.email', ir.incoming_email)
+ ir.incoming_messages.size.should == 1
+ InfoRequest.holding_pen_request.incoming_messages.size.should == 1 # arrives in holding pen
+
+ # should be a message to admin regarding holding pen
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ mail = deliveries[0]
+ mail.to.should == [ MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') ]
+ deliveries.clear
+ end
+
+ it "should dump messages to a request if marked to do so" do
+ # mark request as anti-spam
+ ir = info_requests(:fancy_dog_request)
+ ir.allow_new_responses_from = 'nobody'
+ ir.handle_rejected_responses = 'blackhole'
+ ir.save!
+
+ # test what happens if something arrives - should be nothing
+ ir = info_requests(:fancy_dog_request)
+ ir.incoming_messages.size.should == 1
+ InfoRequest.holding_pen_request.incoming_messages.size.should == 0
+ receive_incoming_mail('incoming-request-plain.email', ir.incoming_email)
+ ir.incoming_messages.size.should == 1
+ InfoRequest.holding_pen_request.incoming_messages.size.should == 0
+
+ # should be no messages to anyone
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 0
+ end
+
it "should not mutilate long URLs when trying to word wrap them" do
long_url = 'http://www.this.is.quite.a.long.url.flourish.org/there.is.no.way.it.is.short.whatsoever'
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index c56e15f4c..6852909a6 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -23,10 +23,11 @@ Spec::Runner.configure do |config|
end
# XXX No idea what namespace/class/module to put this in
-def receive_incoming_mail(email_name, email_to)
+def receive_incoming_mail(email_name, email_to, email_from = 'geraldinequango@localhost')
email_name = File.join(Spec::Runner.configuration.fixture_path, email_name)
content = File.read(email_name)
content.gsub!('EMAIL_TO', email_to)
+ content.gsub!('EMAIL_FROM', email_from)
RequestMailer.receive(content)
end