From 91a128ae7eb8b2ba400e7c4efd5520acf499cf6e Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Fri, 24 Jul 2015 15:09:54 +0100 Subject: [PATCH] Check existence of secret token before using it. People were forgetting to create config/environment.yml, which meant that RAILS_SECRET_TOKEN wasn't being set, which meant that all tests involving notifications failed. Unfortunately, the resulting wall of error messages (https://gist.github.com/sha1sum/5debae6b700ff8fc0c76) did not make the root cause remotely clear, leading to much confusion and head-scratching all round. This commit checks for the existence of RAILS_SECRET_TOKEN and fails with an informative error message if it's missing. --- app/mailers/notifier.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb index a37d65d67..5ffb862d6 100644 --- a/app/mailers/notifier.rb +++ b/app/mailers/notifier.rb @@ -2,12 +2,19 @@ class Notifier < ActionMailer::Base include NotificationsHelper default from: "Growstuff " + def verifier() + if ENV['RAILS_SECRET_TOKEN'] + return ActiveSupport::MessageVerifier.new(ENV['RAILS_SECRET_TOKEN']) + else + raise "RAILS_SECRET_TOKEN environment variable not set - have you created config/application.yml?" + end + end + def notify(notification) @notification = notification @reply_link = reply_link(@notification) # Encrypting - verifier = ActiveSupport::MessageVerifier.new(ENV['RAILS_SECRET_TOKEN']) @signed_message = verifier.generate ({ member_id: @notification.recipient.id, type: :send_notification_email }) mail(:to => @notification.recipient.email, @@ -21,7 +28,6 @@ class Notifier < ActionMailer::Base @harvests = @member.harvests.first(5) # Encrypting - verifier = ActiveSupport::MessageVerifier.new(ENV['RAILS_SECRET_TOKEN']) @signed_message = verifier.generate ({ member_id: @member.id, type: :send_planting_reminder }) if @member.send_planting_reminder