From f5048ecf7cf1ae3c903e76278aceb9d5f4f69ef6 Mon Sep 17 00:00:00 2001 From: Rob H Date: Fri, 12 Sep 2014 13:24:17 +1000 Subject: [PATCH] Sends confirmation email when Enterprise is created --- .../templates/registration/finished.html.haml | 9 ++++----- app/mailers/enterprise_mailer.rb | 12 ++++++++++++ app/models/enterprise.rb | 6 ++++++ .../creation_confirmation.html.haml | 9 +++++++++ spec/mailers/enterprise_mailer_spec.rb | 13 +++++++++++++ 5 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 app/mailers/enterprise_mailer.rb create mode 100644 app/views/enterprise_mailer/creation_confirmation.html.haml create mode 100644 spec/mailers/enterprise_mailer_spec.rb diff --git a/app/assets/javascripts/templates/registration/finished.html.haml b/app/assets/javascripts/templates/registration/finished.html.haml index 8e99ac1870..75489c607a 100644 --- a/app/assets/javascripts/templates/registration/finished.html.haml +++ b/app/assets/javascripts/templates/registration/finished.html.haml @@ -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 > - \ No newline at end of file diff --git a/app/mailers/enterprise_mailer.rb b/app/mailers/enterprise_mailer.rb new file mode 100644 index 0000000000..73c09e1e56 --- /dev/null +++ b/app/mailers/enterprise_mailer.rb @@ -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 diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index ccca96ab26..537ac78295 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -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 diff --git a/app/views/enterprise_mailer/creation_confirmation.html.haml b/app/views/enterprise_mailer/creation_confirmation.html.haml new file mode 100644 index 0000000000..0df3bf06a0 --- /dev/null +++ b/app/views/enterprise_mailer/creation_confirmation.html.haml @@ -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 diff --git a/spec/mailers/enterprise_mailer_spec.rb b/spec/mailers/enterprise_mailer_spec.rb new file mode 100644 index 0000000000..412870bad7 --- /dev/null +++ b/spec/mailers/enterprise_mailer_spec.rb @@ -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 \ No newline at end of file