Add support to multipart e-mails (just put them in your mailers folder) and headers customization by simply defining headers_for in your model.

This commit is contained in:
José Valim 2010-03-26 10:01:24 +01:00
parent 4d3a3ceb43
commit 12b64c691f
8 changed files with 34 additions and 15 deletions

View File

@ -7,7 +7,14 @@
* Devise.orm is deprecated. This reduces the required API to hook your ORM with devise.
* Use metal for failure app.
* HTML e-mails now have proper formatting.
* Do not remove options from Datamapper and MongoMapper in find
* Do not remove options from Datamapper and MongoMapper in find.
* Allow to give :skip and :controllers in routes.
* Move trackable logic to the model.
* E-mails now use any template available in the filesystem. Easy to create multipart e-mails.
* E-mails asks headers_for in the model to set the proper headers.
* bug fix
* Do not use lock! on lockable since it's part of ActiveRecord API.
* deprecations
* Rails 3 compatible only.

View File

@ -2,7 +2,7 @@ source "http://gemcutter.org"
# Need to install Rails from source
gem "rails", :git => "git://github.com/rails/rails.git"
gem "warden", "0.9.7"
gem "warden", "0.10.2"
gem "sqlite3-ruby", :require => "sqlite3"
gem "webrat", "0.7"
gem "mocha", :require => false

View File

@ -45,7 +45,7 @@ begin
s.authors = ['José Valim', 'Carlos Antônio']
s.files = FileList["[A-Z]*", "{app,config,lib}/**/*"]
s.extra_rdoc_files = FileList["[A-Z]*"] - %w(Gemfile Rakefile)
s.add_dependency("warden", "~> 0.9.7")
s.add_dependency("warden", "~> 0.10.2")
end
Jeweler::GemcutterTasks.new

View File

@ -24,16 +24,23 @@ class Devise::Mailer < ::ActionMailer::Base
raise "Invalid devise resource #{record}" unless @devise_mapping
@resource = instance_variable_set("@#{@devise_mapping.name}", record)
mail(:subject => translate(@devise_mapping, action),
:from => mailer_sender(@devise_mapping), :to => record.email) do |format|
format.html { render_with_scope(action, :controller => "mailer") }
end
template_path = ["devise/mailer"]
template_path.unshift "#{@devise_mapping.as}/mailer" if self.class.scoped_views?
headers = {
:subject => translate(@devise_mapping, action),
:from => mailer_sender(@devise_mapping),
:to => record.email,
:template_path => template_path
}
headers.merge!(record.headers_for(action)) if record.respond_to?(:headers_for)
mail(headers)
end
def mailer_sender(mapping)
if Devise.mailer_sender.is_a?(Proc)
block_args = mapping.name if Devise.mailer_sender.arity > 0
Devise.mailer_sender.call(block_args)
Devise.mailer_sender.call(mapping.name)
else
Devise.mailer_sender
end

View File

@ -4,7 +4,7 @@ module Devise
extend ActiveSupport::Concern
module ClassMethods
def scoped_views
def scoped_views?
defined?(@scoped_views) ? @scoped_views : Devise.scoped_views
end
@ -20,7 +20,7 @@ module Devise
def render_with_scope(action, options={})
controller_name = options.delete(:controller) || self.controller_name
if self.class.scoped_views
if self.class.scoped_views?
begin
render :template => "#{devise_mapping.as}/#{controller_name}/#{action}"
rescue ActionView::MissingTemplate

View File

@ -87,6 +87,11 @@ module Devise
result
end
# Allows you to overwrite mail messages headers for a given mail.
def headers_for(action)
{}
end
protected
# Digests the password using the configured encryptor.

View File

@ -226,7 +226,7 @@ class AuthenticationTest < ActionController::IntegrationTest
end
assert_match /Special user view/, response.body
assert !Devise::PasswordsController.scoped_views
assert !Devise::PasswordsController.scoped_views?
ensure
Devise::SessionsController.send :remove_instance_variable, :@scoped_views
end

View File

@ -23,12 +23,12 @@ class ActiveRecordTest < ActiveSupport::TestCase
end
test 'add modules cherry pick' do
assert_include_modules Admin, :authenticatable, :registerable, :timeoutable
assert_include_modules Admin, :authenticatable, :registerable, :timeoutable, :recoverable
end
test 'order of module inclusion' do
correct_module_order = [:authenticatable, :registerable, :timeoutable]
incorrect_module_order = [:authenticatable, :timeoutable, :registerable]
correct_module_order = [:authenticatable, :recoverable, :registerable, :timeoutable]
incorrect_module_order = [:authenticatable, :timeoutable, :registerable, :recoverable]
assert_include_modules Admin, *incorrect_module_order