Skip to content

Commit 4d687c1

Browse files
syguerIzumiya Keisuke
authored andcommitted
Fix file path on mailer generator
1 parent 924ecab commit 4d687c1

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

lib/generators/haml/mailer/mailer_generator.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ class MailerGenerator < ControllerGenerator
77

88
def copy_view_files
99
if ::Rails.version.to_s >= "4.2.0"
10-
view_base_path = File.join("app/views", class_path, file_name)
10+
view_base_path = File.join("app/views", class_path, file_name + "_mailer")
1111
empty_directory view_base_path
1212

13-
if self.behavior == :invoke
13+
if behavior == :invoke
1414
formats.each do |format|
15-
layout_path = File.join("app/views/layouts", filename_with_extensions("mailer", format))
16-
template filename_with_extensions(:layout, format), layout_path
15+
layout_path = File.join("app/views/layouts", class_path, filename_with_extensions("mailer", format))
16+
template filename_with_extensions(:layout, format), layout_path unless File.exist?(layout_path)
1717
end
1818
end
1919

test/lib/generators/haml/mailer_generator_test.rb

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class Haml::Generators::MailerGeneratorTest < Rails::Generators::TestCase
1313
run_generator
1414

1515
if ::Rails.version.to_s >= '4.2'
16-
1716
assert_file "app/views/layouts/mailer.text.haml" do |view|
1817
assert_match /\= yield/, view
1918
end
@@ -22,25 +21,47 @@ class Haml::Generators::MailerGeneratorTest < Rails::Generators::TestCase
2221
assert_match /\= yield/, view
2322
end
2423

25-
assert_file "app/views/notifier/foo.html.haml" do |view|
26-
assert_match %r(app/views/notifier/foo\.html\.haml), view
24+
assert_file "app/views/notifier_mailer/foo.html.haml" do |view|
25+
assert_match %r(app/views/notifier_mailer/foo\.html\.haml), view
2726
assert_match /\= @greeting/, view
2827
end
2928

30-
assert_file "app/views/notifier/bar.html.haml" do |view|
31-
assert_match %r(app/views/notifier/bar\.html\.haml), view
29+
assert_file "app/views/notifier_mailer/bar.html.haml" do |view|
30+
assert_match %r(app/views/notifier_mailer/bar\.html\.haml), view
3231
assert_match /\= @greeting/, view
3332
end
34-
end
3533

36-
assert_file "app/views/notifier/foo.text.haml" do |view|
37-
assert_match %r(app/views/notifier/foo\.text\.haml), view
38-
assert_match /\= @greeting/, view
39-
end
34+
assert_file "app/views/notifier_mailer/foo.text.haml" do |view|
35+
assert_match %r(app/views/notifier_mailer/foo\.text\.haml), view
36+
assert_match /\= @greeting/, view
37+
end
38+
39+
assert_file "app/views/notifier_mailer/bar.text.haml" do |view|
40+
assert_match %r(app/views/notifier_mailer/bar\.text\.haml), view
41+
assert_match /\= @greeting/, view
42+
end
43+
else
44+
if ::Rails.version.to_s >= '4.1'
45+
assert_file "app/views/notifier/foo.html.haml" do |view|
46+
assert_match %r(app/views/notifier/foo\.html\.haml), view
47+
assert_match /\= @greeting/, view
48+
end
4049

41-
assert_file "app/views/notifier/bar.text.haml" do |view|
42-
assert_match %r(app/views/notifier/bar\.text\.haml), view
43-
assert_match /\= @greeting/, view
50+
assert_file "app/views/notifier/bar.html.haml" do |view|
51+
assert_match %r(app/views/notifier/bar\.html\.haml), view
52+
assert_match /\= @greeting/, view
53+
end
54+
end
55+
56+
assert_file "app/views/notifier/foo.text.haml" do |view|
57+
assert_match %r(app/views/notifier/foo\.text\.haml), view
58+
assert_match /\= @greeting/, view
59+
end
60+
61+
assert_file "app/views/notifier/bar.text.haml" do |view|
62+
assert_match %r(app/views/notifier/bar\.text\.haml), view
63+
assert_match /\= @greeting/, view
64+
end
4465
end
4566
end
4667
end

0 commit comments

Comments
 (0)