mirror of
https://github.com/anteo/redmine_custom_workflows.git
synced 2026-01-25 15:54:19 +00:00
#330 Unit tests
This commit is contained in:
parent
8faae7fa46
commit
6dbbb31848
@ -134,7 +134,7 @@ class CustomWorkflow < ApplicationRecord
|
||||
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
|
||||
|
||||
|
||||
@ -37,8 +37,8 @@ class CustomWorkflowMailer < Mailer
|
||||
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) }
|
||||
|
||||
@ -42,8 +42,22 @@ class CustomWorkflowMailerTest < RedmineCustomWorkflows::Test::UnitTest
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user