Custom fields tests added

This commit is contained in:
Karel Picman 2013-11-15 14:47:34 +01:00
parent 343f3b8ee3
commit a27c7a1381
7 changed files with 173 additions and 51 deletions

35
test/fixtures/custom_fields.yml vendored Normal file
View File

@ -0,0 +1,35 @@
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2013 Karel Picman <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.
---
cf_1:
name: Tag
min_length: 0
regexp: ""
is_for_all: true
is_filter: true
type: DmsfFileRevisionCustomField
max_length: 0
possible_values:
- User documentation
- Technical docuemntation
id: 21
is_required: false
field_format: list
default_value: ''
editable: false
position: 1

30
test/fixtures/custom_values.yml vendored Normal file
View File

@ -0,0 +1,30 @@
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2013 Karel Picman <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.
---
cv_1:
customized_type: DmsfFolder
custom_field_id: 21
customized_id: 1
id: 21
value: 'User documentation'
cv_2:
customized_type: DmsfFileRevision
custom_field_id: 21
customized_id: 1
id: 22
value: 'Technical documentation'

View File

@ -1,44 +1,46 @@
---
dmsf_file_revisions_001:
id: 1
dmsf_file_id: 1
id: 1
dmsf_file_id: 1
source_dmsf_file_revision_id: NULL
name: "test.txt"
dmsf_folder_id: NULL
disk_filename: "test.txt"
size: 4
mime_type: text/plain
title: "Test File"
description: NULL
workflow: NULL
minor_version: 0
major_version: 1
comment: NULL
deleted: 0
deleted_by_user_id: NULL
user_id: 1
dmsf_workflow_assigned_by: 1
name: "test.txt"
dmsf_folder_id: NULL
disk_filename: "test.txt"
size: 4
mime_type: text/plain
title: "Test File"
description: NULL
workflow: NULL
minor_version: 0
major_version: 1
comment: NULL
deleted: 0
deleted_by_user_id: NULL
user_id: 1
dmsf_workflow_assigned_by: 1
dmsf_workflow_started_by: 1
#revision for file on non-enabled project
dmsf_file_revisions_002:
id: 2
dmsf_file_id: 2
id: 2
dmsf_file_id: 2
source_dmsf_file_revision_id: NULL
name: "test.txt"
dmsf_folder_id: NULL
disk_filename: "test.txt"
size: 4
mime_type: text/plain
title: "Test File"
description: NULL
workflow: NULL
minor_version: 0
major_version: 1
comment: NULL
deleted: 0
deleted_by_user_id: NULL
user_id: 1
dmsf_workflow_assigned_by: 1
name: "test.txt"
dmsf_folder_id: NULL
disk_filename: "test.txt"
size: 4
mime_type: text/plain
title: "Test File"
description: NULL
workflow: NULL
minor_version: 0
major_version: 1
comment: NULL
deleted: 0
deleted_by_user_id: NULL
user_id: 1
dmsf_workflow_assigned_by: 1
dmsf_workflow_started_by: 1
#revision for deleted file on dmsf-enabled project
dmsf_file_revisions_003:
@ -59,3 +61,5 @@ dmsf_file_revisions_003:
deleted: 1
deleted_by_user_id: 1
user_id: 1
dmsf_workflow_assigned_by: 1
dmsf_workflow_started_by: 1

View File

@ -1,6 +1,6 @@
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk>
# Copyright (C) 2013 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
@ -16,11 +16,35 @@
# 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.dirname(__FILE__) + '/../test_helper'
require File.expand_path('../../test_helper', __FILE__)
class DmsfControllerTest < ActionController::TestCase
# Replace this with your real tests.
def test_truth
assert true
class DmsfControllerTest < RedmineDmsf::Test::TestCase
fixtures :users, :dmsf_files, :dmsf_file_revisions, :dmsf_folders,
:custom_fields, :custom_values, :projects, :members, :member_roles,
:enabled_modules
def setup
@request.session[:user_id] = 2
@project = Project.find_by_id 1
@folder = DmsfFolder.find_by_id 1
@role = Role.find_by_id 1
@custom_field = CustomField.find_by_id 21
@custom_value_1 = CustomValue.find_by_id 21
end
def test_edit_folder
# Missing permissions
get :edit, :id => @project, :folder_id => @folder
assert_response 403
# Permissions OK
@role.add_permission! :view_dmsf_folders
@role.add_permission! :folder_manipulation
get :edit, :id => @project, :folder_id => @folder
assert_response :success
assert_select 'label', {:text => @custom_field.name}
assert_select 'option', {:value => @custom_value_1.value}
end
end

View File

@ -1,6 +1,6 @@
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk>
# Copyright (C) 2013 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
@ -16,11 +16,40 @@
# 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.dirname(__FILE__) + '/../test_helper'
require File.expand_path('../../test_helper', __FILE__)
class DmsfControllerTest < ActionController::TestCase
# Replace this with your real tests.
def test_truth
assert true
class DmsfFilesControllerTest < RedmineDmsf::Test::TestCase
fixtures :users, :dmsf_files, :dmsf_file_revisions, :custom_fields,
:custom_values, :projects, :members, :member_roles, :enabled_modules,
:dmsf_file_revisions
def setup
@request.session[:user_id] = 2
@file = DmsfFolder.find_by_id 1
@role = Role.find_by_id 1
@custom_field = CustomField.find_by_id 21
@custom_value_2 = CustomValue.find_by_id 22
end
def test_show_file
# Missing permissions
get :show, :id => @file
assert_response 403
# Permissions OK
@role.add_permission! :view_dmsf_files
@role.add_permission! :file_manipulation
get :show, :id => @file
assert_response :success
# The last revision
assert_select 'label', {:text => @custom_field.name}
assert_select '.customfield', {:text => "#{@custom_field.name}: #{@custom_value_2.value}"}
# A new revision
assert_select 'label', {:text => @custom_field.name}
assert_select 'option', {:value => @custom_value_2.value}
end
end

View File

@ -102,13 +102,13 @@ class DmsfWorkflowsControllerTest < RedmineDmsf::Test::TestCase
def test_create
assert_difference 'DmsfWorkflow.count', +1 do
post :create, :dmsf_workflow => {:name => 'wf3'}, :project_id => @project5.id
post :create, :name => 'wf3', :project_id => @project5.id
end
assert_redirected_to settings_project_path(@project5, :tab => 'dmsf')
assert_redirected_to settings_project_path(@project5, :tab => 'dmsf_workflow')
end
def test_update
put :update, :id => @wf1.id, :dmsf_workflow => {:name => 'wf1a'}
put :update, :id => @wf1.id, :name => 'wf1a'
@wf1.reload
assert_equal 'wf1a', @wf1.name
end
@ -118,7 +118,7 @@ class DmsfWorkflowsControllerTest < RedmineDmsf::Test::TestCase
assert_difference 'DmsfWorkflow.count', -1 do
delete :destroy, :id => @wf1.id
end
assert_redirected_to settings_project_path(@project5, :tab => 'dmsf')
assert_redirected_to settings_project_path(@project5, :tab => 'dmsf_workflow')
assert_equal 0, DmsfWorkflowStep.where(:dmsf_workflow_id => id).all.count
end

View File

@ -21,7 +21,7 @@ require File.expand_path('../../test_helper', __FILE__)
class MyControllerTest < RedmineDmsf::Test::TestCase
include Redmine::I18n
fixtures :users, :user_preferences, :dmsf_locks
fixtures :users, :user_preferences
def setup
@request.session[:user_id] = 2