Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Whitespace cleanup

  • Loading branch information...
commit 2aeaf546c7be885ca88de40293442c60d9c919a3 1 parent 47a7b84
Sandro Turriate and Stephen Caudill authored committed
Showing with 29 additions and 29 deletions.
  1. +17 −17 lib/mad_mimi_mailer.rb
  2. +12 −12 test/mad_mimi_mailer_test.rb
View
34 lib/mad_mimi_mailer.rb
@@ -12,13 +12,13 @@ class MadMimiMailer < ActionMailer::Base
# Custom Mailer attributes
def promotion(promotion = nil)
- if promotion.nil?
+ if promotion.nil?
@promotion
else
@promotion = promotion
end
end
-
+
def use_erb(use_erb = nil)
if use_erb.nil?
@use_erb
@@ -26,7 +26,7 @@ def use_erb(use_erb = nil)
@use_erb = use_erb
end
end
-
+
def hidden(hidden = nil)
if hidden.nil?
@hidden
@@ -36,25 +36,25 @@ def hidden(hidden = nil)
end
# Class methods
-
- class << self
-
+
+ class << self
+
def method_missing(method_symbol, *parameters)
if method_symbol.id2name.match(/^deliver_(mimi_[_a-z]\w*)/)
deliver_mimi_mail($1, *parameters)
else
super
- end
+ end
end
-
+
def deliver_mimi_mail(method, *parameters)
- mail = new
+ mail = new
mail.__send__(method, *parameters)
if mail.use_erb
mail.create!(method, *parameters)
end
-
+
return unless perform_deliveries
if delivery_method == :test
@@ -63,12 +63,12 @@ def deliver_mimi_mail(method, *parameters)
call_api!(mail, method)
end
end
-
+
def call_api!(mail, method)
params = {
'username' => api_settings[:username],
'api_key' => api_settings[:api_key],
-
+
'promotion_name' => mail.promotion || method.to_s.sub(/^mimi_/, ''),
'recipients' => serialize(mail.recipients),
'subject' => mail.subject,
@@ -85,11 +85,11 @@ def call_api!(mail, method)
else
params['body'] = mail.body.to_yaml
end
-
+
response = post_request do |request|
request.set_form_data(params)
end
-
+
case response
when Net::HTTPSuccess
response.body
@@ -97,7 +97,7 @@ def call_api!(mail, method)
response.error!
end
end
-
+
def post_request
url = URI.parse(SINGLE_SEND_URL)
request = Net::HTTP::Post.new(url.path)
@@ -108,7 +108,7 @@ def post_request
http.request(request)
end
end
-
+
def serialize(recipients)
case recipients
when String
@@ -122,7 +122,7 @@ def serialize(recipients)
end
end
end
-
+
class ValidationError < StandardError; end
end
View
24 test/mad_mimi_mailer_test.rb
@@ -7,11 +7,11 @@
MadMimiMailer.api_settings = {
:username => "testy@mctestin.com",
:api_key => "w00tb4r"
-}
+}
class MadMimiMailer
self.template_root = File.dirname(__FILE__) + '/templates/'
-
+
def mimi_hola(greeting)
subject greeting
recipients "tyler@obtiva.com"
@@ -46,7 +46,7 @@ def mimi_bye_erb(greeting)
use_erb true
body :message => greeting
end
-
+
def mimi_hello_sans_bcc(greeting)
subject greeting
recipients "tyler@obtiva.com"
@@ -72,7 +72,7 @@ def test_custom_promotion
)
response = Net::HTTPSuccess.new("1.2", '200', 'OK')
response.stubs(:body).returns("123435")
- MadMimiMailer.expects(:post_request).yields(mock_request).returns(response)
+ MadMimiMailer.expects(:post_request).yields(mock_request).returns(response)
MadMimiMailer.deliver_mimi_hola("welcome to mad mimi")
end
@@ -92,7 +92,7 @@ def test_happy_path
)
response = Net::HTTPSuccess.new("1.2", '200', 'OK')
response.stubs(:body).returns("123435")
- MadMimiMailer.expects(:post_request).yields(mock_request).returns(response)
+ MadMimiMailer.expects(:post_request).yields(mock_request).returns(response)
promotion_attempt_id = MadMimiMailer.deliver_mimi_hello("welcome to mad mimi")
assert_equal "123435", promotion_attempt_id
@@ -113,7 +113,7 @@ def test_blank_bcc
)
response = Net::HTTPSuccess.new("1.2", '200', 'OK')
response.stubs(:body).returns("123435")
- MadMimiMailer.expects(:post_request).yields(mock_request).returns(response)
+ MadMimiMailer.expects(:post_request).yields(mock_request).returns(response)
MadMimiMailer.deliver_mimi_hello_sans_bcc("welcome to mad mimi")
end
@@ -133,7 +133,7 @@ def test_erb_render
)
response = Net::HTTPSuccess.new("1.2", '200', 'OK')
response.stubs(:body).returns("123435")
- MadMimiMailer.expects(:post_request).yields(mock_request).returns(response)
+ MadMimiMailer.expects(:post_request).yields(mock_request).returns(response)
MadMimiMailer.deliver_mimi_hello_erb("welcome to mad mimi")
end
@@ -143,13 +143,13 @@ def test_erb_render_fails_without_peek_image
MadMimiMailer.deliver_mimi_bye_erb("welcome to mad mimi")
end
end
-
+
def test_bad_promotion_name
mock_request = mock("request")
mock_request.stubs(:set_form_data)
response = Net::HTTPNotFound.new('1.2', '404', 'Not found')
response.stubs(:body).returns("Could not find promotion by that name")
- MadMimiMailer.expects(:post_request).yields(mock_request).returns(response)
+ MadMimiMailer.expects(:post_request).yields(mock_request).returns(response)
assert_raise(Net::HTTPServerException) do
MadMimiMailer.deliver_mimi_hello("welcome to mad mimi")
@@ -161,19 +161,19 @@ def test_no_more_audience_space
mock_request.stubs(:set_form_data)
response = Net::HTTPPaymentRequired.new('1.2', '402', 'Payment required')
response.stubs(:body).returns("Please upgrade")
- MadMimiMailer.expects(:post_request).yields(mock_request).returns(response)
+ MadMimiMailer.expects(:post_request).yields(mock_request).returns(response)
assert_raise(Net::HTTPServerException) do
MadMimiMailer.deliver_mimi_hello("welcome to mad mimi")
end
end
-
+
def test_no_mailer_api_enabled
mock_request = mock("request")
mock_request.stubs(:set_form_data)
response = Net::HTTPUnauthorized.new('1.2', '401', 'Unauthorized')
response.stubs(:body).returns("Please get an mailer api subscription")
- MadMimiMailer.expects(:post_request).yields(mock_request).returns(response)
+ MadMimiMailer.expects(:post_request).yields(mock_request).returns(response)
assert_raise(Net::HTTPServerException) do
MadMimiMailer.deliver_mimi_hello("welcome to mad mimi")
Please sign in to comment.
Something went wrong with that request. Please try again.