Skip to content

Commit

Permalink
Delivery Method Implementation (hanami#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
inescoelho committed Aug 18, 2015
1 parent 8f6ae1f commit b7732b5
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 244 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ rvm:
- 2.2.2
- rbx-2
- jruby-head
- jruby-9000

matrix:
include:
- rvm: jruby-head
allow_failures:
- rvm: jruby-head
- rvm: jruby-9000
1 change: 1 addition & 0 deletions lib/lotus/mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'lotus/mailer/configuration'
require 'lotus/mailer/dsl'
require 'lotus/mailer/rendering'
require 'mail'

module Lotus
module Mailer
Expand Down
50 changes: 8 additions & 42 deletions lib/lotus/mailer/dsl.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'lotus/mailer/rendering/template_name'
require 'lotus/mailer/rendering/templates_finder'
require 'lotus/mailer/rendering/template_finder'

module Lotus
module Mailer
Expand Down Expand Up @@ -71,39 +70,10 @@ def root(value = nil)
# end
#
# Articles::Show.template(:json) # 'articles'
#
# @example With nested namespace
# require 'lotus/mailer'
#
# module Frontend
# Mailer = Lotus::Mailer.generate(self)
#
# class InvoiceMailer
# include Frontend::Mailer
# end
#
# module Mailers
# class Invoice
# include Frontend::Mailer
# end
#
# module Sessions
# class New
# include Frontend::Mailer
# end
# end
# end
# end
#
# Frontend::InvoiceMailer.template # => 'standalone_mailer'
# Frontend::Mailers::Invoice.template # => 'standalone'
# Frontend::Mailers::Sessions::New.template # => 'sessions/new'
def template(format = nil, value = nil)
if value.nil?
if !@templates.has_key?(format)
@templates[format] = Rendering::TemplateName.new(name, configuration.namespace).to_s
else
@templates[format]
end
else
@templates[format] = Mailer::Template.new("#{ [root, value].join('/') }")
Expand Down Expand Up @@ -142,22 +112,21 @@ def templates(value = nil)
# include Lotus::Mailer
#
# from "noreply@example.com"
#
# end
#
# @example With Procs
# class ProcMailer
# include Lotus::Mailer
#
# from = Proc.new { customized_sender }
# from -> { customized_sender }
#
# def customized_sender
# "user_sender@example.com"
# end
# end
def from (value = nil)
def from(value = nil)
if value.nil?
return new.eval_proc(@from)
new.eval_proc(@from)
else
@from = value
end
Expand All @@ -177,28 +146,26 @@ def from (value = nil)
# include Lotus::Mailer
#
# to "noreply@example.com"
#
# end
#
# @example With Array of Strings
# class ArrayMailer
# include Lotus::Mailer
#
# to ["noreply1@example.com", "noreply2@example.com"]
#
# end
#
# @example With Procs
# class ProcMailer
# include Lotus::Mailer
#
# to = Proc.new { customized_receiver }
# to -> { customized_receiver }
#
# def customized_receiver
# "user_receiver@example.com"
# end
# end
def to (value = nil)
def to(value = nil)
if value.nil?
return new.eval_proc(@to)
end
Expand All @@ -223,22 +190,21 @@ def to (value = nil)
# include Lotus::Mailer
#
# subject "This is the subject"
#
# end
#
# @example With Procs
# class ProcMailer
# include Lotus::Mailer
#
# from = Proc.new { customized_subject }
# subject -> { customized_subject }
#
# def customized_subject
# "This is the subject"
# end
# end
def subject (value = nil)
def subject(value = nil)
if value.nil?
return new.eval_proc(@subject)
new.eval_proc(@subject)
else
@subject = value
end
Expand Down
56 changes: 0 additions & 56 deletions lib/lotus/mailer/rendering/template.rb

This file was deleted.

53 changes: 0 additions & 53 deletions lib/lotus/mailer/rendering/template_finder.rb

This file was deleted.

82 changes: 82 additions & 0 deletions test/dsl_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
require 'test_helper'
require 'lotus/mailer'

describe Lotus::Mailer do
before do
Lotus::Mailer.reset!
end

describe '#root' do
describe 'when a value is given' do
it 'sets it as a Pathname' do
RenderMailer.root 'test'
RenderMailer.configuration.root.must_equal(RenderMailer.root)
end
end
end

describe '#template' do
describe 'set the correct templates' do
it 'has the template in the hash' do
template_test = InvoiceMailer.templates[:html]
template_test.file.must_equal("#{ InvoiceMailer.root }/invoice.html.erb")
end
end
end

describe '#templates' do
describe 'finds all the templates with the same name' do
it 'has the template in the hash' do
template_test = LazyMailer.templates[:html]
template_test.file.must_equal("#{ LazyMailer.root }/lazy_mailer.html.erb")
template_test = LazyMailer.templates[:haml]
template_test.file.must_equal("#{ LazyMailer.root }/lazy_mailer.haml.erb")
end
end
end

describe '#from' do
describe 'sets the correct sender address given a string' do
it 'has the address in the variable' do
StringMailer.from.must_equal 'noreply@example.com'
end
end
describe 'sets the correct sender address given a proc' do
it 'has the address in the variable' do
ProcMailer.from.must_equal 'user_sender@example.com'
end
end
end

describe '#to' do
describe 'sets the correct recipients given a string' do
it 'has the recipients in the variable' do
StringMailer.to.must_equal 'noreply1@example.com'
end
end
describe 'sets the correct recipients given an array' do
it 'has the recipients in the variable' do
ArrayMailer.to.must_equal 'noreply1@example.com,noreply2@example.com'
end
end
describe 'sets the correct recipients given a proc' do
it 'has the recipients in the variable' do
ProcMailer.to.must_equal 'user_receiver@example.com'
end
end
end

describe '#subject' do
describe 'sets the correct subject given a string' do
it 'has the subject in the variable' do
StringMailer.subject.must_equal 'This is the subject'
end
end
describe 'sets the correct subject given a proc' do
it 'has the subject in the variable' do
ProcMailer.subject.must_equal 'This is the subject'
end
end
end

end
28 changes: 0 additions & 28 deletions test/mailer_test.rb

This file was deleted.

Loading

0 comments on commit b7732b5

Please sign in to comment.