Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposing Letter Opener File Save Path #207

Merged
merged 1 commit into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/letter_opener/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def render
File.open(filepath, 'w') do |f|
f.write ERB.new(template).result(binding)
end

mail["location_#{type}"] = filepath
end

def template
Expand Down
17 changes: 17 additions & 0 deletions spec/letter_opener/message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,23 @@ def mail(options={}, &blk)
end
end

describe '#render' do
it 'records the saved email path for plain content type' do
mail = mail(:subject => 'test_mail')
message = described_class.new(mail, location: location)
message.render
expect(mail['location_plain'].value).to end_with('tmp/letter_opener/plain.html')
end


it 'records the saved email path for rich content type' do
mail = mail(:content_type => 'text/html', :subject => 'test_mail')
message = described_class.new(mail, location: location)
message.render
expect(mail['location_rich'].value).to end_with('tmp/letter_opener/rich.html')
end
end

describe '.rendered_messages' do
it 'uses configured default template if options not given' do
allow(LetterOpener.configuration).to receive(:location) { location }
Expand Down