Skip to content

Commit

Permalink
fail properly on wrong mailer name or message, fixes #1965
Browse files Browse the repository at this point in the history
  • Loading branch information
ujifgc committed Sep 17, 2015
1 parent 5932d55 commit f05e39d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion padrino-mailer/lib/padrino-mailer/helpers.rb
Expand Up @@ -106,7 +106,9 @@ def mailer(name, &block)
# deliver(:example, :message, "John")
#
def deliver(mailer_name, message_name, *attributes)
message = registered_mailers[mailer_name].messages[message_name].call(*attributes)
mailer = registered_mailers[mailer_name] or fail "mailer '#{mailer_name}' is not registered"
message = mailer.messages[message_name] or fail "mailer '#{mailer_name}' has no message '#{message_name}'"
message = message.call(*attributes)
message.delivery_method(*delivery_settings)
message.deliver
end
Expand Down
9 changes: 9 additions & 0 deletions padrino-mailer/test/fixtures/padrino_app/app.rb
Expand Up @@ -44,7 +44,9 @@ class PadrinoApp < Padrino::Application
via :test
render 'sample/helper_message'
end
end

mailer :nonexistant do
end

post "/deliver/inline" do
Expand Down Expand Up @@ -72,6 +74,13 @@ class PadrinoApp < Padrino::Application
result ? "mail delivered" : 'mail not delivered'
end

post "/deliver/failing_mailer" do
deliver(:nonregistered, :mailer, "hey")
end

post "/deliver/failing_message" do
deliver(:nonexistant, :message, "hey")
end
end

Padrino.mount("PadrinoApp").to("/")
Expand Down
14 changes: 14 additions & 0 deletions padrino-mailer/test/test_padrino_mailer.rb
Expand Up @@ -110,5 +110,19 @@
:content_type => 'text/html', :delivery_method => @app.delivery_method,
:subject => 'Welcome Helper!', :body => "<a href=\"#\">jim</a>")
end

it 'should fail with proper message if mailer is not registered' do
error = assert_raises RuntimeError do
post '/deliver/failing_mailer'
end
assert_match /is not registered/, error.message
end

it 'should fail with proper message if message does not exist' do
error = assert_raises RuntimeError do
post '/deliver/failing_message'
end
assert_match /has no message/, error.message
end
end
end

0 comments on commit f05e39d

Please sign in to comment.