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