mirror of
https://github.com/anteo/redmine_custom_workflows.git
synced 2026-01-26 08:14:20 +00:00
undefined method 'custom_email' #128
This commit is contained in:
parent
df13f8ba8a
commit
9834ca7def
37
app/models/custom_workflow_mailer.rb
Normal file
37
app/models/custom_workflow_mailer.rb
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# encoding: utf-8
|
||||||
|
#
|
||||||
|
# Redmine plugin for Custom Workflows
|
||||||
|
#
|
||||||
|
# Copyright Anton Argirov
|
||||||
|
# Copyright Karel Pičman <karel.picman@kontron.com>
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
require 'mailer'
|
||||||
|
|
||||||
|
class CustomWorkflowMailer < Mailer
|
||||||
|
layout 'mailer'
|
||||||
|
|
||||||
|
def self.deliver_custom_email(user, subject, text)
|
||||||
|
custom_email(user, subject, text).deliver_later
|
||||||
|
end
|
||||||
|
|
||||||
|
def custom_email(user, subject, text)
|
||||||
|
set_language_if_valid user.language
|
||||||
|
@text = text
|
||||||
|
mail to: user.mail, subject: subject
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
26
app/views/custom_workflow_mailer/custom_email.html.erb
Normal file
26
app/views/custom_workflow_mailer/custom_email.html.erb
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<%
|
||||||
|
# encoding: utf-8
|
||||||
|
#
|
||||||
|
# Redmine plugin for Custom Workflows
|
||||||
|
#
|
||||||
|
# Copyright Anton Argirov
|
||||||
|
# Copyright Karel Pičman <karel.picman@kontron.com>
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
%>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= @text %>
|
||||||
|
</p>
|
||||||
24
app/views/custom_workflow_mailer/custom_email.text.erb
Normal file
24
app/views/custom_workflow_mailer/custom_email.text.erb
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<%
|
||||||
|
# encoding: utf-8
|
||||||
|
#
|
||||||
|
# Redmine plugin for Custom Workflows
|
||||||
|
#
|
||||||
|
# Copyright Anton Argirov
|
||||||
|
# Copyright Karel Pičman <karel.picman@kontron.com>
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
%>
|
||||||
|
|
||||||
|
<%= @text %>
|
||||||
@ -29,7 +29,6 @@ require 'redmine_custom_workflows/errors/workflow_error'
|
|||||||
require 'redmine_custom_workflows/patches/attachment_patch'
|
require 'redmine_custom_workflows/patches/attachment_patch'
|
||||||
require 'redmine_custom_workflows/patches/group_patch'
|
require 'redmine_custom_workflows/patches/group_patch'
|
||||||
require 'redmine_custom_workflows/patches/issue_patch'
|
require 'redmine_custom_workflows/patches/issue_patch'
|
||||||
require 'redmine_custom_workflows/patches/mailer_patch'
|
|
||||||
require 'redmine_custom_workflows/patches/project_patch'
|
require 'redmine_custom_workflows/patches/project_patch'
|
||||||
require 'redmine_custom_workflows/patches/projects_helper_patch'
|
require 'redmine_custom_workflows/patches/projects_helper_patch'
|
||||||
require 'redmine_custom_workflows/patches/time_entry_patch'
|
require 'redmine_custom_workflows/patches/time_entry_patch'
|
||||||
|
|||||||
@ -1,65 +0,0 @@
|
|||||||
# encoding: utf-8
|
|
||||||
#
|
|
||||||
# Redmine plugin for Custom Workflows
|
|
||||||
#
|
|
||||||
# Copyright Anton Argirov
|
|
||||||
# Copyright Karel Pičman <karel.picman@kontron.com>
|
|
||||||
#
|
|
||||||
# This program is free software; you can redistribute it and/or
|
|
||||||
# modify it under the terms of the GNU General Public License
|
|
||||||
# as published by the Free Software Foundation; either version 2
|
|
||||||
# of the License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program; if not, write to the Free Software
|
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
|
|
||||||
module RedmineCustomWorkflows
|
|
||||||
module Patches
|
|
||||||
module MailerPatch
|
|
||||||
|
|
||||||
def self.included(base)
|
|
||||||
base.send(:include, InstanceMethods)
|
|
||||||
base.class_eval do
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
module InstanceMethods
|
|
||||||
|
|
||||||
def self.deliver_custom_email(headers={})
|
|
||||||
user = headers.delete :user
|
|
||||||
headers[:to] = user.mail if user
|
|
||||||
text_body = headers.delete :text_body
|
|
||||||
html_body = headers.delete :html_body
|
|
||||||
template_name = headers.delete :template_name
|
|
||||||
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
|
|
||||||
end
|
|
||||||
elsif template_name
|
|
||||||
template_params.each { |k,v| instance_variable_set("@#{k}", v) }
|
|
||||||
mail headers do |format|
|
|
||||||
format.text { render template_name }
|
|
||||||
format.html { render template_name } unless Setting.plain_text_mail?
|
|
||||||
end
|
|
||||||
else
|
|
||||||
raise 'Not :text_body, :html_body or :template_name specified'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
unless Mailer.include?(RedmineCustomWorkflows::Patches::MailerPatch)
|
|
||||||
Mailer.send(:include, RedmineCustomWorkflows::Patches::MailerPatch)
|
|
||||||
end
|
|
||||||
@ -20,4 +20,6 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
# Load the normal Rails helper
|
# Load the normal Rails helper
|
||||||
require File.expand_path('../../../../test/test_helper', __FILE__)
|
require File.expand_path('../../../../test/test_helper', __FILE__)
|
||||||
|
|
||||||
|
require_relative 'unit_test'
|
||||||
65
test/unit/custom_workflow_mailer_test.rb
Normal file
65
test/unit/custom_workflow_mailer_test.rb
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
# encoding: utf-8
|
||||||
|
#
|
||||||
|
# Redmine plugin for Custom Workflows
|
||||||
|
#
|
||||||
|
# Copyright Anton Argirov
|
||||||
|
# Copyright Karel Pičman <karel.picman@kontron.com>
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
require File.expand_path('../../test_helper', __FILE__)
|
||||||
|
|
||||||
|
class CustomWorkflowMailerTest < RedmineCustomWorkflows::Test::UnitTest
|
||||||
|
include Redmine::I18n
|
||||||
|
|
||||||
|
fixtures :users, :email_addresses
|
||||||
|
|
||||||
|
def setup
|
||||||
|
@user2 = User.find 2
|
||||||
|
# Mailer settings
|
||||||
|
ActionMailer::Base.deliveries.clear
|
||||||
|
Setting.plain_text_mail = '0'
|
||||||
|
Setting.default_language = 'en'
|
||||||
|
User.current = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_truth
|
||||||
|
assert_kind_of User, @user2
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_custom_email
|
||||||
|
CustomWorkflowMailer.deliver_custom_email @user2, 'Subject', 'Body'
|
||||||
|
email = last_email
|
||||||
|
assert text_part(email).body.include? 'Body'
|
||||||
|
assert html_part(email).body.include? 'Body'
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def last_email
|
||||||
|
mail = ActionMailer::Base.deliveries.last
|
||||||
|
assert_not_nil mail
|
||||||
|
mail
|
||||||
|
end
|
||||||
|
|
||||||
|
def text_part(email)
|
||||||
|
email.parts.detect { |part| part.content_type.include?('text/plain') }
|
||||||
|
end
|
||||||
|
|
||||||
|
def html_part(email)
|
||||||
|
email.parts.detect { |part| part.content_type.include?('text/html') }
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
40
test/unit_test.rb
Normal file
40
test/unit_test.rb
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
# encoding: utf-8
|
||||||
|
#
|
||||||
|
# Redmine plugin for Custom Workflows
|
||||||
|
#
|
||||||
|
# Copyright Anton Argirov
|
||||||
|
# Copyright Karel Pičman <karel.picman@kontron.com>
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
module RedmineCustomWorkflows
|
||||||
|
module Test
|
||||||
|
|
||||||
|
class UnitTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
|
# Allow us to override the fixtures method to implement fixtures for our plugin.
|
||||||
|
# Ultimately it allows for better integration without blowing redmine fixtures up,
|
||||||
|
# and allowing us to suppliment redmine fixtures if we need to.
|
||||||
|
def self.fixtures(*table_names)
|
||||||
|
dir = File.join( File.dirname(__FILE__), '/fixtures')
|
||||||
|
table_names.each do |x|
|
||||||
|
ActiveRecord::FixtureSet.create_fixtures(dir, x) if File.exist?("#{dir}/#{x}.yml")
|
||||||
|
end
|
||||||
|
super(table_names)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user