Skip to content

Commit

Permalink
Merge pull request #662 from alphagov/add-html-template-for-feedback-…
Browse files Browse the repository at this point in the history
…messages

Add a HTML template for feedback messages
  • Loading branch information
pixeltrix authored Jul 20, 2018
2 parents 2dd7ac2 + 00b9fa9 commit a1fccab
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
addons:
postgresql: "9.4"
before_install:
- gem install bundler
- gem install bundler -v 1.16.2
- |
export PHANTOMJS_VERSION=2.1.1
export PATH=$PWD/travis_phantomjs/phantomjs-$PHANTOMJS_VERSION-linux-x86_64/bin:$PATH
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,4 @@ DEPENDENCIES
will_paginate

BUNDLED WITH
1.16.0
1.16.2
4 changes: 4 additions & 0 deletions app/models/feedback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ class Feedback < ActiveRecord::Base
validates :comment, presence: true, length: { maximum: 32768 }
validates :petition_link_or_title, length: { maximum: 255 }, allow_blank: true
validates :email, format: { with: EMAIL_REGEX }, length: { maximum: 255 }, allow_blank: true

def petition_link?
petition_link_or_title =~ /\A#{Regexp.escape(Site.url)}/
end
end
23 changes: 23 additions & 0 deletions app/views/feedback_mailer/send_feedback.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<h3>Comments:</h3>
<%= simple_format(@feedback.comment) %>

<hr>

<p>
<strong>Link or title:</strong><br>
<% if @feedback.petition_link? %>
<%= link_to nil, @feedback.petition_link_or_title %>
<% else %>
<%= @feedback.petition_link_or_title %>
<% end %>
</p>

<p>
<strong>Email:</strong><br>
<%= mail_to(@feedback.email) %>
</p>

<p>
<strong>Browser:</strong><br>
<%= @feedback.user_agent %>
</p>
17 changes: 13 additions & 4 deletions app/views/feedback_mailer/send_feedback.text.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
Comments: <%= @feedback.comment %>
Link: <%= @feedback.petition_link_or_title %>
Email: <%= @feedback.email %>
Browser: <%= @feedback.user_agent %>
Comments:
<%= word_wrap(@feedback.comment, line_width: 72) %>

=======================================================================

Link or title:
<%= @feedback.petition_link_or_title %>

Email:
<%= @feedback.email %>

Browser:
<%= @feedback.user_agent %>
2 changes: 1 addition & 1 deletion features/step_definitions/feedback_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Then they should see "#{@feedback.email}" in the email body
Then they should see "#{@feedback.petition_link_or_title}" in the email body
Then they should see "#{@feedback.comment}" in the email body
Then they should see "Browser: Chrome" in the email body
Then they should see "Chrome" in the email body
)
end

Expand Down
6 changes: 6 additions & 0 deletions spec/mailers/previews/feedback_mailer_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Preview all emails at http://localhost:3000/rails/mailers/feedback_mailer
class FeedbackMailerPreview < ActionMailer::Preview
def send_feedback
FeedbackMailer.send_feedback(Feedback.last)
end
end

0 comments on commit a1fccab

Please sign in to comment.