mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Only send one enterprise creation confirmation email
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user