This repository has been archived by the owner on Aug 13, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
As mentioned in 623566, we don't think that the MessageImporter should be responsible for instantiating an IMAP connection and importing messages into the repository.
- Loading branch information
1 parent
6235665
commit 439b544
Showing
4 changed files
with
42 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'gmail_imap_client' | ||
require 'message_repository' | ||
|
||
class AccountMessageImporter | ||
class << self | ||
def import_for(email, password) | ||
imap_client = GmailImapClient.connect(email, password) | ||
MessageImporter.new(imap_client).import_into(MessageRepository.instance) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'test_helper' | ||
require 'account_message_importer' | ||
|
||
class AccountMessageImporterTest < ActiveSupport::TestCase | ||
test 'establishes an imap connection using the given credentials' do | ||
GmailImapClient.expects(:connect).with('dave@example.com', 'password') | ||
MessageImporter.stubs(:new).returns(stub_everything) | ||
|
||
AccountMessageImporter.import_for('dave@example.com', 'password') | ||
end | ||
|
||
test 'uses the established connection for importing' do | ||
gmail_client = stub('gmail-client') | ||
GmailImapClient.stubs(:connect).returns(gmail_client) | ||
MessageImporter.expects(:new).with(gmail_client).returns(stub_everything) | ||
|
||
AccountMessageImporter.import_for('whatever', 'whatever') | ||
end | ||
|
||
test 'uses the default message repository' do | ||
GmailImapClient.stubs(:connect).returns(stub('gmail-client')) | ||
|
||
message_repository = stub('message-repository') | ||
importer = stub('importer') | ||
MessageRepository.stubs(:instance).returns(message_repository) | ||
MessageImporter.stubs(:new).returns(importer) | ||
importer.expects(:import_into).with(message_repository) | ||
|
||
AccountMessageImporter.import_for('whatever', 'whatever') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters