diff --git a/lib/mad_mimi_mailable.rb b/lib/mad_mimi_mailable.rb index 340730a..801885e 100644 --- a/lib/mad_mimi_mailable.rb +++ b/lib/mad_mimi_mailable.rb @@ -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? @@ -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 @@ -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? diff --git a/test/mad_mimi_mailer_test.rb b/test/mad_mimi_mailer_test.rb index 8756890..dcf51ca 100644 --- a/test/mad_mimi_mailer_test.rb +++ b/test/mad_mimi_mailer_test.rb @@ -11,15 +11,15 @@ def setup def test_custom_promotion mock_request = mock("request") mock_request.expects(:set_form_data).with( - 'username' => "testy@mctestin.com", - 'api_key' => "w00tb4r", - 'promotion_name' => "hello", - 'recipients' => "tyler@obtiva.com", - 'subject' => "welcome to mad mimi", - 'bcc' => "Gregg Pollack , David Clymer ", - 'from' => "dave@obtiva.com", - 'body' => "--- \nmessage: welcome to mad mimi\n", - 'hidden' => nil + 'username' => "testy@mctestin.com", + 'api_key' => "w00tb4r", + 'promotion_name' => "hello", + 'recipients' => "tyler@obtiva.com", + 'subject' => "welcome to mad mimi", + 'bcc' => "Gregg Pollack , David Clymer ", + 'from' => "dave@obtiva.com", + 'body' => "--- \nmessage: welcome to mad mimi\n", + 'hidden' => nil ) MadMimiMailer.expects(:post_request).yields(mock_request).returns(@ok_reponse) @@ -29,15 +29,15 @@ def test_custom_promotion def test_happy_path mock_request = mock("request") mock_request.expects(:set_form_data).with( - 'username' => "testy@mctestin.com", - 'api_key' => "w00tb4r", - 'promotion_name' => "hello", - 'recipients' => "tyler@obtiva.com", - 'subject' => "welcome to mad mimi", - 'bcc' => "Gregg Pollack , David Clymer ", - 'from' => "dave@obtiva.com", - 'body' => "--- \nmessage: welcome to mad mimi\n", - 'hidden' => nil + 'username' => "testy@mctestin.com", + 'api_key' => "w00tb4r", + 'promotion_name' => "hello", + 'recipients' => "tyler@obtiva.com", + 'subject' => "welcome to mad mimi", + 'bcc' => "Gregg Pollack , David Clymer ", + 'from' => "dave@obtiva.com", + 'body' => "--- \nmessage: welcome to mad mimi\n", + 'hidden' => nil ) MadMimiMailer.expects(:post_request).yields(mock_request).returns(@ok_reponse) @@ -48,15 +48,15 @@ def test_happy_path def test_blank_bcc mock_request = mock("request") mock_request.expects(:set_form_data).with( - 'username' => "testy@mctestin.com", - 'api_key' => "w00tb4r", - 'promotion_name' => "hello_sans_bcc", - 'recipients' => "tyler@obtiva.com", - 'bcc' => nil, - 'subject' => "welcome to mad mimi", - 'from' => "dave@obtiva.com", - 'body' => "--- \nmessage: welcome to mad mimi\n", - 'hidden' => nil + 'username' => "testy@mctestin.com", + 'api_key' => "w00tb4r", + 'promotion_name' => "hello_sans_bcc", + 'recipients' => "tyler@obtiva.com", + 'bcc' => nil, + 'subject' => "welcome to mad mimi", + 'from' => "dave@obtiva.com", + 'body' => "--- \nmessage: welcome to mad mimi\n", + 'hidden' => nil ) MadMimiMailer.expects(:post_request).yields(mock_request).returns(@ok_reponse) @@ -66,15 +66,15 @@ def test_blank_bcc def test_erb_render mock_request = mock("request") mock_request.expects(:set_form_data).with( - 'username' => "testy@mctestin.com", - 'api_key' => "w00tb4r", - 'promotion_name' => "w00t", - 'recipients' => "tyler@obtiva.com", - 'bcc' => nil, - 'subject' => "welcome to mad mimi", - 'from' => "dave@obtiva.com", - 'raw_html' => "hi there, welcome to mad mimi [[peek_image]]", - 'hidden' => nil + 'username' => "testy@mctestin.com", + 'api_key' => "w00tb4r", + 'promotion_name' => "w00t", + 'recipients' => "tyler@obtiva.com", + 'bcc' => nil, + 'subject' => "welcome to mad mimi", + 'from' => "dave@obtiva.com", + 'raw_html' => "hi there, welcome to mad mimi [[peek_image]]", + 'hidden' => nil ) MadMimiMailer.expects(:post_request).yields(mock_request).returns(@ok_reponse) @@ -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' => "testy@mctestin.com", - 'api_key' => "w00tb4r", - 'promotion_name' => 'w00t', - 'recipients' => "sandro@hashrocket.com", - 'bcc' => nil, - 'subject' => "welcome to mad mimi", - 'from' => "stephen@hashrocket.com", - 'raw_html' => "hi there, welcome to mad mimi [[tracking_beacon]]", - 'raw_plain_text' => "hi there, welcome to mad mimi!", - 'hidden' => nil + 'username' => "testy@mctestin.com", + 'api_key' => "w00tb4r", + 'promotion_name' => 'w00t', + 'recipients' => "sandro@hashrocket.com", + 'bcc' => nil, + 'subject' => "welcome to mad mimi", + 'from' => "stephen@hashrocket.com", + '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' => "testy@mctestin.com", - 'api_key' => "w00tb4r", - 'body' => "--- \nmessage: welcome unconfirmed user\n", - 'promotion_name' => "woot", - 'recipients' => 'egunderson@obtiva.com', - 'bcc' => nil, - 'subject' => "welcome unconfirmed user", - 'from' => "mimi@obtiva.com", - 'hidden' => nil, - 'unconfirmed' => '1' + 'username' => "testy@mctestin.com", + 'api_key' => "w00tb4r", + 'body' => "--- \nmessage: welcome unconfirmed user\n", + 'promotion_name' => "woot", + 'recipients' => 'egunderson@obtiva.com', + 'bcc' => nil, + 'subject' => "welcome unconfirmed user", + 'from' => "mimi@obtiva.com", + '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 'egunderson@obtiva.com' +# from 'mimi@obtiva.com' +# 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' => "testy@mctestin.com", + 'api_key' => "w00tb4r", + 'body' => "--- \nmessage: welcome user\n", + 'promotion_name' => "woot", + 'recipients' => 'egunderson@obtiva.com', + 'bcc' => nil, + 'subject' => "welcome user", + 'from' => "mimi@obtiva.com", + '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 @@ -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") diff --git a/test/test_helper.rb b/test/test_helper.rb index de7ebd8..067a0e0 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -5,8 +5,8 @@ require "mad_mimi_mailer" MadMimiMailer.api_settings = { - :username => "testy@mctestin.com", - :api_key => "w00tb4r" + :username => "testy@mctestin.com", + :api_key => "w00tb4r" } class MadMimiMailer @@ -62,7 +62,7 @@ def mimi_hello_sans_bcc(greeting) from "dave@obtiva.com" body :message => greeting end - + def mimi_unconfirmed(greeting) subject greeting recipients 'egunderson@obtiva.com' @@ -71,7 +71,16 @@ def mimi_unconfirmed(greeting) body :message => greeting unconfirmed true end - + + def mimi_supressed(greeting) + subject greeting + recipients 'egunderson@obtiva.com' + from 'mimi@obtiva.com' + promotion 'woot' + body :message => greeting + check_suppressed true + end + def normal_non_mimi_email subject "Look, I'm normal!" recipients "tyler@obtiva.com"