Skip to content

Commit

Permalink
#330 Unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
picman committed Dec 15, 2023
1 parent 8faae7f commit 6dbbb31
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/models/custom_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions app/models/custom_workflow_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
18 changes: 16 additions & 2 deletions test/unit/custom_workflow_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6dbbb31

Please sign in to comment.