diff --git a/lib/lotus/mailer/rendering.rb b/lib/lotus/mailer/rendering.rb index 0f2e8ea..3f2805f 100644 --- a/lib/lotus/mailer/rendering.rb +++ b/lib/lotus/mailer/rendering.rb @@ -11,15 +11,19 @@ def self.extended(base) end module InstanceMethods + # @private + # @since 0.1.0 + attr_accessor :mail + # Initialize a mailer # # @param locals [Hash] a set of objects available during the rendering process. # # @since 0.1.0 def initialize(locals = {}) - @locals = locals - @scope = self - @mail = Mail.new + @locals = locals + @scope = self + @mail = Mail.new end # Render a single template with the specified format. @@ -33,8 +37,6 @@ def render(format) self.class.templates self.class.templates[format].render @scope, @locals end - - attr_accessor :mail end end end diff --git a/test/fixtures.rb b/test/fixtures.rb index 0210b7f..ccb43c9 100644 --- a/test/fixtures.rb +++ b/test/fixtures.rb @@ -49,23 +49,17 @@ class ArrayMailer class WelcomeMailer include Lotus::Mailer - + from "noreply@sender.com" to "noreply@recipient.com" subject "Welcome" - + def greeting "Ahoy" end end -class User - def initialize(name) - @name = name - end - - attr_reader :name -end +class User < Struct.new(:name); end class SubscriptionMailer include Lotus::Mailer diff --git a/test/fixtures/templates/welcome_mailer.html.erb b/test/fixtures/templates/welcome_mailer.html.erb index 34895e1..cede28f 100644 --- a/test/fixtures/templates/welcome_mailer.html.erb +++ b/test/fixtures/templates/welcome_mailer.html.erb @@ -1,9 +1,8 @@ -
This is a html template
diff --git a/test/fixtures/templates/welcome_mailer.txt.erb b/test/fixtures/templates/welcome_mailer.txt.erb index 9362e81..51015e8 100644 --- a/test/fixtures/templates/welcome_mailer.txt.erb +++ b/test/fixtures/templates/welcome_mailer.txt.erb @@ -1,2 +1,2 @@ This is a txt template -<%=greeting%> +<%= greeting %> diff --git a/test/rendering_test.rb b/test/rendering_test.rb index fd9ae30..511b7cd 100644 --- a/test/rendering_test.rb +++ b/test/rendering_test.rb @@ -1,25 +1,39 @@ require 'test_helper' -require 'lotus/mailer' describe Lotus::Mailer do - describe 'render' do - it 'renders a single template with a given format' do - InvoiceMailer.new.render(:html).must_include %(