diff options
author | Louise Crow <louise.crow@gmail.com> | 2012-11-15 17:25:11 +0000 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2012-11-15 17:25:11 +0000 |
commit | 125ca970ad4e2b5e424265c632ae31c6dde62da7 (patch) | |
tree | 3d7944801defc042a53abf3f93e3d75980777862 | |
parent | f5ced2133cd1a66e18b225208fa96f4f36a20889 (diff) |
Wrap address parsing in a address_from_string method in the mail handler.
-rw-r--r-- | app/models/info_request_event.rb | 2 | ||||
-rw-r--r-- | lib/mail_handler/backends/mail_backend.rb | 4 | ||||
-rw-r--r-- | lib/mail_handler/backends/tmail_backend.rb | 5 | ||||
-rw-r--r-- | spec/models/info_request_event_spec.rb | 47 |
4 files changed, 51 insertions, 7 deletions
diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index 5a8e3416f..09eba31ab 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -384,7 +384,7 @@ class InfoRequestEvent < ActiveRecord::Base if prev_addr.nil? || curr_addr.nil? return false end - return TMail::Address.parse(prev_addr).address == TMail::Address.parse(curr_addr).address + return MailHandler.address_from_string(prev_addr) == MailHandler.address_from_string(curr_addr) end def json_for_api(deep, snippet_highlight_proc = nil) diff --git a/lib/mail_handler/backends/mail_backend.rb b/lib/mail_handler/backends/mail_backend.rb index bc4bf564c..0e198adf0 100644 --- a/lib/mail_handler/backends/mail_backend.rb +++ b/lib/mail_handler/backends/mail_backend.rb @@ -42,6 +42,10 @@ module MailHandler address.address = email address.to_s end + + def address_from_string(string) + Mail::Address.new(string).address + end end end end
\ No newline at end of file diff --git a/lib/mail_handler/backends/tmail_backend.rb b/lib/mail_handler/backends/tmail_backend.rb index 1c5489145..0a1236e77 100644 --- a/lib/mail_handler/backends/tmail_backend.rb +++ b/lib/mail_handler/backends/tmail_backend.rb @@ -52,6 +52,11 @@ module MailHandler name = name.gsub(/(["\\])/, "\\\\\\1") TMail::Address.parse('"' + name + '" <' + email + '>').to_s end + + def address_from_string(string) + TMail::Address.parse(string).address + end + end end end
\ No newline at end of file diff --git a/spec/models/info_request_event_spec.rb b/spec/models/info_request_event_spec.rb index 7352f3be0..796f8b840 100644 --- a/spec/models/info_request_event_spec.rb +++ b/spec/models/info_request_event_spec.rb @@ -54,36 +54,71 @@ describe InfoRequestEvent do end - describe "doing search/index stuff" do + describe "doing search/index stuff" do before(:each) do load_raw_emails_data parse_all_incoming_messages end - it 'should get search text for outgoing messages' do + it 'should get search text for outgoing messages' do event = info_request_events(:useless_outgoing_message_event) message = outgoing_messages(:useless_outgoing_message).body event.search_text_main.should == message + "\n\n" end - it 'should get search text for incoming messages' do + it 'should get search text for incoming messages' do event = info_request_events(:useless_incoming_message_event) event.search_text_main.strip.should == "No way! I'm not going to tell you that in a month of Thursdays.\n\nThe Geraldine Quango" end - it 'should get clipped text for incoming messages, and cache it too' do + it 'should get clipped text for incoming messages, and cache it too' do event = info_request_events(:useless_incoming_message_event) - + event.incoming_message_selective_columns("cached_main_body_text_folded").cached_main_body_text_folded = nil event.search_text_main(true).strip.should == "No way! I'm not going to tell you that in a month of Thursdays.\n\nThe Geraldine Quango" event.incoming_message_selective_columns("cached_main_body_text_folded").cached_main_body_text_folded.should_not == nil end - end + describe 'when asked if it has the same email as a previous send' do + + before do + @info_request_event = InfoRequestEvent.new + end + + it 'should return true if the email in its params and the previous email the request was sent to are both nil' do + @info_request_event.stub!(:params).and_return({}) + @info_request_event.stub_chain(:info_request, :get_previous_email_sent_to).and_return(nil) + @info_request_event.same_email_as_previous_send?.should be_true + end + + it 'should return false if one email address exists and the other does not' do + @info_request_event.stub!(:params).and_return(:email => 'test@example.com') + @info_request_event.stub_chain(:info_request, :get_previous_email_sent_to).and_return(nil) + @info_request_event.same_email_as_previous_send?.should be_false + end + it 'should return true if the addresses are identical' do + @info_request_event.stub!(:params).and_return(:email => 'test@example.com') + @info_request_event.stub_chain(:info_request, :get_previous_email_sent_to).and_return('test@example.com') + @info_request_event.same_email_as_previous_send?.should be_true + end + + it 'should return false if the addresses are different' do + @info_request_event.stub!(:params).and_return(:email => 'test@example.com') + @info_request_event.stub_chain(:info_request, :get_previous_email_sent_to).and_return('different@example.com') + @info_request_event.same_email_as_previous_send?.should be_false + end + + it 'should return true if the addresses have different formats' do + @info_request_event.stub!(:params).and_return(:email => 'A Test <test@example.com>') + @info_request_event.stub_chain(:info_request, :get_previous_email_sent_to).and_return('test@example.com') + @info_request_event.same_email_as_previous_send?.should be_true + end + + end end |