Only send one enterprise creation confirmation email

This commit is contained in:
Rob Harrington
2014-10-17 11:40:28 +11:00
parent b671543a95
commit a6bc9e66f6
4 changed files with 11 additions and 28 deletions

View File

@@ -2,14 +2,14 @@ require 'devise/mailers/helpers'
class EnterpriseMailer < Spree::BaseMailer
include Devise::Mailers::Helpers
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
def confirmation_instructions(record, token, opts={})
@token = token
find_enterprise(record)
opts = {
subject: "Please confirm your email for #{@enterprise.name}",
to: [ @enterprise.owner.email, @enterprise.email ].uniq,
from: from_address,
}
devise_mail(record, :confirmation_instructions, opts)
end

View File

@@ -10,8 +10,6 @@ class Enterprise < ActiveRecord::Base
before_create :check_email
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
@@ -272,10 +270,6 @@ class Enterprise < ActiveRecord::Base
skip_confirmation! if owner.enterprises.confirmed.map(&:email).include?(email)
end
def send_creation_email
EnterpriseMailer.creation_confirmation(self).deliver
end
def strip_url(url)
url.andand.sub(/(https?:\/\/)?/, '')
end

View File

@@ -1,9 +0,0 @@
%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

@@ -1,18 +1,16 @@
require 'spec_helper'
describe EnterpriseMailer do
let!(:enterprise) { create(:enterprise) }
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
it "should send an email confirmation when given an enterprise" do
EnterpriseMailer.confirmation_instructions(@enterprise, 'token').deliver
EnterpriseMailer.confirmation_instructions(enterprise, 'token').deliver
ActionMailer::Base.deliveries.count.should == 1
mail = ActionMailer::Base.deliveries.first
expect(mail.subject).to eq "Please confirm your email for #{enterprise.name}"
end
end