Permalink
Browse files

adding test for email_worker example

  • Loading branch information...
1 parent d05b773 commit 5a3615b33ea9282722f0618fc895ffc2088d6950 Roman Dzvinkovsky committed Dec 15, 2012
Showing with 67 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +11 −0 Gemfile.lock
  3. +1 −0 iron_worker_ng.gemspec
  4. +54 −0 test/examples/test_example_email_worker.rb
View
1 .gitignore
@@ -7,3 +7,4 @@ examples/github_to_hipchat_webhook_worker/webhook_config.yml
examples/worker101/twitter_config.json
examples/actionmailer_standalone/actionmailer_config.json
examples/chargify_to_campfire_webhook_worker/campfire_config.json
+examples/email_worker/email_config.json
View
11 Gemfile.lock
@@ -9,11 +9,19 @@ PATH
GEM
remote: https://rubygems.org/
specs:
+ actionmailer (2.3.14)
+ actionpack (= 2.3.14)
+ actionpack (2.3.14)
+ activesupport (= 2.3.14)
+ rack (~> 1.1.0)
+ activesupport (2.3.14)
ansi (1.4.3)
builder (3.1.4)
faraday (0.8.4)
multipart-post (~> 1.1)
hashie (1.2.0)
+ iron_cache (1.3.0)
+ iron_core (>= 0.4.2)
iron_core (0.4.3)
rest (>= 2.0.2)
mime-types (1.19)
@@ -29,6 +37,7 @@ GEM
powerbar (1.0.11)
ansi (~> 1.4.0)
hashie (>= 1.1.0)
+ rack (1.1.3)
rake (10.0.1)
rest (2.1.1)
net-http-persistent
@@ -47,6 +56,8 @@ PLATFORMS
ruby
DEPENDENCIES
+ actionmailer
+ iron_cache
iron_worker_ng!
minitest
minitest-reporters (>= 0.5.0)
View
1 iron_worker_ng.gemspec
@@ -26,4 +26,5 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'rake'
gem.add_development_dependency 'twitter'
gem.add_development_dependency 'actionmailer'
+ gem.add_development_dependency 'iron_cache'
end
View
54 test/examples/test_example_email_worker.rb
@@ -0,0 +1,54 @@
+require_relative '../helpers'
+require 'rest'
+require 'iron_cache'
+require 'net/imap'
+require 'tempfile'
+
+class ExampleEmailWorkerTest < IWNGTest
+
+ def test_example
+ Dir.chdir 'examples/email_worker' do
+ assert(cli('upload', 'email_worker') =~ /Upload successful/)
+
+ cfg = JSON.parse(File.read('email_config.json'))
+
+ cache = IronCache::Client.new
+ cache.items.delete(cfg['to']) if cache.items.get(cfg['to'])
+
+ cfg['iron'] = { token: client.api.token,
+ project_id: client.api.project_id }
+ tmp = Tempfile.new(['email_config', '.json'])
+ tmp.write cfg.to_json
+ tmp.close
+
+ assert(cli('queue', 'email_worker',
+ payload_file: tmp.path) =~
+ /queued with id='(.*)'/)
+
+ # wait for delivery
+ client.tasks.wait_for($1)
+ sleep 10
+
+ begin
+ imap = Net::IMAP.new('imap.gmail.com',993,true)
+ imap.login(cfg['smtp']['user_name'], cfg['smtp']['password'])
+ imap.select('INBOX')
+ ids = imap.search(['SUBJECT', 'hello from IronWorker'])
+ assert ids.size >= 1
+ id = ids.last
+ msg = imap.fetch(id, 'RFC822')
+ assert msg[0].attr['RFC822'] =~ /hello me/
+ imap.store(id, "+FLAGS", [:Deleted])
+ ensure
+ imap.logout
+ imap.disconnect
+ end
+
+ cache = IronCache::Client.new
+ assert cache.items.get(cfg['to']).value =~ /hello me/
+
+ tmp.unlink
+ end
+ end
+
+end

0 comments on commit 5a3615b

Please sign in to comment.