Skip to content

Instantly share code, notes, and snippets.

@ohboyd
Created July 6, 2018 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ohboyd/619ce1c1669bfde637cbfd68d0715e47 to your computer and use it in GitHub Desktop.
Save ohboyd/619ce1c1669bfde637cbfd68d0715e47 to your computer and use it in GitHub Desktop.
4th diff
commit 7a1a62514ecd6b85460537f8b9050d58d5e628dc
Author: Gary Foster <gary@radicalbear.com>
Date: Fri Jun 15 15:14:53 2018 -0400
Allow override of confirmation instructions
diff --git a/.rubocop.yml b/.rubocop.yml
index 42d8b70..d116dd3 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -15,3 +15,9 @@ Style/Documentation:
Metrics/BlockLength:
Exclude:
- 'spec/models/**/*.rb'
+
+Layout/IndentationConsistency:
+ EnforcedStyle: rails
+
+Metrics/LineLength:
+ Enabled: false
diff --git a/app/helpers/rad_common/application_helper.rb b/app/helpers/rad_common/application_helper.rb
index 19625b5..3693040 100644
--- a/app/helpers/rad_common/application_helper.rb
+++ b/app/helpers/rad_common/application_helper.rb
@@ -139,21 +139,6 @@ module RadCommon
end
end
- def bootstrap_class_for flash_type
- case flash_type.to_s
- when 'success'
- 'alert-success'
- when 'error'
- 'alert-danger'
- when 'alert'
- 'alert-warning'
- when 'notice'
- 'alert-info'
- else
- flash_type.to_s
- end
- end
-
def icon_tag(icon, text)
content_tag(:i, '', class: "right-5px #{icon}") + text
end
diff --git a/app/mailers/radbear_devise_mailer.rb b/app/mailers/radbear_devise_mailer.rb
index a7e7f5e..7dcf146 100644
--- a/app/mailers/radbear_devise_mailer.rb
+++ b/app/mailers/radbear_devise_mailer.rb
@@ -2,26 +2,26 @@ class RadbearDeviseMailer < Devise::Mailer
include Devise::Controllers::UrlHelpers
helper RadCommon::ApplicationHelper
- layout "radbear_mailer"
+ layout 'radbear_mailer'
before_action :set_defaults
- default reply_to: Rails.application.config.respond_to?(:app_admin_email) ? Rails.application.config.app_admin_email : ((ActiveRecord::Base.connection.data_source_exists?("companies") && Company.main) ? "#{Company.main.respond_to?(:app_name) ? Company.main.app_name : I18n::t(:app_name)} Admin <#{Company.main.email}>" : Devise.mailer_sender)
+ default reply_to: Rails.application.config.respond_to?(:app_admin_email) ? Rails.application.config.app_admin_email : ((ActiveRecord::Base.connection.data_source_exists?('companies') && Company.main) ? "#{Company.main.respond_to?(:app_name) ? Company.main.app_name : I18n::t(:app_name)} Admin <#{Company.main.email}>" : Devise.mailer_sender)
- def confirmation_instructions(record, token, opts={})
+ def confirmation_instructions(record, token, opts = {})
@token = token
initialize_from_record(record)
@recipient = @resource
- @message = "Here are your confirmation instructions."
+ @message = I18n.t('rad_common.confirmation_instructions', default: 'Here are your confirmation instructions.')
- @email_action = { message: "You can confirm your account email through this link.",
- button_text: "Confirm My Account",
+ @email_action = { message: 'You can confirm your account email through this link.',
+ button_text: 'Confirm My Account',
button_url: confirmation_url(@resource, confirmation_token: @token) }
super
end
- def reset_password_instructions(record, token, opts={})
+ def reset_password_instructions(record, token, opts = {})
@token = token
initialize_from_record(record)
@@ -29,35 +29,35 @@ class RadbearDeviseMailer < Devise::Mailer
@message = "Someone has requested a link to change your password. If you didn't request this, please ignore this email."
@email_action = { message: "Your password won't change until you click this link and create a new one.",
- button_text: "Change My Password",
+ button_text: 'Change My Password',
button_url: edit_password_url(@resource, reset_password_token: @token) }
super
end
- def unlock_instructions(record, token, opts={})
+ def unlock_instructions(record, token, opts = {})
@token = token
initialize_from_record(record)
@recipient = @resource
- @message = "Your account has been locked due to an excessive number of unsuccessful sign in attempts."
+ @message = 'Your account has been locked due to an excessive number of unsuccessful sign in attempts.'
- @email_action = { message: "Click the link to unlock your account.",
- button_text: "Unlock My Account",
+ @email_action = { message: 'Click the link to unlock your account.',
+ button_text: 'Unlock My Account',
button_url: unlock_url(@resource, unlock_token: @token) }
super
end
- def invitation_instructions(record, token, opts={})
+ def invitation_instructions(record, token, opts = {})
@token = token
initialize_from_record(record)
@recipient = @resource
@message = "Someone has invited you to #{app_name}, you can accept it through the link below. If you don't want to accept the invitation, please ignore this email. Your account won't be created until you access the link and set your password."
- @email_action = { message: "Click the link to accept the invitation.",
- button_text: "Accept",
+ @email_action = { message: 'Click the link to accept the invitation.',
+ button_text: 'Accept',
button_url: accept_invitation_url(@resource, invitation_token: @token) }
super
@@ -66,11 +66,8 @@ class RadbearDeviseMailer < Devise::Mailer
private
def app_name
- if company_exists?
- return Company.main.respond_to?(:app_name) ? Company.main.app_name : t(:app_name)
- else
- return t(:app_name)
- end
+ return t(:app_name) unless company_exists?
+ Company.main.respond_to?(:app_name) ? Company.main.app_name : t(:app_name)
end
def company_exists?
@@ -78,8 +75,8 @@ class RadbearDeviseMailer < Devise::Mailer
end
def set_defaults
- unless File.exist?("app/assets/images/app_logo.png") == File.exist?("public/app_logo.png")
- raise "This mailer requires app_logo.png to be in both places."
+ unless File.exist?('app/assets/images/app_logo.png') == File.exist?('public/app_logo.png')
+ raise 'This mailer requires app_logo.png to be in both places.'
end
@company = Company.main if Company.respond_to?(:main)
diff --git a/spec/mailers/radbear_devise_mailer_spec.rb b/spec/mailers/radbear_devise_mailer_spec.rb
new file mode 100644
index 0000000..2cf0eda
--- /dev/null
+++ b/spec/mailers/radbear_devise_mailer_spec.rb
@@ -0,0 +1,22 @@
+require 'rails_helper'
+
+describe RadbearDeviseMailer, type: :mailer do
+ let(:user) { create :user }
+ let(:email) { ActionMailer::Base.deliveries.last }
+
+ before { ActionMailer::Base.deliveries = [] }
+
+ describe '#confirmation_instructions' do
+ let(:token) { 'foo' }
+
+ before { RadbearDeviseMailer.confirmation_instructions(user, token).deliver_now }
+
+ it 'should have the subject' do
+ expect(email.subject).to include 'Confirmation instructions'
+ end
+
+ it 'should have the instructions' do
+ expect(email.body.encoded).to include 'Here are your confirmation instructions.'
+ end
+ end
+end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment