Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added check_suppressed #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions lib/mad_mimi_mailable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ def hidden(hidden = nil)
@hidden = hidden
end
end

def check_suppressed(check_suppressed = nil)
if check_suppressed.nil?
@check_suppressed
else
@check_suppressed = check_suppressed
end
end

def unconfirmed(value = nil)
if value.nil?
Expand All @@ -56,9 +64,9 @@ def deliver_mimi_mail(method, *parameters)
mail = new
mail.__send__(method, *parameters)

if use_erb?(mail)
mail.create!(method, *parameters)
end
# if use_erb?(mail)
# mail.create!(method, *parameters)
# end

return unless perform_deliveries

Expand All @@ -85,10 +93,11 @@ def call_api!(mail, method)
'subject' => mail.subject,
'bcc' => serialize(mail.bcc || MadMimiMailer.default_parameters[:bcc]),
'from' => (mail.from || MadMimiMailer.default_parameters[:from]),
'hidden' => serialize(mail.hidden)
'hidden' => serialize(mail.hidden),
}

params['unconfirmed'] = '1' if mail.unconfirmed
params['check_suppressed'] = '1' if mail.check_suppressed

if use_erb?(mail)
if mail.parts.any?
Expand Down
149 changes: 88 additions & 61 deletions test/mad_mimi_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ def setup
def test_custom_promotion
mock_request = mock("request")
mock_request.expects(:set_form_data).with(
'username' => "[email protected]",
'api_key' => "w00tb4r",
'promotion_name' => "hello",
'recipients' => "[email protected]",
'subject' => "welcome to mad mimi",
'bcc' => "Gregg Pollack <[email protected]>, David Clymer <david@example>",
'from' => "[email protected]",
'body' => "--- \nmessage: welcome to mad mimi\n",
'hidden' => nil
'username' => "[email protected]",
'api_key' => "w00tb4r",
'promotion_name' => "hello",
'recipients' => "[email protected]",
'subject' => "welcome to mad mimi",
'bcc' => "Gregg Pollack <[email protected]>, David Clymer <david@example>",
'from' => "[email protected]",
'body' => "--- \nmessage: welcome to mad mimi\n",
'hidden' => nil
)
MadMimiMailer.expects(:post_request).yields(mock_request).returns(@ok_reponse)

Expand All @@ -29,15 +29,15 @@ def test_custom_promotion
def test_happy_path
mock_request = mock("request")
mock_request.expects(:set_form_data).with(
'username' => "[email protected]",
'api_key' => "w00tb4r",
'promotion_name' => "hello",
'recipients' => "[email protected]",
'subject' => "welcome to mad mimi",
'bcc' => "Gregg Pollack <[email protected]>, David Clymer <david@example>",
'from' => "[email protected]",
'body' => "--- \nmessage: welcome to mad mimi\n",
'hidden' => nil
'username' => "[email protected]",
'api_key' => "w00tb4r",
'promotion_name' => "hello",
'recipients' => "[email protected]",
'subject' => "welcome to mad mimi",
'bcc' => "Gregg Pollack <[email protected]>, David Clymer <david@example>",
'from' => "[email protected]",
'body' => "--- \nmessage: welcome to mad mimi\n",
'hidden' => nil
)
MadMimiMailer.expects(:post_request).yields(mock_request).returns(@ok_reponse)

Expand All @@ -48,15 +48,15 @@ def test_happy_path
def test_blank_bcc
mock_request = mock("request")
mock_request.expects(:set_form_data).with(
'username' => "[email protected]",
'api_key' => "w00tb4r",
'promotion_name' => "hello_sans_bcc",
'recipients' => "[email protected]",
'bcc' => nil,
'subject' => "welcome to mad mimi",
'from' => "[email protected]",
'body' => "--- \nmessage: welcome to mad mimi\n",
'hidden' => nil
'username' => "[email protected]",
'api_key' => "w00tb4r",
'promotion_name' => "hello_sans_bcc",
'recipients' => "[email protected]",
'bcc' => nil,
'subject' => "welcome to mad mimi",
'from' => "[email protected]",
'body' => "--- \nmessage: welcome to mad mimi\n",
'hidden' => nil
)
MadMimiMailer.expects(:post_request).yields(mock_request).returns(@ok_reponse)

Expand All @@ -66,15 +66,15 @@ def test_blank_bcc
def test_erb_render
mock_request = mock("request")
mock_request.expects(:set_form_data).with(
'username' => "[email protected]",
'api_key' => "w00tb4r",
'promotion_name' => "w00t",
'recipients' => "[email protected]",
'bcc' => nil,
'subject' => "welcome to mad mimi",
'from' => "[email protected]",
'raw_html' => "hi there, welcome to mad mimi [[peek_image]]",
'hidden' => nil
'username' => "[email protected]",
'api_key' => "w00tb4r",
'promotion_name' => "w00t",
'recipients' => "[email protected]",
'bcc' => nil,
'subject' => "welcome to mad mimi",
'from' => "[email protected]",
'raw_html' => "hi there, welcome to mad mimi [[peek_image]]",
'hidden' => nil
)
MadMimiMailer.expects(:post_request).yields(mock_request).returns(@ok_reponse)

