mirror of
https://github.com/anteo/redmine_custom_workflows.git
synced 2026-01-25 15:54:19 +00:00
#324 Tests & Rubocop
This commit is contained in:
parent
2d46569afa
commit
bf87b60215
@ -1,8 +1,9 @@
|
||||
Changelog for Custom Workflows
|
||||
==============================
|
||||
|
||||
2.0.10 *????-??-??*
|
||||
2.1.0 *????-??-??*
|
||||
-------------------
|
||||
Member as an observable object
|
||||
|
||||
2.0.9 *2023-06-06*
|
||||
------------------
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
Custom Workflows plug-in 2.0.10 devel
|
||||
Custom Workflows plug-in 2.1.0 devel
|
||||
=====================================
|
||||
|
||||
[](https://github.com/anteo/redmine_custom_workflows/actions/workflows/rubyonrails.yml)
|
||||
@ -21,6 +21,7 @@ Supported observable objects:
|
||||
* Issue relations
|
||||
* Time entry
|
||||
* User
|
||||
* Member
|
||||
* Version
|
||||
* Wiki
|
||||
* \<Shared code\>
|
||||
@ -55,7 +56,7 @@ Installation
|
||||
From a ZIP file:
|
||||
|
||||
* Download the latest version of the plugin.
|
||||
* In case of an upgrade remove the original *plugins/redmine_custom_workflows* folder.
|
||||
* In case of an upgrade, remove the original *plugins/redmine_custom_workflows* folder.
|
||||
* Unzip it to /plugins.
|
||||
|
||||
From the Git repository:
|
||||
|
||||
@ -21,12 +21,13 @@
|
||||
|
||||
# Custom workflow model
|
||||
class CustomWorkflow < ApplicationRecord
|
||||
OBSERVABLES = %i[issue issue_relation issue_attachments user member attachment group group_users project project_attachments
|
||||
wiki_content wiki_page_attachments time_entry version shared].freeze
|
||||
OBSERVABLES = %i[issue issue_relation issue_attachments user member attachment group group_users project
|
||||
project_attachments wiki_content wiki_page_attachments time_entry version shared].freeze
|
||||
PROJECT_OBSERVABLES = %i[issue issue_attachments project project_attachments wiki_content wiki_page_attachments
|
||||
time_entry version].freeze
|
||||
time_entry version member].freeze
|
||||
COLLECTION_OBSERVABLES = %i[group_users issue_attachments project_attachments wiki_page_attachments].freeze
|
||||
SINGLE_OBSERVABLES = %i[issue issue_relation user member group attachment project wiki_content time_entry version].freeze
|
||||
SINGLE_OBSERVABLES = %i[issue issue_relation user member group attachment project wiki_content time_entry version]
|
||||
.freeze
|
||||
|
||||
acts_as_list
|
||||
|
||||
|
||||
@ -76,17 +76,19 @@ cs:
|
||||
text_custom_workflow_issue_relation_code_note: Skripty jsou vykonávány v rámci objektu vazby mezi úkoly stejně jako
|
||||
volání `before_save` a `after_save` funkcí. Takže lze použít přímo vlastností vazby mezi úkoly. Proměnné (@variable)
|
||||
jsou rovněž dostupné a lze jich použít.
|
||||
text_custom_workflow_shared_code_note: Tento kód bude spuštěn pře jakýmkoli jiným procesem a může obsahovat sdílený
|
||||
text_custom_workflow_shared_code_note: Tento kód bude spuštěn před jakýmkoli jiným procesem a může obsahovat sdílený
|
||||
kód, např. funkce a třídy, které jsou potřeba v jiných procesech
|
||||
text_custom_workflow_user_code_note: Skripty jsou vykonávány v rámci objektu uživatel, když se objekt mění (maže).
|
||||
Můžete přímo použít metody a vlastnosti objektu.
|
||||
text_custom_workflow_member_code_note: Skripty jsou vykonávány v rámci objektu člen, když se objekt mění (maže).
|
||||
Můžete přímo použít metody a vlastnosti objektu.
|
||||
text_custom_workflow_group_code_note: Skripty jsou vykonávány v rámci objektu skupina, když se objekt mění (maže).
|
||||
Můžete přímo použít metody a vlastnosti objektu.
|
||||
text_custom_workflow_group_users_code_note: Tyto skripty jsou vykonávány, když je uživatel přidán nebo odebrán ze
|
||||
skupiny. Pro přístup k objektům použijte proměnné @user a @group.
|
||||
text_custom_workflow_attachment_code_note: Skripty jsou vykonávány v rámci objektu příloha, když se tento objekt mění
|
||||
(maže se). Můžete přímo použít metody a vlastnosti objektu. Mějte na paměti, že se to týká všech typů příloh
|
||||
(u úkolů, dokumentů, wiki stránek atd.), takže byste měli zkontrolovat proměnnou 'container_type' pro určení,
|
||||
(u úkolů, dokumentů, wiki stránek, atd.), takže byste měli zkontrolovat proměnnou 'container_type' pro určení,
|
||||
o jakou přílohu se jedná.
|
||||
text_custom_workflow_issue_attachments_code_note: Tento skripty se vykonávají když je příloha přidána nebo odebrába
|
||||
z úkolu. Můžete použít proměnné @issue a @attachment pro přístup k těmto objektům ve skriptu.
|
||||
@ -115,6 +117,7 @@ cs:
|
||||
custom_workflow_observable_group: Skupina
|
||||
custom_workflow_observable_user: Uživatel
|
||||
custom_workflow_observable_attachment: Příloha
|
||||
custom_workflow_observable_member: Člen
|
||||
custom_workflow_observable_project: Projekt
|
||||
custom_workflow_observable_project_attachments: Soubory
|
||||
custom_workflow_observable_wiki_content: Wiki
|
||||
|
||||
@ -79,7 +79,9 @@ es:
|
||||
text_custom_workflow_shared_code_note: Este código se ejecutará antes que cualquier otro workflow y puede contener código compartido,
|
||||
por ejemplo, funciones y clases necesarias para otros flujos de trabajo
|
||||
text_custom_workflow_user_code_note: Los scripts se ejecutan en el contexto del objeto User cuando el usuario cambia
|
||||
(destruye). Utilice métodos y propiedades del usuario directamente (o a través de `self`)
|
||||
(destruye). Utilice métodos y propiedades del usuario directamente (o a través de `self`)
|
||||
text_custom_workflow_member_code_note: Scripts are executed in the context of Member object when member object changes
|
||||
(destroys). Use methods and properties of the @member directly (or through `self`)
|
||||
text_custom_workflow_group_code_note: Los scripts se ejecutan en el contexto del objeto Group cuando el grupo cambia
|
||||
(destruye). Utilice métodos y propiedades del grupo directamente (o a través de `self`)
|
||||
text_custom_workflow_group_users_code_note: Estos scripts se ejecutan cuando el usuario se añade al grupo/se elimina del
|
||||
@ -115,6 +117,7 @@ es:
|
||||
custom_workflow_observable_issue_attachments: Ficheros de petición
|
||||
custom_workflow_observable_group: Grupo
|
||||
custom_workflow_observable_user: Usuario
|
||||
custom_workflow_observable_member: Miembro
|
||||
custom_workflow_observable_attachment: Ficheros
|
||||
custom_workflow_observable_project: Proyecto
|
||||
custom_workflow_observable_project_attachments: Adjuntos de proyecto / Ficheros
|
||||
|
||||
@ -80,6 +80,8 @@ pt-BR:
|
||||
e.g. functions and classes needed by other workflows.
|
||||
text_custom_workflow_user_code_note: Both scripts are executed in the context of the user object when user object
|
||||
changes. Use methods and properties of the user directly (or through `self`)
|
||||
text_custom_workflow_member_code_note: Scripts are executed in the context of Member object when member object changes
|
||||
(destroys). Use methods and properties of the @member directly (or through `self`)
|
||||
text_custom_workflow_group_code_note: Both scripts are executed in the context of the group object when group object
|
||||
changes. Use methods and properties of the group directly (or through `self`)
|
||||
text_custom_workflow_group_users_code_note: These scripts are executed when user being added to group/removed from
|
||||
@ -115,6 +117,7 @@ pt-BR:
|
||||
custom_workflow_observable_group: Group
|
||||
custom_workflow_observable_user: User
|
||||
custom_workflow_observable_attachment: Attachment
|
||||
custom_workflow_observable_member: Membro
|
||||
custom_workflow_observable_project: Project
|
||||
custom_workflow_observable_project_attachments: Project Attachments / Files
|
||||
custom_workflow_observable_wiki_content: Wiki Content
|
||||
|
||||
2
init.rb
2
init.rb
@ -25,7 +25,7 @@ Redmine::Plugin.register :redmine_custom_workflows do
|
||||
author_url 'https://github.com/anteo/redmine_custom_workflows/graphs/contributors'
|
||||
author 'Anton Argirov/Karel Pičman'
|
||||
description 'It allows to create custom workflows for objects, defined in a plain Ruby language'
|
||||
version '2.0.10 devel'
|
||||
version '2.1.0 devel'
|
||||
|
||||
requires_redmine version_or_higher: '4.1.0'
|
||||
|
||||
|
||||
@ -35,6 +35,7 @@ require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/models/issue
|
||||
require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/models/project_patch"
|
||||
require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/models/time_entry_patch"
|
||||
require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/models/user_patch"
|
||||
require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/models/member_patch"
|
||||
require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/models/version_patch"
|
||||
require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/models/wiki_content_patch"
|
||||
require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/models/wiki_page_patch"
|
||||
@ -47,6 +48,7 @@ require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/controllers/
|
||||
require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/controllers/projects_controller_patch"
|
||||
require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/controllers/timelog_controller_patch"
|
||||
require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/controllers/users_controller_patch"
|
||||
require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/controllers/members_controller_patch"
|
||||
require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/controllers/versions_controller_patch"
|
||||
require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/controllers/wiki_controller_patch"
|
||||
|
||||
|
||||
@ -0,0 +1,79 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Redmine plugin for Custom Workflows
|
||||
#
|
||||
# Copyright © 2015-19 Anton Argirov
|
||||
# Copyright © 2019-23 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 Controllers
|
||||
# Members controller patch
|
||||
module MembersControllerPatch
|
||||
################################################################################################################
|
||||
# New methods
|
||||
#
|
||||
|
||||
def self.prepended(base)
|
||||
base.class_eval do
|
||||
before_action :set_env
|
||||
after_action :display_custom_workflow_messages
|
||||
end
|
||||
end
|
||||
|
||||
def set_env
|
||||
objects = model_objects
|
||||
return unless objects&.any?
|
||||
|
||||
objects.each do |o|
|
||||
o.custom_workflow_env[:remote_ip] = request.remote_ip
|
||||
end
|
||||
end
|
||||
|
||||
def display_custom_workflow_messages
|
||||
objects = model_objects
|
||||
return unless objects&.any?
|
||||
|
||||
objects.each do |o|
|
||||
next if o&.custom_workflow_messages&.empty?
|
||||
|
||||
o.custom_workflow_messages.each do |key, value|
|
||||
if value&.present?
|
||||
flash[key] = value
|
||||
else
|
||||
flash.delete key
|
||||
end
|
||||
end
|
||||
o.custom_workflow_messages.clear
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def model_objects
|
||||
if @members
|
||||
@members
|
||||
elsif @member
|
||||
[@member]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
MembersController.prepend RedmineCustomWorkflows::Patches::Controllers::MembersControllerPatch
|
||||
@ -74,5 +74,5 @@ end
|
||||
if Redmine::Plugin.installed?('easy_extensions')
|
||||
RedmineExtensions::PatchManager.register_model_patch 'Member', 'RedmineCustomWorkflows::Patches::Models::MemberPatch'
|
||||
else
|
||||
User.prepend RedmineCustomWorkflows::Patches::Models::MemberPatch
|
||||
Member.prepend RedmineCustomWorkflows::Patches::Models::MemberPatch
|
||||
end
|
||||
|
||||
24
test/fixtures/custom_workflows.yml
vendored
24
test/fixtures/custom_workflows.yml
vendored
@ -220,4 +220,26 @@ custom_workflows_010:
|
||||
after_remove: NULL
|
||||
before_destroy: "self.custom_workflow_messages[:warning] = self.custom_workflow_env[:remote_ip]\n
|
||||
Rails.logger.info \">>> #{self.class.name} #{self.id }#{self.custom_workflow_env[:remote_ip]}\""
|
||||
after_destroy: ''
|
||||
after_destroy: ''
|
||||
|
||||
custom_workflows_011:
|
||||
id: 11
|
||||
before_save: ''
|
||||
after_save: ''
|
||||
name: 'Member CW test'
|
||||
description: 'Testing workflow'
|
||||
position: 11
|
||||
is_for_all: 0
|
||||
author: 'karel.picman@kontron.com'
|
||||
created_at: 2023-10-06 09:29:27 +02:00
|
||||
updated_at: 2023-10-06 09:29:27 +02:00
|
||||
active: 1
|
||||
observable: 'member'
|
||||
shared_code: NULL
|
||||
before_add: NULL
|
||||
after_add: NULL
|
||||
before_remove: NULL
|
||||
after_remove: NULL
|
||||
before_destroy: "self.custom_workflow_messages[:notice] = 'Custom workflow'\n
|
||||
self.custom_workflow_messages[:warning] = self.custom_workflow_env[:remote_ip]"
|
||||
after_destroy: ''
|
||||
4
test/fixtures/custom_workflows_projects.yml
vendored
4
test/fixtures/custom_workflows_projects.yml
vendored
@ -22,3 +22,7 @@ custom_workflows_projects_005:
|
||||
custom_workflows_projects_006:
|
||||
project_id: 1
|
||||
custom_workflow_id: 10 # Wiki page
|
||||
|
||||
custom_workflows_projects_007:
|
||||
project_id: 1
|
||||
custom_workflow_id: 11 # Member
|
||||
|
||||
45
test/functional/members_controller_patch_test.rb
Normal file
45
test/functional/members_controller_patch_test.rb
Normal file
@ -0,0 +1,45 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Redmine plugin for Document Management System "Features"
|
||||
#
|
||||
# Copyright © 2019-23 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__)
|
||||
|
||||
# Users controller patch test
|
||||
class MembersControllerPatchTest < RedmineCustomWorkflows::Test::TestCase
|
||||
fixtures :user_preferences, :roles, :members, :member_roles, :custom_workflows, :custom_workflows_projects
|
||||
|
||||
def setup
|
||||
super
|
||||
@member1 = Member.find 1
|
||||
@request.session[:user_id] = @jsmith.id
|
||||
@controller = MembersController.new
|
||||
end
|
||||
|
||||
def test_delete_with_cw
|
||||
delete :destroy, params: { id: @member1 }
|
||||
assert_response :redirect
|
||||
assert_equal 'Custom workflow', @controller.flash[:notice]
|
||||
end
|
||||
|
||||
def test_cw_env
|
||||
delete :destroy, params: { id: @member1 }
|
||||
assert_response :redirect
|
||||
assert_equal request.remote_ip, @controller.flash[:warning]
|
||||
end
|
||||
end
|
||||
45
test/unit/member_patch_test.rb
Normal file
45
test/unit/member_patch_test.rb
Normal file
@ -0,0 +1,45 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Redmine plugin for Custom Workflows
|
||||
#
|
||||
# Copyright © 2015-19 Anton Argirov
|
||||
# Copyright © 2019-23 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__)
|
||||
|
||||
# Member patch test class
|
||||
class MemberPatchTest < RedmineCustomWorkflows::Test::UnitTest
|
||||
fixtures :members
|
||||
|
||||
def setup
|
||||
@member1 = Member.find 1
|
||||
end
|
||||
|
||||
def test_truth
|
||||
assert_kind_of Member, @member1
|
||||
end
|
||||
|
||||
def test_custom_workflow_messages
|
||||
@member1.custom_workflow_messages[:notice] = 'Okay'
|
||||
assert_equal 'Okay', @member1.custom_workflow_messages[:notice]
|
||||
end
|
||||
|
||||
def test_custom_workflow_env
|
||||
@member1.custom_workflow_env[:remote_ip] = '127.0.0.1'
|
||||
assert_equal '127.0.0.1', @member1.custom_workflow_env[:remote_ip]
|
||||
end
|
||||
end
|
||||
@ -21,7 +21,7 @@
|
||||
|
||||
require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
# user patch test class
|
||||
# User patch test class
|
||||
class UserPatchTest < RedmineCustomWorkflows::Test::UnitTest
|
||||
fixtures :users
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user