Permalink
Browse files

Mail views a scoped as well.

  • Loading branch information...
1 parent b842a72 commit 0a5ba20931fc1904dc54a09262132d2212d81f9b @josevalim josevalim committed Dec 15, 2009
View
@@ -1,5 +1,6 @@
* enhancements
* Do not care about blank passwords on update
+ * Mail views are scoped as well
== 0.7.2
@@ -26,15 +26,27 @@ def reset_password_instructions(record)
# Configure default email options
def setup_mail(record, key)
- mapping = Devise.mappings.values.find { |m| m.to == record.class }
+ mapping = Devise::Mapping.find_by_class(record.class)
raise "Invalid devise resource #{record}" unless mapping
subject translate(mapping, key)
from self.class.sender
recipients record.email
sent_on Time.now
content_type 'text/html'
- body mapping.name => record, :resource => record
+ body render_with_scope(key, mapping, mapping.name => record, :resource => record)
+ end
+
+ def render_with_scope(key, mapping, assigns)
+ if Devise.scoped_views
+ begin
+ render :file => "devise_mailer/#{mapping.as}/#{key}", :body => assigns
+ rescue ActionView::MissingTemplate
+ render :file => "devise_mailer/#{key}", :body => assigns
+ end
+ else
+ render :file => "devise_mailer/#{key}", :body => assigns
+ end
end
# Setup subject namespaced by model. It means you're able to setup your
@@ -56,4 +56,10 @@ def mail
confirmation_url_regexp = %r{<a href=\"http://#{host}/users/confirmation\?confirmation_token=#{user.confirmation_token}">}
assert_match confirmation_url_regexp, mail.body
end
+
+ test 'renders a scoped if scoped_views is set to true' do
+ swap Devise, :scoped_views => true do
+ assert_equal user.email, mail.body
+ end
+ end
end
@@ -0,0 +1 @@
+<%= @resource.email %>

0 comments on commit 0a5ba20

Please sign in to comment.