From a6bc9e66f671f4ad6266479f526f645e85ed3f1d Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 17 Oct 2014 11:40:28 +1100 Subject: [PATCH] Only send one enterprise creation confirmation email --- app/mailers/enterprise_mailer.rb | 12 ++++++------ app/models/enterprise.rb | 6 ------ .../creation_confirmation.html.haml | 9 --------- spec/mailers/enterprise_mailer_spec.rb | 12 +++++------- 4 files changed, 11 insertions(+), 28 deletions(-) delete mode 100644 app/views/enterprise_mailer/creation_confirmation.html.haml diff --git a/app/mailers/enterprise_mailer.rb b/app/mailers/enterprise_mailer.rb index f5f92aed3f..4e37d112e0 100644 --- a/app/mailers/enterprise_mailer.rb +++ b/app/mailers/enterprise_mailer.rb @@ -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 diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 22182a4c9a..069c8860cc 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -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 diff --git a/app/views/enterprise_mailer/creation_confirmation.html.haml b/app/views/enterprise_mailer/creation_confirmation.html.haml deleted file mode 100644 index 0df3bf06a0..0000000000 --- a/app/views/enterprise_mailer/creation_confirmation.html.haml +++ /dev/null @@ -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 diff --git a/spec/mailers/enterprise_mailer_spec.rb b/spec/mailers/enterprise_mailer_spec.rb index 6b53d7d561..dd1e150eb7 100644 --- a/spec/mailers/enterprise_mailer_spec.rb +++ b/spec/mailers/enterprise_mailer_spec.rb @@ -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 \ No newline at end of file