Skip to content

Commit c41886a

Browse files
committed
Fix EmailEmail bug for generator
1 parent c5bcaa5 commit c41886a

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

lib/generators/supermail/email/email_generator.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,22 @@ class EmailGenerator < ::Rails::Generators::NamedBase
99
desc "Generate a new email class"
1010

1111
def create_email_file
12-
template 'email.rb', "app/emails/#{file_path}_email.rb"
12+
template 'email.rb', "app/emails/#{file_path}.rb"
1313
end
1414

1515
private
1616

1717
def file_path
18-
name.underscore
18+
"#{base_name.underscore}_email"
1919
end
2020

2121
def class_name
22-
name.camelize
22+
"#{base_name.camelize}Email"
23+
end
24+
25+
def base_name
26+
stripped = name.to_s.sub(/_?email\z/i, '')
27+
stripped.empty? ? name : stripped
2328
end
2429
end
2530
end

lib/generators/supermail/email/templates/email.rb.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
class <%= class_name %>Email < ApplicationEmail
3+
class <%= class_name %> < ApplicationEmail
44
def body = <<~PLAIN
55

66
PLAIN

spec/generators/email_generator_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,14 @@
3131
it { is_expected.to match(/def body = <<~PLAIN/) }
3232
end
3333
end
34+
35+
describe "with email suffix provided" do
36+
before { run_generator ["WelcomeEmail"] }
37+
38+
describe "app/emails/welcome_email.rb" do
39+
subject { File.read(EMAIL_DESTINATION_PATH.join("app/emails/welcome_email.rb")) }
40+
it { is_expected.to match(/class WelcomeEmail < ApplicationEmail/) }
41+
it { is_expected.not_to match(/WelcomeEmailEmail/) }
42+
end
43+
end
3444
end

0 commit comments

Comments
 (0)