Skip to content

Commit

Permalink
Delivey Method Implementation (hanami#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
inescoelho committed Aug 24, 2015
1 parent a45b1c4 commit 24de222
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ gem 'tilt'

gem 'simplecov', require: false
gem 'coveralls', require: false
gem 'mail'
41 changes: 40 additions & 1 deletion lib/lotus/mailer/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ def load!
# Reset the configuration
def reset!
root(DEFAULT_ROOT)

@mailers = Set.new
@modules = []
end
Expand All @@ -183,10 +182,50 @@ def copy!(base)
end
end

# Specify a global delivery method
#
# @param method [Symbol] delivery method
# @param options [Hash] optional settings
#
# @return [Array] an array containing the delivery method and the optional settings as an Hash
#
# @since 0.1.0
#
# @example With Method only
# Lotus::Mailer.configure do
# delivery_method :sendmail
# end
#
# @example With Method and Options
# Lotus::Mailer.configure do
# delivery_method :smtp, address: "localhost", port: 1025
# end
#
# @example Using a Method Alias
# Lotus::Mailer.configure do
# delivery :test
# end
#
# @example With Custom Method
# MyCustomDeliveryMethod = :smtp
#
# Lotus::Mailer.configure do
# delivery_method MyCustomDeliveryMethod, foo: 'bar'
# end
def delivery_method(method = nil, options = {})
if method.nil?
@delivery_method
else
@delivery_method = [method, options]
end
end

alias_method :unload!, :reset!
alias_method :delivery, :delivery_method

protected
attr_writer :root
attr_writer :delivery_method
attr_writer :namespace
attr_writer :modules
end
Expand Down
12 changes: 12 additions & 0 deletions test/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,17 @@ class PrepareMailer
@configuration.root.must_equal root
end
end

describe '#delivery_method' do
before do
MyCustomDeliveryMethod = :smtp
Lotus::Mailer.configure do
delivery_method MyCustomDeliveryMethod, foo: 'bar'
end
end

it 'saves the delivery method in the configuration' do
Lotus::Mailer.configuration.delivery_method.must_equal [:smtp, { foo: 'bar' }]
end
end
end
2 changes: 2 additions & 0 deletions test/fixtures.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'mail'

class InvoiceMailer
include Lotus::Mailer
template :html, 'invoice.html.erb'
Expand Down

0 comments on commit 24de222

Please sign in to comment.