From dc86a571aeb13dbe6068346c21abc08e57435b96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 2 Nov 2009 23:14:27 -0200 Subject: [PATCH] [DEPRECATION] Notifier is deprecated, use DeviseMailer instead. Remember to rename app/views/notifier to app/views/devise_mailer and I18n key from devise.notifier to devise.mailer. --- CHANGELOG.rdoc | 9 +++++--- README.rdoc | 8 +++---- app/models/{notifier.rb => devise_mailer.rb} | 21 +++++++++++++------ .../confirmation_instructions.html.erb | 0 .../reset_password_instructions.html.erb | 0 lib/devise/locales/en.yml | 2 +- lib/devise/models/confirmable.rb | 4 ++-- lib/devise/models/recoverable.rb | 2 +- lib/devise/models/rememberable.rb | 4 ++-- .../mailers/confirmation_instructions_test.rb | 6 +++--- .../reset_password_instructions_test.rb | 6 +++--- test/models/rememberable_test.rb | 10 +-------- 12 files changed, 38 insertions(+), 34 deletions(-) rename app/models/{notifier.rb => devise_mailer.rb} (75%) rename app/views/{notifier => devise_mailer}/confirmation_instructions.html.erb (100%) rename app/views/{notifier => devise_mailer}/reset_password_instructions.html.erb (100%) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 386b37ec..d1c3d4c1 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,9 +1,12 @@ +* deprecations + * Notifier is deprecated, use DeviseMailer instead. Remember to rename + app/views/notifier to app/views/devise_mailer and I18n key from + devise.notifier to devise.mailer + * Model configuration is on Devise::Models.config and not on Devise.config anymore. + * enhancement * [#16] Allow devise to be more agnostic. Do not require ActiveRecord to be loaded. -* deprecations - * Model configuration is on Devise::Models.config and not on Devise.config anymore. - == 0.3.0 * bug fix diff --git a/README.rdoc b/README.rdoc index 67168a47..61487aed 100644 --- a/README.rdoc +++ b/README.rdoc @@ -182,7 +182,7 @@ After signing in a user, confirming it's account or updating it's password, devi You also need to setup default url options for the mailer, if you are using confirmable or recoverable. Here's is the configuration for development: - Notifier.sender = "no-reply@yourapp.com" + DeviseMailer.sender = "no-reply@yourapp.com" ActionMailer::Base.default_url_options = { :host => 'localhost:3000' } == Tidying up @@ -220,7 +220,7 @@ You can also copy devise views to your application, being able to modify them ba script/generate devise_views -This is gonna copy all session, password, confirmation and notifier views to your app/views folder. +This is gonna copy all session, password, confirmation and mailer views to your app/views folder. == I18n @@ -241,11 +241,11 @@ You can also create distinct messages based on the resource you've configured us admin: signed_in: 'Hello admin!' -Devise notifier uses the same pattern to create subject messages: +Devise mailer uses the same pattern to create subject messages: en: devise: - notifier: + mailer: confirmation_instructions: 'Hello everybody!' user: confirmation_instructions: 'Hello User! Please confirm your email' diff --git a/app/models/notifier.rb b/app/models/devise_mailer.rb similarity index 75% rename from app/models/notifier.rb rename to app/models/devise_mailer.rb index 9e501f05..79d9bdd3 100644 --- a/app/models/notifier.rb +++ b/app/models/devise_mailer.rb @@ -1,5 +1,15 @@ -class Notifier < ::ActionMailer::Base - cattr_accessor :sender +class DeviseMailer < ::ActionMailer::Base + + # Sets who is sending the e-mail + def self.sender=(value) + @@sender = value + end + + # Reads who is sending the e-mail + def self.sender + @@sender + end + self.sender = nil # Deliver confirmation instructions when the user is created or its email is # updated, and also when confirmation is manually requested @@ -33,12 +43,11 @@ class Notifier < ::ActionMailer::Base # # en: # devise: - # notifier: + # mailer: # confirmation_instructions: '...' # user: - # notifier: - # confirmation_instructions: '...' + # confirmation_instructions: '...' def translate(mapping, key) - I18n.t(:"#{mapping.name}.#{key}", :scope => [:devise, :notifier], :default => key) + I18n.t(:"#{mapping.name}.#{key}", :scope => [:devise, :mailer], :default => key) end end diff --git a/app/views/notifier/confirmation_instructions.html.erb b/app/views/devise_mailer/confirmation_instructions.html.erb similarity index 100% rename from app/views/notifier/confirmation_instructions.html.erb rename to app/views/devise_mailer/confirmation_instructions.html.erb diff --git a/app/views/notifier/reset_password_instructions.html.erb b/app/views/devise_mailer/reset_password_instructions.html.erb similarity index 100% rename from app/views/notifier/reset_password_instructions.html.erb rename to app/views/devise_mailer/reset_password_instructions.html.erb diff --git a/lib/devise/locales/en.yml b/lib/devise/locales/en.yml index 3a4ae5ec..080f5973 100644 --- a/lib/devise/locales/en.yml +++ b/lib/devise/locales/en.yml @@ -12,7 +12,7 @@ en: confirmations: send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.' confirmed: 'Your account was successfully confirmed. You are now signed in.' - notifier: + mailer: confirmation_instructions: 'Confirmation instructions' reset_password_instructions: 'Reset password instructions' diff --git a/lib/devise/models/confirmable.rb b/lib/devise/models/confirmable.rb index ec4f7cc8..f4b56a61 100644 --- a/lib/devise/models/confirmable.rb +++ b/lib/devise/models/confirmable.rb @@ -56,7 +56,7 @@ module Devise # Send confirmation instructions by email def send_confirmation_instructions - ::Notifier.deliver_confirmation_instructions(self) + ::DeviseMailer.deliver_confirmation_instructions(self) end # Remove confirmation date and send confirmation instructions, to ensure @@ -101,7 +101,7 @@ module Devise # def confirmation_period_valid? confirmation_sent_at? && - (Date.today - confirmation_sent_at.to_date).days < confirm_within + (Time.now.utc - confirmation_sent_at.utc) < confirm_within end # Checks whether the record is confirmed or not, yielding to the block diff --git a/lib/devise/models/recoverable.rb b/lib/devise/models/recoverable.rb index f6b90402..4c6c5db3 100644 --- a/lib/devise/models/recoverable.rb +++ b/lib/devise/models/recoverable.rb @@ -35,7 +35,7 @@ module Devise # Resets reset password token and send reset password instructions by email def send_reset_password_instructions generate_reset_password_token! - ::Notifier.deliver_reset_password_instructions(self) + ::DeviseMailer.deliver_reset_password_instructions(self) end protected diff --git a/lib/devise/models/rememberable.rb b/lib/devise/models/rememberable.rb index 2e45ca78..0bec5c8f 100644 --- a/lib/devise/models/rememberable.rb +++ b/lib/devise/models/rememberable.rb @@ -45,7 +45,7 @@ module Devise # Generate a new remember token and save the record without validations. def remember_me! self.remember_token = friendly_token - self.remember_created_at = Time.now + self.remember_created_at = Time.now.utc save(false) end @@ -66,7 +66,7 @@ module Devise # Remember token should be expired if expiration time not overpass now. def remember_expired? - remember_expires_at <= Time.now + remember_expires_at <= Time.now.utc end # Remember token expires at created time + remember_for configuration diff --git a/test/mailers/confirmation_instructions_test.rb b/test/mailers/confirmation_instructions_test.rb index 644b9b4e..ecf0a0fd 100644 --- a/test/mailers/confirmation_instructions_test.rb +++ b/test/mailers/confirmation_instructions_test.rb @@ -4,7 +4,7 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase def setup setup_mailer - Notifier.sender = 'test@example.com' + DeviseMailer.sender = 'test@example.com' end def user @@ -36,13 +36,13 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase end test 'setup subject from I18n' do - store_translations :en, :devise => { :notifier => { :confirmation_instructions => 'Account Confirmation' } } do + store_translations :en, :devise => { :mailer => { :confirmation_instructions => 'Account Confirmation' } } do assert_equal 'Account Confirmation', mail.subject end end test 'subject namespaced by model' do - store_translations :en, :devise => { :notifier => { :user => { :confirmation_instructions => 'User Account Confirmation' } } } do + store_translations :en, :devise => { :mailer => { :user => { :confirmation_instructions => 'User Account Confirmation' } } } do assert_equal 'User Account Confirmation', mail.subject end end diff --git a/test/mailers/reset_password_instructions_test.rb b/test/mailers/reset_password_instructions_test.rb index 835dcbc2..5931c7a0 100644 --- a/test/mailers/reset_password_instructions_test.rb +++ b/test/mailers/reset_password_instructions_test.rb @@ -4,7 +4,7 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase def setup setup_mailer - Notifier.sender = 'test@example.com' + DeviseMailer.sender = 'test@example.com' end def user @@ -39,13 +39,13 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase end test 'setup subject from I18n' do - store_translations :en, :devise => { :notifier => { :reset_password_instructions => 'Reset instructions' } } do + store_translations :en, :devise => { :mailer => { :reset_password_instructions => 'Reset instructions' } } do assert_equal 'Reset instructions', mail.subject end end test 'subject namespaced by model' do - store_translations :en, :devise => { :notifier => { :user => { :reset_password_instructions => 'User Reset Instructions' } } } do + store_translations :en, :devise => { :mailer => { :user => { :reset_password_instructions => 'User Reset Instructions' } } } do assert_equal 'User Reset Instructions', mail.subject end end diff --git a/test/models/rememberable_test.rb b/test/models/rememberable_test.rb index 11ab470d..a302240c 100644 --- a/test/models/rememberable_test.rb +++ b/test/models/rememberable_test.rb @@ -20,14 +20,6 @@ class RememberableTest < ActiveSupport::TestCase assert_not user.changed? end - test 'remember_me should calculate expires_at based on remember_for setup' do - user = create_user - assert_not user.remember_created_at? - user.remember_me! - assert user.remember_created_at? - assert_equal Date.today, user.remember_created_at.to_date - end - test 'forget_me should clear remember token and save the record without validating' do user = create_user user.remember_me! @@ -38,7 +30,7 @@ class RememberableTest < ActiveSupport::TestCase assert_not user.changed? end - test 'forget_me should clear remember_expires_at' do + test 'forget_me should clear remember_created_at' do user = create_user user.remember_me! assert user.remember_created_at?