From 5c999fd9cffcb0816544d66131a6bf183f2f72ad Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 4 Apr 2014 12:36:33 +1300 Subject: [PATCH] Adding a signup confirmation email --- app/mailers/spree/user_mailer_decorator.rb | 8 ++++++++ app/models/spree/user_decorator.rb | 5 +++++ .../user_mailer/signup_confirmation.text.erb | 13 ++++++++++++ spec/mailers/user_mailer_spec.rb | 20 +++++++++++++++++++ spec/models/spree/user_spec.rb | 9 +++++++++ 5 files changed, 55 insertions(+) create mode 100644 app/mailers/spree/user_mailer_decorator.rb create mode 100644 app/views/spree/user_mailer/signup_confirmation.text.erb create mode 100644 spec/mailers/user_mailer_spec.rb create mode 100644 spec/models/spree/user_spec.rb diff --git a/app/mailers/spree/user_mailer_decorator.rb b/app/mailers/spree/user_mailer_decorator.rb new file mode 100644 index 0000000000..ff8bdc4691 --- /dev/null +++ b/app/mailers/spree/user_mailer_decorator.rb @@ -0,0 +1,8 @@ +Spree::UserMailer.class_eval do + + def signup_confirmation(user) + @user = user + mail(:to => user.email, :from => from_address, + :subject => 'Welcome to ' + Spree::Config[:site_name]) + end +end diff --git a/app/models/spree/user_decorator.rb b/app/models/spree/user_decorator.rb index 5acaff924e..9dbc8226f5 100644 --- a/app/models/spree/user_decorator.rb +++ b/app/models/spree/user_decorator.rb @@ -6,6 +6,7 @@ Spree.user_class.class_eval do accepts_nested_attributes_for :enterprise_roles, :allow_destroy => true attr_accessible :enterprise_ids, :enterprise_roles_attributes + after_create :send_signup_confirmation def build_enterprise_roles Enterprise.all.each do |enterprise| @@ -14,4 +15,8 @@ Spree.user_class.class_eval do end end end + + def send_signup_confirmation + Spree::UserMailer.signup_confirmation(self).deliver + end end diff --git a/app/views/spree/user_mailer/signup_confirmation.text.erb b/app/views/spree/user_mailer/signup_confirmation.text.erb new file mode 100644 index 0000000000..c6e57efc8a --- /dev/null +++ b/app/views/spree/user_mailer/signup_confirmation.text.erb @@ -0,0 +1,13 @@ +Hello, + +Welcome to Australia's Open Food Network! Your login email is <%= @user.email %> + +You can go online and start shopping through food hubs and local producers you like at vic.openfoodnetwork.org.au + +We welcome all your questions and feedback; you can use the Send Feedback button on the site or email us at hello@openfoodnetwork.org + +Thanks for getting on board and we look forward to introducing you to many more great farmers, food hubs and food! + +Cheers, +Kirsten Larsen and the OFN Team + diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rb new file mode 100644 index 0000000000..97e0eb4430 --- /dev/null +++ b/spec/mailers/user_mailer_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe Spree::UserMailer do + let(:user) { build(:user) } + + after do + ActionMailer::Base.deliveries.clear + end + + before do + ActionMailer::Base.delivery_method = :test + ActionMailer::Base.perform_deliveries = true + ActionMailer::Base.deliveries = [] + end + + it "sends an email when given a user" do + Spree::UserMailer.signup_confirmation(user).deliver + ActionMailer::Base.deliveries.count.should == 1 + end +end diff --git a/spec/models/spree/user_spec.rb b/spec/models/spree/user_spec.rb new file mode 100644 index 0000000000..4e9ad94fac --- /dev/null +++ b/spec/models/spree/user_spec.rb @@ -0,0 +1,9 @@ +describe Spree.user_class do + context "#create" do + + it "should send a signup email" do + Spree::UserMailer.should_receive(:signup_confirmation).and_return(double(:deliver => true)) + create(:user) + end + end +end