Skip to content

Commit adfdd87

Browse files
committed
Fix generator for mailer
1 parent 5f20071 commit adfdd87

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/generators/rspec/mailer/mailer_generator.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ class MailerGenerator < Base
88
argument :actions, type: :array, default: [], banner: "method method"
99

1010
def generate_mailer_spec
11-
template "mailer_spec.rb", target_path('mailers', class_path, "#{file_name}_spec.rb")
11+
file_suffix = file_name.end_with?('mailer') ? 'spec.rb' : 'mailer_spec.rb'
12+
template "mailer_spec.rb", target_path('mailers', class_path, [file_name, file_suffix].join('_'))
1213
end
1314

1415
def generate_fixtures_files
@@ -21,7 +22,8 @@ def generate_fixtures_files
2122
def generate_preview_files
2223
return unless RSpec::Rails::FeatureCheck.has_action_mailer_preview?
2324

24-
template "preview.rb", target_path("mailers/previews", class_path, "#{file_name}_preview.rb")
25+
file_suffix = file_name.end_with?('mailer') ? 'preview.rb' : 'mailer_preview.rb'
26+
template "preview.rb", target_path("mailers/previews", class_path, [file_name, file_suffix].join('_'))
2527
end
2628
end
2729
end

lib/generators/rspec/mailer/templates/preview.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<% module_namespacing do -%>
22
# Preview all emails at http://localhost:3000/rails/mailers/<%= file_path %>
3-
class <%= class_name %>Preview < ActionMailer::Preview
3+
class <%= class_name %><%= 'Mailer' unless class_name.end_with?('Mailer') %>Preview < ActionMailer::Preview
44
<% actions.each do |action| -%>
55
66
# Preview this email at http://localhost:3000/rails/mailers/<%= file_path %>/<%= action %>

0 commit comments

Comments
 (0)