diff --git a/app/models/custom_workflow.rb b/app/models/custom_workflow.rb index 6f8e483..63f6746 100644 --- a/app/models/custom_workflow.rb +++ b/app/models/custom_workflow.rb @@ -134,7 +134,7 @@ def validate_syntax_for(object, event) object.instance_eval(self[event]) if respond_to?(event) && self[event] rescue RedmineCustomWorkflows::Errors::WorkflowError => _e # Do nothing - rescue StandardError => e + rescue StandardError, ScriptError => e errors.add event, :invalid_script, error: e end diff --git a/app/models/custom_workflow_mailer.rb b/app/models/custom_workflow_mailer.rb index 5c81da3..dcc555b 100644 --- a/app/models/custom_workflow_mailer.rb +++ b/app/models/custom_workflow_mailer.rb @@ -37,8 +37,8 @@ def custom_email(user, headers) template_params = headers.delete(:template_params) || {} if text_body || html_body mail headers do |format| - format.text { render text: text_body } if text_body - format.html { render text: html_body } if html_body + format.text { render plain: text_body } if text_body.present? + format.html { render plain: html_body } if html_body.present? && !Setting.plain_text_mail? end elsif template_name template_params.each { |k, v| instance_variable_set("@#{k}", v) } diff --git a/test/unit/custom_workflow_mailer_test.rb b/test/unit/custom_workflow_mailer_test.rb index ed5ba90..027d780 100644 --- a/test/unit/custom_workflow_mailer_test.rb +++ b/test/unit/custom_workflow_mailer_test.rb @@ -42,8 +42,22 @@ def test_truth def test_custom_email CustomWorkflowMailer.deliver_custom_email @user2, subject: 'Subject', text_body: 'Body', html_body: 'Body' email = last_email - assert text_part(email).body.include? 'Body' - assert html_part(email).body.include? 'Body' + text = text_part(email).body + html = html_part(email).body + assert text.include?('Body'), "'Body' expected\n'#{text}' present'" + assert html.include?('Body'), "'Body' expected\n'#{html}' present'" + end + + def test_custom_email_template + CustomWorkflowMailer.deliver_custom_email @user2, + subject: 'Subject', + template_name: 'mailer/test_email', + template_params: { url: Setting.host_name } + email = last_email + text = text_part(email).body + html = html_part(email).body + assert text.include?(Setting.host_name), "'#{Setting.host_name} expected\n'#{text}' present'" + assert html.include?(Setting.host_name), "'#{Setting.host_name} expected\n'#{html}' present'" end private