diff --git a/.github/workflows/rubyonrails.yml b/.github/workflows/rubyonrails.yml index c701e6b0..ff724c04 100644 --- a/.github/workflows/rubyonrails.yml +++ b/.github/workflows/rubyonrails.yml @@ -140,7 +140,9 @@ jobs: - name: Helpers tests run: | cd /opt/redmine + ruby plugins/redmine_dmsf/test/helpers/dmsf_files_helper_test.rb ruby plugins/redmine_dmsf/test/helpers/dmsf_helper_test.rb + ruby plugins/redmine_dmsf/test/helpers/dmsf_links_helper_test.rb ruby plugins/redmine_dmsf/test/helpers/dmsf_queries_helper_test.rb - name: Rubocop # Run the Rubocop tests diff --git a/.rubocop.yml b/.rubocop.yml index 82abac08..770b807d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -26,8 +26,7 @@ AllCops: Exclude: - '**/vendor/**/*' -# Enable extensions -require: +plugins: - rubocop-performance - rubocop-rails diff --git a/lib/redmine_dmsf/macros.rb b/lib/redmine_dmsf/macros.rb index 55eb8dd0..55dccadd 100644 --- a/lib/redmine_dmsf/macros.rb +++ b/lib/redmine_dmsf/macros.rb @@ -117,6 +117,7 @@ module RedmineDmsf file = DmsfFile.visible.find_by(id: args[0]) return "{{dmsfversion(#{args[0]})}}" unless file + unless User.current&.allowed_to?(:view_dmsf_files, file.project, { id: file.id }) raise ::I18n.t(:notice_not_authorized) end @@ -127,7 +128,7 @@ module RedmineDmsf revision = DmsfFileRevision.find_by(id: args[1], dmsf_file_id: args[0]) return "{{dmsfversion(#{args[0]}, #{args[1]})}}" unless revision end - textilizable revision.version + revision.version end # dmsflastupdate - text referring to the document's last update date diff --git a/test/functional/dmsf_context_menus_controller_test.rb b/test/functional/dmsf_context_menus_controller_test.rb index 313dca88..78423d33 100644 --- a/test/functional/dmsf_context_menus_controller_test.rb +++ b/test/functional/dmsf_context_menus_controller_test.rb @@ -23,8 +23,6 @@ require File.expand_path('../../test_helper', __FILE__) class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase include Redmine::I18n - fixtures :dmsf_folders, :dmsf_files, :dmsf_file_revisions, :dmsf_links, :dmsf_locks - def setup super @file_link2 = DmsfLink.find 2 diff --git a/test/functional/dmsf_controller_test.rb b/test/functional/dmsf_controller_test.rb index f215d93a..372c5279 100644 --- a/test/functional/dmsf_controller_test.rb +++ b/test/functional/dmsf_controller_test.rb @@ -25,9 +25,6 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase include Redmine::I18n include DmsfHelper - fixtures :custom_fields, :custom_values, :dmsf_links, :dmsf_folder_permissions, :dmsf_locks, - :dmsf_folders, :dmsf_files, :dmsf_file_revisions - def setup super @link2 = DmsfLink.find 2 diff --git a/test/functional/dmsf_files_controller_test.rb b/test/functional/dmsf_files_controller_test.rb index 8a67c2bb..e29fa353 100644 --- a/test/functional/dmsf_files_controller_test.rb +++ b/test/functional/dmsf_files_controller_test.rb @@ -21,8 +21,6 @@ require File.expand_path('../../test_helper', __FILE__) # DmsfFiles controller class DmsfFilesControllerTest < RedmineDmsf::Test::TestCase - fixtures :dmsf_folders, :dmsf_files, :dmsf_file_revisions, :dmsf_locks - def teardown super DmsfFile.clear_previews diff --git a/test/functional/dmsf_folder_permissions_controller_test.rb b/test/functional/dmsf_folder_permissions_controller_test.rb index 8206a993..745e7add 100644 --- a/test/functional/dmsf_folder_permissions_controller_test.rb +++ b/test/functional/dmsf_folder_permissions_controller_test.rb @@ -21,8 +21,6 @@ require File.expand_path('../../test_helper', __FILE__) # Folder permissions controller class DmsfFolderPermissionsControllerTest < RedmineDmsf::Test::TestCase - fixtures :dmsf_folder_permissions, :dmsf_folders, :dmsf_files, :dmsf_file_revisions - def setup super post '/login', params: { username: 'jsmith', password: 'jsmith' } diff --git a/test/functional/dmsf_help_controller_test.rb b/test/functional/dmsf_help_controller_test.rb index 570c8fad..5b69eafd 100644 --- a/test/functional/dmsf_help_controller_test.rb +++ b/test/functional/dmsf_help_controller_test.rb @@ -21,8 +21,6 @@ require File.expand_path('../../test_helper', __FILE__) # Help controller class DmsfHelpControllerTest < RedmineDmsf::Test::TestCase - fixtures :dmsf_folders, :dmsf_files, :dmsf_file_revisions - def test_wiki_syntax post '/login', params: { username: 'jsmith', password: 'jsmith' } get '/dmsf/help/wiki_syntax' diff --git a/test/functional/dmsf_links_controller_test.rb b/test/functional/dmsf_links_controller_test.rb index d94efbe6..f490ac2c 100644 --- a/test/functional/dmsf_links_controller_test.rb +++ b/test/functional/dmsf_links_controller_test.rb @@ -23,8 +23,6 @@ require File.expand_path('../../test_helper', __FILE__) class DmsfLinksControllerTest < RedmineDmsf::Test::TestCase include Redmine::I18n - fixtures :dmsf_links, :dmsf_folders, :dmsf_files, :dmsf_file_revisions - def setup super @file_link = DmsfLink.find 1 diff --git a/test/functional/dmsf_public_urls_controller_test.rb b/test/functional/dmsf_public_urls_controller_test.rb index ec88b226..c1aab7ae 100644 --- a/test/functional/dmsf_public_urls_controller_test.rb +++ b/test/functional/dmsf_public_urls_controller_test.rb @@ -21,8 +21,6 @@ require File.expand_path('../../test_helper', __FILE__) # Public URL controller class DmsfPublicUrlsControllerTest < RedmineDmsf::Test::TestCase - fixtures :dmsf_public_urls, :dmsf_folders, :dmsf_files, :dmsf_file_revisions - def test_show_valid_url get '/dmsf_public_urls', params: { token: 'd8d33e21914a433b280fdc94450ee212' } assert_response :success diff --git a/test/functional/dmsf_state_controller_test.rb b/test/functional/dmsf_state_controller_test.rb index 68d08f10..19e9b426 100644 --- a/test/functional/dmsf_state_controller_test.rb +++ b/test/functional/dmsf_state_controller_test.rb @@ -23,8 +23,6 @@ require File.expand_path('../../test_helper', __FILE__) class DmsfStateControllerTest < RedmineDmsf::Test::TestCase include Redmine::I18n - fixtures :dmsf_folders, :dmsf_files, :dmsf_file_revisions, :queries - def setup super @query401 = Query.find 401 diff --git a/test/functional/dmsf_workflow_controller_test.rb b/test/functional/dmsf_workflow_controller_test.rb index 2ebf678f..d611981d 100644 --- a/test/functional/dmsf_workflow_controller_test.rb +++ b/test/functional/dmsf_workflow_controller_test.rb @@ -23,9 +23,6 @@ require File.expand_path('../../test_helper', __FILE__) class DmsfWorkflowsControllerTest < RedmineDmsf::Test::TestCase include Redmine::I18n - fixtures :dmsf_workflows, :dmsf_workflow_steps, :dmsf_workflow_step_assignments, - :dmsf_folders, :dmsf_files, :dmsf_file_revisions, :dmsf_locks - def setup super @wfs1 = DmsfWorkflowStep.find 1 # step 1 diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 41748964..d459bf16 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -21,10 +21,6 @@ require File.expand_path('../../test_helper', __FILE__) # Issues controller class IssuesControllerTest < RedmineDmsf::Test::TestCase - fixtures :user_preferences, :issues, :versions, :trackers, :projects_trackers, :issue_statuses, - :enabled_modules, :dmsf_folders, :dmsf_files, :dmsf_file_revisions, :enumerations, - :issue_categories - def setup super @issue1 = Issue.find 1 diff --git a/test/functional/my_controller_test.rb b/test/functional/my_controller_test.rb index d5a7b222..953e7df9 100644 --- a/test/functional/my_controller_test.rb +++ b/test/functional/my_controller_test.rb @@ -23,9 +23,6 @@ require File.expand_path('../../test_helper', __FILE__) class MyControllerTest < RedmineDmsf::Test::TestCase include Redmine::I18n - fixtures :user_preferences, :dmsf_workflows, :dmsf_workflow_steps, :dmsf_workflow_step_assignments, - :dmsf_workflow_step_actions, :dmsf_folders, :dmsf_files, :dmsf_file_revisions, :dmsf_locks - def test_page_with_open_approvals_one_approval post '/login', params: { username: 'jsmith', password: 'jsmith' } DmsfFileRevision.where(id: 5).delete_all diff --git a/test/helper_test.rb b/test/helper_test.rb index af4c90f9..c10dc397 100644 --- a/test/helper_test.rb +++ b/test/helper_test.rb @@ -21,22 +21,15 @@ module RedmineDmsf module Test # Helper test class HelperTest < ActiveSupport::TestCase - fixtures :users, :email_addresses, :projects, :roles, :members, :member_roles - - # 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) + def initialize(name) + super(name) + # Load all plugin's fixtures dir = File.join(File.dirname(__FILE__), 'fixtures') - redmine_table_names = [] - table_names.each do |x| - if File.exist?(File.join(dir, "#{x}.yml")) - ActiveRecord::FixtureSet.create_fixtures(dir, x) - else - redmine_table_names << x - end + ext = '.yml' + Dir.glob("#{dir}/**/*#{ext}").each do |file| + fixture = File.basename(file, ext) + ActiveRecord::FixtureSet.create_fixtures dir, fixture end - super(redmine_table_names) if redmine_table_names.any? end def setup diff --git a/test/helpers/dmsf_helper_test.rb b/test/helpers/dmsf_helper_test.rb index fea0e73d..1c8dac4a 100644 --- a/test/helpers/dmsf_helper_test.rb +++ b/test/helpers/dmsf_helper_test.rb @@ -23,8 +23,6 @@ require File.expand_path('../../test_helper', __FILE__) class DmsfHelperTest < RedmineDmsf::Test::HelperTest include DmsfHelper - fixtures :dmsf_folders - def setup super @folder1 = DmsfFolder.find 1 diff --git a/test/helpers/dmsf_queries_helper_test.rb b/test/helpers/dmsf_queries_helper_test.rb index 4eb8ecac..78854535 100644 --- a/test/helpers/dmsf_queries_helper_test.rb +++ b/test/helpers/dmsf_queries_helper_test.rb @@ -25,8 +25,6 @@ class DmsfQueriesHelperTest < RedmineDmsf::Test::HelperTest include ActionView::Helpers::NumberHelper include ActionView::Helpers::TagHelper - fixtures :dmsf_folders - def setup @folder1 = DmsfFolder.find 1 super diff --git a/test/integration/rest_api/dmsf_api_test.rb b/test/integration/rest_api/dmsf_api_test.rb index 9cda40cc..192c710a 100644 --- a/test/integration/rest_api/dmsf_api_test.rb +++ b/test/integration/rest_api/dmsf_api_test.rb @@ -23,8 +23,6 @@ require File.expand_path('../../../test_helper', __FILE__) class DmsfFileApiTest < RedmineDmsf::Test::IntegrationTest include Redmine::I18n - fixtures :dmsf_folders, :dmsf_files, :dmsf_file_revisions, :dmsf_locks, :dmsf_links - def setup super Setting.rest_api_enabled = '1' diff --git a/test/integration/rest_api/dmsf_file_api_test.rb b/test/integration/rest_api/dmsf_file_api_test.rb index 7091a12c..37a42fb2 100644 --- a/test/integration/rest_api/dmsf_file_api_test.rb +++ b/test/integration/rest_api/dmsf_file_api_test.rb @@ -23,8 +23,6 @@ require File.expand_path('../../../test_helper', __FILE__) class DmsfFileApiTest < RedmineDmsf::Test::IntegrationTest include Redmine::I18n - fixtures :dmsf_files, :dmsf_file_revisions, :dmsf_locks, :custom_fields - def setup super Setting.rest_api_enabled = '1' diff --git a/test/integration/rest_api/dmsf_folder_api_test.rb b/test/integration/rest_api/dmsf_folder_api_test.rb index ab4b467a..6e12addc 100644 --- a/test/integration/rest_api/dmsf_folder_api_test.rb +++ b/test/integration/rest_api/dmsf_folder_api_test.rb @@ -23,9 +23,6 @@ require File.expand_path('../../../test_helper', __FILE__) class DmsfFolderApiTest < RedmineDmsf::Test::IntegrationTest include Redmine::I18n - fixtures :dmsf_folders, :dmsf_files, :dmsf_file_revisions, :dmsf_locks, :dmsf_links, :custom_fields, - :custom_values - def setup super Setting.rest_api_enabled = '1' diff --git a/test/integration/rest_api/dmsf_link_api_test.rb b/test/integration/rest_api/dmsf_link_api_test.rb index e43d1c79..3d2c54bc 100644 --- a/test/integration/rest_api/dmsf_link_api_test.rb +++ b/test/integration/rest_api/dmsf_link_api_test.rb @@ -23,8 +23,6 @@ require File.expand_path('../../../test_helper', __FILE__) class DmsfLinkApiTest < RedmineDmsf::Test::IntegrationTest include Redmine::I18n - fixtures :dmsf_files, :dmsf_file_revisions, :dmsf_links - def setup super Setting.rest_api_enabled = '1' diff --git a/test/integration/webdav/dmsf_webdav_custom_middleware_test.rb b/test/integration/webdav/dmsf_webdav_custom_middleware_test.rb index 625f74a5..c0e67436 100644 --- a/test/integration/webdav/dmsf_webdav_custom_middleware_test.rb +++ b/test/integration/webdav/dmsf_webdav_custom_middleware_test.rb @@ -21,8 +21,6 @@ require File.expand_path('../../../test_helper', __FILE__) # Custom middleware test class DmsfWebdavCustomMiddlewareTest < RedmineDmsf::Test::IntegrationTest - fixtures :dmsf_folders, :dmsf_files - def test_options_for_root_path process :options, '/' assert_response :method_not_allowed diff --git a/test/integration/webdav/dmsf_webdav_delete_test.rb b/test/integration/webdav/dmsf_webdav_delete_test.rb index 87f90741..4cc72f60 100644 --- a/test/integration/webdav/dmsf_webdav_delete_test.rb +++ b/test/integration/webdav/dmsf_webdav_delete_test.rb @@ -23,8 +23,6 @@ require File.expand_path('../../../test_helper', __FILE__) class DmsfWebdavDeleteTest < RedmineDmsf::Test::IntegrationTest include Redmine::I18n - fixtures :dmsf_folders, :dmsf_files, :dmsf_file_revisions, :dmsf_locks - def test_not_authenticated delete '/dmsf/webdav' assert_response :unauthorized diff --git a/test/integration/webdav/dmsf_webdav_get_test.rb b/test/integration/webdav/dmsf_webdav_get_test.rb index cdf870c8..40b8087b 100644 --- a/test/integration/webdav/dmsf_webdav_get_test.rb +++ b/test/integration/webdav/dmsf_webdav_get_test.rb @@ -21,8 +21,6 @@ require File.expand_path('../../../test_helper', __FILE__) # WebDAV GET test class DmsfWebdavGetTest < RedmineDmsf::Test::IntegrationTest - fixtures :dmsf_folders, :dmsf_files, :dmsf_file_revisions - def test_should_deny_anonymous get '/dmsf/webdav' assert_response :unauthorized diff --git a/test/integration/webdav/dmsf_webdav_head_test.rb b/test/integration/webdav/dmsf_webdav_head_test.rb index 223f97c5..5d3861b5 100644 --- a/test/integration/webdav/dmsf_webdav_head_test.rb +++ b/test/integration/webdav/dmsf_webdav_head_test.rb @@ -21,7 +21,6 @@ require File.expand_path('../../../test_helper', __FILE__) # WebDAV HEAD tests class DmsfWebdavHeadTest < RedmineDmsf::Test::IntegrationTest - fixtures :dmsf_folders, :dmsf_files, :dmsf_file_revisions def test_head_requires_authentication head "/dmsf/webdav/#{@project1.identifier}" diff --git a/test/integration/webdav/dmsf_webdav_lock_test.rb b/test/integration/webdav/dmsf_webdav_lock_test.rb index bf540255..d58b5fbb 100644 --- a/test/integration/webdav/dmsf_webdav_lock_test.rb +++ b/test/integration/webdav/dmsf_webdav_lock_test.rb @@ -22,7 +22,6 @@ require 'fileutils' # WebDAV LOCK test class DmsfWebdavLockTest < RedmineDmsf::Test::IntegrationTest - fixtures :dmsf_folders, :dmsf_files, :dmsf_file_revisions, :dmsf_locks def setup super diff --git a/test/integration/webdav/dmsf_webdav_mkcol_test.rb b/test/integration/webdav/dmsf_webdav_mkcol_test.rb index 62630c25..6ac04e14 100644 --- a/test/integration/webdav/dmsf_webdav_mkcol_test.rb +++ b/test/integration/webdav/dmsf_webdav_mkcol_test.rb @@ -21,8 +21,6 @@ require File.expand_path('../../../test_helper', __FILE__) # WebDAV MKCOL tests class DmsfWebdavMkcolTest < RedmineDmsf::Test::IntegrationTest - fixtures :dmsf_folders - def test_mkcol_requires_authentication process :mkcol, '/dmsf/webdav/test1' assert_response :unauthorized diff --git a/test/integration/webdav/dmsf_webdav_move_test.rb b/test/integration/webdav/dmsf_webdav_move_test.rb index d6615df4..a9f999d6 100644 --- a/test/integration/webdav/dmsf_webdav_move_test.rb +++ b/test/integration/webdav/dmsf_webdav_move_test.rb @@ -22,8 +22,6 @@ require 'fileutils' # WebDAV MOVE tests class DmsfWebdavMoveTest < RedmineDmsf::Test::IntegrationTest - fixtures :dmsf_folders, :dmsf_files, :dmsf_file_revisions - def test_move_denied_for_anonymous new_name = "#{@file1.name}.moved" assert_no_difference '@file1.dmsf_file_revisions.count' do diff --git a/test/integration/webdav/dmsf_webdav_options_test.rb b/test/integration/webdav/dmsf_webdav_options_test.rb index e02be686..7f438978 100644 --- a/test/integration/webdav/dmsf_webdav_options_test.rb +++ b/test/integration/webdav/dmsf_webdav_options_test.rb @@ -21,8 +21,6 @@ require File.expand_path('../../../test_helper', __FILE__) # WebDAV OPTIONS tests class DmsfWebdavOptionsTest < RedmineDmsf::Test::IntegrationTest - fixtures :dmsf_folders - def test_options_requires_no_authentication_for_root_level process :options, '/dmsf/webdav' assert_response :success diff --git a/test/integration/webdav/dmsf_webdav_post_test.rb b/test/integration/webdav/dmsf_webdav_post_test.rb index 37071a42..0c00fbc5 100644 --- a/test/integration/webdav/dmsf_webdav_post_test.rb +++ b/test/integration/webdav/dmsf_webdav_post_test.rb @@ -21,7 +21,6 @@ require File.expand_path('../../../test_helper', __FILE__) # WebDAV POST tests class DmsfWebdavPostTest < RedmineDmsf::Test::IntegrationTest - # Test that any post request is authenticated def test_post_request_authenticated post '/dmsf/webdav/' assert_response :unauthorized diff --git a/test/integration/webdav/dmsf_webdav_propfind_test.rb b/test/integration/webdav/dmsf_webdav_propfind_test.rb index 18af9221..5e5ceb30 100644 --- a/test/integration/webdav/dmsf_webdav_propfind_test.rb +++ b/test/integration/webdav/dmsf_webdav_propfind_test.rb @@ -22,8 +22,6 @@ require 'uri' # WebDAV PROPFIND tests class DmsfWebdavPropfindTest < RedmineDmsf::Test::IntegrationTest - fixtures :dmsf_folders, :dmsf_files, :dmsf_file_revisions - def test_propfind_denied_for_anonymous process :propfind, '/dmsf/webdav/', params: nil, headers: @anonymous.merge!({ HTTP_DEPTH: '0' }) assert_response :unauthorized diff --git a/test/integration/webdav/dmsf_webdav_put_test.rb b/test/integration/webdav/dmsf_webdav_put_test.rb index 38de9c66..34834ab3 100644 --- a/test/integration/webdav/dmsf_webdav_put_test.rb +++ b/test/integration/webdav/dmsf_webdav_put_test.rb @@ -22,8 +22,6 @@ require 'fileutils' # WebDAV PUT tests class DmsfWebdavPutTest < RedmineDmsf::Test::IntegrationTest - fixtures :dmsf_folders, :dmsf_files, :dmsf_file_revisions, :custom_fields, :custom_values - def setup super @cv22 = CustomValue.find(22) diff --git a/test/integration/webdav/dmsf_webdav_unlock_test.rb b/test/integration/webdav/dmsf_webdav_unlock_test.rb index be5e5cbc..d8ab4564 100644 --- a/test/integration/webdav/dmsf_webdav_unlock_test.rb +++ b/test/integration/webdav/dmsf_webdav_unlock_test.rb @@ -22,8 +22,6 @@ require 'fileutils' # WebDAV UNLOCK tests class DmsfWebdavUnlockTest < RedmineDmsf::Test::IntegrationTest - fixtures :dmsf_folders, :dmsf_files, :dmsf_file_revisions, :dmsf_locks - def test_unlock_file log_user 'admin', 'admin' l = @file2.locks.first diff --git a/test/integration_test.rb b/test/integration_test.rb index 0795864b..38404b44 100644 --- a/test/integration_test.rb +++ b/test/integration_test.rb @@ -21,7 +21,16 @@ module RedmineDmsf module Test # Integration test class IntegrationTest < Redmine::IntegrationTest - fixtures :users, :email_addresses, :projects, :roles, :members, :member_roles + def initialize(name) + super(name) + # Load all plugin's fixtures + dir = File.join(File.dirname(__FILE__), 'fixtures') + ext = '.yml' + Dir.glob("#{dir}/**/*#{ext}").each do |file| + fixture = File.basename(file, ext) + ActiveRecord::FixtureSet.create_fixtures dir, fixture + end + end def setup @admin = credentials('admin', 'admin') @@ -71,19 +80,6 @@ module RedmineDmsf Rails.logger.error e.message end - def self.fixtures(*table_names) - dir = File.join(File.dirname(__FILE__), 'fixtures') - redmine_table_names = [] - table_names.each do |x| - if File.exist?(File.join(dir, "#{x}.yml")) - ActiveRecord::FixtureSet.create_fixtures(dir, x) - else - redmine_table_names << x - end - end - super(redmine_table_names) if redmine_table_names.any? - end - protected def check_headers_exist diff --git a/test/test_case.rb b/test/test_case.rb index 00fff643..b44c3463 100644 --- a/test/test_case.rb +++ b/test/test_case.rb @@ -21,22 +21,15 @@ module RedmineDmsf module Test # Test case class TestCase < ActionDispatch::IntegrationTest - fixtures :users, :email_addresses, :projects, :roles, :members, :member_roles - - # 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) + def initialize(name) + super(name) + # Load all plugin's fixtures dir = File.join(File.dirname(__FILE__), 'fixtures') - redmine_table_names = [] - table_names.each do |x| - if File.exist?(File.join(dir, "#{x}.yml")) - ActiveRecord::FixtureSet.create_fixtures(dir, x) - else - redmine_table_names << x - end + ext = '.yml' + Dir.glob("#{dir}/**/*#{ext}").each do |file| + fixture = File.basename(file, ext) + ActiveRecord::FixtureSet.create_fixtures dir, fixture end - super(redmine_table_names) if redmine_table_names.any? end def setup diff --git a/test/unit/custom_field_dmsf_file_format_test.rb b/test/unit/custom_field_dmsf_file_format_test.rb index 2a471ff7..a02ff337 100644 --- a/test/unit/custom_field_dmsf_file_format_test.rb +++ b/test/unit/custom_field_dmsf_file_format_test.rb @@ -21,7 +21,6 @@ require File.expand_path('../../test_helper', __FILE__) # File revision tests class CustomFieldDmsfFileFormatTest < RedmineDmsf::Test::UnitTest - fixtures :custom_fields, :projects, :issues, :trackers def setup super User.current = @jsmith diff --git a/test/unit/dmsf_file_revision_test.rb b/test/unit/dmsf_file_revision_test.rb index 1ed4f03d..1f8eba09 100644 --- a/test/unit/dmsf_file_revision_test.rb +++ b/test/unit/dmsf_file_revision_test.rb @@ -23,8 +23,6 @@ require File.expand_path('../../test_helper', __FILE__) class DmsfFileRevisionTest < RedmineDmsf::Test::UnitTest include Redmine::I18n - fixtures :dmsf_locks, :dmsf_workflows, :dmsf_folders, :dmsf_files, :dmsf_file_revisions - def setup super @revision1 = DmsfFileRevision.find 1 diff --git a/test/unit/dmsf_file_test.rb b/test/unit/dmsf_file_test.rb index 0495e80d..d293e1f7 100644 --- a/test/unit/dmsf_file_test.rb +++ b/test/unit/dmsf_file_test.rb @@ -21,9 +21,6 @@ require File.expand_path('../../test_helper', __FILE__) # File tests class DmsfFileTest < RedmineDmsf::Test::UnitTest - fixtures :dmsf_locks, :issues, :dmsf_links, :dmsf_workflows, :dmsf_workflow_steps, - :dmsf_workflow_step_assignments, :dmsf_folders, :dmsf_files, :dmsf_file_revisions - def setup super @issue1 = Issue.find 1 diff --git a/test/unit/dmsf_folder_permission_test.rb b/test/unit/dmsf_folder_permission_test.rb index cfd7110a..a56ba087 100644 --- a/test/unit/dmsf_folder_permission_test.rb +++ b/test/unit/dmsf_folder_permission_test.rb @@ -21,8 +21,6 @@ require File.expand_path('../../test_helper', __FILE__) # Folder permissions tests class DmsfFolderPermissionTest < RedmineDmsf::Test::UnitTest - fixtures :dmsf_folder_permissions, :dmsf_folders, :dmsf_files, :dmsf_file_revisions - def setup super @permission1 = DmsfFolderPermission.find 1 diff --git a/test/unit/dmsf_folder_test.rb b/test/unit/dmsf_folder_test.rb index 0fe6ba0a..3fe5e2f5 100644 --- a/test/unit/dmsf_folder_test.rb +++ b/test/unit/dmsf_folder_test.rb @@ -21,9 +21,6 @@ require File.expand_path('../../test_helper', __FILE__) # Folder tests class DmsfFolderTest < RedmineDmsf::Test::UnitTest - fixtures :dmsf_folder_permissions, :dmsf_locks, :dmsf_folders, :dmsf_files, :dmsf_file_revisions, - :dmsf_links - def setup super @link2 = DmsfLink.find 2 diff --git a/test/unit/dmsf_link_test.rb b/test/unit/dmsf_link_test.rb index fad945c9..50ad085e 100644 --- a/test/unit/dmsf_link_test.rb +++ b/test/unit/dmsf_link_test.rb @@ -21,8 +21,6 @@ require File.expand_path('../../test_helper', __FILE__) # Link tests class DmsfLinksTest < RedmineDmsf::Test::UnitTest - fixtures :dmsf_links, :dmsf_folders, :dmsf_files, :dmsf_file_revisions, :custom_fields, :custom_values - def test_create_folder_link folder_link = DmsfLink.new folder_link.target_project_id = @project1.id diff --git a/test/unit/dmsf_lock_test.rb b/test/unit/dmsf_lock_test.rb index 01f69e66..edceac8b 100644 --- a/test/unit/dmsf_lock_test.rb +++ b/test/unit/dmsf_lock_test.rb @@ -21,8 +21,6 @@ require File.expand_path('../../test_helper.rb', __FILE__) # Lock tests class DmsfLockTest < RedmineDmsf::Test::UnitTest - fixtures :dmsf_locks, :dmsf_folders, :dmsf_files, :dmsf_file_revisions - def setup super @lock = DmsfLock.find 1 diff --git a/test/unit/dmsf_mailer_test.rb b/test/unit/dmsf_mailer_test.rb index aeea3898..50ade2bc 100644 --- a/test/unit/dmsf_mailer_test.rb +++ b/test/unit/dmsf_mailer_test.rb @@ -23,8 +23,6 @@ require File.expand_path('../../test_helper', __FILE__) class DmsfMailerTest < RedmineDmsf::Test::UnitTest include Redmine::I18n - fixtures :dmsf_workflows, :dmsf_folders, :dmsf_files, :dmsf_file_revisions - def setup super @file1.notify_activate diff --git a/test/unit/dmsf_public_url_test.rb b/test/unit/dmsf_public_url_test.rb index 6e0976ff..1e7d3e40 100644 --- a/test/unit/dmsf_public_url_test.rb +++ b/test/unit/dmsf_public_url_test.rb @@ -21,8 +21,6 @@ require File.expand_path('../../test_helper', __FILE__) # Public URL tests class DmsfPublicUrlsTest < RedmineDmsf::Test::UnitTest - fixtures :dmsf_public_urls, :dmsf_folders, :dmsf_files, :dmsf_file_revisions - def setup super @dmsf_public_url1 = DmsfPublicUrl.find 1 diff --git a/test/unit/dmsf_query_test.rb b/test/unit/dmsf_query_test.rb index ffdfdacb..f7c081c2 100644 --- a/test/unit/dmsf_query_test.rb +++ b/test/unit/dmsf_query_test.rb @@ -21,8 +21,6 @@ require File.expand_path('../../test_helper', __FILE__) # Query tests class DmsfQueryTest < RedmineDmsf::Test::UnitTest - fixtures :queries, :dmsf_folders, :dmsf_files, :dmsf_file_revisions - def setup super @query401 = Query.find 401 diff --git a/test/unit/dmsf_upload_test.rb b/test/unit/dmsf_upload_test.rb index 89f551a3..e7e56e9c 100644 --- a/test/unit/dmsf_upload_test.rb +++ b/test/unit/dmsf_upload_test.rb @@ -21,8 +21,6 @@ require File.expand_path('../../test_helper', __FILE__) # Upload tests class DmsfUploadTest < RedmineDmsf::Test::UnitTest - fixtures :projects - def setup super @uploaded = { diff --git a/test/unit/dmsf_workflow_step_action_test.rb b/test/unit/dmsf_workflow_step_action_test.rb index 23a16197..0931c240 100644 --- a/test/unit/dmsf_workflow_step_action_test.rb +++ b/test/unit/dmsf_workflow_step_action_test.rb @@ -23,9 +23,6 @@ require File.expand_path('../../test_helper', __FILE__) class DmsfWorkflowStepActionTest < RedmineDmsf::Test::UnitTest include Redmine::I18n - fixtures :dmsf_workflow_steps, :dmsf_workflow_step_actions, :dmsf_folders, :dmsf_files, - :dmsf_file_revisions - def setup @wfsac1 = DmsfWorkflowStepAction.find 1 @wfsac2 = DmsfWorkflowStepAction.find 2 diff --git a/test/unit/dmsf_workflow_step_assignment_test.rb b/test/unit/dmsf_workflow_step_assignment_test.rb index 543ba154..b1104715 100644 --- a/test/unit/dmsf_workflow_step_assignment_test.rb +++ b/test/unit/dmsf_workflow_step_assignment_test.rb @@ -21,9 +21,6 @@ require File.expand_path('../../test_helper', __FILE__) # Workflow step assignment tests class WorkflowStepAssignmentTest < RedmineDmsf::Test::UnitTest - fixtures :dmsf_workflow_steps, :dmsf_workflow_step_assignments, :dmsf_folders, :dmsf_files, - :dmsf_file_revisions - def setup @wfsa1 = DmsfWorkflowStepAssignment.find 1 @wfsa2 = DmsfWorkflowStepAssignment.find 2 diff --git a/test/unit/dmsf_workflow_step_test.rb b/test/unit/dmsf_workflow_step_test.rb index 961a4147..647d1755 100644 --- a/test/unit/dmsf_workflow_step_test.rb +++ b/test/unit/dmsf_workflow_step_test.rb @@ -23,8 +23,6 @@ require File.expand_path('../../test_helper', __FILE__) class DmsfWorkflowStepTest < RedmineDmsf::Test::UnitTest include Redmine::I18n - fixtures :dmsf_workflows, :dmsf_workflow_steps, :dmsf_folders, :dmsf_files, :dmsf_file_revisions - def setup @wfs1 = DmsfWorkflowStep.find 1 @wfs2 = DmsfWorkflowStep.find 2 diff --git a/test/unit/dmsf_workflow_test.rb b/test/unit/dmsf_workflow_test.rb index 1b0a576b..9b00257b 100644 --- a/test/unit/dmsf_workflow_test.rb +++ b/test/unit/dmsf_workflow_test.rb @@ -21,9 +21,6 @@ require File.expand_path('../../test_helper', __FILE__) # Workflow tests class DmsfWorkflowTest < RedmineDmsf::Test::UnitTest - fixtures :dmsf_file_revisions, :dmsf_workflows, :dmsf_workflow_steps, :dmsf_workflow_step_assignments, - :dmsf_workflow_step_actions, :dmsf_folders, :dmsf_files, :dmsf_file_revisions - def setup super @wf1 = DmsfWorkflow.find 1 diff --git a/test/unit/issue_patch_test.rb b/test/unit/issue_patch_test.rb index 62eec31e..5149f017 100644 --- a/test/unit/issue_patch_test.rb +++ b/test/unit/issue_patch_test.rb @@ -21,8 +21,6 @@ require File.expand_path('../../test_helper', __FILE__) # Issue tests class IssuePatchTest < RedmineDmsf::Test::UnitTest - fixtures :issues, :dmsf_folders, :dmsf_files, :dmsf_file_revisions - def setup @issue1 = Issue.find 1 end diff --git a/test/unit/lib/redmine_dmsf/dmsf_macros_test.rb b/test/unit/lib/redmine_dmsf/dmsf_macros_test.rb index 207ab983..e76969ea 100644 --- a/test/unit/lib/redmine_dmsf/dmsf_macros_test.rb +++ b/test/unit/lib/redmine_dmsf/dmsf_macros_test.rb @@ -21,8 +21,6 @@ require File.expand_path('../../../../test_helper', __FILE__) # Macros tests class DmsfMacrosTest < RedmineDmsf::Test::HelperTest - fixtures :dmsf_folders, :dmsf_files, :dmsf_file_revisions - # Mock view context for macros class DmsfView include ApplicationHelper diff --git a/test/unit/lib/redmine_dmsf/dmsf_zip_test.rb b/test/unit/lib/redmine_dmsf/dmsf_zip_test.rb index 5c177583..8f72de4d 100644 --- a/test/unit/lib/redmine_dmsf/dmsf_zip_test.rb +++ b/test/unit/lib/redmine_dmsf/dmsf_zip_test.rb @@ -22,7 +22,6 @@ require File.expand_path('../../../../../lib/redmine_dmsf/dmsf_zip', __FILE__) # Plugin tests class DmsfZipTest < RedmineDmsf::Test::HelperTest - fixtures :dmsf_folders, :dmsf_files, :dmsf_file_revisions, :attachments def setup @zip = RedmineDmsf::DmsfZip::Zip.new diff --git a/test/unit/project_patch_test.rb b/test/unit/project_patch_test.rb index 9b5a792a..49060d9d 100644 --- a/test/unit/project_patch_test.rb +++ b/test/unit/project_patch_test.rb @@ -21,8 +21,6 @@ require File.expand_path('../../test_helper', __FILE__) # project tests class ProjectPatchTest < RedmineDmsf::Test::UnitTest - fixtures :dmsf_links, :dmsf_workflows, :dmsf_locks, :dmsf_folders, :dmsf_files, :dmsf_file_revisions - def test_project_has_dmsf_files assert @project1.respond_to?(:dmsf_files) end diff --git a/test/unit/user_patch_test.rb b/test/unit/user_patch_test.rb index 1ddad4f1..310092be 100644 --- a/test/unit/user_patch_test.rb +++ b/test/unit/user_patch_test.rb @@ -21,10 +21,6 @@ require File.expand_path('../../test_helper', __FILE__) # User tests class UserPatchTest < RedmineDmsf::Test::UnitTest - fixtures :dmsf_links, :dmsf_locks, :dmsf_workflows, :dmsf_workflow_steps, - :dmsf_workflow_step_assignments, :dmsf_workflow_step_actions, :dmsf_folders, - :dmsf_files, :dmsf_file_revisions, :custom_fields, :custom_values - def test_remove_dmsf_references id = @jsmith.id @jsmith.destroy diff --git a/test/unit/user_preference_patch_test.rb b/test/unit/user_preference_patch_test.rb index d233bb99..bbfdad45 100644 --- a/test/unit/user_preference_patch_test.rb +++ b/test/unit/user_preference_patch_test.rb @@ -21,8 +21,6 @@ require File.expand_path('../../test_helper', __FILE__) # User preference tests class UserPreferencePatchTest < RedmineDmsf::Test::UnitTest - fixtures :dmsf_folders, :dmsf_files, :dmsf_file_revisions - def test_user_preference_has_dmsf_attachments_upload_choice assert @jsmith.pref.respond_to?(:dmsf_attachments_upload_choice) end diff --git a/test/unit_test.rb b/test/unit_test.rb index 488d1e41..cf7f24aa 100644 --- a/test/unit_test.rb +++ b/test/unit_test.rb @@ -21,7 +21,16 @@ module RedmineDmsf module Test # Unit test class UnitTest < ActiveSupport::TestCase - fixtures :users, :email_addresses, :projects, :roles, :members, :member_roles + def initialize(name) + super(name) + # Load all plugin's fixtures + dir = File.join(File.dirname(__FILE__), 'fixtures') + ext = '.yml' + Dir.glob("#{dir}/**/*#{ext}").each do |file| + fixture = File.basename(file, ext) + ActiveRecord::FixtureSet.create_fixtures dir, fixture + end + end def setup @admin = User.find_by(login: 'admin') @@ -71,22 +80,6 @@ module RedmineDmsf Rails.logger.error e.message end - # 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') - redmine_table_names = [] - table_names.each do |x| - if File.exist?(File.join(dir, "#{x}.yml")) - ActiveRecord::FixtureSet.create_fixtures(dir, x) - else - redmine_table_names << x - end - end - super(redmine_table_names) if redmine_table_names.any? - end - protected def last_email