diff options
-rw-r--r-- | app/controllers/request_controller.rb | 33 | ||||
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 20 | ||||
-rw-r--r-- | spec/factories/outgoing_messages.rb | 10 |
3 files changed, 57 insertions, 6 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 3fa0ef0ce..9e2c291dc 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -365,8 +365,21 @@ class RequestController < ApplicationController end # This automatically saves dependent objects, such as @outgoing_message, in the same transaction @info_request.save! - # TODO: send_message needs the database id, so we send after saving, which isn't ideal if the request broke here. - @outgoing_message.send_message + + # TODO: Sending the message needs the database id, so we send after + # saving, which isn't ideal if the request broke here. + if @outgoing_message.sendable? + mail_message = OutgoingMailer.initial_request( + @outgoing_message.info_request, + @outgoing_message + ).deliver + + @outgoing_message.record_email_delivery( + mail_message.to_addrs.join(', '), + mail_message.message_id + ) + end + flash[:notice] = _("<p>Your {{law_used_full}} request has been <strong>sent on its way</strong>!</p> <p><strong>We will email you</strong> when there is a response, or after {{late_number_of_days}} working days if the authority still hasn't replied by then.</p> @@ -668,13 +681,27 @@ class RequestController < ApplicationController end # Send a follow up message - @outgoing_message.send_message + @outgoing_message.sendable? + + mail_message = OutgoingMailer.followup( + @outgoing_message.info_request, + @outgoing_message, + @outgoing_message.incoming_message_followup + ).deliver + + @outgoing_message.record_email_delivery( + mail_message.to_addrs.join(', '), + mail_message.message_id + ) + @outgoing_message.save! + if @outgoing_message.what_doing == 'internal_review' flash[:notice] = _("Your internal review request has been sent on its way.") else flash[:notice] = _("Your follow up message has been sent on its way.") end + redirect_to request_url(@info_request) end else diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index f7c935af3..6c0f4573e 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1827,7 +1827,15 @@ describe RequestController, "when sending a followup message" do # make the followup session[:user_id] = users(:bob_smith_user).id - post :show_response, :outgoing_message => { :body => "What a useless response! You suck.", :what_doing => 'normal_sort' }, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :submitted_followup => 1 + + post :show_response, + :outgoing_message => { + :body => "What a useless response! You suck.", + :what_doing => 'normal_sort' + }, + :id => info_requests(:fancy_dog_request).id, + :incoming_message_id => incoming_messages(:useless_incoming_message), + :submitted_followup => 1 # check it worked deliveries = ActionMailer::Base.deliveries @@ -1982,7 +1990,15 @@ describe RequestController, "sending overdue request alerts" do :info_request_id => chicken_request.id, :body => 'Some text', :what_doing => 'normal_sort') - outgoing_message.send_message + + outgoing_message.sendable? + mail_message = OutgoingMailer.followup( + outgoing_message.info_request, + outgoing_message, + outgoing_message.incoming_message_followup + ).deliver + outgoing_message.record_email_delivery(mail_message.to_addrs.join(', '), mail_message.message_id) + outgoing_message.save! chicken_request = InfoRequest.find(chicken_request.id) diff --git a/spec/factories/outgoing_messages.rb b/spec/factories/outgoing_messages.rb index 3887d3f48..e11cbdfb9 100644 --- a/spec/factories/outgoing_messages.rb +++ b/spec/factories/outgoing_messages.rb @@ -10,7 +10,9 @@ FactoryGirl.define do body 'Some information please' what_doing 'normal_sort' end + end + factory :internal_review_request do ignore do status 'ready' @@ -18,6 +20,7 @@ FactoryGirl.define do body 'I want a review' what_doing 'internal_review' end + end # FIXME: This here because OutgoingMessage has an after_initialize, @@ -30,9 +33,14 @@ FactoryGirl.define do :message_type => message_type, :body => body, :what_doing => what_doing }) } + after_create do |outgoing_message| - outgoing_message.send_message + outgoing_message.sendable? + outgoing_message.record_email_delivery( + 'test@example.com', + 'ogm-14+537f69734b97c-1ebd@localhost') end + end end |