* VRFS-513; model in place to take feedback from corporate website
This commit is contained in:
parent
7c7d9ec4e2
commit
aa7a6b3e04
|
|
@ -25,6 +25,7 @@ require "jam_ruby/environment"
|
|||
require "jam_ruby/init"
|
||||
require "jam_ruby/app/mailers/user_mailer"
|
||||
require "jam_ruby/app/mailers/invited_user_mailer"
|
||||
require "jam_ruby/app/mailers/corp_mailer"
|
||||
require "jam_ruby/app/uploaders/artifact_uploader"
|
||||
require "jam_ruby/app/uploaders/perf_data_uploader"
|
||||
require "jam_ruby/lib/desk_multipass"
|
||||
|
|
@ -33,6 +34,8 @@ require "jam_ruby/lib/s3_manager"
|
|||
require "jam_ruby/lib/profanity"
|
||||
require "jam_ruby/amqp/amqp_connection_manager"
|
||||
require "jam_ruby/message_factory"
|
||||
require "jam_ruby/models/feedback"
|
||||
require "jam_ruby/models/feedback_observer"
|
||||
require "jam_ruby/models/max_mind_geo"
|
||||
require "jam_ruby/models/max_mind_isp"
|
||||
require "jam_ruby/models/genre"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
module JamRuby
|
||||
# CorpMail must be configured to work
|
||||
# Some common configs occur in jam_ruby/init.rb
|
||||
# Environment specific configs occur in spec_helper.rb in jam-ruby and jam-web (to put it into test mode),
|
||||
# and in config/initializers/email.rb in rails to configure sendmail account settings
|
||||
# If UserMailer were to be used in another project, it would need to be configured there, as well.
|
||||
|
||||
# Templates for UserMailer can be found in jam_ruby/app/views/jam_ruby/user_mailer
|
||||
class CorpMailer < ActionMailer::Base
|
||||
include SendGrid
|
||||
|
||||
layout "user_mailer"
|
||||
|
||||
DEFAULT_SENDER = "noreply@jamkazam.com"
|
||||
|
||||
default :from => DEFAULT_SENDER
|
||||
|
||||
sendgrid_category :use_subject_lines
|
||||
#sendgrid_enable :opentrack, :clicktrack # this makes our emails creepy, imo (seth)
|
||||
sendgrid_unique_args :env => Environment.mode
|
||||
|
||||
def feedback(feedback)
|
||||
@email = feedback.email
|
||||
@body = feedback.body
|
||||
|
||||
sendgrid_category "Corporate"
|
||||
sendgrid_unique_args :type => "feedback"
|
||||
|
||||
mail(:to => "info@jamkazam.com", :subject => "Feedback received from #{@email} ") do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,71 +1,71 @@
|
|||
module JamRuby
|
||||
# UserMailer must be configured to work
|
||||
# Some common configs occur in jam_ruby/init.rb
|
||||
# Environment specific configs occur in spec_helper.rb in jam-ruby and jam-web (to put it into test mode),
|
||||
# and in config/initializers/email.rb in rails to configure sendmail account settings
|
||||
# If UserMailer were to be used in another project, it would need to be configured there, as well.
|
||||
module JamRuby
|
||||
# UserMailer must be configured to work
|
||||
# Some common configs occur in jam_ruby/init.rb
|
||||
# Environment specific configs occur in spec_helper.rb in jam-ruby and jam-web (to put it into test mode),
|
||||
# and in config/initializers/email.rb in rails to configure sendmail account settings
|
||||
# If UserMailer were to be used in another project, it would need to be configured there, as well.
|
||||
|
||||
# Templates for UserMailer can be found in jam_ruby/app/views/jam_ruby/user_mailer
|
||||
class UserMailer < ActionMailer::Base
|
||||
include SendGrid
|
||||
# Templates for UserMailer can be found in jam_ruby/app/views/jam_ruby/user_mailer
|
||||
class UserMailer < ActionMailer::Base
|
||||
include SendGrid
|
||||
|
||||
layout "user_mailer"
|
||||
layout "user_mailer"
|
||||
|
||||
DEFAULT_SENDER = "support@jamkazam.com"
|
||||
DEFAULT_SENDER = "support@jamkazam.com"
|
||||
|
||||
default :from => DEFAULT_SENDER
|
||||
default :from => DEFAULT_SENDER
|
||||
|
||||
sendgrid_category :use_subject_lines
|
||||
#sendgrid_enable :opentrack, :clicktrack # this makes our emails creepy, imo (seth)
|
||||
sendgrid_unique_args :env => Environment.mode
|
||||
sendgrid_category :use_subject_lines
|
||||
#sendgrid_enable :opentrack, :clicktrack # this makes our emails creepy, imo (seth)
|
||||
sendgrid_unique_args :env => Environment.mode
|
||||
|
||||
def welcome_message(user, signup_confirm_url)
|
||||
@user = user
|
||||
@signup_confirm_url = signup_confirm_url
|
||||
sendgrid_category "Welcome"
|
||||
sendgrid_unique_args :type => "welcome_message"
|
||||
def welcome_message(user, signup_confirm_url)
|
||||
@user = user
|
||||
@signup_confirm_url = signup_confirm_url
|
||||
sendgrid_category "Welcome"
|
||||
sendgrid_unique_args :type => "welcome_message"
|
||||
|
||||
mail(:to => user.email, :subject => "Welcome to Jamkazam, #{user.first_name} ") do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def password_changed(user)
|
||||
@user = user
|
||||
sendgrid_unique_args :type => "password_changed"
|
||||
mail(:to => user.email, :subject => "Jamkazam Password Changed") do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def password_reset(user, password_reset_url)
|
||||
@user = user
|
||||
@password_reset_url = password_reset_url
|
||||
sendgrid_unique_args :type => "password_reset"
|
||||
mail(:to => user.email, :subject => "Jamkazam Password Reset") do |format|
|
||||
format.text
|
||||
format.html
|
||||
mail(:to => user.email, :subject => "Welcome to Jamkazam, #{user.first_name} ") do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def updating_email(user)
|
||||
@user = user
|
||||
sendgrid_unique_args :type => "updating_email"
|
||||
mail(:to => user.update_email, :subject => "Jamkazam Email Change Confirmation") do |format|
|
||||
format.text
|
||||
format.html
|
||||
def password_changed(user)
|
||||
@user = user
|
||||
sendgrid_unique_args :type => "password_changed"
|
||||
mail(:to => user.email, :subject => "Jamkazam Password Changed") do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def updated_email(user)
|
||||
@user = user
|
||||
sendgrid_unique_args :type => "updated_email"
|
||||
mail(:to => user.email, :subject => "Jamkazam Email Changed") do |format|
|
||||
format.text
|
||||
format.html
|
||||
def password_reset(user, password_reset_url)
|
||||
@user = user
|
||||
@password_reset_url = password_reset_url
|
||||
sendgrid_unique_args :type => "password_reset"
|
||||
mail(:to => user.email, :subject => "Jamkazam Password Reset") do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def updating_email(user)
|
||||
@user = user
|
||||
sendgrid_unique_args :type => "updating_email"
|
||||
mail(:to => user.update_email, :subject => "Jamkazam Email Change Confirmation") do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def updated_email(user)
|
||||
@user = user
|
||||
sendgrid_unique_args :type => "updated_email"
|
||||
mail(:to => user.email, :subject => "Jamkazam Email Changed") do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
<html>
|
||||
<body>
|
||||
<h3>Feedback Received</h3>
|
||||
<h4>From <%= @email %>:</h4>
|
||||
<p><%= @body %></p>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<p>
|
||||
This email was received because someone left feedback at <a href="http://www.jamkazam.com/corp/contact">http://www.jamkazam.com/corp/contact</a>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
Feedback Received
|
||||
|
||||
From <%= @email %>:
|
||||
|
||||
<%= @body %>
|
||||
|
||||
|
||||
This email was received because someone left feedback at http://www.jamkazam.com/corp/contact
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
module JamRuby
|
||||
class Feedback
|
||||
include ActiveModel::Validations
|
||||
include ActiveModel::Validations::Callbacks
|
||||
include ActiveModel::Observing
|
||||
extend ActiveModel::Callbacks
|
||||
|
||||
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
|
||||
validates :email, presence: true, format: {with: VALID_EMAIL_REGEX}
|
||||
validates :body, :presence => true
|
||||
|
||||
attr_accessor :email, :body
|
||||
|
||||
|
||||
def save
|
||||
|
||||
return valid?
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
module JamRuby
|
||||
class FeedbackObserver < ActiveRecord::Observer
|
||||
|
||||
observe JamRuby::Feedback
|
||||
|
||||
def after_validation(feedback)
|
||||
CorpMailer.feedback(feedback).deliver unless feedback.errors.any?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Feedback do
|
||||
|
||||
let(:feedback) { Feedback.new }
|
||||
|
||||
before(:each) do
|
||||
CorpMailer.deliveries.clear
|
||||
end
|
||||
|
||||
describe "empty model" do
|
||||
|
||||
before(:each) do
|
||||
feedback.save
|
||||
end
|
||||
|
||||
it { feedback.valid?.should be_false }
|
||||
it { feedback.errors.keys.length.should == 2}
|
||||
it { feedback.errors["email"].length.should == 2}
|
||||
it { feedback.errors["email"][0].include?("blank").should be_true}
|
||||
it { feedback.errors["email"][1].include?("invalid").should be_true}
|
||||
it { feedback.errors["body"].length.should == 1}
|
||||
it { feedback.errors["body"][0].include?("blank").should be_true}
|
||||
it { CorpMailer.deliveries.length.should == 0}
|
||||
|
||||
end
|
||||
|
||||
describe "bad email" do
|
||||
before(:each) do
|
||||
feedback.email = "blarg"
|
||||
feedback.body = "here's the problem!"
|
||||
feedback.save
|
||||
end
|
||||
|
||||
it { feedback.valid?.should be_false }
|
||||
it { feedback.errors.keys.length.should == 1}
|
||||
it { feedback.errors["email"].length.should == 1}
|
||||
it { feedback.errors["email"][0].include?("invalid").should be_true}
|
||||
it { CorpMailer.deliveries.length.should == 0}
|
||||
end
|
||||
|
||||
describe "populated model" do
|
||||
before(:each) do
|
||||
feedback.email = "seth@jamkazam.com"
|
||||
feedback.body = "here's the problem!"
|
||||
feedback.save
|
||||
end
|
||||
|
||||
it { feedback.valid?.should be_true }
|
||||
it { feedback.errors.keys.length.should == 0 }
|
||||
it { CorpMailer.deliveries.length.should == 1}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -25,6 +25,7 @@ include JamRuby
|
|||
# manually register observers
|
||||
ActiveRecord::Base.add_observer InvitedUserObserver.instance
|
||||
ActiveRecord::Base.add_observer UserObserver.instance
|
||||
ActiveRecord::Base.add_observer FeedbackObserver.instance
|
||||
|
||||
|
||||
# put ActionMailer into test mode
|
||||
|
|
|
|||
Loading…
Reference in New Issue