File tree Expand file tree Collapse file tree
lib/generators/supermail/email Expand file tree Collapse file tree Original file line number Diff line number Diff 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
2530end
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
3- class <%= class_name %>Email < ApplicationEmail
3+ class <%= class_name %> < ApplicationEmail
44 def body = <<~PLAIN
55
66 PLAIN
Original file line number Diff line number Diff line change 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
3444end
You can’t perform that action at this time.
0 commit comments