Skip to content
This repository was archived by the owner on Mar 2, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/mail_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def call(env)
end

def call(env)
request = Rack::Request.new(env)
@request = Rack::Request.new(env)

if request.path_info == "" || request.path_info == "/"
links = self.actions.map do |action|
Expand Down Expand Up @@ -67,6 +67,10 @@ def call(env)
def actions
public_methods(false).map(&:to_s).sort - ['call']
end

def request
@request
end

def email_template
Tilt.new(email_template_path)
Expand Down Expand Up @@ -110,7 +114,7 @@ def find_preferred_part(mail, formats)
end

def part_body_url(part)
'?part=%s' % Rack::Utils.escape([part.main_type, part.sub_type].compact.join('/'))
"?#{request.params.merge({'part' => [part.main_type, part.sub_type].compact.join('/')}).to_param}"
end

def find_part(mail, matching_content_type)
Expand Down
4 changes: 2 additions & 2 deletions lib/mail_view/email.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
<% if mail.multipart? %>
<dd>
<select onchange="document.getElementsByName('messageBody')[0].src=this.options[this.selectedIndex].value;">
<option value="?part=text%2Fhtml">View as HTML email</option>
<option value="?part=text%2Fplain">View as plain-text email</option>
<option value="?#{ request.params.merge({'part' => 'text/html' }).to_param }">View as HTML email</option>
<option value="?#{ request.params.merge({'part' => 'text/plain'}).to_param }">View as plain-text email</option>
</select>
</dd>
<% end %>
Expand Down
14 changes: 14 additions & 0 deletions test/test_mail_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ def plain_text_message
yield self if block_given?
end
end

def use_request_params_in_preview
locale = request.params['locale']
Mail.new do
to '[email protected]'
body "Locale: #{locale}"
yield self if block_given?
end
end

def plain_text_message_with_display_names
Mail.new do
Expand Down Expand Up @@ -145,6 +154,11 @@ def test_index
assert_match '/html_message', last_response.body
assert_match '/multipart_alternative', last_response.body
end

def test_use_request_params_in_preview
get '/use_request_params_in_preview?locale=en&part='
assert_match 'Locale: en', last_response.body
end

def test_mounted_index
get '/', {}, 'SCRIPT_NAME' => '/boom'
Expand Down