Expand All @@ -84,47 +84,74 @@ def test_erb_render
def test_multipart_erb_render
mock_request = mock("request")
mock_request.expects(:set_form_data).with(
'username' => "[email protected]",
'api_key' => "w00tb4r",
'promotion_name' => 'w00t',
'recipients' => "[email protected]",
'bcc' => nil,
'subject' => "welcome to mad mimi",
'from' => "[email protected]",
'raw_html' => "hi there, welcome to mad mimi [[tracking_beacon]]",
'raw_plain_text' => "hi there, welcome to mad mimi!",
'hidden' => nil
'username' => "[email protected]",
'api_key' => "w00tb4r",
'promotion_name' => 'w00t',
'recipients' => "[email protected]",
'bcc' => nil,
'subject' => "welcome to mad mimi",
'from' => "[email protected]",
'raw_html' => "hi there, welcome to mad mimi [[tracking_beacon]]",
'raw_plain_text' => "hi there, welcome to mad mimi!",
'hidden' => nil
)
MadMimiMailer.expects(:post_request).yields(mock_request).returns(@ok_reponse)

MadMimiMailer.deliver_mimi_multipart_hello_erb("welcome to mad mimi")
end

def test_delivers_contain_unconfirmed_param_if_unconfirmed_is_set
mock_request = mock("request")
mock_request.expects(:set_form_data).with(
'username' => "[email protected]",
'api_key' => "w00tb4r",
'body' => "--- \nmessage: welcome unconfirmed user\n",
'promotion_name' => "woot",
'recipients' => '[email protected]',
'bcc' => nil,
'subject' => "welcome unconfirmed user",
'from' => "[email protected]",
'hidden' => nil,
'unconfirmed' => '1'
'username' => "[email protected]",
'api_key' => "w00tb4r",
'body' => "--- \nmessage: welcome unconfirmed user\n",
'promotion_name' => "woot",
'recipients' => '[email protected]',
'bcc' => nil,
'subject' => "welcome unconfirmed user",
'from' => "[email protected]",
'hidden' => nil,
'unconfirmed' => '1'
)
MadMimiMailer.expects(:post_request).yields(mock_request).returns(@ok_reponse)

MadMimiMailer.deliver_mimi_unconfirmed("welcome unconfirmed user")
end

# check_suppressed true
# subject greeting
# recipients '[email protected]'
# from '[email protected]'
# promotion 'woot'
# body :message => greeting
# unconfirmed true

def test_delivers_check_suppressed_param_if_check_suppressed_is_set
mock_request = mock("request")
mock_request.expects(:set_form_data).with(
'username' => "[email protected]",
'api_key' => "w00tb4r",
'body' => "--- \nmessage: welcome user\n",
'promotion_name' => "woot",
'recipients' => '[email protected]',
'bcc' => nil,
'subject' => "welcome user",
'from' => "[email protected]",
'hidden' => nil,
'check_suppressed' => '1'
)
MadMimiMailer.expects(:post_request).yields(mock_request).returns(@ok_reponse)

MadMimiMailer.deliver_mimi_supressed("welcome user")
end

def test_deliveries_contain_tmail_objects_when_use_erb_in_test_mode
ActionMailer::Base.delivery_method = :test
MadMimiMailer.deliver_mimi_multipart_hello_erb("welcome to mad mimi")
ActionMailer::Base.delivery_method = :smtp

assert ActionMailer::Base.deliveries.all?{|m| m.kind_of?(TMail::Mail)}
assert ActionMailer::Base.deliveries.all? { |m| m.kind_of?(TMail::Mail) }
end

def test_erb_render_fails_without_peek_image
Expand Down Expand Up @@ -168,13 +195,13 @@ def test_no_mailer_api_enabled
MadMimiMailer.deliver_mimi_hello("welcome to mad mimi")
end
end

def test_normal_non_mimi_email
ActionMailer::Base.delivery_method = :test
MadMimiMailer.expects(:post_request).never
MadMimiMailer.deliver_normal_non_mimi_email
MadMimiMailer.deliver_normal_non_mimi_email
end

def test_assert_mail_sent
ActionMailer::Base.delivery_method = :test
MadMimiMailer.deliver_mimi_hello("welcome to mad mimi")
Expand Down
17 changes: 13 additions & 4 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
require "mad_mimi_mailer"

MadMimiMailer.api_settings = {
:username => "[email protected]",
:api_key => "w00tb4r"
:username => "[email protected]",
:api_key => "w00tb4r"
}

class MadMimiMailer
Expand Down Expand Up @@ -62,7 +62,7 @@ def mimi_hello_sans_bcc(greeting)
from "[email protected]"
body :message => greeting
end

def mimi_unconfirmed(greeting)
subject greeting
recipients '[email protected]'
Expand All @@ -71,7 +71,16 @@ def mimi_unconfirmed(greeting)
body :message => greeting
unconfirmed true
end


def mimi_supressed(greeting)
subject greeting
recipients '[email protected]'
from '[email protected]'
promotion 'woot'
body :message => greeting
check_suppressed true
end

def normal_non_mimi_email
subject "Look, I'm normal!"
recipients "[email protected]"
Expand Down