mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
commit
39c936b760
6 changed files with 38 additions and 20 deletions
|
@ -12,6 +12,6 @@ Example:
|
||||||
|
|
||||||
creates a Notifications mailer class, views, and test:
|
creates a Notifications mailer class, views, and test:
|
||||||
Mailer: app/mailers/notifications_mailer.rb
|
Mailer: app/mailers/notifications_mailer.rb
|
||||||
Views: app/views/notifications/signup.text.erb [...]
|
Views: app/views/notifications_mailer/signup.text.erb [...]
|
||||||
Test: test/mailers/notifications_test.rb
|
Test: test/mailers/notifications_mailer_test.rb
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ module Erb # :nodoc:
|
||||||
argument :actions, type: :array, default: [], banner: "method method"
|
argument :actions, type: :array, default: [], banner: "method method"
|
||||||
|
|
||||||
def copy_view_files
|
def copy_view_files
|
||||||
view_base_path = File.join("app/views", class_path, file_name)
|
view_base_path = File.join("app/views", class_path, file_name + '_mailer')
|
||||||
empty_directory view_base_path
|
empty_directory view_base_path
|
||||||
|
|
||||||
if self.behavior == :invoke
|
if self.behavior == :invoke
|
||||||
|
@ -31,6 +31,10 @@ module Erb # :nodoc:
|
||||||
def formats
|
def formats
|
||||||
[:text, :html]
|
[:text, :html]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def file_name
|
||||||
|
@_file_name ||= super.gsub(/\_mailer/i, '')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,6 +16,11 @@ module TestUnit # :nodoc:
|
||||||
def create_preview_files
|
def create_preview_files
|
||||||
template "preview.rb", File.join('test/mailers/previews', class_path, "#{file_name}_mailer_preview.rb")
|
template "preview.rb", File.join('test/mailers/previews', class_path, "#{file_name}_mailer_preview.rb")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
def file_name
|
||||||
|
@_file_name ||= super.gsub(/\_mailer/i, '')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,7 @@ require 'test_helper'
|
||||||
class <%= class_name %>MailerTest < ActionMailer::TestCase
|
class <%= class_name %>MailerTest < ActionMailer::TestCase
|
||||||
<% actions.each do |action| -%>
|
<% actions.each do |action| -%>
|
||||||
test "<%= action %>" do
|
test "<%= action %>" do
|
||||||
mail = <%= class_name %>.<%= action %>
|
mail = <%= class_name %>Mailer.<%= action %>
|
||||||
assert_equal <%= action.to_s.humanize.inspect %>, mail.subject
|
assert_equal <%= action.to_s.humanize.inspect %>, mail.subject
|
||||||
assert_equal ["to@example.org"], mail.to
|
assert_equal ["to@example.org"], mail.to
|
||||||
assert_equal ["from@example.com"], mail.from
|
assert_equal ["from@example.com"], mail.from
|
||||||
|
|
|
@ -78,13 +78,13 @@ class MailerGeneratorTest < Rails::Generators::TestCase
|
||||||
|
|
||||||
def test_invokes_default_text_template_engine
|
def test_invokes_default_text_template_engine
|
||||||
run_generator
|
run_generator
|
||||||
assert_file "app/views/notifier/foo.text.erb" do |view|
|
assert_file "app/views/notifier_mailer/foo.text.erb" do |view|
|
||||||
assert_match(%r(\sapp/views/notifier/foo\.text\.erb), view)
|
assert_match(%r(\sapp/views/notifier_mailer/foo\.text\.erb), view)
|
||||||
assert_match(/<%= @greeting %>/, view)
|
assert_match(/<%= @greeting %>/, view)
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_file "app/views/notifier/bar.text.erb" do |view|
|
assert_file "app/views/notifier_mailer/bar.text.erb" do |view|
|
||||||
assert_match(%r(\sapp/views/notifier/bar\.text\.erb), view)
|
assert_match(%r(\sapp/views/notifier_mailer/bar\.text\.erb), view)
|
||||||
assert_match(/<%= @greeting %>/, view)
|
assert_match(/<%= @greeting %>/, view)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -95,13 +95,13 @@ class MailerGeneratorTest < Rails::Generators::TestCase
|
||||||
|
|
||||||
def test_invokes_default_html_template_engine
|
def test_invokes_default_html_template_engine
|
||||||
run_generator
|
run_generator
|
||||||
assert_file "app/views/notifier/foo.html.erb" do |view|
|
assert_file "app/views/notifier_mailer/foo.html.erb" do |view|
|
||||||
assert_match(%r(\sapp/views/notifier/foo\.html\.erb), view)
|
assert_match(%r(\sapp/views/notifier_mailer/foo\.html\.erb), view)
|
||||||
assert_match(/<%= @greeting %>/, view)
|
assert_match(/<%= @greeting %>/, view)
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_file "app/views/notifier/bar.html.erb" do |view|
|
assert_file "app/views/notifier_mailer/bar.html.erb" do |view|
|
||||||
assert_match(%r(\sapp/views/notifier/bar\.html\.erb), view)
|
assert_match(%r(\sapp/views/notifier_mailer/bar\.html\.erb), view)
|
||||||
assert_match(/<%= @greeting %>/, view)
|
assert_match(/<%= @greeting %>/, view)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ class MailerGeneratorTest < Rails::Generators::TestCase
|
||||||
|
|
||||||
def test_invokes_default_template_engine_even_with_no_action
|
def test_invokes_default_template_engine_even_with_no_action
|
||||||
run_generator ["notifier"]
|
run_generator ["notifier"]
|
||||||
assert_file "app/views/notifier"
|
assert_file "app/views/notifier_mailer"
|
||||||
assert_file "app/views/layouts/mailer.text.erb"
|
assert_file "app/views/layouts/mailer.text.erb"
|
||||||
assert_file "app/views/layouts/mailer.html.erb"
|
assert_file "app/views/layouts/mailer.html.erb"
|
||||||
end
|
end
|
||||||
|
@ -133,8 +133,8 @@ class MailerGeneratorTest < Rails::Generators::TestCase
|
||||||
assert_match(/class Farm::AnimalMailerPreview < ActionMailer::Preview/, preview)
|
assert_match(/class Farm::AnimalMailerPreview < ActionMailer::Preview/, preview)
|
||||||
assert_match(/\# Preview this email at http:\/\/localhost\:3000\/rails\/mailers\/farm\/animal\/moos/, preview)
|
assert_match(/\# Preview this email at http:\/\/localhost\:3000\/rails\/mailers\/farm\/animal\/moos/, preview)
|
||||||
end
|
end
|
||||||
assert_file "app/views/farm/animal/moos.text.erb"
|
assert_file "app/views/farm/animal_mailer/moos.text.erb"
|
||||||
assert_file "app/views/farm/animal/moos.html.erb"
|
assert_file "app/views/farm/animal_mailer/moos.html.erb"
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_actions_are_turned_into_methods
|
def test_actions_are_turned_into_methods
|
||||||
|
@ -173,5 +173,14 @@ class MailerGeneratorTest < Rails::Generators::TestCase
|
||||||
|
|
||||||
assert_no_file "app/mailers/notifier_mailer_mailer.rb"
|
assert_no_file "app/mailers/notifier_mailer_mailer.rb"
|
||||||
assert_file "app/mailers/notifier_mailer.rb"
|
assert_file "app/mailers/notifier_mailer.rb"
|
||||||
|
|
||||||
|
assert_no_file "app/views/notifier_mailer_mailer/"
|
||||||
|
assert_file "app/views/notifier_mailer/"
|
||||||
|
|
||||||
|
assert_no_file "test/mailers/notifier_mailer_mailer_test.rb"
|
||||||
|
assert_file "test/mailers/notifier_mailer_test.rb"
|
||||||
|
|
||||||
|
assert_no_file "test/mailers/previews/notifier_mailer_mailer_preview.rb"
|
||||||
|
assert_file "test/mailers/previews/notifier_mailer_preview.rb"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -173,20 +173,20 @@ class NamespacedMailerGeneratorTest < NamespacedGeneratorTestCase
|
||||||
|
|
||||||
def test_invokes_default_template_engine
|
def test_invokes_default_template_engine
|
||||||
run_generator
|
run_generator
|
||||||
assert_file "app/views/test_app/notifier/foo.text.erb" do |view|
|
assert_file "app/views/test_app/notifier_mailer/foo.text.erb" do |view|
|
||||||
assert_match(%r(app/views/test_app/notifier/foo\.text\.erb), view)
|
assert_match(%r(app/views/test_app/notifier_mailer/foo\.text\.erb), view)
|
||||||
assert_match(/<%= @greeting %>/, view)
|
assert_match(/<%= @greeting %>/, view)
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_file "app/views/test_app/notifier/bar.text.erb" do |view|
|
assert_file "app/views/test_app/notifier_mailer/bar.text.erb" do |view|
|
||||||
assert_match(%r(app/views/test_app/notifier/bar\.text\.erb), view)
|
assert_match(%r(app/views/test_app/notifier_mailer/bar\.text\.erb), view)
|
||||||
assert_match(/<%= @greeting %>/, view)
|
assert_match(/<%= @greeting %>/, view)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_invokes_default_template_engine_even_with_no_action
|
def test_invokes_default_template_engine_even_with_no_action
|
||||||
run_generator ["notifier"]
|
run_generator ["notifier"]
|
||||||
assert_file "app/views/test_app/notifier"
|
assert_file "app/views/test_app/notifier_mailer"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue