diff options
-rw-r--r-- | app/controllers/api_controller.rb | 6 | ||||
-rw-r--r-- | app/models/request_mailer.rb | 4 | ||||
-rw-r--r-- | spec/controllers/api_controller_spec.rb | 18 |
3 files changed, 22 insertions, 6 deletions
diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index c1156845d..524aa44b7 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -139,11 +139,11 @@ class ApiController < ApplicationController attachment_hashes = [] (attachments || []).each_with_index do |attachment, i| filename = File.basename(attachment.original_filename) - body = attachment.read - content_type = AlaveteliFileTypes.filename_and_content_to_mimetype(filename, body) || 'application/octet-stream' + attachment_body = attachment.read + content_type = AlaveteliFileTypes.filename_and_content_to_mimetype(filename, attachment_body) || 'application/octet-stream' attachment_hashes.push( :content_type => content_type, - :body => body, + :body => attachment_body, :filename => filename ) end diff --git a/app/models/request_mailer.rb b/app/models/request_mailer.rb index f7cc088c1..5ea5df802 100644 --- a/app/models/request_mailer.rb +++ b/app/models/request_mailer.rb @@ -35,6 +35,10 @@ class RequestMailer < ApplicationMailer @recipients = info_request.incoming_name_and_email @body = { :body => body } + # ActionMailer only works properly when the time is in the local timezone: + # see https://rails.lighthouseapp.com/projects/8994/tickets/3113-actionmailer-only-works-correctly-with-sent_on-times-that-are-in-the-local-time-zone + @sent_on = sent_at.dup.localtime + attachments.each do |attachment_hash| attachment attachment_hash end diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb index a39471775..1f65576b6 100644 --- a/spec/controllers/api_controller_spec.rb +++ b/spec/controllers/api_controller_spec.rb @@ -1,5 +1,17 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +def normalise_whitespace(s) + s = s.gsub(/^\s+|\s+$/, "") + s = s.gsub(/\s+/, " ") + return s +end + +Spec::Matchers.define :be_equal_modulo_whitespace_to do |expected| + match do |actual| + normalise_whitespace(actual) == normalise_whitespace(expected) + end +end + describe ApiController, "when using the API" do it "should check the API key" do request_data = { @@ -99,7 +111,7 @@ describe ApiController, "when using the API" do incoming_message = incoming_messages[0] incoming_message.sent_at.should == Time.iso8601(sent_at) - incoming_message.get_main_body_text_folded.should == response_body + incoming_message.get_main_body_text_folded.should be_equal_modulo_whitespace_to(response_body) end it "should add a followup to a request" do @@ -221,7 +233,7 @@ describe ApiController, "when using the API" do incoming_message = incoming_messages[0] incoming_message.sent_at.should == Time.iso8601(sent_at) - incoming_message.get_main_body_text_folded.should == response_body + incoming_message.get_main_body_text_folded.should be_equal_modulo_whitespace_to(response_body) # Get the attachment attachments = incoming_message.get_attachments_for_display @@ -229,7 +241,7 @@ describe ApiController, "when using the API" do attachment = attachments[0] attachment.filename.should == "tfl.pdf" - attachment.body.should == open("files/tfl.pdf", &:read) + attachment.body.should == load_file_fixture("tfl.pdf") end it "should show information about a request" do |