Sends confirmation email when Enterprise is created

This commit is contained in:
Rob H
2014-09-12 13:24:17 +10:00
parent 5c7ab2efa3
commit f5048ecf7c
5 changed files with 44 additions and 5 deletions

View File

@@ -1,8 +1,8 @@
.container#registration-finished
.header
%h2 Well done!
%h5
You have successfully completed the profile for
%h5
You have successfully completed the profile for
%span.brick{"ng-show" => "enterprise.is_distributor"}
{{ enterprise.name }}
%span.turquoise{"ng-show" => "!enterprise.is_distributor" }
@@ -10,10 +10,9 @@
.content{ style: 'text-align: center'}
%h3 Why not check it out on the Open Food Network?
%a.button.primary{ type: "button", href: "/map" } Go to Map Page >
%br
%br
%h3 Next step - add some products:
%a.button.primary{ type: "button", href: "/admin/products/new" } Add a Product >

View File

@@ -0,0 +1,12 @@
class EnterpriseMailer < Spree::BaseMailer
def creation_confirmation(enterprise)
find_enterprise(enterprise)
subject = "#{@enterprise.name} is now on #{Spree::Config[:site_name]}"
mail(:to => @enterprise.owner.email, :from => from_address, :subject => subject)
end
private
def find_enterprise(enterprise)
@enterprise = enterprise.is_a?(Enterprise) ? enterprise : Enterprise.find(enterprise)
end
end

View File

@@ -6,6 +6,8 @@ class Enterprise < ActiveRecord::Base
acts_as_gmappable :process_geocoding => false
after_create :send_creation_email
has_and_belongs_to_many :groups, class_name: 'EnterpriseGroup'
has_many :producer_properties, foreign_key: 'producer_id'
has_many :supplied_products, :class_name => 'Spree::Product', :foreign_key => 'supplier_id', :dependent => :destroy
@@ -227,6 +229,10 @@ class Enterprise < ActiveRecord::Base
private
def send_creation_email
EnterpriseMailer.creation_confirmation(self).deliver
end
def strip_url(url)
url.andand.sub /(https?:\/\/)?/, ''
end

View File

@@ -0,0 +1,9 @@
%h1
= @enterprise.name + " has been created"
%h3
Why not check it out on
%a{ href: "#{map_url}" }
= Spree::Config[:site_name] + "?"
If you have any questions, please get in touch with us at: hello@openfoodnetwork.org

View File

@@ -0,0 +1,13 @@
require 'spec_helper'
describe EnterpriseMailer do
before do
@enterprise = create(:enterprise)
ActionMailer::Base.deliveries = []
end
it "should send an email when given an enterprise" do
EnterpriseMailer.creation_confirmation(@enterprise).deliver
ActionMailer::Base.deliveries.count.should == 1
end
end