finish application mailers

This commit is contained in:
Torsten Ruger 2016-05-19 16:17:33 +03:00
parent 2de9c9eac8
commit b26aff5601
12 changed files with 135 additions and 8 deletions

View File

@ -1,5 +1,5 @@
class AppliesController < ApplicationController
before_action :set_apply, only: [:show , :create , :cancel]
before_action :set_apply, only: [:show , :create , :cancel ]
# GET /applies/1
# GET /applies/1.json
@ -12,7 +12,8 @@ class AppliesController < ApplicationController
@apply.user = current_user
if @apply.save
redirect_to application_path, notice: 'Application was successfully submitted. Your will receive further instructions from us within a week'
redirect_to application_path, notice: 'Application was successfully submitted. Your will receive further instructions from us within a week'
ApplyMailer.submit( @apply ).deliver_now
else
render :edit
end
@ -20,6 +21,7 @@ class AppliesController < ApplicationController
end
def cancel
ApplyMailer.cancel( @apply , params[:reason]).deliver_now
@apply.delete
redirect_to edit_user_registration_path, alert: 'Application was canceled.'
end
@ -33,6 +35,6 @@ class AppliesController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def apply_params
params.require(:apply).permit(:primary_choice_course_id, :secondary_choice_course_id, :comment,
:discount_code , :user_id, :sent)
:discount_code , :user_id, :sent , :plan)
end
end

View File

@ -13,6 +13,7 @@ class ApplyDashboard < Administrate::BaseDashboard
primary_choice_course_id: Field::Number,
secondary_choice_course_id: Field::Number,
comment: Field::Text,
plan: Field::String,
sent: Field::DateTime,
created_at: Field::DateTime,
updated_at: Field::DateTime,
@ -37,6 +38,7 @@ class ApplyDashboard < Administrate::BaseDashboard
:id,
:primary_choice_course_id,
:secondary_choice_course_id,
:plan ,
:comment,
:sent,
:created_at,
@ -50,6 +52,7 @@ class ApplyDashboard < Administrate::BaseDashboard
:user,
:primary_choice_course_id,
:secondary_choice_course_id,
:plan,
:comment,
:sent,
]

View File

@ -4,9 +4,6 @@ module AppliesHelper
end
def plan_select
{ free: "Free - Only applies on the free course" ,
standard: "2100¢ - 8 week prepayment, no cancellation" ,
flex: "2400¢ - 8 week prepayment, 2 week cancellation" ,
super_flex: "2900¢ - 2 week prepayment, stop anytime" }
Apply::PLANS
end
end

View File

@ -0,0 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: "info@webdev.camp" , bcc: "torsten@webdev.camp"
layout 'mailer'
end

View File

@ -0,0 +1,23 @@
class ApplyMailer < ApplicationMailer
# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
# en.apply.submit.subject
#
def submit( application )
@application = application
mail(to: @application.user.email, subject: "Your application has been submitted")
end
# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
# en.apply.cancel.subject
#
def cancel( application , reason)
@application = application
@reason = reason
mail(to: @application.user.email, subject: "Your application has been cancelled")
end
end

View File

@ -1,7 +1,16 @@
class Apply < ActiveRecord::Base
PLANS = { free: "Free - Only applies on the free course" ,
standard: "2100¢ - 8 week prepayment, no cancellation" ,
flex: "2400¢ - 8 week prepayment, 2 week cancellation" ,
super_flex: "2900¢ - 2 week prepayment, stop anytime" }
belongs_to :user
belongs_to :primary_choice_course , class_name: :Course
belongs_to :secondary_choice_course , class_name: :Course
validates_presence_of :primary_choice_course_id
def plan_name
PLANS[self.plan.to_sym]
end
end

View File

@ -22,7 +22,13 @@
%td
%b Secondary choice:
%td
= @apply.secondary_choice_course.full_name if @apply.secondary_choice_course
- if @apply.secondary_choice_course
= @apply.secondary_choice_course.full_name
- else
None
%tr
%td Payment plan:
%td= @apply.plan_name
%tr
%td Discount:
%td= @apply.discount_code || "None"

View File

@ -0,0 +1,14 @@
Hello <%=@application.user.name%>,
This is to confirm that we have received your application cancellation.
<% if @reason.blank? %>
Since you have not given a reason for the cancellation, we assume you won't apply again
and may wish to cancel your account as well.
<% else %>
You may apply again if your situation changes.
<% end %>
We wish you best in your career endeavours
The Web Dev Team

View File

@ -0,0 +1,21 @@
Hello <%= @application.user.name %>,
this is to confirm that we have received your application for the web dev course: <%=@application.primary_choice_course.full_name%>
We will review you application and email you within one week.
If your situation changes or you have additional questions or concerns, you can get in touch by replying to this email.
Best Regards
The Web Dev Team
Application details: http://webdev.camp/application
---------------------------------------------------
Primary course choice: <%=@application.primary_choice_course.full_name%>
<%unless @application.secondary_choice_course_id%>Secondary course choice: <%=@application.primary_choice_course.full_name%>
<%end%>
Payment plan: <%=@application.plan_name%>
Discount code: <%=@application.comment%>
Comment: <%=@application.comment%>

View File

@ -0,0 +1 @@
= yield

View File

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Apply, type: :mailer do
describe "submit" do
let(:mail) { Apply.submit }
it "renders the headers" do
expect(mail.subject).to eq("Submit")
expect(mail.to).to eq(["to@example.org"])
expect(mail.from).to eq(["info@webdev.camp"])
end
it "renders the body" do
expect(mail.body.encoded).to match("received")
end
end
describe "cancel" do
let(:mail) { Apply.cancel }
it "renders the headers" do
expect(mail.subject).to eq("Cancel")
expect(mail.to).to eq(["to@example.org"])
expect(mail.bcc).to eq(["torsten@webdev.camp"])
expect(mail.from).to eq(["info@webdev.camp"])
end
it "renders the body" do
expect(mail.body.encoded).to match("cancel")
end
end
end

View File

@ -0,0 +1,14 @@
# Preview all emails at http://localhost:3000/rails/mailers/apply
class ApplyPreview < ActionMailer::Preview
# Preview this email at http://localhost:3000/rails/mailers/apply/submit
def submit
Apply.submit
end
# Preview this email at http://localhost:3000/rails/mailers/apply/cancel
def cancel
Apply.cancel
end
end