Skip to content
This repository
Browse code

Add support to multipart e-mails (just put them in your mailers folde…

…r) and headers customization by simply defining headers_for in your model.
  • Loading branch information...
commit 12b64c691f31a7a057c6fbb0d3ae72e482e493a6 1 parent 4d3a3ce
José Valim josevalim authored
9 CHANGELOG.rdoc
Source Rendered
@@ -7,7 +7,14 @@
7 7 * Devise.orm is deprecated. This reduces the required API to hook your ORM with devise.
8 8 * Use metal for failure app.
9 9 * HTML e-mails now have proper formatting.
10   - * Do not remove options from Datamapper and MongoMapper in find
  10 + * Do not remove options from Datamapper and MongoMapper in find.
  11 + * Allow to give :skip and :controllers in routes.
  12 + * Move trackable logic to the model.
  13 + * E-mails now use any template available in the filesystem. Easy to create multipart e-mails.
  14 + * E-mails asks headers_for in the model to set the proper headers.
  15 +
  16 +* bug fix
  17 + * Do not use lock! on lockable since it's part of ActiveRecord API.
11 18
12 19 * deprecations
13 20 * Rails 3 compatible only.
2  Gemfile
@@ -2,7 +2,7 @@ source "http://gemcutter.org"
2 2
3 3 # Need to install Rails from source
4 4 gem "rails", :git => "git://github.com/rails/rails.git"
5   -gem "warden", "0.9.7"
  5 +gem "warden", "0.10.2"
6 6 gem "sqlite3-ruby", :require => "sqlite3"
7 7 gem "webrat", "0.7"
8 8 gem "mocha", :require => false
2  Rakefile
@@ -45,7 +45,7 @@ begin
45 45 s.authors = ['José Valim', 'Carlos Antônio']
46 46 s.files = FileList["[A-Z]*", "{app,config,lib}/**/*"]
47 47 s.extra_rdoc_files = FileList["[A-Z]*"] - %w(Gemfile Rakefile)
48   - s.add_dependency("warden", "~> 0.9.7")
  48 + s.add_dependency("warden", "~> 0.10.2")
49 49 end
50 50
51 51 Jeweler::GemcutterTasks.new
19 app/models/devise/mailer.rb
@@ -24,16 +24,23 @@ def setup_mail(record, action)
24 24 raise "Invalid devise resource #{record}" unless @devise_mapping
25 25 @resource = instance_variable_set("@#{@devise_mapping.name}", record)
26 26
27   - mail(:subject => translate(@devise_mapping, action),
28   - :from => mailer_sender(@devise_mapping), :to => record.email) do |format|
29   - format.html { render_with_scope(action, :controller => "mailer") }
30   - end
  27 + template_path = ["devise/mailer"]
  28 + template_path.unshift "#{@devise_mapping.as}/mailer" if self.class.scoped_views?
  29 +
  30 + headers = {
  31 + :subject => translate(@devise_mapping, action),
  32 + :from => mailer_sender(@devise_mapping),
  33 + :to => record.email,
  34 + :template_path => template_path
  35 + }
  36 +
  37 + headers.merge!(record.headers_for(action)) if record.respond_to?(:headers_for)
  38 + mail(headers)
31 39 end
32 40
33 41 def mailer_sender(mapping)
34 42 if Devise.mailer_sender.is_a?(Proc)
35   - block_args = mapping.name if Devise.mailer_sender.arity > 0
36   - Devise.mailer_sender.call(block_args)
  43 + Devise.mailer_sender.call(mapping.name)
37 44 else
38 45 Devise.mailer_sender
39 46 end
4 lib/devise/controllers/scoped_views.rb
@@ -4,7 +4,7 @@ module ScopedViews
4 4 extend ActiveSupport::Concern
5 5
6 6 module ClassMethods
7   - def scoped_views
  7 + def scoped_views?
8 8 defined?(@scoped_views) ? @scoped_views : Devise.scoped_views
9 9 end
10 10
@@ -20,7 +20,7 @@ def scoped_views=(value)
20 20 def render_with_scope(action, options={})
21 21 controller_name = options.delete(:controller) || self.controller_name
22 22
23   - if self.class.scoped_views
  23 + if self.class.scoped_views?
24 24 begin
25 25 render :template => "#{devise_mapping.as}/#{controller_name}/#{action}"
26 26 rescue ActionView::MissingTemplate
5 lib/devise/models/authenticatable.rb
@@ -87,6 +87,11 @@ def update_with_password(params={})
87 87 result
88 88 end
89 89
  90 + # Allows you to overwrite mail messages headers for a given mail.
  91 + def headers_for(action)
  92 + {}
  93 + end
  94 +
90 95 protected
91 96
92 97 # Digests the password using the configured encryptor.
2  test/integration/authenticatable_test.rb
@@ -226,7 +226,7 @@ class AuthenticationTest < ActionController::IntegrationTest
226 226 end
227 227
228 228 assert_match /Special user view/, response.body
229   - assert !Devise::PasswordsController.scoped_views
  229 + assert !Devise::PasswordsController.scoped_views?
230 230 ensure
231 231 Devise::SessionsController.send :remove_instance_variable, :@scoped_views
232 232 end
6 test/models_test.rb
@@ -23,12 +23,12 @@ def assert_include_modules(klass, *modules)
23 23 end
24 24
25 25 test 'add modules cherry pick' do
26   - assert_include_modules Admin, :authenticatable, :registerable, :timeoutable
  26 + assert_include_modules Admin, :authenticatable, :registerable, :timeoutable, :recoverable
27 27 end
28 28
29 29 test 'order of module inclusion' do
30   - correct_module_order = [:authenticatable, :registerable, :timeoutable]
31   - incorrect_module_order = [:authenticatable, :timeoutable, :registerable]
  30 + correct_module_order = [:authenticatable, :recoverable, :registerable, :timeoutable]
  31 + incorrect_module_order = [:authenticatable, :timeoutable, :registerable, :recoverable]
32 32
33 33 assert_include_modules Admin, *incorrect_module_order
34 34

0 comments on commit 12b64c6

Please sign in to comment.
Something went wrong with that request. Please try again.