From 34ba3d82d16f28c9c670c7979854e57b4b0fcab9 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Mon, 22 Oct 2012 17:54:41 +0100 Subject: Adding new spec from https://github.com/mysociety/alaveteli/commit/cdb1c9420169ed6eafdd4e57ca21e1809c95e5cb --- spec/controllers/request_controller_spec.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 77f43b618..5867c994f 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -245,7 +245,7 @@ describe RequestController, "when showing one request" do response.should have_tag('#anyone_actions', /Add an annotation/) end end - + describe 'when the request does not allow comments' do it 'should not have a comment link' do get :show, { :url_title => 'spam_1' }, @@ -253,7 +253,7 @@ describe RequestController, "when showing one request" do response.should_not have_tag('#anyone_actions', /Add an annotation/) end end - + describe 'when the request is being viewed by an admin' do describe 'if the request is awaiting description' do @@ -1746,6 +1746,17 @@ describe RequestController, "sending overdue request alerts" do assigns[:info_request].should == info_requests(:naughty_chicken_request) end + it "should not resend alerts to people who've already received them" do + chicken_request = info_requests(:naughty_chicken_request) + chicken_request.outgoing_messages[0].last_sent_at = Time.now() - 60.days + chicken_request.outgoing_messages[0].save! + RequestMailer.alert_overdue_requests + chicken_mails = ActionMailer::Base.deliveries.select{|x| x.body =~ /chickens/} + chicken_mails.size.should == 1 + RequestMailer.alert_overdue_requests + chicken_mails = ActionMailer::Base.deliveries.select{|x| x.body =~ /chickens/} + chicken_mails.size.should == 1 + end end describe RequestController, "sending unclassified new response reminder alerts" do -- cgit v1.2.3 From 59a7d94010d54c5883f967f0d3f4aeeac7fc2ae8 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 23 Oct 2012 09:05:18 +0100 Subject: Add extra checks from https://github.com/mysociety/alaveteli/commit/cdb1c9420169ed6eafdd4e57ca21e1809c95e5cb and some extra description. --- spec/controllers/request_controller_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 5867c994f..1f79b0ef1 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1709,15 +1709,17 @@ describe RequestController, "sending overdue request alerts" do mail.to_addrs.first.to_s.should == info_requests(:naughty_chicken_request).user.name_and_email end - it "should send not actually send the overdue alert if the user is banned" do + it "should send not actually send the overdue alert if the user is banned but should + record it as sent" do user = info_requests(:naughty_chicken_request).user user.ban_text = 'Banned' user.save! - + UserInfoRequestSentAlert.find_all_by_user_id(user.id).count.should == 0 RequestMailer.alert_overdue_requests deliveries = ActionMailer::Base.deliveries deliveries.size.should == 0 + UserInfoRequestSentAlert.find_all_by_user_id(user.id).count.should > 0 end it "should send a very overdue alert mail to creators of very overdue requests" do -- cgit v1.2.3 From 1b1dbc393a5f596e791b99d6e8e0c0eea06c8f87 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 23 Oct 2012 14:28:38 +0100 Subject: Add spec - currently failing due to typo. --- spec/controllers/request_controller_spec.rb | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 1f79b0ef1..b0223588e 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1759,6 +1759,48 @@ describe RequestController, "sending overdue request alerts" do chicken_mails = ActionMailer::Base.deliveries.select{|x| x.body =~ /chickens/} chicken_mails.size.should == 1 end + + it 'should send alerts for requests where the last event forming the initial request is a followup + being sent following a request for clarification' do + chicken_request = info_requests(:naughty_chicken_request) + chicken_request.outgoing_messages[0].last_sent_at = Time.now() - 60.days + chicken_request.outgoing_messages[0].save! + RequestMailer.alert_overdue_requests + chicken_mails = ActionMailer::Base.deliveries.select{|x| x.body =~ /chickens/} + chicken_mails.size.should == 1 + + # Request is waiting clarification + chicken_request.set_described_state('waiting_clarification') + + # Followup message is sent + outgoing_message = OutgoingMessage.new(:status => 'ready', + :message_type => 'followup', + :info_request_id => chicken_request.id, + :body => 'Some text', + :what_doing => 'normal_sort') + outgoing_message.send_message + outgoing_message.save! + + chicken_request = InfoRequest.find(chicken_request.id) + + # Last event forming the request is now the followup + chicken_request.last_event_forming_initial_request.event_type.should == 'followup_sent' + + # This isn't overdue, so no email + RequestMailer.alert_overdue_requests + chicken_mails = ActionMailer::Base.deliveries.select{|x| x.body =~ /chickens/} + chicken_mails.size.should == 1 + + # Make the followup older + outgoing_message.last_sent_at = Time.now() - 60.days + outgoing_message.save! + + # Now it should be alerted on + RequestMailer.alert_overdue_requests + chicken_mails = ActionMailer::Base.deliveries.select{|x| x.body =~ /chickens/} + chicken_mails.size.should == 2 + end + end describe RequestController, "sending unclassified new response reminder alerts" do -- cgit v1.2.3