Skip to content

Commit

Permalink
Add multiple recipients.
Browse files Browse the repository at this point in the history
  • Loading branch information
seliverstov-maxim authored and NOX73 committed May 27, 2014
1 parent da75bf7 commit 26c9e31
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source :rubygems
source 'https://rubygems.org'

gemspec
15 changes: 5 additions & 10 deletions lib/mail_sandbox/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,26 @@

module MailSandbox
class Message

attr_accessor :data, :recipient, :sender, :completed_at,
:user,
:password

attr_accessor :data, :recipients, :sender, :completed_at, :user, :password

def initialize
@data = []
@recipients = []
end

def to_json
to_a.to_json
to_hash.to_json
end


def to_a
def to_hash
{
:password => password,
:user => user,
:recipient => recipient,
:recipients => recipients.join(','),
:sender => sender,
:completed_at => completed_at,
:data => data.join("\r\n"),
}
end

end
end
2 changes: 1 addition & 1 deletion lib/mail_sandbox/observer/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(url, method = :post)
end

def update(message)
body = {:message => message.to_a}
body = {:message => message.to_hash}

MailSandbox.logger.debug "Observer::Http send to #{@url} method #{@method} body #{body.to_s}"

Expand Down
2 changes: 1 addition & 1 deletion lib/mail_sandbox/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def receive_sender(sender)
end

def receive_recipient(recipient)
message.recipient = recipient
message.recipients << recipient
true
end

Expand Down
29 changes: 29 additions & 0 deletions test/integration/em_server_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require "test_helper"

class EmServerTest < MiniTest::Unit::TestCase
def setup
@em_host = 'localhost'
@em_port = 2525
end

def test_multiple_recipients
c = nil
EM.run {
EM.start_server(@em_host, @em_port, MailSandbox::Server) { |conn| c = conn }

EM::Timer.new(5) { EM.stop }

EM::Protocols::SmtpClient.send ({
host: @em_host,
port: @em_port,
domain: "example.com",
from: "me@example.com",
to: ["you@example.com", "we@example.com"],
header: {"Subject"=>"Email subject line", "Reply-to"=>"me@example.com"},
body: "Not much of interest here."
})
}

assert_equal( c.message.recipients, ["<you@example.com>", "<we@example.com>"] )
end
end
4 changes: 0 additions & 4 deletions test/integration/spawn_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,4 @@ def test_server_auth

assert alive?
end




end
4 changes: 3 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
require "socket"
require 'support/my_observer'
require 'net/smtp'
require 'mocha'

require "minitest/unit"
require "mocha/mini_test"

module SpawnHelper
PID_FILE = "/tmp/mail_sandbox.#{rand*1000.to_i}.pid"
Expand Down
2 changes: 1 addition & 1 deletion test/unit/subscribe_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_observer_notify

def test_http_observer
url = "http://localhost/api"
body = {:body => {:message => @message.to_a}}
body = {:body => {:message => @message.to_hash}}

http_mock = mock()
http_mock.stubs(:callback)
Expand Down

0 comments on commit 26c9e31

Please sign in to comment.