Complete functional and unit tests for already implemented features of approval workflow
This commit is contained in:
parent
c9a4c35f10
commit
e63e561c1d
@ -256,21 +256,21 @@ class DmsfController < ApplicationController
|
|||||||
{:controller => "dmsf", :action => "show", :id => @project, :folder_id => @folder.folder}
|
{:controller => "dmsf", :action => "show", :id => @project, :folder_id => @folder.folder}
|
||||||
end
|
end
|
||||||
|
|
||||||
def assign
|
# def assign
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
def assignment
|
# def assignment
|
||||||
revision = DmsfFileRevision.find_by_id params[:dmsf_file_revision_id]
|
# revision = DmsfFileRevision.find_by_id params[:dmsf_file_revision_id]
|
||||||
if revision
|
# if revision
|
||||||
revision.set_workflow(params[:dmsf_workflow_id], params[:action])
|
# revision.set_workflow(params[:dmsf_workflow_id], params[:action])
|
||||||
revision.assign_workflow(params[:dmsf_workflow_id])
|
# revision.assign_workflow(params[:dmsf_workflow_id])
|
||||||
if request.post? && revision.save
|
# if request.post? && revision.save
|
||||||
flash[:notice] = l(:notice_successful_create)
|
# flash[:notice] = l(:notice_successful_create)
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
redirect_to params[:current] ? params[:current] :
|
# redirect_to params[:current] ? params[:current] :
|
||||||
{:controller => "dmsf", :action => "show", :id => @project, :folder_id => @folder.folder}
|
# {:controller => "dmsf", :action => "show", :id => @project, :folder_id => @folder.folder}
|
||||||
end
|
# end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
|||||||
@ -97,7 +97,7 @@ class DmsfFilesController < ApplicationController
|
|||||||
@revision.disk_filename = @revision.new_storage_filename
|
@revision.disk_filename = @revision.new_storage_filename
|
||||||
@revision.mime_type = Redmine::MimeType.of(file_upload.original_filename)
|
@revision.mime_type = Redmine::MimeType.of(file_upload.original_filename)
|
||||||
end
|
end
|
||||||
@revision.set_workflow(params[:dmsf_workflow_id], params[:commit])
|
#@revision.set_workflow(params[:dmsf_workflow_id], params[:commit])
|
||||||
|
|
||||||
@file.name = @revision.name
|
@file.name = @revision.name
|
||||||
@file.folder = @revision.folder
|
@file.folder = @revision.folder
|
||||||
|
|||||||
@ -122,7 +122,7 @@ class DmsfUploadController < ApplicationController
|
|||||||
new_revision.description = commited_file["description"]
|
new_revision.description = commited_file["description"]
|
||||||
new_revision.comment = commited_file["comment"]
|
new_revision.comment = commited_file["comment"]
|
||||||
new_revision.increase_version(commited_file["version"].to_i, true)
|
new_revision.increase_version(commited_file["version"].to_i, true)
|
||||||
new_revision.set_workflow(commited_file[:dmsf_workflow_id], nil)
|
#new_revision.set_workflow(commited_file[:dmsf_workflow_id], nil)
|
||||||
new_revision.mime_type = Redmine::MimeType.of(new_revision.name)
|
new_revision.mime_type = Redmine::MimeType.of(new_revision.name)
|
||||||
new_revision.size = File.size(commited_disk_filepath)
|
new_revision.size = File.size(commited_disk_filepath)
|
||||||
|
|
||||||
|
|||||||
@ -22,12 +22,13 @@ class DmsfWorkflowsController < ApplicationController
|
|||||||
|
|
||||||
before_filter :find_workflow, :except => [:create, :new, :index, :assign, :assignment]
|
before_filter :find_workflow, :except => [:create, :new, :index, :assign, :assignment]
|
||||||
before_filter :find_project, :except => [:start]
|
before_filter :find_project, :except => [:start]
|
||||||
before_filter :authorize_global
|
before_filter :authorize_global
|
||||||
|
before_filter :authorize_custom
|
||||||
|
|
||||||
def index
|
def index
|
||||||
if @project
|
if @project
|
||||||
@workflow_pages, @workflows = paginate DmsfWorkflow.where(:project_id => @project.id), :per_page => 25
|
@workflow_pages, @workflows = paginate DmsfWorkflow.where(:project_id => @project.id), :per_page => 25
|
||||||
else
|
else
|
||||||
@workflow_pages, @workflows = paginate DmsfWorkflow.where(:project_id => nil), :per_page => 25
|
@workflow_pages, @workflows = paginate DmsfWorkflow.where(:project_id => nil), :per_page => 25
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -130,7 +131,7 @@ class DmsfWorkflowsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def add_step
|
def add_step
|
||||||
if request.post?
|
if request.post?
|
||||||
users = User.find_all_by_id(params[:user_ids])
|
users = User.find_all_by_id(params[:user_ids])
|
||||||
if params[:step] == '0'
|
if params[:step] == '0'
|
||||||
if @workflow.steps.count > 0
|
if @workflow.steps.count > 0
|
||||||
@ -142,14 +143,13 @@ class DmsfWorkflowsController < ApplicationController
|
|||||||
step = params[:step].to_i
|
step = params[:step].to_i
|
||||||
end
|
end
|
||||||
operator = (params[:commit] == l(:dmsf_and)) ? DmsfWorkflowStep::OPERATOR_AND : DmsfWorkflowStep::OPERATOR_OR
|
operator = (params[:commit] == l(:dmsf_and)) ? DmsfWorkflowStep::OPERATOR_AND : DmsfWorkflowStep::OPERATOR_OR
|
||||||
users.each do |user|
|
users.each do |user|
|
||||||
@workflow.dmsf_workflow_steps << DmsfWorkflowStep.new(
|
@workflow.dmsf_workflow_steps << DmsfWorkflowStep.new(
|
||||||
:dmsf_workflow_id => @workflow.id,
|
:dmsf_workflow_id => @workflow.id,
|
||||||
:step => step,
|
:step => step,
|
||||||
:user_id => user.id,
|
:user_id => user.id,
|
||||||
:operator => operator)
|
:operator => operator)
|
||||||
end
|
end
|
||||||
@workflow.save
|
|
||||||
end
|
end
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html
|
format.html
|
||||||
@ -157,17 +157,19 @@ class DmsfWorkflowsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def remove_step
|
def remove_step
|
||||||
if request.delete?
|
if request.delete?
|
||||||
DmsfWorkflowStep.where(:dmsf_workflow_id => @workflow.id, :step => params[:step]).each do |ws|
|
DmsfWorkflowStep.where(:dmsf_workflow_id => @workflow.id, :step => params[:step]).each do |ws|
|
||||||
@workflow.dmsf_workflow_steps.delete(ws)
|
@workflow.dmsf_workflow_steps.delete(ws)
|
||||||
end
|
end
|
||||||
@workflow.dmsf_workflow_steps.each do |ws|
|
@workflow.dmsf_workflow_steps.each do |ws|
|
||||||
n = ws.step.to_i
|
n = ws.step.to_i
|
||||||
if n > params[:step].to_i
|
if n > params[:step].to_i
|
||||||
ws.step = n - 1
|
ws.step = n - 1
|
||||||
ws.save
|
unless ws.save
|
||||||
|
flash[:error] = l(:notice_cannot_renumber_steps)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html
|
format.html
|
||||||
@ -176,7 +178,9 @@ class DmsfWorkflowsController < ApplicationController
|
|||||||
|
|
||||||
def reorder_steps
|
def reorder_steps
|
||||||
if request.put?
|
if request.put?
|
||||||
@workflow.reorder_steps params[:step].to_i, params[:workflow_step][:move_to]
|
unless @workflow.reorder_steps(params[:step].to_i, params[:workflow_step][:move_to])
|
||||||
|
flash[:error] = l(:notice_cannot_renumber_steps)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html
|
format.html
|
||||||
@ -187,8 +191,12 @@ class DmsfWorkflowsController < ApplicationController
|
|||||||
revision = DmsfFileRevision.find_by_id(params[:dmsf_file_revision_id])
|
revision = DmsfFileRevision.find_by_id(params[:dmsf_file_revision_id])
|
||||||
if revision
|
if revision
|
||||||
revision.set_workflow(@workflow.id, params[:action])
|
revision.set_workflow(@workflow.id, params[:action])
|
||||||
if request.post? && revision.save
|
if request.post?
|
||||||
flash[:notice] = l(:notice_successful_update)
|
if revision.save
|
||||||
|
flash[:notice] = l(:notice_successful_update)
|
||||||
|
else
|
||||||
|
flash[:error] = l(:notice_cannot_start_workflow)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
redirect_to :back
|
redirect_to :back
|
||||||
@ -205,12 +213,16 @@ class DmsfWorkflowsController < ApplicationController
|
|||||||
@project = @workflow.project
|
@project = @workflow.project
|
||||||
elsif params[:project_id].present?
|
elsif params[:project_id].present?
|
||||||
@project = Project.find_by_id params[:project_id]
|
@project = Project.find_by_id params[:project_id]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def workflows_layout
|
def workflows_layout
|
||||||
find_workflow
|
find_workflow
|
||||||
find_project
|
find_project
|
||||||
@project ? 'base' : 'admin'
|
@project ? 'base' : 'admin'
|
||||||
|
end
|
||||||
|
|
||||||
|
def authorize_custom
|
||||||
|
require_admin unless @project
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -19,7 +19,7 @@
|
|||||||
module DmsfWorkflowsHelper
|
module DmsfWorkflowsHelper
|
||||||
|
|
||||||
def render_principals_for_new_dmsf_workflow_users(workflow, dmsf_workflow_step_assignment_id, dmsf_file_revision_id)
|
def render_principals_for_new_dmsf_workflow_users(workflow, dmsf_workflow_step_assignment_id, dmsf_file_revision_id)
|
||||||
scope = workflow.delegates(params[:q], dmsf_workflow_step_assignment_id, dmsf_file_revision_id, nil)
|
scope = workflow.delegates(params[:q], dmsf_workflow_step_assignment_id, dmsf_file_revision_id)
|
||||||
principal_count = scope.count
|
principal_count = scope.count
|
||||||
principal_pages = Redmine::Pagination::Paginator.new principal_count, 10, params['page']
|
principal_pages = Redmine::Pagination::Paginator.new principal_count, 10, params['page']
|
||||||
principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all
|
principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all
|
||||||
|
|||||||
@ -156,12 +156,11 @@ class DmsfFileRevision < ActiveRecord::Base
|
|||||||
return new_revision
|
return new_revision
|
||||||
end
|
end
|
||||||
|
|
||||||
def workflow_str(name)
|
def workflow_str(name)
|
||||||
|
str = ''
|
||||||
if name && dmsf_workflow_id
|
if name && dmsf_workflow_id
|
||||||
wf = DmsfWorkflow.find_by_id(dmsf_workflow_id)
|
wf = DmsfWorkflow.find_by_id(dmsf_workflow_id)
|
||||||
str = "#{wf.name} - " if wf
|
str = "#{wf.name} - " if wf
|
||||||
else
|
|
||||||
str = ''
|
|
||||||
end
|
end
|
||||||
case workflow
|
case workflow
|
||||||
when DmsfWorkflow::STATE_WAITING_FOR_APPROVAL
|
when DmsfWorkflow::STATE_WAITING_FOR_APPROVAL
|
||||||
@ -177,28 +176,22 @@ class DmsfFileRevision < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_workflow(dmsf_workflow_id, commit)
|
def set_workflow(dmsf_workflow_id, commit)
|
||||||
if User.current.allowed_to?(:file_approval, self.file.project)
|
self.dmsf_workflow_id = dmsf_workflow_id
|
||||||
unless dmsf_workflow_id.blank?
|
if commit == 'start'
|
||||||
self.dmsf_workflow_id = dmsf_workflow_id
|
self.workflow = DmsfWorkflow::STATE_WAITING_FOR_APPROVAL
|
||||||
if commit == 'start'
|
self.dmsf_workflow_started_by = User.current.id if User.current
|
||||||
self.workflow = DmsfWorkflow::STATE_WAITING_FOR_APPROVAL
|
self.dmsf_workflow_started_at = DateTime.now
|
||||||
self.dmsf_workflow_started_by = User.current.id if User.current
|
else
|
||||||
self.dmsf_workflow_started_at = DateTime.now
|
self.workflow = DmsfWorkflow::STATE_DRAFT
|
||||||
else
|
self.dmsf_workflow_assigned_by = User.current.id if User.current
|
||||||
self.workflow = DmsfWorkflow::STATE_DRAFT
|
self.dmsf_workflow_assigned_at = DateTime.now
|
||||||
self.dmsf_workflow_assigned_by = User.current.id if User.current
|
end
|
||||||
self.dmsf_workflow_assigned_at = DateTime.now
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def assign_workflow(dmsf_workflow_id)
|
def assign_workflow(dmsf_workflow_id)
|
||||||
if User.current.allowed_to?(:file_approval, self.file.project)
|
wf = DmsfWorkflow.find_by_id(dmsf_workflow_id)
|
||||||
wf = DmsfWorkflow.find_by_id(dmsf_workflow_id)
|
wf.assign(self.id) if wf && self.id
|
||||||
wf.assign(self.id) if wf && self.id
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def increase_version(version_to_increase, new_content)
|
def increase_version(version_to_increase, new_content)
|
||||||
@ -248,7 +241,7 @@ class DmsfFileRevision < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Overrides Redmine::Acts::Customizable::InstanceMethods#available_custom_fields
|
# Overrides Redmine::Acts::Customizable::InstanceMethods#available_custom_fields
|
||||||
def available_custom_fields
|
def available_custom_fields
|
||||||
search_project = nil
|
search_project = nil
|
||||||
if self.project.present?
|
if self.project.present?
|
||||||
search_project = self.project
|
search_project = self.project
|
||||||
|
|||||||
@ -39,37 +39,17 @@ class DmsfWorkflow < ActiveRecord::Base
|
|||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
name
|
name
|
||||||
end
|
end
|
||||||
|
|
||||||
def approvals(step)
|
|
||||||
wa = Array.new
|
|
||||||
dmsf_workflow_steps.each do |s|
|
|
||||||
if s.step == step
|
|
||||||
wa << s
|
|
||||||
end
|
|
||||||
end
|
|
||||||
wa
|
|
||||||
end
|
|
||||||
|
|
||||||
def steps
|
|
||||||
ws = Array.new
|
|
||||||
dmsf_workflow_steps.each do |s|
|
|
||||||
unless ws.include? s.step
|
|
||||||
ws << s.step
|
|
||||||
end
|
|
||||||
end
|
|
||||||
ws
|
|
||||||
end
|
|
||||||
|
|
||||||
def reorder_steps(step, move_to)
|
def reorder_steps(step, move_to)
|
||||||
case move_to
|
case move_to
|
||||||
when 'highest'
|
when 'highest'
|
||||||
unless step == 1
|
unless step == 1
|
||||||
dmsf_workflow_steps.each do |ws|
|
dmsf_workflow_steps.each do |ws|
|
||||||
if ws.step < step
|
if ws.step < step
|
||||||
ws.update_attribute('step', ws.step + 1)
|
return false unless ws.update_attribute('step', ws.step + 1)
|
||||||
elsif ws.step == step
|
elsif ws.step == step
|
||||||
ws.update_attribute('step', 1)
|
return false unless ws.update_attribute('step', 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -77,42 +57,41 @@ class DmsfWorkflow < ActiveRecord::Base
|
|||||||
unless step == 1
|
unless step == 1
|
||||||
dmsf_workflow_steps.each do |ws|
|
dmsf_workflow_steps.each do |ws|
|
||||||
if ws.step == step - 1
|
if ws.step == step - 1
|
||||||
ws.update_attribute('step', step)
|
return false unless ws.update_attribute('step', step)
|
||||||
elsif ws.step == step
|
elsif ws.step == step
|
||||||
ws.update_attribute('step', step - 1)
|
return false unless ws.update_attribute('step', step - 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
when 'lower'
|
when 'lower'
|
||||||
unless step == steps.count
|
unless step == dmsf_workflow_steps.collect{|s| s.step}.uniq.count
|
||||||
dmsf_workflow_steps.each do |ws|
|
dmsf_workflow_steps.each do |ws|
|
||||||
if ws.step == step + 1
|
if ws.step == step + 1
|
||||||
ws.update_attribute('step', step)
|
return false unless ws.update_attribute('step', step)
|
||||||
elsif ws.step == step
|
elsif ws.step == step
|
||||||
ws.update_attribute('step', step + 1)
|
return false unless ws.update_attribute('step', step + 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
when 'lowest'
|
when 'lowest'
|
||||||
size = steps.count
|
size = dmsf_workflow_steps.collect{|s| s.step}.uniq.count
|
||||||
unless step == size
|
unless step == size
|
||||||
dmsf_workflow_steps.each do |ws|
|
dmsf_workflow_steps.each do |ws|
|
||||||
if ws.step > step
|
if ws.step > step
|
||||||
ws.update_attribute('step', ws.step - 1)
|
return false unless ws.update_attribute('step', ws.step - 1)
|
||||||
elsif ws.step == step
|
elsif ws.step == step
|
||||||
ws.update_attribute('step', size)
|
return false unless ws.update_attribute('step', size)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return reload
|
||||||
end
|
end
|
||||||
|
|
||||||
def delegates(q, dmsf_workflow_step_assignment_id, dmsf_file_revision_id, project_id)
|
def delegates(q, dmsf_workflow_step_assignment_id, dmsf_file_revision_id)
|
||||||
if project_id
|
if dmsf_workflow_step_assignment_id && dmsf_file_revision_id
|
||||||
sql = ['id IN (SELECT user_id FROM members WHERE project_id = ?', project_id]
|
|
||||||
elsif dmsf_workflow_step_assignment_id && dmsf_file_revision_id
|
|
||||||
sql = [
|
sql = [
|
||||||
'id NOT IN (SELECT a.user_id FROM dmsf_workflow_step_assignments a WHERE id = ?) AND id IN (SELECT m.user_id FROM members m JOIN dmsf_file_revisions r ON m.project_id = r.project_id WHERE r.id = ?)',
|
'id NOT IN (SELECT a.user_id FROM dmsf_workflow_step_assignments a WHERE id = ?) AND id IN (SELECT m.user_id FROM members m JOIN dmsf_files f ON f.project_id = m.project_id JOIN dmsf_file_revisions r ON r.dmsf_file_id = f.id WHERE r.id = ?)',
|
||||||
dmsf_workflow_step_assignment_id,
|
dmsf_workflow_step_assignment_id,
|
||||||
dmsf_file_revision_id]
|
dmsf_file_revision_id]
|
||||||
else
|
else
|
||||||
@ -127,12 +106,27 @@ class DmsfWorkflow < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def next_assignments(dmsf_file_revision_id)
|
def next_assignments(dmsf_file_revision_id)
|
||||||
self.dmsf_workflow_steps.each do |step|
|
results = Array.new
|
||||||
unless step.finished?(dmsf_file_revision_id)
|
self.dmsf_workflow_steps.each do |step|
|
||||||
return step.next_assignments(dmsf_file_revision_id)
|
break unless results.empty? || results[0].step.step == step.step
|
||||||
|
step.dmsf_workflow_step_assignments.each do |assignment|
|
||||||
|
if assignment.dmsf_file_revision_id == dmsf_file_revision_id
|
||||||
|
if assignment.dmsf_workflow_step_actions.empty?
|
||||||
|
results << assignment
|
||||||
|
next
|
||||||
|
end
|
||||||
|
add = true
|
||||||
|
assignment.dmsf_workflow_step_actions.each do |action|
|
||||||
|
if action.is_finished?
|
||||||
|
add = false
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
results << assignment if add
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return nil
|
results
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.assignments_to_users_str(assignments)
|
def self.assignments_to_users_str(assignments)
|
||||||
@ -157,27 +151,29 @@ class DmsfWorkflow < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def try_finish(dmsf_file_revision_id, action, user_id)
|
def try_finish(dmsf_file_revision_id, action, user_id)
|
||||||
res = nil
|
revision = DmsfFileRevision.find_by_id dmsf_file_revision_id
|
||||||
case action.action
|
case action.action
|
||||||
when DmsfWorkflowStepAction::ACTION_APPROVE
|
when DmsfWorkflowStepAction::ACTION_APPROVE
|
||||||
self.dmsf_workflow_steps.each do |step|
|
self.dmsf_workflow_steps.each do |step|
|
||||||
res = step.result dmsf_file_revision_id
|
step.dmsf_workflow_step_assignments.each do |assignment|
|
||||||
unless step.finished? dmsf_file_revision_id
|
if assignment.dmsf_file_revision_id == dmsf_file_revision_id.to_i
|
||||||
return
|
if assignment.dmsf_workflow_step_actions.empty?
|
||||||
end
|
return
|
||||||
end
|
end
|
||||||
|
assignment.dmsf_workflow_step_actions.each do |act|
|
||||||
|
return unless act.is_finished?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
# TODO: update_attribute doesn't wotk in unit tests because of "Couldn't find Project with id=0" error
|
||||||
|
revision.update_attribute(:workflow, DmsfWorkflow::STATE_APPROVED) if revision
|
||||||
when DmsfWorkflowStepAction::ACTION_REJECT
|
when DmsfWorkflowStepAction::ACTION_REJECT
|
||||||
res = DmsfWorkflow::STATE_REJECTED
|
revision.update_attribute(:workflow, DmsfWorkflow::STATE_REJECTED) if revision
|
||||||
when DmsfWorkflowStepAction::ACTION_DELEGATE
|
when DmsfWorkflowStepAction::ACTION_DELEGATE
|
||||||
assignment = DmsfWorkflowStepAssignment.find_by_id(action.dmsf_workflow_step_assignment_id)
|
assignment = DmsfWorkflowStepAssignment.find_by_id(action.dmsf_workflow_step_assignment_id)
|
||||||
assignment.update_attribute(:user_id, user_id) if assignment
|
assignment.update_attribute(:user_id, user_id) if assignment
|
||||||
end
|
end
|
||||||
|
|
||||||
if res
|
|
||||||
revision = DmsfFileRevision.find_by_id dmsf_file_revision_id
|
|
||||||
revision.update_attribute(:workflow, res) if revision
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -44,53 +44,5 @@ class DmsfWorkflowStep < ActiveRecord::Base
|
|||||||
:user_id => user_id,
|
:user_id => user_id,
|
||||||
:dmsf_file_revision_id => dmsf_file_revision_id)
|
:dmsf_file_revision_id => dmsf_file_revision_id)
|
||||||
step_assignment.save
|
step_assignment.save
|
||||||
end
|
end
|
||||||
|
|
||||||
def finished?(dmsf_file_revision_id)
|
|
||||||
res = self.result(dmsf_file_revision_id)
|
|
||||||
res == DmsfWorkflow::STATE_APPROVED || res == DmsfWorkflow::STATE_REJECTED
|
|
||||||
end
|
|
||||||
|
|
||||||
def result(dmsf_file_revision_id)
|
|
||||||
assignments = DmsfWorkflowStepAssignment.where(
|
|
||||||
:dmsf_workflow_step_id => self.id, :dmsf_file_revision_id => dmsf_file_revision_id).all
|
|
||||||
assignments.each do |assignment|
|
|
||||||
actions = DmsfWorkflowStepAction.where(
|
|
||||||
:dmsf_workflow_step_assignment_id => assignment.id).all
|
|
||||||
if actions.empty?
|
|
||||||
return
|
|
||||||
end
|
|
||||||
actions.each do |action|
|
|
||||||
if DmsfWorkflowStepAction.is_finished?(action.action)
|
|
||||||
case action.action
|
|
||||||
when DmsfWorkflowStepAction::ACTION_APPROVE
|
|
||||||
return DmsfWorkflow::STATE_APPROVED
|
|
||||||
when DmsfWorkflowStepAction::ACTION_REJECT
|
|
||||||
return DmsfWorkflow::STATE_REJECTED
|
|
||||||
else
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def next_assignments(dmsf_file_revision_id)
|
|
||||||
results = Array.new
|
|
||||||
assignments = DmsfWorkflowStepAssignment.where(
|
|
||||||
:dmsf_workflow_step_id => self.id,
|
|
||||||
:dmsf_file_revision_id => dmsf_file_revision_id)
|
|
||||||
assignments.each do |assignment|
|
|
||||||
add = true
|
|
||||||
assignment.dmsf_workflow_step_actions.each do |action|
|
|
||||||
if action.is_finished?
|
|
||||||
add = false
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
results << assignment if add
|
|
||||||
end
|
|
||||||
return results
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -19,9 +19,12 @@
|
|||||||
class DmsfWorkflowStepAssignment < ActiveRecord::Base
|
class DmsfWorkflowStepAssignment < ActiveRecord::Base
|
||||||
belongs_to :dmsf_workflow_step
|
belongs_to :dmsf_workflow_step
|
||||||
|
|
||||||
has_many :dmsf_workflow_step_actions, :dependent => :destroy
|
has_many :dmsf_workflow_step_actions, :dependent => :destroy
|
||||||
has_one :dmsf_workflow_step_assignment
|
|
||||||
|
|
||||||
validates :dmsf_workflow_step_id, :presence => true
|
validates :dmsf_workflow_step_id, :presence => true
|
||||||
validates :dmsf_file_revision_id, :presence => true
|
validates :dmsf_file_revision_id, :presence => true
|
||||||
|
|
||||||
|
def step
|
||||||
|
DmsfWorkflowStep.find_by_id self.dmsf_workflow_step_id
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@ -17,7 +17,7 @@
|
|||||||
<%= label_tag 'delegate', l(:label_dmsf_wokflow_action_delegate) %><br/>
|
<%= label_tag 'delegate', l(:label_dmsf_wokflow_action_delegate) %><br/>
|
||||||
<%= text_field_tag 'user_search', nil %>
|
<%= text_field_tag 'user_search', nil %>
|
||||||
<%= javascript_tag "observeSearchfield('user_search', 'users_for_delegate', '#{ escape_javascript autocomplete_for_user_dmsf_workflow_path(@workflow, :dmsf_workflow_step_assignment_id => params[:dmsf_workflow_step_assignment_id], :dmsf_file_revision_id => params[:dmsf_file_revision_id]) }')" %>
|
<%= javascript_tag "observeSearchfield('user_search', 'users_for_delegate', '#{ escape_javascript autocomplete_for_user_dmsf_workflow_path(@workflow, :dmsf_workflow_step_assignment_id => params[:dmsf_workflow_step_assignment_id], :dmsf_file_revision_id => params[:dmsf_file_revision_id]) }')" %>
|
||||||
<%= content_tag('div', principals_radio_button_tags('step_action', @workflow.delegates(nil, params[:dmsf_workflow_step_assignment_id], params[:dmsf_file_revision_id], nil)), :id => 'users_for_delegate') %>
|
<%= content_tag('div', principals_radio_button_tags('step_action', @workflow.delegates(nil, params[:dmsf_workflow_step_assignment_id], params[:dmsf_file_revision_id])), :id => 'users_for_delegate') %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p class="buttons">
|
<p class="buttons">
|
||||||
|
|||||||
@ -20,31 +20,32 @@
|
|||||||
<div class="tab-content" id="tab-content-members">
|
<div class="tab-content" id="tab-content-members">
|
||||||
|
|
||||||
<div class="splitcontentleft">
|
<div class="splitcontentleft">
|
||||||
<% if @workflow.steps.any? %>
|
<% steps = @workflow.dmsf_workflow_steps.collect{|s| s.step}.uniq %>
|
||||||
<table class="list steps">
|
<% if steps.any? %>
|
||||||
|
<table class="list">
|
||||||
<thead><tr>
|
<thead><tr>
|
||||||
<th><%= l(:label_dmsf_workflow_step) %></th>
|
<th><%= l(:label_dmsf_workflow_step) %></th>
|
||||||
<th><%= l(:label_dmsf_workflow_approval_plural) %></th>
|
<th><%= l(:label_dmsf_workflow_approval_plural) %></th>
|
||||||
<th><%=l(:button_sort)%></th>
|
<th><%=l(:button_sort)%></th>
|
||||||
<th style="width:15%"></th>
|
<th/>
|
||||||
</tr></thead>
|
</tr></thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @workflow.steps.each do |step| %>
|
<% steps.each do |i|%>
|
||||||
<tr id="step-<%= step %>" class="<%= cycle 'odd', 'even' %> step">
|
<tr id="step-<%= i %>" class="<%= cycle 'odd', 'even' %> step">
|
||||||
<td class="step"><%= step %></td>
|
<td class="step"><%= i %></td>
|
||||||
<td class="approval">
|
<td class="approval">
|
||||||
<% @workflow.approvals(step).each_with_index do |approval, i| %>
|
<% @workflow.dmsf_workflow_steps.collect{|s| (s.step == i) ? s : nil}.compact.each_with_index do |step, j| %>
|
||||||
<% if i != 0 %>
|
<% if j != 0 %>
|
||||||
<b><%= approval.soperator %></b> 
|
<b><%= step.soperator %></b> 
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= link_to_user approval.user %>
|
<%= link_to_user step.user %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
<td align="center" style="width:15%;">
|
<td class="reorder">
|
||||||
<%= reorder_links('workflow_step', {:action => 'edit', :id => @workflow, :step => step}, :put) %>
|
<%= reorder_links('workflow_step', {:action => 'edit', :id => @workflow, :step => i}, :put) %>
|
||||||
</td>
|
</td>
|
||||||
<td class="buttons">
|
<td class="buttons">
|
||||||
<%= delete_link edit_dmsf_workflow_path(@workflow, :step => step) %>
|
<%= delete_link edit_dmsf_workflow_path(@workflow, :step => i) %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end; reset_cycle %>
|
<% end; reset_cycle %>
|
||||||
@ -70,7 +71,7 @@
|
|||||||
<p>
|
<p>
|
||||||
<%= l(:label_dmsf_workflow_step) %>
|
<%= l(:label_dmsf_workflow_step) %>
|
||||||
<%= select_tag 'step',
|
<%= select_tag 'step',
|
||||||
dmsf_workflow_steps_options_for_select(@workflow.steps),
|
dmsf_workflow_steps_options_for_select(steps),
|
||||||
:id => 'selected_step', :style => "width:100px" %>
|
:id => 'selected_step', :style => "width:100px" %>
|
||||||
</p>
|
</p>
|
||||||
<p><%= submit_tag l(:dmsf_and) %> <%= submit_tag l(:dmsf_or) %></p>
|
<p><%= submit_tag l(:dmsf_and) %> <%= submit_tag l(:dmsf_or) %></p>
|
||||||
|
|||||||
@ -260,10 +260,19 @@ table.list td.note {
|
|||||||
width: 30%;
|
width: 30%;
|
||||||
}
|
}
|
||||||
|
|
||||||
table.list td.step, td.date {
|
table.list td.date {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table.list td.reorder {
|
||||||
|
width: 15%;
|
||||||
|
}
|
||||||
|
|
||||||
|
table.list td.step {
|
||||||
|
text-align: center;
|
||||||
|
width: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
.log_header_box{
|
.log_header_box{
|
||||||
padding:6px;
|
padding:6px;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
|
|||||||
@ -210,6 +210,8 @@ en:
|
|||||||
error_unable_delete_dmsf_workflow: 'Unable to delete the workflow'
|
error_unable_delete_dmsf_workflow: 'Unable to delete the workflow'
|
||||||
error_empty_note: "The note can't be empty"
|
error_empty_note: "The note can't be empty"
|
||||||
error_workflow_assign: 'An error occured while assigning'
|
error_workflow_assign: 'An error occured while assigning'
|
||||||
|
error_cannot_start_workflow: "Workflow can't be started"
|
||||||
|
error_cannot_renumber_steps: "Steps can't be renumbered"
|
||||||
label_dmsf_workflow_new: 'New approval workflow'
|
label_dmsf_workflow_new: 'New approval workflow'
|
||||||
label_dmsf_workflow: 'Approval workflow'
|
label_dmsf_workflow: 'Approval workflow'
|
||||||
label_dmsf_workflow_plural: 'Approval workflows'
|
label_dmsf_workflow_plural: 'Approval workflows'
|
||||||
@ -236,6 +238,4 @@ en:
|
|||||||
dmsf_new_step: New step
|
dmsf_new_step: New step
|
||||||
message_dmsf_wokflow_note: Your note...
|
message_dmsf_wokflow_note: Your note...
|
||||||
info_revision: "r%{rev}"
|
info_revision: "r%{rev}"
|
||||||
link_workflow: Workflow
|
link_workflow: Workflow
|
||||||
|
|
||||||
|
|
||||||
2
init.rb
2
init.rb
@ -57,7 +57,7 @@ Redmine::Plugin.register :redmine_dmsf do
|
|||||||
:dmsf_upload => [:upload_files, :upload_file, :commit_files]}
|
:dmsf_upload => [:upload_files, :upload_file, :commit_files]}
|
||||||
permission :file_approval, {:dmsf_files => [:delete_revision, :notify_activate, :notify_deactivate],
|
permission :file_approval, {:dmsf_files => [:delete_revision, :notify_activate, :notify_deactivate],
|
||||||
:dmsf => [:notify_activate, :notify_deactivate],
|
:dmsf => [:notify_activate, :notify_deactivate],
|
||||||
:dmsf_workflows => [:new, :create, :destroy, :edit, :add_step, :remove_step, :reorder_steps, :update, :start, :assign, :assignment, :action, :new_action, :log]}
|
:dmsf_workflows => [:index, :new, :create, :destroy, :edit, :add_step, :remove_step, :reorder_steps, :update, :start, :assign, :assignment, :action, :new_action, :log]}
|
||||||
permission :force_file_unlock, {}
|
permission :force_file_unlock, {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
4
test/fixtures/dmsf_file_revisions.yml
vendored
4
test/fixtures/dmsf_file_revisions.yml
vendored
@ -1,5 +1,6 @@
|
|||||||
---
|
---
|
||||||
dmsf_file_revisions_001:
|
dmsf_file_revisions_001:
|
||||||
|
id: 1
|
||||||
dmsf_file_id: 1
|
dmsf_file_id: 1
|
||||||
source_dmsf_file_revision_id: NULL
|
source_dmsf_file_revision_id: NULL
|
||||||
name: "test.txt"
|
name: "test.txt"
|
||||||
@ -19,6 +20,7 @@ dmsf_file_revisions_001:
|
|||||||
|
|
||||||
#revision for file on non-enabled project
|
#revision for file on non-enabled project
|
||||||
dmsf_file_revisions_002:
|
dmsf_file_revisions_002:
|
||||||
|
id: 2
|
||||||
dmsf_file_id: 2
|
dmsf_file_id: 2
|
||||||
source_dmsf_file_revision_id: NULL
|
source_dmsf_file_revision_id: NULL
|
||||||
name: "test.txt"
|
name: "test.txt"
|
||||||
@ -38,6 +40,7 @@ dmsf_file_revisions_002:
|
|||||||
|
|
||||||
#revision for deleted file on dmsf-enabled project
|
#revision for deleted file on dmsf-enabled project
|
||||||
dmsf_file_revisions_003:
|
dmsf_file_revisions_003:
|
||||||
|
id: 3
|
||||||
dmsf_file_id: 3
|
dmsf_file_id: 3
|
||||||
source_dmsf_file_revision_id: NULL
|
source_dmsf_file_revision_id: NULL
|
||||||
name: "deleted.txt"
|
name: "deleted.txt"
|
||||||
@ -54,4 +57,3 @@ dmsf_file_revisions_003:
|
|||||||
deleted: 1
|
deleted: 1
|
||||||
deleted_by_user_id: 1
|
deleted_by_user_id: 1
|
||||||
user_id: 1
|
user_id: 1
|
||||||
|
|
||||||
|
|||||||
30
test/fixtures/dmsf_workflow_step_actions.yml
vendored
30
test/fixtures/dmsf_workflow_step_actions.yml
vendored
@ -9,14 +9,28 @@ wfsac1:
|
|||||||
|
|
||||||
wfsac2:
|
wfsac2:
|
||||||
id: 2
|
id: 2
|
||||||
dmsf_workflow_step_assignment_id: 1
|
dmsf_workflow_step_assignment_id: 5
|
||||||
action: 2
|
action: 1
|
||||||
note: 'Rejection'
|
note: 'Approval'
|
||||||
created_at: '2013-05-03 10:45:36'
|
created_at: '2013-05-03 10:45:35'
|
||||||
|
|
||||||
wfsac3:
|
wfsac3:
|
||||||
id: 3
|
id: 3
|
||||||
dmsf_workflow_step_assignment_id: 1
|
dmsf_workflow_step_assignment_id: 6
|
||||||
action: 3
|
action: 1
|
||||||
note: 'Delegation'
|
note: 'Approval'
|
||||||
created_at: '2013-05-03 10:45:37'
|
created_at: '2013-05-03 10:45:35'
|
||||||
|
|
||||||
|
wfsac4:
|
||||||
|
id: 4
|
||||||
|
dmsf_workflow_step_assignment_id: 7
|
||||||
|
action: 1
|
||||||
|
note: 'Approval'
|
||||||
|
created_at: '2013-05-03 10:45:35'
|
||||||
|
|
||||||
|
wfsac5:
|
||||||
|
id: 5
|
||||||
|
dmsf_workflow_step_assignment_id: 8
|
||||||
|
action: 1
|
||||||
|
note: 'Approval'
|
||||||
|
created_at: '2013-05-03 10:45:35'
|
||||||
44
test/fixtures/dmsf_workflow_step_assignments.yml
vendored
44
test/fixtures/dmsf_workflow_step_assignments.yml
vendored
@ -3,4 +3,46 @@ wfsa1:
|
|||||||
id: 1
|
id: 1
|
||||||
dmsf_workflow_step_id: 1
|
dmsf_workflow_step_id: 1
|
||||||
user_id: 1
|
user_id: 1
|
||||||
dmsf_file_revision_id: 2
|
dmsf_file_revision_id: 2
|
||||||
|
|
||||||
|
wfsa2:
|
||||||
|
id: 2
|
||||||
|
dmsf_workflow_step_id: 1
|
||||||
|
user_id: 2
|
||||||
|
dmsf_file_revision_id: 2
|
||||||
|
|
||||||
|
wfsa3:
|
||||||
|
id: 3
|
||||||
|
dmsf_workflow_step_id: 2
|
||||||
|
user_id: 1
|
||||||
|
dmsf_file_revision_id: 2
|
||||||
|
|
||||||
|
wfsa4:
|
||||||
|
id: 4
|
||||||
|
dmsf_workflow_step_id: 2
|
||||||
|
user_id: 2
|
||||||
|
dmsf_file_revision_id: 2
|
||||||
|
|
||||||
|
wfsa5:
|
||||||
|
id: 5
|
||||||
|
dmsf_workflow_step_id: 1
|
||||||
|
user_id: 1
|
||||||
|
dmsf_file_revision_id: 1
|
||||||
|
|
||||||
|
wfsa6:
|
||||||
|
id: 6
|
||||||
|
dmsf_workflow_step_id: 1
|
||||||
|
user_id: 2
|
||||||
|
dmsf_file_revision_id: 1
|
||||||
|
|
||||||
|
wfsa7:
|
||||||
|
id: 7
|
||||||
|
dmsf_workflow_step_id: 2
|
||||||
|
user_id: 1
|
||||||
|
dmsf_file_revision_id: 1
|
||||||
|
|
||||||
|
wfsa8:
|
||||||
|
id: 8
|
||||||
|
dmsf_workflow_step_id: 2
|
||||||
|
user_id: 2
|
||||||
|
dmsf_file_revision_id: 1
|
||||||
30
test/fixtures/dmsf_workflow_steps.yml
vendored
30
test/fixtures/dmsf_workflow_steps.yml
vendored
@ -1,11 +1,4 @@
|
|||||||
---
|
---
|
||||||
wfs1:
|
|
||||||
id: 1
|
|
||||||
dmsf_workflow_id: 1
|
|
||||||
step: 1
|
|
||||||
user_id: 1
|
|
||||||
operator: 1
|
|
||||||
|
|
||||||
wfs2:
|
wfs2:
|
||||||
id: 2
|
id: 2
|
||||||
dmsf_workflow_id: 1
|
dmsf_workflow_id: 1
|
||||||
@ -13,9 +6,30 @@ wfs2:
|
|||||||
user_id: 2
|
user_id: 2
|
||||||
operator: 1
|
operator: 1
|
||||||
|
|
||||||
|
wfs1:
|
||||||
|
id: 1
|
||||||
|
dmsf_workflow_id: 1
|
||||||
|
step: 1
|
||||||
|
user_id: 1
|
||||||
|
operator: 0
|
||||||
|
|
||||||
wfs3:
|
wfs3:
|
||||||
id: 3
|
id: 3
|
||||||
dmsf_workflow_id: 1
|
dmsf_workflow_id: 1
|
||||||
step: 3
|
step: 2
|
||||||
user_id: 1
|
user_id: 1
|
||||||
operator: 1
|
operator: 1
|
||||||
|
|
||||||
|
wfs4:
|
||||||
|
id: 4
|
||||||
|
dmsf_workflow_id: 1
|
||||||
|
step: 1
|
||||||
|
user_id: 2
|
||||||
|
operator: 1
|
||||||
|
|
||||||
|
wfs5:
|
||||||
|
id: 5
|
||||||
|
dmsf_workflow_id: 1
|
||||||
|
step: 3
|
||||||
|
user_id: 2
|
||||||
|
operator: 1
|
||||||
|
|||||||
1
test/fixtures/dmsf_workflows.yml
vendored
1
test/fixtures/dmsf_workflows.yml
vendored
@ -2,6 +2,7 @@
|
|||||||
wf1:
|
wf1:
|
||||||
id: 1
|
id: 1
|
||||||
name: wf1
|
name: wf1
|
||||||
|
project_id: 5
|
||||||
|
|
||||||
wf2:
|
wf2:
|
||||||
id: 2
|
id: 2
|
||||||
|
|||||||
@ -1,171 +1,279 @@
|
|||||||
require File.expand_path('../../test_helper', __FILE__)
|
require File.expand_path('../../test_helper', __FILE__)
|
||||||
|
|
||||||
class DmsfWorkflowsControllerTest < RedmineDmsf::Test::TestCase
|
class DmsfWorkflowsControllerTest < RedmineDmsf::Test::TestCase
|
||||||
|
include Redmine::I18n
|
||||||
|
|
||||||
fixtures :users, :dmsf_workflows, :dmsf_workflow_steps, :projects, :roles,
|
fixtures :users, :dmsf_workflows, :dmsf_workflow_steps, :projects, :roles,
|
||||||
:members, :member_roles
|
:members, :member_roles
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
User.current = nil
|
@user_admin = User.find_by_id 1 # Redmine admin
|
||||||
|
@user_member = User.find_by_id 2 # John Smith - manager
|
||||||
|
@user_non_member = User.find_by_id 3 #Dave Lopper
|
||||||
|
@request.session[:user_id] = @user_member.id
|
||||||
|
@role_manager = Role.where(:name => 'Manager').first
|
||||||
|
@role_manager.add_permission! :file_approval
|
||||||
|
@wfs1 = DmsfWorkflowStep.find_by_id 1 # step 1
|
||||||
|
@wfs2 = DmsfWorkflowStep.find_by_id 2 # step 2
|
||||||
|
@wfs3 = DmsfWorkflowStep.find_by_id 3 # step 1
|
||||||
|
@wfs4 = DmsfWorkflowStep.find_by_id 4 # step 2
|
||||||
|
@wfs5 = DmsfWorkflowStep.find_by_id 5 # step 3
|
||||||
@manager_role = Role.find_by_name('Manager')
|
@manager_role = Role.find_by_name('Manager')
|
||||||
@project = Project.find(5)
|
@project1 = Project.find_by_id 1
|
||||||
|
@project5 = Project.find_by_id 5
|
||||||
|
@wf1 = DmsfWorkflow.find_by_id 1
|
||||||
|
@wfsa2 = DmsfWorkflowStepAssignment.find_by_id 2
|
||||||
|
@revision1 = DmsfFileRevision.find_by_id 1
|
||||||
|
@revision2 = DmsfFileRevision.find_by_id 2
|
||||||
|
@revision3 = DmsfFileRevision.find_by_id 3
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_index_admin
|
def test_authorize
|
||||||
@request.session[:user_id] = 1 # admin
|
# Admin
|
||||||
|
@request.session[:user_id] = @user_admin.id
|
||||||
get :index
|
get :index
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
assert_template 'index'
|
||||||
|
|
||||||
|
# Non member
|
||||||
|
@request.session[:user_id] = @user_non_member.id
|
||||||
|
get :index, :project_id => @project5.id
|
||||||
|
assert_response :forbidden
|
||||||
|
|
||||||
|
# Member
|
||||||
|
@request.session[:user_id] = @user_member.id
|
||||||
|
# Administration
|
||||||
|
get :index
|
||||||
|
assert_response :forbidden
|
||||||
|
# Project
|
||||||
|
get :index, :project_id => @project5.id
|
||||||
|
assert_response :success
|
||||||
|
assert_template 'index'
|
||||||
|
# Without the module
|
||||||
|
@project5.disable_module!(:dmsf)
|
||||||
|
get :index, :project_id => @project5.id
|
||||||
|
assert_response :forbidden
|
||||||
|
# Without permissions
|
||||||
|
@project5.enable_module!(:dmsf)
|
||||||
|
@role_manager.remove_permission! :file_approval
|
||||||
|
get :index, :project_id => @project5.id
|
||||||
|
assert_response :forbidden
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_index
|
||||||
|
get :index, :project_id => @project5.id
|
||||||
|
assert_response :success
|
||||||
assert_template 'index'
|
assert_template 'index'
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_index_user
|
def test_new
|
||||||
@request.session[:user_id] = 2 # non admin
|
get :new, :project_id => @project5.id
|
||||||
get :index
|
|
||||||
assert_response :forbidden
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_index_member
|
|
||||||
old_controller = @controller
|
|
||||||
@controller = ProjectsController.new
|
|
||||||
|
|
||||||
@request.session[:user_id] = 2
|
|
||||||
get :settings, :id => @project.id
|
|
||||||
assert_response :success
|
|
||||||
assert_template 'settings'
|
|
||||||
|
|
||||||
@controller = old_controller
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_new_admin
|
|
||||||
@request.session[:user_id] = 1 # admin
|
|
||||||
get :new
|
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_template 'new'
|
assert_template 'new'
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_new_member_no_permission
|
|
||||||
@project.enable_module!(:dmsf)
|
|
||||||
@manager_role.remove_permission! :approval_workflows
|
|
||||||
@request.session[:user_id] = 2
|
|
||||||
get :new, {:project_id => @project.id}
|
|
||||||
assert_response :forbidden
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_new_member_no_module
|
|
||||||
@project.disable_module!(:dmsf)
|
|
||||||
@manager_role.add_permission! :approval_workflows
|
|
||||||
@request.session[:user_id] = 2
|
|
||||||
get :new, {:project_id => @project.id}
|
|
||||||
assert_response :forbidden
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_new_member
|
|
||||||
@manager_role.add_permission! :approval_workflows
|
|
||||||
@request.session[:user_id] = 2
|
|
||||||
@project.enable_module!(:dmsf)
|
|
||||||
get :new, {:project_id => @project.id}
|
|
||||||
assert_response :success
|
|
||||||
assert_template 'new'
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_new_no_member
|
|
||||||
@manager_role.add_permission! :approval_workflows
|
|
||||||
@request.session[:user_id] = 3
|
|
||||||
@project.enable_module!(:dmsf)
|
|
||||||
get :new, {:project_id => @project.id}
|
|
||||||
assert_response :forbidden
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_edit
|
def test_edit
|
||||||
@request.session[:user_id] = 1 # admin
|
get :edit, :id => @wf1.id
|
||||||
get :edit, :id => 1
|
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_template 'edit'
|
assert_template 'edit'
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_create
|
def test_create
|
||||||
@request.session[:user_id] = 1 # admin
|
|
||||||
assert_difference 'DmsfWorkflow.count', +1 do
|
assert_difference 'DmsfWorkflow.count', +1 do
|
||||||
post :create, :dmsf_workflow => {:name => 'wf3'}
|
post :create, :dmsf_workflow => {:name => 'wf3'}, :project_id => @project5.id
|
||||||
end
|
end
|
||||||
workflow = DmsfWorkflow.first(:order => 'id DESC')
|
assert_redirected_to settings_project_path(@project5, :tab => 'dmsf')
|
||||||
assert_redirected_to dmsf_workflows_path
|
|
||||||
assert_equal 'wf3', workflow.name
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_update
|
def test_update
|
||||||
@request.session[:user_id] = 1 # admin
|
put :update, :id => @wf1.id, :dmsf_workflow => {:name => 'wf1a'}
|
||||||
put :update, :id => 1, :dmsf_workflow => {:name => 'wf1a'}
|
@wf1.reload
|
||||||
workflow = DmsfWorkflow.find(1)
|
assert_equal 'wf1a', @wf1.name
|
||||||
assert_equal 'wf1a', workflow.name
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_destroy
|
def test_destroy
|
||||||
@request.session[:user_id] = 1 # admin
|
id = @wf1.id
|
||||||
assert_difference 'DmsfWorkflow.count', -1 do
|
assert_difference 'DmsfWorkflow.count', -1 do
|
||||||
delete :destroy, :id => 1
|
delete :destroy, :id => @wf1.id
|
||||||
end
|
end
|
||||||
assert_redirected_to dmsf_workflows_path
|
assert_redirected_to settings_project_path(@project5, :tab => 'dmsf')
|
||||||
assert_nil DmsfWorkflow.find_by_id(1)
|
assert_equal 0, DmsfWorkflowStep.where(:dmsf_workflow_id => id).all.count
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_add_step
|
def test_add_step
|
||||||
@request.session[:user_id] = 1 # admin
|
|
||||||
assert_difference 'DmsfWorkflowStep.count', +1 do
|
assert_difference 'DmsfWorkflowStep.count', +1 do
|
||||||
post :add_step, :commit => 'OR', :step => 1, :id => 1, :user_ids =>[3]
|
post :add_step, :commit => l(:dmsf_or), :step => 1, :id => @wf1.id, :user_ids =>[@user_non_member.id]
|
||||||
end
|
end
|
||||||
assert_response :success
|
assert_response :success
|
||||||
ws = DmsfWorkflowStep.first(:order => 'id DESC')
|
ws = DmsfWorkflowStep.first(:order => 'id DESC')
|
||||||
assert_equal 1, ws.dmsf_workflow_id
|
assert_equal @wf1.id, ws.dmsf_workflow_id
|
||||||
assert_equal 1, ws.step
|
assert_equal 1, ws.step
|
||||||
assert_equal 3, ws.user_id
|
assert_equal @user_non_member.id, ws.user_id
|
||||||
assert_equal 0, ws.operator
|
assert_equal DmsfWorkflowStep::OPERATOR_OR, ws.operator
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_remove_step
|
def test_remove_step
|
||||||
@request.session[:user_id] = 1 # admin
|
n = DmsfWorkflowStep.where(:dmsf_workflow_id => @wf1.id, :step => 1).count
|
||||||
n = DmsfWorkflowStep.where(:dmsf_workflow_id => 1, :step => 1).count
|
|
||||||
assert_difference 'DmsfWorkflowStep.count', -n do
|
assert_difference 'DmsfWorkflowStep.count', -n do
|
||||||
delete :remove_step, :step => 1, :id => 1
|
delete :remove_step, :step => @wfs1.id, :id => @wf1.id
|
||||||
end
|
end
|
||||||
assert_response :success
|
assert_response :success
|
||||||
ws = DmsfWorkflowStep.where(:dmsf_workflow_id => 1).first(:order => 'id ASC')
|
ws = DmsfWorkflowStep.where(:dmsf_workflow_id => @wf1.id).first(:order => 'id ASC')
|
||||||
assert_equal 1, ws.step
|
assert_equal 1, ws.step
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_reorder_steps_to_lower
|
def test_reorder_steps_to_lower
|
||||||
@request.session[:user_id] = 1 # admin
|
put :reorder_steps, :step => 1, :id => @wf1.id, :workflow_step => {:move_to => 'lower'}
|
||||||
put :reorder_steps, :step => 1, :id => 1, :workflow_step => {:move_to => 'lower'}
|
assert_response :success
|
||||||
assert_response :success
|
@wfs1.reload
|
||||||
assert_equal 2, DmsfWorkflowStep.find(1).step
|
@wfs2.reload
|
||||||
assert_equal 1, DmsfWorkflowStep.find(2).step
|
@wfs3.reload
|
||||||
assert_equal 3, DmsfWorkflowStep.find(3).step
|
@wfs4.reload
|
||||||
|
@wfs5.reload
|
||||||
|
assert_equal 1, @wfs2.step
|
||||||
|
assert_equal 1, @wfs3.step
|
||||||
|
assert_equal 2, @wfs1.step
|
||||||
|
assert_equal 2, @wfs4.step
|
||||||
|
assert_equal 3, @wfs5.step
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_reorder_steps_to_lowest
|
def test_reorder_steps_to_lowest
|
||||||
@request.session[:user_id] = 1 # admin
|
put :reorder_steps, :step => 1, :id => @wf1.id, :workflow_step => {:move_to => 'lowest'}
|
||||||
put :reorder_steps, :step => 1, :id => 1, :workflow_step => {:move_to => 'lowest'}
|
assert_response :success
|
||||||
assert_response :success
|
@wfs1.reload
|
||||||
assert_equal 3, DmsfWorkflowStep.find(1).step
|
@wfs2.reload
|
||||||
assert_equal 1, DmsfWorkflowStep.find(2).step
|
@wfs3.reload
|
||||||
assert_equal 2, DmsfWorkflowStep.find(3).step
|
@wfs4.reload
|
||||||
|
@wfs5.reload
|
||||||
|
assert_equal 1, @wfs2.step
|
||||||
|
assert_equal 1, @wfs3.step
|
||||||
|
assert_equal 2, @wfs5.step
|
||||||
|
assert_equal 3, @wfs1.step
|
||||||
|
assert_equal 3, @wfs4.step
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_reorder_steps_to_higher
|
def test_reorder_steps_to_higher
|
||||||
@request.session[:user_id] = 1 # admin
|
put :reorder_steps, :step => 3, :id => @wf1.id, :workflow_step => {:move_to => 'higher'}
|
||||||
put :reorder_steps, :step => 2, :id => 1, :workflow_step => {:move_to => 'higher'}
|
assert_response :success
|
||||||
assert_response :success
|
@wfs1.reload
|
||||||
assert_equal 2, DmsfWorkflowStep.find(1).step
|
@wfs2.reload
|
||||||
assert_equal 1, DmsfWorkflowStep.find(2).step
|
@wfs3.reload
|
||||||
assert_equal 3, DmsfWorkflowStep.find(3).step
|
@wfs4.reload
|
||||||
|
@wfs5.reload
|
||||||
|
assert_equal 1, @wfs1.step
|
||||||
|
assert_equal 1, @wfs4.step
|
||||||
|
assert_equal 2, @wfs5.step
|
||||||
|
assert_equal 3, @wfs2.step
|
||||||
|
assert_equal 3, @wfs3.step
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_reorder_steps_to_highest
|
def test_reorder_steps_to_highest
|
||||||
@request.session[:user_id] = 1 # admin
|
put :reorder_steps, :step => 3, :id => @wf1.id, :workflow_step => {:move_to => 'highest'}
|
||||||
put :reorder_steps, :step => 3, :id => 1, :workflow_step => {:move_to => 'highest'}
|
assert_response :success
|
||||||
assert_response :success
|
@wfs1.reload
|
||||||
assert_equal 2, DmsfWorkflowStep.find(1).step
|
@wfs2.reload
|
||||||
assert_equal 3, DmsfWorkflowStep.find(2).step
|
@wfs3.reload
|
||||||
assert_equal 1, DmsfWorkflowStep.find(3).step
|
@wfs4.reload
|
||||||
|
@wfs5.reload
|
||||||
|
assert_equal 1, @wfs5.step
|
||||||
|
assert_equal 2, @wfs1.step
|
||||||
|
assert_equal 2, @wfs4.step
|
||||||
|
assert_equal 3, @wfs2.step
|
||||||
|
assert_equal 3, @wfs3.step
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_action_approve
|
||||||
|
@request.env['HTTP_REFERER'] = 'http://test.host/projects/2/dmsf'
|
||||||
|
post(
|
||||||
|
:new_action,
|
||||||
|
:commit => l(:button_submit),
|
||||||
|
:id => @wf1.id,
|
||||||
|
:dmsf_workflow_step_assignment_id => @wfsa2.id,
|
||||||
|
:dmsf_file_revision_id => @revision2.id,
|
||||||
|
:step_action => DmsfWorkflowStepAction::ACTION_APPROVE,
|
||||||
|
:user_id => nil,
|
||||||
|
:note => '')
|
||||||
|
assert_response :redirect
|
||||||
|
assert DmsfWorkflowStepAction.where(
|
||||||
|
:dmsf_workflow_step_assignment_id => @wfsa2.id,
|
||||||
|
:action => DmsfWorkflowStepAction::ACTION_APPROVE).first
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_action_reject
|
||||||
|
@request.env['HTTP_REFERER'] = 'http://test.host/projects/2/dmsf'
|
||||||
|
post(
|
||||||
|
:new_action,
|
||||||
|
:commit => l(:button_submit),
|
||||||
|
:id => @wf1.id,
|
||||||
|
:dmsf_workflow_step_assignment_id => @wfsa2.id,
|
||||||
|
:dmsf_file_revision_id => @revision2.id,
|
||||||
|
:step_action => DmsfWorkflowStepAction::ACTION_REJECT,
|
||||||
|
:note => 'Rejected because...')
|
||||||
|
assert_response :redirect
|
||||||
|
assert DmsfWorkflowStepAction.where(
|
||||||
|
:dmsf_workflow_step_assignment_id => @wfsa2.id,
|
||||||
|
:action => DmsfWorkflowStepAction::ACTION_REJECT).first
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_action
|
||||||
|
xhr(
|
||||||
|
:get,
|
||||||
|
:action,
|
||||||
|
:project_id => @project5.id,
|
||||||
|
:id => @wf1.id,
|
||||||
|
:dmsf_workflow_step_assignment_id => @wfsa2.id,
|
||||||
|
:dmsf_file_revision_id => @revision2.id,
|
||||||
|
:title => l(:title_waiting_for_approval))
|
||||||
|
assert_response :success
|
||||||
|
assert_match /ajax-modal/, response.body
|
||||||
|
assert_template 'action'
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_new_action_delegate
|
||||||
|
@request.env['HTTP_REFERER'] = 'http://test.host/projects/2/dmsf'
|
||||||
|
post(
|
||||||
|
:new_action,
|
||||||
|
:commit => l(:button_submit),
|
||||||
|
:id => @wf1.id,
|
||||||
|
:dmsf_workflow_step_assignment_id => @wfsa2.id,
|
||||||
|
:dmsf_file_revision_id => @revision2.id,
|
||||||
|
:step_action => DmsfWorkflowStepAction::ACTION_DELEGATE,
|
||||||
|
:user_id => @user_admin.id,
|
||||||
|
:note => 'Delegated because...')
|
||||||
|
assert_response :redirect
|
||||||
|
assert DmsfWorkflowStepAction.where(
|
||||||
|
:dmsf_workflow_step_assignment_id => @wfsa2.id,
|
||||||
|
:action => DmsfWorkflowStepAction::ACTION_DELEGATE).first
|
||||||
|
@wfsa2.reload
|
||||||
|
assert_equal @wfsa2.user_id, @user_admin.id
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_assign
|
||||||
|
xhr(
|
||||||
|
:get,
|
||||||
|
:assign,
|
||||||
|
:project_id => @project5.id,
|
||||||
|
:id => @wf1.id,
|
||||||
|
:dmsf_file_revision_id => @revision1.id,
|
||||||
|
:title => l(:label_dmsf_wokflow_action_assign))
|
||||||
|
assert_response :success
|
||||||
|
assert_match /ajax-modal/, response.body
|
||||||
|
assert_template 'assign'
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_assignment
|
||||||
|
# TODO: There is a strange error: 'ActiveRecord::RecordNotFound: Couldn't find Project with id=0'
|
||||||
|
# while saving the revision
|
||||||
|
# @request.env['HTTP_REFERER'] = 'http://test.host/projects/3/dmsf'
|
||||||
|
# post(
|
||||||
|
# :assignment,
|
||||||
|
# :commit => l(:button_submit),
|
||||||
|
# :id => @wf1.id,
|
||||||
|
# :dmsf_workflow_id => @wf1.id,
|
||||||
|
# :dmsf_file_revision_id => @revision3.id,
|
||||||
|
# :action => 'assignment',
|
||||||
|
# :project_id => @project5.id)
|
||||||
|
# assert_response :redirect
|
||||||
|
assert true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
require File.expand_path('../../test_helper', __FILE__)
|
require File.expand_path('../../test_helper', __FILE__)
|
||||||
|
|
||||||
class DmsfWorkflowStepActionTest < RedmineDmsf::Test::UnitTest
|
class DmsfWorkflowStepActionTest < RedmineDmsf::Test::UnitTest
|
||||||
|
include Redmine::I18n
|
||||||
|
|
||||||
fixtures :dmsf_workflow_steps
|
fixtures :dmsf_workflow_steps
|
||||||
fixtures :dmsf_workflow_step_actions
|
fixtures :dmsf_workflow_step_actions
|
||||||
@ -53,8 +53,49 @@ class DmsfWorkflowStepActionTest < RedmineDmsf::Test::UnitTest
|
|||||||
assert_equal 1, @wfsac1.errors.count
|
assert_equal 1, @wfsac1.errors.count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_validate_note
|
||||||
|
@wfsac1.note = ''
|
||||||
|
@wfsac1.action = DmsfWorkflowStepAction::ACTION_REJECT
|
||||||
|
assert !@wfsac1.save
|
||||||
|
assert_equal 1, @wfsac1.errors.count
|
||||||
|
@wfsac1.note = 'Rejected because....'
|
||||||
|
assert @wfsac1.save
|
||||||
|
@wfsac1.action = DmsfWorkflowStepAction::ACTION_DELEGATE
|
||||||
|
@wfsac1.note = ''
|
||||||
|
assert !@wfsac1.save
|
||||||
|
assert_equal 1, @wfsac1.errors.count
|
||||||
|
@wfsac1.note = 'Delegated because'
|
||||||
|
assert @wfsac1.save
|
||||||
|
@wfsac1.note = ''
|
||||||
|
@wfsac1.action = DmsfWorkflowStepAction::ACTION_APPROVE
|
||||||
|
assert @wfsac1.save
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_validate_author_id
|
||||||
|
@wfsac1.author_id = nil
|
||||||
|
assert !@wfsac1.save
|
||||||
|
assert_equal 1, @wfsac1.errors.count
|
||||||
|
end
|
||||||
|
|
||||||
def test_destroy
|
def test_destroy
|
||||||
@wfsac1.destroy
|
@wfsac1.destroy
|
||||||
assert_nil DmsfWorkflowStepAction.find_by_id(1)
|
assert_nil DmsfWorkflowStepAction.find_by_id(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_is_finished
|
||||||
|
@wfsac1.action = DmsfWorkflowStepAction::ACTION_APPROVE
|
||||||
|
assert @wfsac1.is_finished?
|
||||||
|
@wfsac1.action = DmsfWorkflowStepAction::ACTION_REJECT
|
||||||
|
assert @wfsac1.is_finished?
|
||||||
|
@wfsac1.action = DmsfWorkflowStepAction::ACTION_DELEGATE
|
||||||
|
assert !@wfsac1.is_finished?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_action_str
|
||||||
|
assert_equal DmsfWorkflowStepAction.action_str(DmsfWorkflowStepAction::ACTION_APPROVE), l(:title_approved)
|
||||||
|
assert_equal DmsfWorkflowStepAction.action_str(DmsfWorkflowStepAction::ACTION_REJECT), l(:title_rejected)
|
||||||
|
assert_equal DmsfWorkflowStepAction.action_str(DmsfWorkflowStepAction::ACTION_DELEGATE), l(:title_delegated)
|
||||||
|
assert_equal DmsfWorkflowStepAction.action_str(DmsfWorkflowStepAction::ACTION_ASSIGN), l(:title_assigned)
|
||||||
|
assert_equal DmsfWorkflowStepAction.action_str(DmsfWorkflowStepAction::ACTION_START), l(:title_started)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -14,7 +14,7 @@ class WorkflowStepAssignmentTest < RedmineDmsf::Test::UnitTest
|
|||||||
|
|
||||||
def test_create
|
def test_create
|
||||||
wfsa = DmsfWorkflowStepAssignment.new(
|
wfsa = DmsfWorkflowStepAssignment.new(
|
||||||
:dmsf_workflow_step_id => 2,
|
:dmsf_workflow_step_id => 5,
|
||||||
:user_id => 2,
|
:user_id => 2,
|
||||||
:dmsf_file_revision_id => 2)
|
:dmsf_file_revision_id => 2)
|
||||||
assert wfsa.save
|
assert wfsa.save
|
||||||
@ -50,4 +50,8 @@ class WorkflowStepAssignmentTest < RedmineDmsf::Test::UnitTest
|
|||||||
assert_nil DmsfWorkflowStepAssignment.find_by_id(1)
|
assert_nil DmsfWorkflowStepAssignment.find_by_id(1)
|
||||||
assert_nil DmsfWorkflowStepAction.find_by_id(1)
|
assert_nil DmsfWorkflowStepAction.find_by_id(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_step
|
||||||
|
assert_equal @wfsa1.step, DmsfWorkflowStep.find_by_id(@wfsa1.dmsf_workflow_step_id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,12 +1,15 @@
|
|||||||
require File.expand_path('../../test_helper', __FILE__)
|
require File.expand_path('../../test_helper', __FILE__)
|
||||||
|
|
||||||
class DmsfWorkflowStepTest < RedmineDmsf::Test::UnitTest
|
class DmsfWorkflowStepTest < RedmineDmsf::Test::UnitTest
|
||||||
|
include Redmine::I18n
|
||||||
|
|
||||||
fixtures :users, :dmsf_workflows, :dmsf_workflow_steps
|
fixtures :users, :dmsf_workflows, :dmsf_workflow_steps
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@wfs1 = DmsfWorkflowStep.find(1)
|
@wfs1 = DmsfWorkflowStep.find(1)
|
||||||
@wfs2 = DmsfWorkflowStep.find(2)
|
@wfs2 = DmsfWorkflowStep.find(2)
|
||||||
|
@wfs5 = DmsfWorkflowStep.find(5)
|
||||||
|
@revision1 = DmsfFileRevision.find_by_id 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_truth
|
def test_truth
|
||||||
@ -17,7 +20,7 @@ class DmsfWorkflowStepTest < RedmineDmsf::Test::UnitTest
|
|||||||
wfs = DmsfWorkflowStep.new(
|
wfs = DmsfWorkflowStep.new(
|
||||||
:dmsf_workflow_id => 1,
|
:dmsf_workflow_id => 1,
|
||||||
:step => 2,
|
:step => 2,
|
||||||
:user_id => 1,
|
:user_id => 3,
|
||||||
:operator => 1)
|
:operator => 1)
|
||||||
assert wfs.save
|
assert wfs.save
|
||||||
end
|
end
|
||||||
@ -69,8 +72,25 @@ class DmsfWorkflowStepTest < RedmineDmsf::Test::UnitTest
|
|||||||
assert_equal 1, @wfs2.errors.count
|
assert_equal 1, @wfs2.errors.count
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_destroy
|
def test_destroy
|
||||||
|
assert DmsfWorkflowStepAssignment.where(:dmsf_workflow_step_id => @wfs2.id).all.count > 0
|
||||||
@wfs2.destroy
|
@wfs2.destroy
|
||||||
assert_nil DmsfWorkflowStep.find_by_id(2)
|
assert_nil DmsfWorkflowStep.find_by_id(2)
|
||||||
|
assert_equal DmsfWorkflowStepAssignment.where(:dmsf_workflow_step_id => @wfs2.id).all.count, 0
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_soperator
|
||||||
|
assert_equal @wfs1.soperator, l(:dmsf_or)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_user
|
||||||
|
assert_equal @wfs1.user, User.find_by_id(@wfs1.user_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_assign
|
||||||
|
@wfs5.assign(@revision1.id)
|
||||||
|
assert DmsfWorkflowStepAssignment.where(
|
||||||
|
:dmsf_workflow_step_id => @wfs5.id,
|
||||||
|
:dmsf_file_revision_id => @revision1.id).first
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,12 +2,24 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
|
|
||||||
class DmsfWorkflowTest < RedmineDmsf::Test::UnitTest
|
class DmsfWorkflowTest < RedmineDmsf::Test::UnitTest
|
||||||
|
|
||||||
fixtures :projects, :dmsf_workflows, :dmsf_workflow_steps
|
fixtures :projects, :members, :dmsf_files, :dmsf_file_revisions,
|
||||||
|
:dmsf_workflows, :dmsf_workflow_steps, :dmsf_workflow_step_assignments,
|
||||||
|
:dmsf_workflow_step_actions
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@wf1 = DmsfWorkflow.find(1)
|
User.current = User.find_by_id 1 # Admin
|
||||||
@wf2 = DmsfWorkflow.find(2)
|
@wf1 = DmsfWorkflow.find_by_id(1)
|
||||||
@wfs1 = DmsfWorkflowStep.find(1)
|
@wf2 = DmsfWorkflow.find_by_id(2)
|
||||||
|
@wfs1 = DmsfWorkflowStep.find_by_id(1)
|
||||||
|
@wfs2 = DmsfWorkflowStep.find_by_id(2)
|
||||||
|
@wfs3 = DmsfWorkflowStep.find_by_id(3)
|
||||||
|
@wfs4 = DmsfWorkflowStep.find_by_id(4)
|
||||||
|
@wfs5 = DmsfWorkflowStep.find_by_id(5)
|
||||||
|
@wfsa1 = DmsfWorkflowStepAssignment.find_by_id(1)
|
||||||
|
@wfsac1 = DmsfWorkflowStepAction.find_by_id(1)
|
||||||
|
@revision1 = DmsfFileRevision.find_by_id 1
|
||||||
|
@revision2 = DmsfFileRevision.find_by_id 2
|
||||||
|
@project = Project.find_by_id 2
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_truth
|
def test_truth
|
||||||
@ -51,4 +63,116 @@ class DmsfWorkflowTest < RedmineDmsf::Test::UnitTest
|
|||||||
assert_nil DmsfWorkflow.find_by_id(1)
|
assert_nil DmsfWorkflow.find_by_id(1)
|
||||||
assert_nil DmsfWorkflowStep.find_by_id(@wfs1.id)
|
assert_nil DmsfWorkflowStep.find_by_id(@wfs1.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_project
|
||||||
|
# Global workflow
|
||||||
|
assert_nil @wf1.project
|
||||||
|
# Project workflow
|
||||||
|
@wf1.project_id = 5
|
||||||
|
assert @wf1.project
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_to_s
|
||||||
|
assert_equal @wf1.name, @wf1.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_reorder_steps_highest
|
||||||
|
@wf1.reorder_steps(3, 'highest')
|
||||||
|
@wfs1.reload
|
||||||
|
@wfs2.reload
|
||||||
|
@wfs3.reload
|
||||||
|
@wfs4.reload
|
||||||
|
@wfs5.reload
|
||||||
|
assert_equal @wfs5.step, 1
|
||||||
|
assert_equal @wfs1.step, 2
|
||||||
|
assert_equal @wfs4.step, 2
|
||||||
|
assert_equal @wfs2.step, 3
|
||||||
|
assert_equal @wfs3.step, 3
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_reorder_steps_higher
|
||||||
|
@wf1.reorder_steps(3, 'higher')
|
||||||
|
@wfs1.reload
|
||||||
|
@wfs2.reload
|
||||||
|
@wfs3.reload
|
||||||
|
@wfs4.reload
|
||||||
|
@wfs5.reload
|
||||||
|
assert_equal @wfs1.step, 1
|
||||||
|
assert_equal @wfs4.step, 1
|
||||||
|
assert_equal @wfs5.step, 2
|
||||||
|
assert_equal @wfs2.step, 3
|
||||||
|
assert_equal @wfs3.step, 3
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_reorder_steps_lower
|
||||||
|
@wf1.reorder_steps(1, 'lower')
|
||||||
|
@wfs1.reload
|
||||||
|
@wfs2.reload
|
||||||
|
@wfs3.reload
|
||||||
|
@wfs4.reload
|
||||||
|
@wfs5.reload
|
||||||
|
assert_equal @wfs2.step, 1
|
||||||
|
assert_equal @wfs3.step, 1
|
||||||
|
assert_equal @wfs1.step, 2
|
||||||
|
assert_equal @wfs4.step, 2
|
||||||
|
assert_equal @wfs5.step, 3
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_reorder_steps_lowest
|
||||||
|
@wf1.reorder_steps(1, 'lowest')
|
||||||
|
@wfs1.reload
|
||||||
|
@wfs2.reload
|
||||||
|
@wfs3.reload
|
||||||
|
@wfs4.reload
|
||||||
|
@wfs5.reload
|
||||||
|
assert_equal @wfs2.step, 1
|
||||||
|
assert_equal @wfs3.step, 1
|
||||||
|
assert_equal @wfs5.step, 2
|
||||||
|
assert_equal @wfs1.step, 3
|
||||||
|
assert_equal @wfs4.step, 3
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_delegates
|
||||||
|
delegates = @wf1.delegates(nil, nil, nil)
|
||||||
|
assert_equal delegates.size, User.active.all.size
|
||||||
|
delegates = @wf1.delegates('Redmine', nil, nil)
|
||||||
|
assert_equal delegates.size, 1
|
||||||
|
delegates = @wf1.delegates(nil, @wfsa1.id, 2)
|
||||||
|
assert !delegates.any?{|user| user.id == @wfsa1.user_id}
|
||||||
|
assert delegates.any?{|user| user.id == 8}
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_next_assignments
|
||||||
|
assignments = @wf1.next_assignments(2)
|
||||||
|
assert_equal assignments.size, 1
|
||||||
|
assert_equal assignments[0].user_id, 2
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_assignments_to_users_str
|
||||||
|
assignments = @wf1.next_assignments(2)
|
||||||
|
str = DmsfWorkflow.assignments_to_users_str(assignments)
|
||||||
|
assert_equal str, 'John Smith', str
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_assign
|
||||||
|
@wf1.assign(1)
|
||||||
|
@wf1.dmsf_workflow_steps.each do |step|
|
||||||
|
assert_kind_of DmsfWorkflowStepAssignment, DmsfWorkflowStepAssignment.where(
|
||||||
|
:dmsf_workflow_step_id => step.id, :dmsf_file_revision_id => 1).first
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_try_finish
|
||||||
|
#def try_finish(dmsf_file_revision_id, action, user_id)
|
||||||
|
# TODO: There is a strange error: 'ActiveRecord::RecordNotFound: Couldn't find Project with id=0'
|
||||||
|
# while saving the revision
|
||||||
|
# @revision1.set_workflow @wf1.id, 'start'
|
||||||
|
# @wf1.try_finish @revision1.id, @wfsac1, User.current.id
|
||||||
|
# @revision1.reload
|
||||||
|
# assert_equal @revision1.workflow, DmsfWorkflow::STATE_APPROVED
|
||||||
|
# @revision2.set_workflow @wf1.id, 'start'
|
||||||
|
# @wf1.try_finish @revision2.id, @wfsac1, User.current.id
|
||||||
|
# assert_equal @revision2.workflow, DmsfWorkflow::STATE_WAITING_FOR_APPROVAL
|
||||||
|
assert true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user