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

Mailer for on-boarding newcomer #3025

Merged
merged 6 commits into from
Jul 10, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def create
flash[:warning] = I18n.t('users_controller.account_migrated_create_new_password')
redirect_to "/profile/edit"
else
WelcomeMailer.notify_newcomer(@user).deliver_now
flash[:notice] = I18n.t('users_controller.registration_successful').html_safe
flash[:warning] = I18n.t('users_controller.spectralworkbench_or_mapknitter', :url1 => "'#{session[:openid_return_to]}'").html_safe if session[:openid_return_to]
session[:openid_return_to] = nil
Expand Down
9 changes: 9 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ def feature(title)
end
end

def feature_node(title)
features = Node.where(type: 'feature', title: title)
if !features.empty?
return features.last
else
''
end
end

def locale_name_pairs
I18n.available_locales.map do |locale|
[I18n.t('language', locale: locale), locale]
Expand Down
10 changes: 9 additions & 1 deletion app/mailers/welcome_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class WelcomeMailer < ActionMailer::Base
helper :application
include ApplicationHelper
# default from: "notifications@#{ActionMailer::Base.default_url_options[:host]}"
default from: "notifications@#{ActionMailer::Base.default_url_options[:host]}"

# PasswordResetMailer.reset_notify(user).deliver_now
def add_to_list(user, list)
Expand All @@ -10,4 +10,12 @@ def add_to_list(user, list)
@footer = feature('email-footer')
mail(to: list + '+subscribe@googlegroups.com', subject: subject, from: user.email)
end

def notify_newcomer(user)
subject = 'Welcome to Public Lab'
@user = user
@footer = feature('email-footer')
@body = feature_node('welcome-email-body')
mail(to: user.email, subject: subject)
end
end
4 changes: 4 additions & 0 deletions app/views/welcome_mailer/notify_newcomer.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

<%= raw auto_link(@body.latest.render_body_email(ActionMailer::Base.default_url_options[:host]), sanitize: false) %>

<%= @footer %>
10 changes: 10 additions & 0 deletions test/fixtures/nodes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,13 @@ draft:
type: "note"
cached_likes: 0
slug: test-<%= Time.now.strftime("%m-%d-%Y") %>-draft-note token:briRpnTHzKHepo6-j8-b5w

welcome_feature:
nid: 22
uid: 1
title: "welcome-email-body"
created: <%= Time.now.to_i %>
changed: <%= Time.now.to_i %>
status: 1
type: "feature"
cached_likes: 0
7 changes: 7 additions & 0 deletions test/fixtures/revisions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,10 @@ checkbox_two:
# Heading 1
List of things
* [x]

email_body:
nid: 22
uid: 1
title: "welcome-email-body"
body: Welcome email body
timestamp: <%= (Time.now - 1.week).to_i %>
20 changes: 20 additions & 0 deletions test/unit/welcome_mailer_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'test_helper'

class WelcomeMailerTest < ActionMailer::TestCase

test 'notify newcomer with welcome email' do
user = users(:bob)
@body = nodes(:welcome_feature)

assert_difference 'ActionMailer::Base.deliveries.size', 1 do
WelcomeMailer.notify_newcomer(user).deliver_now
end
assert !ActionMailer::Base.deliveries.empty?

email = ActionMailer::Base.deliveries.last
assert_equal ["notifications@#{request_host}"], email.from
assert_equal [user.email], email.to
assert_equal "Welcome to Public Lab", email.subject
assert email.body.include?("Welcome email body")
end
end