Skip to content
Browse files

Introduce AccountMessageImporter.

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 439b544e59baf8948eca06bf3d1c018e90efba8c @chrisroos-and-lazyatom chrisroos-and-lazyatom committed Mar 23, 2012
View
11 lib/account_message_importer.rb
@@ -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
View
11 lib/message_importer.rb
@@ -1,15 +1,4 @@
-require 'gmail_imap_client'
-require 'message_repository'
-
class MessageImporter
-
- class << self
- def import_for(email, password)
- imap_client = GmailImapClient.connect(email, password)
- new(imap_client).import_into(MessageRepository.instance)
- end
- end
-
attr_reader :message_client
def initialize(message_client)
View
31 test/unit/account_message_importer_test.rb
@@ -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
View
29 test/unit/message_importer_test.rb
@@ -1,34 +1,5 @@
require 'test_helper'
-class MessageImporter::WhenCoordinating < 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)
-
- MessageImporter.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)
- MessageImporter.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)
-
- MessageImporter.import_for('whatever', 'whatever')
- end
-end
-
class MessageImporterTest < ActiveSupport::TestCase
test 'imports messages' do
gmail_client = stub('gmail-client', inbox_messages: [:message1, :message2])

0 comments on commit 439b544

Please sign in to comment.
Something went wrong with that request. Please try again.