Compare commits

..

4 Commits

Author SHA1 Message Date
José Valim
d1dc18cb1a Bump to 0.8.2. 2010-01-13 17:46:16 +01:00
José Valim
6bb1901830 Add tests for mail with proc. 2010-01-13 17:45:02 +01:00
Jonas Grimfelt
37119616ff Devise.mailer_sender accepts a proc too, passing mapping. Useful if sender e-mail should differ for different devise scopes or current locale.
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-01-13 17:36:05 +01:00
David Palm
5ca178aa7e Devise::Mapping#raw_path considers the relative_url_root to fix issue with Passenger and RailsBaseURI directives
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-01-13 17:30:27 +01:00
8 changed files with 55 additions and 7 deletions

View File

@@ -1,3 +1,13 @@
== 0.8.2
* enhancements
* Allow Devise.mailer_sender to be a proc (by github/grimen)
* bug fix
* Fix bug with passenger, update is required to anyone deploying on passenger (by github/dvdpalm)
== 0.8.1
* enhancements
* Move salt to encryptors

View File

@@ -19,7 +19,7 @@ class DeviseMailer < ::ActionMailer::Base
raise "Invalid devise resource #{record}" unless mapping
subject translate(mapping, key)
from Devise.mailer_sender
from mailer_sender(mapping)
recipients record.email
sent_on Time.now
content_type 'text/html'
@@ -38,6 +38,14 @@ class DeviseMailer < ::ActionMailer::Base
end
end
def mailer_sender(mapping)
if Devise.mailer_sender.is_a?(Proc)
Devise.mailer_sender.call(mapping.name)
else
Devise.mailer_sender
end
end
# Setup subject namespaced by model. It means you're able to setup your
# messages using specific resource scope, or provide a default one.
# Example (i18n locale file):

View File

@@ -1,5 +1,5 @@
# After each sign in, update sign in time, sign in count and sign in IP.
Warden::Manager.after_set_user :event => [:authentication, :set_user] do |record, warden, options|
Warden::Manager.after_set_user :except => :fetch do |record, warden, options|
scope = options[:scope]
if Devise.mappings[scope].try(:trackable?) && warden.authenticated?(scope)
old_current, new_current = record.current_sign_in_at, Time.now

View File

@@ -92,9 +92,9 @@ module Devise
self.path_prefix.count("/")
end
# Returns the raw path using path_prefix and as.
# Returns the raw path using the current relative_url_root, path_prefix and as.
def raw_path
path_prefix + as.to_s
ActionController::Base.relative_url_root.to_s + path_prefix + as.to_s
end
# Returns the parsed path. If you need meta information in your path_prefix,

View File

@@ -1,3 +1,3 @@
module Devise
VERSION = "0.8.1".freeze
VERSION = "0.8.2".freeze
end

View File

@@ -62,4 +62,10 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
assert_equal user.email, mail.body
end
end
test 'mailer sender accepts a proc' do
swap Devise, :mailer_sender => lambda { "another@example.com" } do
assert_equal ['another@example.com'], mail.from
end
end
end

View File

@@ -59,4 +59,10 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
reset_url_regexp = %r{<a href=\"http://#{host}/users/password/edit\?reset_password_token=#{user.reset_password_token}">}
assert_match reset_url_regexp, mail.body
end
test 'mailer sender accepts a proc' do
swap Devise, :mailer_sender => lambda { "another@example.com" } do
assert_equal ['another@example.com'], mail.from
end
end
end

View File

@@ -86,7 +86,7 @@ class MappingTest < ActiveSupport::TestCase
mapping = Devise.mappings[:manager]
assert_equal '/:locale/', mapping.path_prefix
end
test 'retrieve as from the proper position' do
assert_equal 1, Devise.mappings[:user].as_position
assert_equal 2, Devise.mappings[:manager].as_position
@@ -96,6 +96,18 @@ class MappingTest < ActiveSupport::TestCase
assert_equal '/users', Devise.mappings[:user].raw_path
assert_equal '/:locale/accounts', Devise.mappings[:manager].raw_path
end
test 'raw path adds in the relative_url_root' do
swap ActionController::Base, :relative_url_root => '/abc' do
assert_equal '/abc/users', Devise.mappings[:user].raw_path
end
end
test 'raw path deals with a nil relative_url_root' do
swap ActionController::Base, :relative_url_root => nil do
assert_equal '/users', Devise.mappings[:user].raw_path
end
end
test 'parsed path is returned' do
begin
@@ -106,7 +118,13 @@ class MappingTest < ActiveSupport::TestCase
Devise.default_url_options {{ }}
end
end
test 'parsed path deals with non-standard relative_url_roots' do
swap ActionController::Base, :relative_url_root => "/abc" do
assert_equal '/abc/users', Devise.mappings[:user].parsed_path
end
end
test 'should have default route options' do
assert_equal({}, Devise.mappings[:user].route_options)
end