diff --git a/.github/workflows/rubyonrails.yml b/.github/workflows/rubyonrails.yml index 45b6bf78..250f572c 100644 --- a/.github/workflows/rubyonrails.yml +++ b/.github/workflows/rubyonrails.yml @@ -84,7 +84,7 @@ jobs: sudo apt-get install -y litmus libreoffice - name: Clone Redmine # Get the latest stable Redmine - run: svn export http://svn.redmine.org/redmine/branches/5.0-stable/ /opt/redmine + run: svn export http://svn.redmine.org/redmine/branches/5.1-stable/ /opt/redmine - name: Checkout code uses: actions/checkout@v3 - name: Link the plugin @@ -95,7 +95,7 @@ jobs: uses: ruby/setup-ruby@0a29871fe2b0200a17a4497bae54fe5df0d973aa # v1.115.3 with: bundler-cache: true - ruby-version: '3.0' + ruby-version: '3.1' - name: Setup database # Create the database run: | diff --git a/.rubocop.yml b/.rubocop.yml index 15b064ef..b7a50872 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -17,7 +17,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. AllCops: - TargetRubyVersion: 2.7 + TargetRubyVersion: 3.1 TargetRailsVersion: 6.1 SuggestExtensions: false @@ -41,6 +41,9 @@ Lint/ScriptPermission: Exclude: - extra/xapian_indexer.rb +Naming/BlockForwarding: + EnforcedStyle: explicit + Metrics/AbcSize: Enabled: false @@ -72,6 +75,17 @@ Naming/AccessorMethodName: Exclude: - lib/dav4rack/resource.rb +Style/HashSyntax: + EnforcedShorthandSyntax: either + +Style/ZeroLengthPredicate: + Exclude: + - lib/redmine_dmsf/webdav/dmsf_resource.rb + +Rails/DangerousColumnNames: + Exclude: + - db/migrate/20170330131901_create_dmsf_folder_permissions.rb + Rails/DynamicFindBy: AllowedMethods: - find_by_token diff --git a/README.md b/README.md index 38e42b38..e12ebc6d 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Features Dependencies ------------ - * Redmine 5.0.0 or higher + * Redmine 5..0 or higher ### Full-text search (optional) diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index 83a08b0b..ba48fc89 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -512,8 +512,6 @@ class DmsfController < ApplicationController } @back_url = params[:back_url] render action: 'email_entries' - rescue StandardError - raise ensure zip&.close end @@ -541,8 +539,6 @@ class DmsfController < ApplicationController type: 'application/zip', disposition: 'attachment' ) - rescue StandardError - raise ensure zip&.close end diff --git a/app/controllers/dmsf_workflows_controller.rb b/app/controllers/dmsf_workflows_controller.rb index b5b8d1a4..d14447eb 100644 --- a/app/controllers/dmsf_workflows_controller.rb +++ b/app/controllers/dmsf_workflows_controller.rb @@ -275,10 +275,6 @@ class DmsfWorkflowsController < ApplicationController end end - def edit - redirect_to dmsf_workflow_path(@dmsf_workflow) - end - def new @dmsf_workflow = DmsfWorkflow.new # Reload @@ -291,6 +287,10 @@ class DmsfWorkflowsController < ApplicationController render layout: !request.xhr? end + def edit + redirect_to dmsf_workflow_path(@dmsf_workflow) + end + def create if params[:dmsf_workflow] if params[:dmsf_workflow][:id].to_i.positive? @@ -399,7 +399,7 @@ class DmsfWorkflowsController < ApplicationController def remove_step if request.delete? DmsfWorkflowStep.where(dmsf_workflow_id: @dmsf_workflow.id, step: params[:step]).find_each do |ws| - @dmsf_workflow.dmsf_workflow_steps.delete(ws) + @dmsf_workflow.dmsf_workflow_steps.delete ws end @dmsf_workflow.dmsf_workflow_steps.each do |ws| n = ws.step.to_i diff --git a/app/helpers/dmsf_helper.rb b/app/helpers/dmsf_helper.rb index 01ff35a7..8b2e30d1 100644 --- a/app/helpers/dmsf_helper.rb +++ b/app/helpers/dmsf_helper.rb @@ -37,7 +37,7 @@ module DmsfHelper def self.temp_filename(filename) filename = sanitize_filename(filename) timestamp = DateTime.current.strftime('%y%m%d%H%M%S') - timestamp.succ! while File.exist?(Rails.root.join("tmp/#{timestamp}_#{filename}")) + timestamp.succ! while Rails.root.join("tmp/#{timestamp}_#{filename}").exist? "#{timestamp}_#{filename}" end @@ -47,7 +47,7 @@ module DmsfHelper # Replace all non alphanumeric, hyphens or periods with underscore just_filename.gsub!(/[^\w.\-]/, '_') # Keep the extension if any - if !(/^[a-zA-Z0-9_.\-]*$/).match?(just_filename) && just_filename =~ /(.[a-zA-Z0-9]+)$/ + if !/^[a-zA-Z0-9_.\-]*$/.match?(just_filename) && just_filename =~ /(.[a-zA-Z0-9]+)$/ extension = Regexp.last_match(1) just_filename = Digest::SHA256.hexdigest(just_filename) << extension end diff --git a/app/helpers/dmsf_upload_helper.rb b/app/helpers/dmsf_upload_helper.rb index 45c1d479..bfa3e650 100644 --- a/app/helpers/dmsf_upload_helper.rb +++ b/app/helpers/dmsf_upload_helper.rb @@ -156,7 +156,7 @@ module DmsfUploadHelper end if failed_uploads.present? && controller controller.flash[:warning] = l(:warning_some_files_were_not_committed, - files: failed_uploads.map { |u| u['name'] }.join(', ')) + files: failed_uploads.pluck(:name).join(', ')) end [files, failed_uploads] end diff --git a/app/helpers/dmsf_workflows_helper.rb b/app/helpers/dmsf_workflows_helper.rb index 04833153..8aa0da62 100644 --- a/app/helpers/dmsf_workflows_helper.rb +++ b/app/helpers/dmsf_workflows_helper.rb @@ -62,7 +62,7 @@ module DmsfWorkflowsHelper def dmsf_workflows_for_select(project, dmsf_workflow_id) options = [['', -1]] - DmsfWorkflow.active.sorted.where(['project_id = ? OR project_id IS NULL', project.id]).each do |wf| + DmsfWorkflow.active.sorted.where(['project_id = ? OR project_id IS NULL', project.id]).find_each do |wf| options << if wf.project_id [wf.name, wf.id] else @@ -74,7 +74,7 @@ module DmsfWorkflowsHelper def dmsf_all_workflows_for_select(dmsf_workflow_id) options = [['', 0]] - DmsfWorkflow.active.sorted.all.each do |wf| + DmsfWorkflow.active.sorted.find_each do |wf| if wf.project_id prj = Project.find_by(id: wf.project_id) if User.current.allowed_to?(:manage_workflows, prj) diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb index fb3c3a12..69afae5c 100644 --- a/app/models/dmsf_file.rb +++ b/app/models/dmsf_file.rb @@ -194,7 +194,7 @@ class DmsfFile < ApplicationRecord end def workflow - last_revision ? last_revision.workflow : nil + last_revision&.workflow end def size @@ -430,8 +430,8 @@ class DmsfFile < ApplicationRecord dmsf_attrs = filename.scan(%r{^([^/]+/[^_]+)_(\d+)_(.*)$}) id_attribute = 0 id_attribute = dmsf_attrs[0][1] if dmsf_attrs.length.positive? - next if dmsf_attrs.length.zero? || id_attribute.to_i.zero? - next unless results.select { |f| f.id.to_s == id_attribute }.empty? + next if dmsf_attrs.empty? || id_attribute.to_i.zero? + next unless results.none? { |f| f.id.to_s == id_attribute } dmsf_file = DmsfFile.visible.where(limit_options).find_by(id: id_attribute) diff --git a/app/models/dmsf_file_revision.rb b/app/models/dmsf_file_revision.rb index 83ef89b0..eb6f356f 100644 --- a/app/models/dmsf_file_revision.rb +++ b/app/models/dmsf_file_revision.rb @@ -177,7 +177,7 @@ class DmsfFileRevision < ApplicationRecord def disk_file(search_if_not_exists: true) path = storage_base_path begin - FileUtils.mkdir_p(path) unless File.exist?(path) + FileUtils.mkdir_p(path) rescue StandardError => e Rails.logger.error e.message end diff --git a/app/models/dmsf_folder.rb b/app/models/dmsf_folder.rb index 15baadc9..a4b31042 100644 --- a/app/models/dmsf_folder.rb +++ b/app/models/dmsf_folder.rb @@ -124,13 +124,13 @@ class DmsfFolder < ApplicationRecord if folder.dmsf_folder_permissions.any? role_ids = User.current.roles_for_project(folder.project).map(&:id) role_permission_ids = folder.dmsf_folder_permissions.roles.map(&:object_id) - return true if (role_ids & role_permission_ids).any? + return true if role_ids.intersect?(role_permission_ids) principal_ids = folder.dmsf_folder_permissions.users.map(&:object_id) return true if principal_ids.include?(User.current.id) user_group_ids = User.current.groups.map(&:id) - (principal_ids & user_group_ids).any? + principal_ids.intersect?(user_group_ids) else DmsfFolder.permissions? folder.dmsf_folder, allow_system: allow_system, file: file end @@ -511,7 +511,7 @@ class DmsfFolder < ApplicationRecord save end - ALL_INVALID_CHARACTERS = /[#{INVALID_CHARACTERS}]/.freeze + ALL_INVALID_CHARACTERS = /[#{INVALID_CHARACTERS}]/ def self.get_valid_title(title) # 1. Invalid characters are replaced with dots. # 2. Two or more dots in a row are replaced with a single dot. diff --git a/app/validators/dmsf_file_name_validator.rb b/app/validators/dmsf_file_name_validator.rb index 7b5b193f..e28a0fed 100644 --- a/app/validators/dmsf_file_name_validator.rb +++ b/app/validators/dmsf_file_name_validator.rb @@ -21,7 +21,7 @@ # File name validator class DmsfFileNameValidator < ActiveModel::EachValidator - ALL_INVALID_CHARACTERS = /\A[^#{DmsfFolder::INVALID_CHARACTERS}]*\z/.freeze + ALL_INVALID_CHARACTERS = /\A[^#{DmsfFolder::INVALID_CHARACTERS}]*\z/ def validate_each(record, attribute, value) record.errors.add attribute, :error_contains_invalid_character unless ALL_INVALID_CHARACTERS.match?(value) diff --git a/db/migrate/01_create_hierarchy.rb b/db/migrate/01_create_hierarchy.rb index f9cb2351..0a7dfcaf 100644 --- a/db/migrate/01_create_hierarchy.rb +++ b/db/migrate/01_create_hierarchy.rb @@ -69,7 +69,7 @@ class CreateHierarchy < ActiveRecord::Migration[4.2] create_table :dmsf_user_prefs do |t| t.references :project, null: false t.references :user, null: false - t.boolean :email_notify + t.boolean :email_notify, null: false, default: false t.timestamps end end diff --git a/db/migrate/04_dmsf_0_9_0.rb b/db/migrate/04_dmsf_0_9_0.rb index 113aa442..86e67c20 100644 --- a/db/migrate/04_dmsf_0_9_0.rb +++ b/db/migrate/04_dmsf_0_9_0.rb @@ -22,7 +22,7 @@ # Add column class Dmsf090 < ActiveRecord::Migration[4.2] def up - add_column :members, :dmsf_mail_notification, :boolean + add_column :members, :dmsf_mail_notification, :boolean, null: false, default: false drop_table :dmsf_user_prefs end @@ -31,7 +31,7 @@ class Dmsf090 < ActiveRecord::Migration[4.2] create_table :dmsf_user_prefs do |t| t.references :project, null: false t.references :user, null: false - t.boolean :email_notify + t.boolean :email_notify, null: false, default: false t.timestamps end end diff --git a/db/migrate/07_dmsf_1_4_4.rb b/db/migrate/07_dmsf_1_4_4.rb index c91d4649..5e3849a6 100644 --- a/db/migrate/07_dmsf_1_4_4.rb +++ b/db/migrate/07_dmsf_1_4_4.rb @@ -24,6 +24,7 @@ require 'uuidtools' # Locking class Dmsf144 < ActiveRecord::Migration[4.2] + # File lock class DmsfFileLock < ApplicationRecord belongs_to :file, class_name: 'DmsfFile', foreign_key: 'dmsf_file_id' belongs_to :user diff --git a/db/migrate/20130819013955_update_projects.rb b/db/migrate/20130819013955_update_projects.rb index 72a85af8..54907243 100644 --- a/db/migrate/20130819013955_update_projects.rb +++ b/db/migrate/20130819013955_update_projects.rb @@ -22,6 +22,6 @@ class UpdateProjects < ActiveRecord::Migration[4.2] def change # DMSF - project's root folder notification - add_column :projects, :dmsf_notification, :boolean + add_column :projects, :dmsf_notification, :boolean, null: false, default: false end end diff --git a/db/migrate/20160215125801_approval_workflow_status.rb b/db/migrate/20160215125801_approval_workflow_status.rb index cee5130b..a44e0b31 100644 --- a/db/migrate/20160215125801_approval_workflow_status.rb +++ b/db/migrate/20160215125801_approval_workflow_status.rb @@ -24,7 +24,7 @@ class ApprovalWorkflowStatus < ActiveRecord::Migration[4.2] add_column :dmsf_workflows, :status, :integer, null: false, default: DmsfWorkflow::STATUS_ACTIVE DmsfWorkflow.reset_column_information - DmsfWorkflow.all.each { |wf| wf.update_attribute(:status, DmsfWorkflow::STATUS_ACTIVE) } + DmsfWorkflow.find_each { |wf| wf.update_attribute(:status, DmsfWorkflow::STATUS_ACTIVE) } end def down diff --git a/db/migrate/20160222140401_approval_workflow_std_fields.rb b/db/migrate/20160222140401_approval_workflow_std_fields.rb index eed89a85..c71531bd 100644 --- a/db/migrate/20160222140401_approval_workflow_std_fields.rb +++ b/db/migrate/20160222140401_approval_workflow_std_fields.rb @@ -28,7 +28,7 @@ class ApprovalWorkflowStdFields < ActiveRecord::Migration[4.2] end DmsfWorkflow.reset_column_information # Set updated_on - DmsfWorkflow.all.each(&:touch) + DmsfWorkflow.find_each(&:touch) # Set created_on and author_id admin_ids = User.active.where(admin: true).limit(1).ids DmsfWorkflow.update_all ['created_on = updated_on, author_id = ?', admin_ids.first] diff --git a/db/migrate/20170217141601_add_dmsf_not_inheritable_to_custom_fields.rb b/db/migrate/20170217141601_add_dmsf_not_inheritable_to_custom_fields.rb index 30744dbf..448586d1 100644 --- a/db/migrate/20170217141601_add_dmsf_not_inheritable_to_custom_fields.rb +++ b/db/migrate/20170217141601_add_dmsf_not_inheritable_to_custom_fields.rb @@ -21,6 +21,7 @@ # Add column class AddDmsfNotInheritableToCustomFields < ActiveRecord::Migration[4.2] def change - add_column :custom_fields, :dmsf_not_inheritable, :boolean, null: true + add_column :custom_fields, :dmsf_not_inheritable, :boolean, + null: false, default: false end end diff --git a/db/migrate/20170422104901_migrate_documents.rb b/db/migrate/20170422104901_migrate_documents.rb index 849c7525..21bd4f5f 100644 --- a/db/migrate/20170422104901_migrate_documents.rb +++ b/db/migrate/20170422104901_migrate_documents.rb @@ -38,7 +38,7 @@ class MigrateDocuments < ActiveRecord::Migration[4.2] begin FileUtils.mv origin, target, verbose: true folder = storage_base_path(dmsf_file_revision) - Dir.rmdir(folder) if folder && (Dir.entries(folder).size == 2) + Dir.rmdir(folder) if folder && Dir.empty?(folder) rescue StandardError => e msg = "DmsfFileRevisions ID #{dmsf_file_revision.id}: #{e.message}" say msg @@ -91,7 +91,7 @@ class MigrateDocuments < ActiveRecord::Migration[4.2] begin FileUtils.mv origin, target, verbose: true folder = dmsf_file_revision.storage_base_path - Dir.rmdir(folder) if folder && (Dir.entries(folder).size == 2) + Dir.rmdir(folder) if folder && Dir.empty?(folder) rescue StandardError => e msg = "DmsfFileRevisions ID #{dmsf_file_revision.id}: #{e.message}" say msg @@ -136,7 +136,7 @@ class MigrateDocuments < ActiveRecord::Migration[4.2] def disk_file(dmsf_file_revision) path = storage_base_path(dmsf_file_revision) if path - FileUtils.mkdir_p(path) unless File.exist?(path) + FileUtils.mkdir_p(path) return "#{path}/#{dmsf_file_revision.disk_filename}" end nil diff --git a/lib/redmine_dmsf/field_formats/dmsf_file_revision_format.rb b/lib/redmine_dmsf/field_formats/dmsf_file_revision_format.rb index 59e54ccd..91f2602f 100644 --- a/lib/redmine_dmsf/field_formats/dmsf_file_revision_format.rb +++ b/lib/redmine_dmsf/field_formats/dmsf_file_revision_format.rb @@ -63,7 +63,7 @@ module RedmineDmsf options = [] if object&.project files = object.project.dmsf_files.visible.to_a - DmsfFolder.visible(false).where(project_id: object.project.id).each do |f| + DmsfFolder.visible(false).where(project_id: object.project.id).find_each do |f| files += f.dmsf_files.visible.to_a end files.sort! { |a, b| a.title.casecmp(b.title) } diff --git a/lib/redmine_dmsf/hooks/views/issue_view_hooks.rb b/lib/redmine_dmsf/hooks/views/issue_view_hooks.rb index a758513e..1bbd4641 100644 --- a/lib/redmine_dmsf/hooks/views/issue_view_hooks.rb +++ b/lib/redmine_dmsf/hooks/views/issue_view_hooks.rb @@ -100,8 +100,8 @@ module RedmineDmsf links = get_links(context[:container]) return unless links.present? && Setting.thumbnails_enabled? - images = links.map { |x| x[0] }.select(&:image?) - return 'yes' if images.any? + images = links.pluck(0).select(&:image?) + 'yes' if images.any? end def view_issues_edit_notes_bottom_style(context = {}) @@ -142,7 +142,7 @@ module RedmineDmsf links << [dmsf_file, dmsf_link, dmsf_link.created_at] if dmsf_file&.last_revision end # Sort by 'create_at' - links.sort! { |x, y| x[2] <=> y[2] } + links.sort_by! { |a| a[2] } end links end diff --git a/lib/redmine_dmsf/patches/project_patch.rb b/lib/redmine_dmsf/patches/project_patch.rb index a2d89b09..fe6787c5 100644 --- a/lib/redmine_dmsf/patches/project_patch.rb +++ b/lib/redmine_dmsf/patches/project_patch.rb @@ -35,7 +35,7 @@ module RedmineDmsf def copy(project, options = {}) super(project, options) - project = project.is_a?(Project) ? project : Project.find(project) + project = Project.find(project) unless project.is_a?(Project) to_be_copied = %w[dmsf dmsf_folders approval_workflows] to_be_copied &= Array.wrap(options[:only]) if options[:only] if save diff --git a/lib/redmine_dmsf/plugin.rb b/lib/redmine_dmsf/plugin.rb index e3037853..e6256ee7 100644 --- a/lib/redmine_dmsf/plugin.rb +++ b/lib/redmine_dmsf/plugin.rb @@ -25,7 +25,7 @@ module RedmineDmsf # Checking physical presence of the plugin as Redmine::Plugin.installed? may return false due to alphabetical # registering of available plugins. def self.present?(id) - Dir.exist? Rails.root.join('plugins', id.to_s) + Rails.root.join('plugins', id.to_s).exist? end # Return true if a plugin that overrides Redmine::Notifiable and use the deprecated method alias_method_chain is diff --git a/lib/redmine_dmsf/webdav/base_resource.rb b/lib/redmine_dmsf/webdav/base_resource.rb index ec5cfe12..cbcab464 100644 --- a/lib/redmine_dmsf/webdav/base_resource.rb +++ b/lib/redmine_dmsf/webdav/base_resource.rb @@ -32,10 +32,10 @@ module RedmineDmsf DIR_FILE = %( - %s - %s - %s - %s + %s + %s + %s + %s ) diff --git a/lib/redmine_dmsf/webdav/resource_proxy.rb b/lib/redmine_dmsf/webdav/resource_proxy.rb index a0a3c8b8..1bb37b4f 100644 --- a/lib/redmine_dmsf/webdav/resource_proxy.rb +++ b/lib/redmine_dmsf/webdav/resource_proxy.rb @@ -204,7 +204,7 @@ module RedmineDmsf def get_resource_class(path) pinfo = path.split('/').drop(1) - return IndexResource if pinfo.length.zero? + return IndexResource if pinfo.empty? return ProjectResource if pinfo.length == 1 diff --git a/test/functional/dmsf_context_menus_controller_test.rb b/test/functional/dmsf_context_menus_controller_test.rb index e809a9bf..a85e84fd 100644 --- a/test/functional/dmsf_context_menus_controller_test.rb +++ b/test/functional/dmsf_context_menus_controller_test.rb @@ -24,7 +24,7 @@ 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 + fixtures :dmsf_folders, :dmsf_files, :dmsf_file_revisions, :dmsf_links, :dmsf_locks def setup super @@ -32,14 +32,13 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase @file_link6 = DmsfLink.find 6 @folder_link1 = DmsfLink.find 1 @url_link5 = DmsfLink.find 5 - User.current = nil - @request.session[:user_id] = @jsmith.id end def test_dmsf_file + post '/login', params: { username: 'jsmith', password: 'jsmith' } with_settings notified_events: ['dmsf_legacy_notifications'] do with_settings plugin_redmine_dmsf: { 'dmsf_webdav' => '1', 'dmsf_webdav_strategy' => 'WEBDAV_READ_WRITE' } do - get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + get '/projects/dmsf/context_menu', params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } assert_response :success assert_select 'a.icon-edit', text: l(:button_edit) assert_select 'a.icon-lock', text: l(:button_lock) @@ -53,9 +52,10 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase end def test_dmsf_file_locked + post '/login', params: { username: 'jsmith', password: 'jsmith' } with_settings notified_events: ['dmsf_legacy_notifications'] do with_settings plugin_redmine_dmsf: { 'dmsf_webdav' => '1', 'dmsf_webdav_strategy' => 'WEBDAV_READ_WRITE' } do - get :dmsf, params: { id: @file2.project.id, ids: ["file-#{@file2.id}"] } + get '/projects/dmsf/context_menu', params: { id: @file2.project.id, ids: ["file-#{@file2.id}"] } assert_response :success assert_select 'a.icon-edit.disabled', text: l(:button_edit) assert_select 'a.icon-unlock', text: l(:button_unlock) @@ -68,11 +68,11 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase end def test_dmsf_edit_file_locked_by_myself + post '/login', params: { username: 'jsmith', password: 'jsmith' } User.current = @jsmith @file1.lock! - User.current = nil with_settings plugin_redmine_dmsf: { 'dmsf_webdav' => '1', 'dmsf_webdav_strategy' => 'WEBDAV_READ_WRITE' } do - get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + get '/projects/dmsf/context_menu', params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } assert_select 'a.icon-unlock', text: l(:button_unlock) assert_select 'a.icon-unlock.disabled', text: l(:button_edit_content), count: 0 assert_select 'a.icon-file', text: l(:button_edit_content) @@ -81,22 +81,25 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase end def test_dmsf_file_locked_force_unlock_permission_off - get :dmsf, params: { id: @file2.project.id, ids: ["file-#{@file2.id}"] } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get '/projects/dmsf/context_menu', params: { id: @file2.project.id, ids: ["file-#{@file2.id}"] } assert_response :success assert_select 'a.icon-unlock.disabled', text: l(:button_unlock) end def test_dmsf_file_locked_force_unlock_permission_on + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_developer.add_permission! :force_file_unlock - get :dmsf, params: { id: @file2.project.id, ids: ["file-#{@file2.id}"] } + get '/projects/dmsf/context_menu', params: { id: @file2.project.id, ids: ["file-#{@file2.id}"] } assert_response :success assert_select 'a.icon-unlock.disabled', text: l(:button_unlock), count: 0 end def test_dmsf_file_notification_on + post '/login', params: { username: 'jsmith', password: 'jsmith' } @file1.notify_activate with_settings notified_events: ['dmsf_legacy_notifications'] do - get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + get '/projects/dmsf/context_menu', params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } assert_response :success assert_select 'a.icon-email', text: l(:label_notifications_off) assert_select 'a.icon-email-add', text: l(:label_notifications_on), count: 0 @@ -104,9 +107,10 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase end def test_dmsf_file_manipulation_permission_off + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :file_manipulation with_settings notified_events: ['dmsf_legacy_notifications'] do - get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + get '/projects/dmsf/context_menu', params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } assert_response :success assert_select 'a.icon-edit.disabled', text: l(:button_edit) assert_select 'a.icon-lock.disabled', text: l(:button_lock) @@ -116,8 +120,9 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase end def test_dmsf_file_manipulation_permission_on + post '/login', params: { username: 'jsmith', password: 'jsmith' } with_settings notified_events: ['dmsf_legacy_notifications'] do - get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + get '/projects/dmsf/context_menu', params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } assert_response :success assert_select 'a:not(icon-edit.disabled)', text: l(:button_edit) assert_select 'a:not(icon-lock.disabled)', text: l(:button_lock) @@ -127,75 +132,86 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase end def test_dmsf_file_email_permission_off + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :email_documents - get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + get '/projects/dmsf/context_menu', params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } assert_response :success assert_select 'a.icon-email.disabled', text: l(:field_mail) end def test_dmsf_file_email_permission_on + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :email_document - get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + get '/projects/dmsf/context_menu', params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } assert_response :success assert_select 'a:not(icon-email.disabled)', text: l(:field_mail) end def test_dmsf_file_delete_permission_off + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :file_manipulation - get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + get '/projects/dmsf/context_menu', params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } assert_response :success assert_select 'a.icon-del.disabled', text: l(:button_delete) end def test_dmsf_file_delete_permission_on - get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get '/projects/dmsf/context_menu', params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } assert_response :success assert_select 'a:not(icon-del.disabled)', text: l(:button_delete) assert_select 'a.icon-del', text: l(:button_delete) end def test_dmsf_file_edit_content + post '/login', params: { username: 'jsmith', password: 'jsmith' } with_settings plugin_redmine_dmsf: { 'dmsf_webdav' => '1', 'dmsf_webdav_strategy' => 'WEBDAV_READ_WRITE' } do - get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + get '/projects/dmsf/context_menu', params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } assert_response :success assert_select 'a.dmsf-icon-file', text: l(:button_edit_content) end end def test_dmsf_file_edit_content_webdav_disabled + post '/login', params: { username: 'jsmith', password: 'jsmith' } with_settings plugin_redmine_dmsf: { 'dmsf_webdav' => nil } do - get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + get '/projects/dmsf/context_menu', params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } assert_response :success assert_select 'a:not(dmsf-icon-file)' end end def test_dmsf_file_edit_content_webdav_readonly + post '/login', params: { username: 'jsmith', password: 'jsmith' } with_settings plugin_redmine_dmsf: { 'dmsf_webdav' => '1', 'dmsf_webdav_strategy' => 'WEBDAV_READ_ONLY' } do - get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + get '/projects/dmsf/context_menu', params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } assert_response :success assert_select 'a.dmsf-icon-file.disabled', text: l(:button_edit_content) end end def test_dmsf_file_watch - get :dmsf, params: { id: @file1.project, ids: ["file-#{@file1.id}"] } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get '/projects/dmsf/context_menu', params: { id: @file1.project, ids: ["file-#{@file1.id}"] } assert_response :success assert_select 'a.icon-fav-off', text: l(:button_watch) end def test_dmsf_file_unwatch + post '/login', params: { username: 'jsmith', password: 'jsmith' } @file1.add_watcher @jsmith - get :dmsf, params: { id: @file1.project, ids: ["file-#{@file1.id}"] } + get '/projects/dmsf/context_menu', params: { id: @file1.project, ids: ["file-#{@file1.id}"] } assert_response :success assert_select 'a.icon-fav', text: l(:button_unwatch) end def test_dmsf_file_link + post '/login', params: { username: 'jsmith', password: 'jsmith' } with_settings notified_events: ['dmsf_legacy_notifications'] do with_settings plugin_redmine_dmsf: { 'dmsf_webdav' => '1', 'dmsf_webdav_strategy' => 'WEBDAV_READ_WRITE' } do - get :dmsf, params: { id: @file_link6.project.id, folder_id: @file_link6.dmsf_folder, - ids: ["file-link-#{@file_link6.id}"] } + get '/projects/dmsf/context_menu', + params: { id: @file_link6.project.id, folder_id: @file_link6.dmsf_folder, + ids: ["file-link-#{@file_link6.id}"] } assert_response :success assert_select 'a.icon-edit', text: l(:button_edit) assert_select 'a.icon-lock', text: l(:button_lock) @@ -209,10 +225,12 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase end def test_dmsf_file_link_locked + post '/login', params: { username: 'jsmith', password: 'jsmith' } assert @file_link2.target_file.locked? with_settings notified_events: ['dmsf_legacy_notifications'] do - get :dmsf, params: { id: @file_link2.project.id, folder_id: @file_link2.dmsf_folder.id, - ids: ["file-link-#{@file_link2.id}"] } + get '/projects/dmsf/context_menu', + params: { id: @file_link2.project.id, folder_id: @file_link2.dmsf_folder.id, + ids: ["file-link-#{@file_link2.id}"] } assert_response :success assert_select 'a.icon-edit.disabled', text: l(:button_edit) assert_select 'a.icon-unlock', text: l(:button_unlock) @@ -223,14 +241,16 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase end def test_dmsf_url_link - get :dmsf, params: { id: @url_link5.project.id, ids: ["url-link-#{@url_link5.id}"] } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get :'/projects/dmsf/context_menu', params: { id: @url_link5.project.id, ids: ["url-link-#{@url_link5.id}"] } assert_response :success assert_select 'a.icon-del', text: l(:button_delete) end def test_dmsf_folder + post '/login', params: { username: 'jsmith', password: 'jsmith' } with_settings notified_events: ['dmsf_legacy_notifications'] do - get :dmsf, params: { id: @folder1.project.id, ids: ["folder-#{@folder1.id}"] } + get '/projects/dmsf/context_menu', params: { id: @folder1.project.id, ids: ["folder-#{@folder1.id}"] } assert_response :success assert_select 'a.icon-edit', text: l(:button_edit) assert_select 'a.icon-lock', text: l(:button_lock) @@ -243,9 +263,10 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase end def test_dmsf_folder_locked + post '/login', params: { username: 'jsmith', password: 'jsmith' } assert @folder5.locked? with_settings notified_events: ['dmsf_legacy_notifications'] do - get :dmsf, params: { id: @folder5.project.id, ids: ["folder-#{@folder5.id}"] } + get '/projects/dmsf/context_menu', params: { id: @folder5.project.id, ids: ["folder-#{@folder5.id}"] } assert_response :success assert_select 'a.icon-edit.disabled', text: l(:button_edit) assert_select 'a.icon-unlock', text: l(:button_unlock) @@ -256,26 +277,27 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase end def test_dmsf_folder_locked_force_unlock_permission_off - @request.session[:user_id] = @dlopper.id - get :dmsf, params: { id: @folder2.project.id, ids: ["folder-#{@folder2.id}"] } + post '/login', params: { username: 'dlopper', password: 'foo' } + get '/projects/dmsf/context_menu', params: { id: @folder2.project.id, ids: ["folder-#{@folder2.id}"] } assert_response :success # @folder2 is locked by @jsmith, therefore @dlopper can't unlock it assert_select 'a.icon-unlock.disabled', text: l(:button_unlock) end def test_dmsf_folder_locked_force_unlock_permission_om - @request.session[:user_id] = @dlopper.id + post '/login', params: { username: 'dlopper', password: 'foo' } @role_developer.add_permission! :force_file_unlock - get :dmsf, params: { id: @folder2.project.id, ids: ["folder-#{@folder2.id}"] } + get '/projects/dmsf/context_menu', params: { id: @folder2.project.id, ids: ["folder-#{@folder2.id}"] } assert_response :success # @folder2 is locked by @jsmith, but @dlopper can unlock it assert_select 'a.icon-unlock.disabled', text: l(:button_unlock), count: 0 end def test_dmsf_folder_notification_on + post '/login', params: { username: 'jsmith', password: 'jsmith' } @folder5.notify_activate with_settings notified_events: ['dmsf_legacy_notifications'] do - get :dmsf, params: { id: @folder5.project.id, ids: ["folder-#{@folder5.id}"] } + get '/projects/dmsf/context_menu', params: { id: @folder5.project.id, ids: ["folder-#{@folder5.id}"] } assert_response :success assert_select 'a.icon-email', text: l(:label_notifications_off) assert_select 'a.icon-email-add', text: l(:label_notifications_on), count: 0 @@ -283,9 +305,10 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase end def test_dmsf_folder_manipulation_permmissions_off + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :folder_manipulation with_settings notified_events: ['dmsf_legacy_notifications'] do - get :dmsf, params: { id: @folder1.project.id, ids: ["folder-#{@folder1.id}"] } + get '/projects/dmsf/context_menu', params: { id: @folder1.project.id, ids: ["folder-#{@folder1.id}"] } assert_response :success assert_select 'a.icon-edit.disabled', text: l(:button_edit) assert_select 'a.icon-lock.disabled', text: l(:button_lock) @@ -295,8 +318,9 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase end def test_dmsf_folder_manipulation_permmissions_on + post '/login', params: { username: 'jsmith', password: 'jsmith' } with_settings notified_events: ['dmsf_legacy_notifications'] do - get :dmsf, params: { id: @folder1.project.id, ids: ["folder-#{@folder1.id}"] } + get '/projects/dmsf/context_menu', params: { id: @folder1.project.id, ids: ["folder-#{@folder1.id}"] } assert_response :success assert_select 'a:not(icon-edit.disabled)', text: l(:button_edit) assert_select 'a:not(icon-lock.disabled)', text: l(:button_lock) @@ -306,34 +330,39 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase end def test_dmsf_folder_email_permmissions_off + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :email_documents - get :dmsf, params: { id: @folder5.project.id, ids: ["folder-#{@folder5.id}"] } + get '/projects/dmsf/context_menu', params: { id: @folder5.project.id, ids: ["folder-#{@folder5.id}"] } assert_response :success assert_select 'a.icon-email.disabled', text: l(:field_mail) end def test_dmsf_folder_email_permmissions_on - get :dmsf, params: { id: @folder5.project.id, ids: ["folder-#{@folder5.id}"] } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get '/projects/dmsf/context_menu', params: { id: @folder5.project.id, ids: ["folder-#{@folder5.id}"] } assert_response :success assert_select 'a:not(icon-email.disabled)', text: l(:field_mail) end def test_dmsf_folder_watch - get :dmsf, params: { id: @folder1.project, ids: ["folder-#{@folder1.id}"] } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get '/projects/dmsf/context_menu', params: { id: @folder1.project, ids: ["folder-#{@folder1.id}"] } assert_response :success assert_select 'a.icon-fav-off', text: l(:button_watch) end def test_dmsf_folder_unwatch + post '/login', params: { username: 'jsmith', password: 'jsmith' } @folder1.add_watcher @jsmith - get :dmsf, params: { id: @folder1.project, ids: ["folder-#{@folder1.id}"] } + get '/projects/dmsf/context_menu', params: { id: @folder1.project, ids: ["folder-#{@folder1.id}"] } assert_response :success assert_select 'a.icon-fav', text: l(:button_unwatch) end def test_dmsf_folder_link + post '/login', params: { username: 'jsmith', password: 'jsmith' } with_settings notified_events: ['dmsf_legacy_notifications'] do - get :dmsf, params: { id: @folder_link1.project.id, ids: ["folder-#{@folder_link1.id}"] } + get '/projects/dmsf/context_menu', params: { id: @folder_link1.project.id, ids: ["folder-#{@folder_link1.id}"] } assert_response :success assert_select 'a.icon-edit', text: l(:button_edit) assert_select 'a.icon-lock', text: l(:button_lock) @@ -345,9 +374,10 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase end def test_dmsf_folder_link_locked + post '/login', params: { username: 'jsmith', password: 'jsmith' } @folder_link1.target_folder.lock! with_settings notified_events: ['dmsf_legacy_notifications'] do - get :dmsf, params: { id: @folder_link1.project.id, ids: ["folder-#{@folder_link1.id}"] } + get '/projects/dmsf/context_menu', params: { id: @folder_link1.project.id, ids: ["folder-#{@folder_link1.id}"] } assert_response :success assert_select 'a.icon-edit.disabled', text: l(:button_edit) assert_select 'a.icon-unlock', text: l(:button_unlock) @@ -358,7 +388,8 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase end def test_dmsf_multiple - get :dmsf, params: { id: @project1.id, ids: ["folder-#{@folder1.id}", "file-#{@file1.id}"] } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get '/projects/dmsf/context_menu', params: { id: @project1.id, ids: ["folder-#{@folder1.id}", "file-#{@file1.id}"] } assert_response :success assert_select 'a.icon-edit', text: l(:button_edit), count: 0 assert_select 'a.icon-unlock', text: l(:button_unlock), count: 0 @@ -371,78 +402,90 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase end def test_dmsf_project_watch - get :dmsf, params: { ids: ["project-#{@project1.id}"] } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get '/projects/dmsf/context_menu', params: { ids: ["project-#{@project1.id}"] } assert_response :success assert_select 'a.icon-fav-off', text: l(:button_watch) end def test_dmsf_project_unwatch + post '/login', params: { username: 'jsmith', password: 'jsmith' } @project1.add_watcher @jsmith - get :dmsf, params: { ids: ["project-#{@project1.id}"] } + get '/projects/dmsf/context_menu', params: { ids: ["project-#{@project1.id}"] } assert_response :success assert_select 'a.icon-fav', text: l(:button_unwatch) end def test_trash_file - get :trash, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get "/projects/#{@file1.project.id}/dmsf/trash/context_menu", params: { ids: ["file-#{@file1.id}"] } assert_response :success assert_select 'a.icon-cancel', text: l(:title_restore) assert_select 'a.icon-del', text: l(:button_delete) end def test_trash_file_manipulation_permissions_off + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :file_delete @role_manager.remove_permission! :file_manipulation - get :trash, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + get "/projects/#{@file1.project.id}/dmsf/trash/context_menu", params: { ids: ["file-#{@file1.id}"] } assert_response :success assert_select 'a.icon-cancel.disabled', text: l(:title_restore) assert_select 'a.icon-del.disabled', text: l(:button_delete) end def test_trash_file_manipulation_permissions_on - get :trash, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get "/projects/#{@file1.project.id}/dmsf/trash/context_menu", params: { ids: ["file-#{@file1.id}"] } assert_response :success assert_select 'a:not(icon-cancel.disabled)', text: l(:title_restore) assert_select 'a:not(icon-del.disabled)', text: l(:button_delete) end def test_trash_file_delete_permissions_off + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :file_delete - get :trash, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + get "/projects/#{@file1.project.id}/dmsf/trash/context_menu", params: { ids: ["file-#{@file1.id}"] } assert_response :success assert_select 'a.icon-del.disabled', text: l(:button_delete) end def test_trash_file_delete_permissions_on - get :trash, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get "/projects/#{@file1.project.id}/dmsf/trash/context_menu", params: { ids: ["file-#{@file1.id}"] } assert_response :success assert_select 'a:not(icon-del.disabled)', text: l(:button_delete) end def test_trash_folder - get :trash, params: { id: @folder5.project.id, ids: ["folder-#{@folder5.id}"] } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get "/projects/#{@folder5.project.id}/dmsf/trash/context_menu", params: { ids: ["folder-#{@folder5.id}"] } assert_response :success assert_select 'a.icon-cancel', text: l(:title_restore) assert_select 'a.icon-del', text: l(:button_delete) end def test_trash_folder_manipulation_permissions_off + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :folder_manipulation - get :trash, params: { id: @folder1.project.id, ids: ["folder-#{@folder1.id}"] } + get "/projects/#{@folder1.project.id}/dmsf/trash/context_menu", params: { ids: ["folder-#{@folder1.id}"] } assert_response :success assert_select 'a.icon-cancel.disabled', text: l(:title_restore) assert_select 'a.icon-del.disabled', text: l(:button_delete) end def test_trash_folder_manipulation_permissions_on - get :trash, params: { id: @folder1.project.id, ids: ["folder-#{@folder1.id}"] } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get "/projects/#{@folder1.project.id}/dmsf/trash/context_menu", params: { ids: ["folder-#{@folder1.id}"] } assert_response :success assert_select 'a:not(icon-cancel.disabled)', text: l(:title_restore) assert_select 'a:not(icon-del.disabled)', text: l(:button_delete) end def test_trash_multiple - get :trash, params: { id: @project1.id, ids: ["file-#{@file1.id}", "folder-#{@folder1.id}"] } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get "/projects/#{@file1.project.id}/dmsf/trash/context_menu", + params: { ids: ["file-#{@file1.id}", "folder-#{@folder1.id}"] } assert_response :success assert_select 'a.icon-cancel', text: l(:title_restore) assert_select 'a.icon-del', text: l(:button_delete) diff --git a/test/functional/dmsf_controller_test.rb b/test/functional/dmsf_controller_test.rb index 85062d9b..03ae67e8 100644 --- a/test/functional/dmsf_controller_test.rb +++ b/test/functional/dmsf_controller_test.rb @@ -34,21 +34,21 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase @link1 = DmsfLink.find 1 @custom_field = CustomField.find 21 @custom_value = CustomValue.find 21 - User.current = nil - @request.session[:user_id] = @jsmith.id - default_url_options[:host] = 'http://example.com' + default_url_options[:host] = 'www.example.com' end def test_edit_folder_forbidden # Missing permissions + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :folder_manipulation - get :edit, params: { id: @project1, folder_id: @folder1 } + get "/projects/#{@project1.id}/dmsf/edit", params: { folder_id: @folder1 } assert_response :forbidden end def test_edit_folder_allowed # Permissions OK - get :edit, params: { id: @project1, folder_id: @folder1 } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get "/projects/#{@project1.id}/dmsf/edit", params: { folder_id: @folder1.id } assert_response :success # Custom fields assert_select 'label', { text: @custom_field.name } @@ -64,35 +64,42 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase end def test_edit_folder_redirection_to_the_parent_folder - post :save, params: { id: @project1, folder_id: @folder2.id, parent_id: @folder2.dmsf_folder.id, - dmsf_folder: { title: @folder2.title, description: @folder2.description } } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + post "/projects/#{@project1.id}/dmsf/save", + params: { folder_id: @folder2.id, parent_id: @folder2.dmsf_folder.id, + dmsf_folder: { title: @folder2.title, description: 'Updated folder' } } assert_redirected_to dmsf_folder_path(id: @project1, folder_id: @folder2.dmsf_folder.id) end def test_edit_folder_redirection_to_the_same_folder - post :save, params: { id: @project1, folder_id: @folder2.id, parent_id: @folder2.dmsf_folder.id, - dmsf_folder: { title: @folder2.title, description: @folder2.description, - redirect_to_folder_id: @folder2.id } } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + post "/projects/#{@project1.id}/dmsf/save", + params: { folder_id: @folder2.id, parent_id: @folder2.dmsf_folder.id, + dmsf_folder: { title: @folder2.title, description: 'Updated folder', + redirect_to_folder_id: @folder2.id } } assert_redirected_to dmsf_folder_path(id: @project1, folder_id: @folder2.id) end def test_trash_forbidden # Missing permissions + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :file_delete - get :trash, params: { id: @project1 } + get "/projects/#{@project1.id}/dmsf/trash" assert_response :forbidden end def test_trash_allowed # Permissions OK - get :trash, params: { id: @project1 } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get "/projects/#{@project1.id}/dmsf/trash" assert_response :success assert_select 'h2', { text: l(:link_trash_bin) } end def test_trash + post '/login', params: { username: 'jsmith', password: 'jsmith' } @folder1.delete commit: false - get :trash, params: { id: @project1 } + get "/projects/#{@project1.id}/dmsf/trash" assert_response :success assert_select 'a', href: dmsf_folder_path(id: @folder1.project.id, folder_id: @folder1.id) assert_select 'a', href: dmsf_folder_path(id: @folder2.project.id, folder_id: @folder2.id) @@ -101,7 +108,8 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase end def test_empty_trash - get :empty_trash, params: { id: @project1.id } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get "/projects/#{@project1.id}/dmsf/empty_trash" assert_equal 0, DmsfFolder.deleted.where(project_id: @project1.id).all.size assert_equal 0, DmsfFile.deleted.where(project_id: @project1.id).all.size assert_equal 0, DmsfLink.deleted.where(project_id: @project1.id).all.size @@ -110,89 +118,103 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase def test_empty_trash_forbidden # Missing permissions + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :file_delete - get :empty_trash, params: { id: @project1.id } + get "/projects/#{@project1.id}/dmsf/empty_trash" assert_response :forbidden end def test_delete_forbidden # Missing permissions + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :folder_manipulation - get :delete, params: { id: @project1, folder_id: @folder1.id, commit: false } + delete "/projects/#{@project1.id}/dmsf/delete", params: { folder_id: @folder1.id, commit: false } assert_response :forbidden end def test_delete_locked # Permissions OK but the folder is locked + post '/login', params: { username: 'jsmith', password: 'jsmith' } @request.env['HTTP_REFERER'] = dmsf_folder_path(id: @project1, folder_id: @folder2.id) - get :delete, params: { id: @project1, folder_id: @folder2.id, commit: false } + delete "/projects/#{@project1.id}/dmsf/delete", params: { folder_id: @folder2.id, commit: false } assert_response :redirect assert_include l(:error_folder_is_locked), flash[:error] end def test_delete_ok # Empty and not locked folder - @request.env['HTTP_REFERER'] = dmsf_folder_path(id: @project1, folder_id: @folder1.dmsf_folder) - get :delete, params: { id: @project1, folder_id: @folder1, parent_id: @folder1.dmsf_folder, commit: false } - assert_redirected_to dmsf_folder_path(id: @project1, folder_id: @folder1.dmsf_folder) + post '/login', params: { username: 'jsmith', password: 'jsmith' } + @request.env['HTTP_REFERER'] = dmsf_folder_path(id: @project1) + delete "/projects/#{@project1.id}/dmsf/delete", + params: { folder_id: @folder1.id, commit: false } + assert_redirected_to dmsf_folder_path(id: @project1) end def test_delete_subfolder - @request.env['HTTP_REFERER'] = dmsf_folder_path(id: @project1, folder_id: @folder2.dmsf_folder) - get :delete, params: { id: @project1, folder_id: @folder2, parent_id: @folder2.dmsf_folder, commit: false } - assert_redirected_to dmsf_folder_path(id: @project1, folder_id: @folder2.dmsf_folder) + post '/login', params: { username: 'jsmith', password: 'jsmith' } + @request.env['HTTP_REFERER'] = dmsf_folder_path(id: @project1, folder_id: @folder1.id) + delete "/projects/#{@folder2.project.id}/dmsf/delete", + params: { folder_id: @folder2.id, parent_id: @folder1.id, commit: false } + assert_redirected_to dmsf_folder_path(id: @project1, folder_id: @folder1.id) end def test_restore_forbidden # Missing permissions + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_developer.remove_permission! :folder_manipulation @folder4.deleted = 1 @folder4.save - get :restore, params: { id: @folder4.project.id, folder_id: @folder4.id } + get "/projects/#{@folder4.project.id}/dmsf/restore", params: { folder_id: @folder4.id } assert_response :forbidden end def test_restore_ok # Permissions OK + post '/login', params: { username: 'jsmith', password: 'jsmith' } @request.env['HTTP_REFERER'] = trash_dmsf_path(id: @project1) @folder1.deleted = 1 @folder1.save - get :restore, params: { id: @project1, folder_id: @folder1.id } + get "/projects/#{@project1.id}/dmsf/restore", params: { folder_id: @folder1.id } assert_response :redirect end def test_delete_entries_forbidden # Missing permissions + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :folder_manipulation - get :entries_operation, params: { id: @project1, delete_entries: 'Delete', - ids: ["folder-#{@folder1.id}", "file-#{@file1.id}", "folder-link-#{@link1.id}", - "file-link-#{@link2.id}"] } + post "/projects/#{@project1.id}/dmsf/entries", + params: { delete_entries: true, + ids: ["folder-#{@folder1.id}", "file-#{@file1.id}", "folder-link-#{@link1.id}", + "file-link-#{@link2.id}"] } assert_response :forbidden end def test_delete_entries_ok # Permissions OK + post '/login', params: { username: 'jsmith', password: 'jsmith' } @request.env['HTTP_REFERER'] = dmsf_folder_path(id: @project1) flash[:error] = nil - get :entries_operation, params: { id: @project1, delete_entries: 'Delete', - ids: ["folder-#{@folder7.id}", "file-#{@file1.id}", "file-link-#{@link2.id}"] } + post "/projects/#{@project1.id}/dmsf/entries", + params: { delete_entries: true, ids: ["folder-#{@folder7.id}", "file-#{@file1.id}", "file-link-#{@link2.id}"] } assert_response :redirect assert_nil flash[:error] end def test_restore_entries # Restore + post '/login', params: { username: 'jsmith', password: 'jsmith' } @request.env['HTTP_REFERER'] = trash_dmsf_path(id: @project1) flash[:error] = nil - get :entries_operation, params: { id: @project1, restore_entries: 'Restore', - ids: ["file-#{@file1.id}", "file-link-#{@link2.id}"] } + post "/projects/#{@project1.id}/dmsf/entries", + params: { restore_entries: true, ids: ["file-#{@file1.id}", "file-link-#{@link2.id}"] } assert_response :redirect assert_nil flash[:error] end def test_show + post '/login', params: { username: 'jsmith', password: 'jsmith' } with_settings plugin_redmine_dmsf: { 'dmsf_webdav' => '1', 'dmsf_webdav_strategy' => 'WEBDAV_READ_WRITE' } do - get :show, params: { id: @project1.id } + get "/projects/#{@project1.id}/dmsf" assert_response :success # New file link assert_select 'a[href$=?]', '/dmsf/upload/multi_upload' @@ -217,15 +239,17 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase end def test_show_webdav_disabled + post '/login', params: { username: 'jsmith', password: 'jsmith' } with_settings plugin_redmine_dmsf: { 'dmsf_webdav' => nil } do - get :show, params: { id: @project1.id } + get "/projects/#{@project1.id}/dmsf" assert_response :success assert_select 'a.webdav', text: 'WebDAV', count: 0 end end def test_show_filters_found - get :show, params: { id: @project1.id, f: ['title'], op: { 'title' => '~' }, v: { 'title' => ['Zero'] } } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get "/projects/#{@project1.id}/dmsf", params: { f: ['title'], op: { 'title' => '~' }, v: { 'title' => ['Zero'] } } assert_response :success # 'Zero Size File' document assert_select 'a', text: @file10.title @@ -234,15 +258,17 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase end def test_show_filters_not_found - get :show, params: { id: @project1.id, f: ['title'], op: { 'title' => '~' }, v: { 'title' => ['xxx'] } } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get "/projects/#{@project1.id}/dmsf", params: { f: ['title'], op: { 'title' => '~' }, v: { 'title' => ['xxx'] } } assert_response :success # 'Zero Size File' document assert_select 'a', text: @file10.title, count: 0 end def test_show_filters_custom_field - get :show, params: { id: @project1.id, set_filter: '1', f: ['cf_21', ''], op: { 'cf_21' => '=' }, - v: { 'cf_21' => ['User documentation'] } } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get "/projects/#{@project1.id}/dmsf", + params: { set_filter: '1', f: ['cf_21', ''], op: { 'cf_21' => '=' }, v: { 'cf_21' => ['User documentation'] } } assert_response :success # Folder 1 with Tag=User documentation assert_select 'a', text: @folder1.title @@ -251,27 +277,31 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase end def test_show_without_file_manipulation + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :file_manipulation - get :show, params: { id: @project1.id } + get "/projects/#{@project1.id}/dmsf" assert_response :success # New file link should be missing assert_select 'a[href$=?]', '/dmsf/upload/multi_upload', count: 0 end def test_show_csv - get :show, params: { id: @project1.id, format: 'csv' } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get "/projects/#{@project1.id}/dmsf", params: { format: 'csv' } assert_response :success assert @response.media_type.include?('text/csv') end def test_show_folder_doesnt_correspond_the_project + post '/login', params: { username: 'jsmith', password: 'jsmith' } assert @project1 != @folder3.project - get :show, params: { id: @project1.id, folder_id: @folder3.id } + get "/projects/#{@project1.id}/dmsf", params: { folder_id: @folder3.id } assert_response :not_found end def test_folder_link_to_folder - get :show, params: { id: @link1.project_id, folder_id: @link1.dmsf_folder_id } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get "/projects/#{@link1.project_id}/dmsf", params: { folder_id: @link1.dmsf_folder_id } assert_response :success assert_select 'a', text: @link1.title, count: 1 assert_select 'a[href$=?]', @@ -280,121 +310,140 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase end def test_folder_link_to_project + post '/login', params: { username: 'jsmith', password: 'jsmith' } @link1.target_project_id = @project2.id @link1.target_id = nil assert @link1.save - get :show, params: { id: @link1.project_id, folder_id: @link1.dmsf_folder_id } + get "/projects/#{@link1.project_id}/dmsf", params: { folder_id: @link1.dmsf_folder_id } assert_response :success assert_select 'a', text: @link1.title, count: 1 assert_select 'a[href$=?]', "/projects/#{@project2.identifier}/dmsf", count: 1 end def test_new_forbidden + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :folder_manipulation - get :new, params: { id: @project1, parent_id: nil } + get "/projects/#{@project1.id}/dmsf/new" assert_response :forbidden end def test_new - get :new, params: { id: @project1, parent_id: nil } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get "/projects/#{@project1.id}/dmsf/new" assert_response :success end def test_email_entries_email_from_forbidden + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :email_documents with_settings plugin_redmine_dmsf: { 'dmsf_documents_email_from' => 'karel.picman@kontron.com' } do - get :entries_operation, params: { id: @project1, email_entries: 'Email', ids: ["file-#{@file1.id}"] } + post "/projects/#{@project1.id}/dmsf/entries", params: { email_entries: true, ids: ["file-#{@file1.id}"] } assert_response :forbidden end end def test_email_entries_email_from + post '/login', params: { username: 'jsmith', password: 'jsmith' } with_settings plugin_redmine_dmsf: { 'dmsf_documents_email_from' => 'karel.picman@kontron.com' } do - get :entries_operation, params: { id: @project1, email_entries: 'Email', ids: ["file-#{@file1.id}"] } + post "/projects/#{@project1.id}/dmsf/entries", params: { email_entries: true, ids: ["file-#{@file1.id}"] } assert_response :success assert_select "input:match('value', ?)", Setting.plugin_redmine_dmsf['dmsf_documents_email_from'] end end def test_email_entries_reply_to + post '/login', params: { username: 'jsmith', password: 'jsmith' } with_settings plugin_redmine_dmsf: { 'dmsf_documents_email_reply_to' => 'karel.picman@kontron.com' } do - get :entries_operation, params: { id: @project1, email_entries: 'Email', ids: ["file-#{@file1.id}"] } + post "/projects/#{@project1.id}/dmsf/entries", params: { email_entries: true, ids: ["file-#{@file1.id}"] } assert_response :success assert_select "input:match('value', ?)", Setting.plugin_redmine_dmsf['dmsf_documents_email_reply_to'] end end def test_email_entries_links_only + post '/login', params: { username: 'jsmith', password: 'jsmith' } with_settings plugin_redmine_dmsf: { 'dmsf_documents_email_links_only' => '1' } do - get :entries_operation, params: { id: @project1, email_entries: 'Email', ids: ["file-#{@file1.id}"] } + post "/projects/#{@project1.id}/dmsf/entries", params: { email_entries: true, ids: ["file-#{@file1.id}"] } assert_response :success assert_select 'input[id=email_links_only][value=1]' end end def test_entries_email + post '/login', params: { username: 'jsmith', password: 'jsmith' } zip_file = Tempfile.new('test', Rails.root.join('tmp')) - get :entries_email, - params: { id: @project1, email: { to: 'to@test.com', from: 'from@test.com', subject: 'subject', body: 'body', - expired_at: '2015-01-01', folders: [], files: [@file1.id], - zipped_content: zip_file.path } } + post "/projects/#{@project1.id}/dmsf/entries/email", + params: { email: { to: 'to@test.com', from: 'from@test.com', subject: 'subject', body: 'body', + expired_at: '2015-01-01', folders: [], files: [@file1.id], + zipped_content: zip_file.path } } assert_redirected_to dmsf_folder_path(id: @project1) ensure zip_file.unlink end def test_add_email_forbidden + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :view_dmsf_files - get :add_email, params: { id: @project1.id }, xhr: true + get '/projects/dmsf/add_email', params: { id: @project1.id }, xhr: true assert_response :forbidden end def test_add_email - get :add_email, params: { id: @project1.id }, xhr: true + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get '/projects/dmsf/add_email', params: { id: @project1.id }, xhr: true assert_response :success end def test_append_email_forbidden + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :view_dmsf_files - post :append_email, params: { id: @project1, user_ids: @project1.members.collect { |m| m.user.id }, - format: 'js' } + post '/projects/dmsf/append_email', + params: { id: @project1, user_ids: @project1.members.collect { |m| m.user.id }, format: 'js' } assert_response :forbidden end def test_append_email - post :append_email, params: { id: @project1, user_ids: @project1.members.collect { |m| m.user.id }, format: 'js' } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + post '/projects/dmsf/append_email', + params: { id: @project1, user_ids: @project1.members.collect { |m| m.user.id }, format: 'js' } assert_response :success end def test_autocomplete_for_user_forbidden + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :view_dmsf_files - get :autocomplete_for_user, params: { id: @project1.id }, xhr: true + get '/projects/dmsf/autocomplete_for_user', params: { id: @project1.id }, xhr: true assert_response :forbidden end def test_autocomplete_for_user - get :autocomplete_for_user, params: { id: @project1 }, xhr: true + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get '/projects/dmsf/autocomplete_for_user', params: { id: @project1 }, xhr: true assert_response :success end def test_create_folder_in_root + post '/login', params: { username: 'jsmith', password: 'jsmith' } assert_difference 'DmsfFolder.count', +1 do - post :create, params: { id: @project1.id, dmsf_folder: { title: 'New folder', description: 'Unit tests' } } + post "/projects/#{@project1.id}/dmsf/create", + params: { dmsf_folder: { title: 'New folder', description: 'Unit tests' } } end assert_redirected_to dmsf_folder_path(id: @project1, folder_id: nil) end def test_create_folder + post '/login', params: { username: 'jsmith', password: 'jsmith' } assert_difference 'DmsfFolder.count', +1 do - post :create, params: { id: @project1.id, parent_id: @folder1.id, - dmsf_folder: { title: 'New folder', description: 'Unit tests' } } + post "/projects/#{@project1.id}/dmsf/create", + params: { parent_id: @folder1.id, dmsf_folder: { title: 'New folder', description: 'Unit tests' } } end assert_redirected_to dmsf_folder_path(id: @project1, folder_id: @folder1) end def test_show_with_sub_projects + post '/login', params: { username: 'jsmith', password: 'jsmith' } with_settings plugin_redmine_dmsf: { 'dmsf_projects_as_subfolders' => '1' } do - get :show, params: { id: @project1.id } + get "/projects/#{@project1.id}/dmsf" assert_response :success # @project5 is as a sub-folder assert_select "tr##{@project5.id}pspan", count: 1 @@ -402,21 +451,24 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase end def test_show_without_sub_projects - get :show, params: { id: @project1.id } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get "/projects/#{@project1.id}/dmsf" assert_response :success # @project5 is not as a sub-folder assert_select "tr##{@project5.id}pspan", count: 0 end def test_show_default_sort_column - get :show, params: { id: @project1.id } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get "/projects/#{@project1.id}/dmsf" assert_response :success # The default column Title's header is displayed as sorted '^' assert_select 'a.icon-sorted-desc', text: l(:label_column_title) end def test_index - get :index + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get '/dmsf' assert_response :success # Projects assert_select 'table.dmsf' do @@ -436,8 +488,8 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase end def test_index_non_member - @request.session[:user_id] = @dlopper.id - get :index + post '/login', params: { username: 'dlopper', password: 'foo' } + get '/dmsf' assert_response :success assert_select 'table.dmsf' do assert_select 'tr' do @@ -450,46 +502,54 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase end def test_index_no_membership - @request.session[:user_id] = @someone.id - get :index + post '/login', params: { username: 'someone', password: 'foo' } + get '/dmsf' assert_response :forbidden end def test_copymove_authorize_admin - @request.session[:user_id] = @admin.id - get :copymove, params: { id: @file1.project, folder_id: @file1.dmsf_folder, ids: ["file-#{@file1.id}"] } + post '/login', params: { username: 'admin', password: 'admin' } + get "/projects/#{@project1.id}/entries/copymove", + params: { folder_id: @file1.dmsf_folder, ids: ["file-#{@file1.id}"] } assert_response :success assert_template 'copymove' end def test_copymove_authorize_non_member - @request.session[:user_id] = @someone.id - get :copymove, params: { id: @file1.project, folder_id: @file1.dmsf_folder, ids: ["file-#{@file1.id}"] } + post '/login', params: { username: 'someone', password: 'foo' } + get "/projects/#{@project1.id}/entries/copymove", + params: { folder_id: @file1.dmsf_folder, ids: ["file-#{@file1.id}"] } assert_response :forbidden end def test_copymove_authorize_member_no_module + post '/login', params: { username: 'jsmith', password: 'jsmith' } @file1.project.disable_module! :dmsf - get :copymove, params: { id: @file1.project, folder_id: @file1.dmsf_folder, ids: ["file-#{@file1.id}"] } + get "/projects/#{@project1.id}/entries/copymove", + params: { folder_id: @file1.dmsf_folder, ids: ["file-#{@file1.id}"] } assert_response :forbidden end def test_copymove_authorize_forbidden + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :folder_manipulation - get :copymove, params: { id: @file1.project, folder_id: @file1.dmsf_folder, ids: ["file-#{@file1.id}"] } + get "/projects/#{@project1.id}/entries/copymove", + params: { folder_id: @file1.dmsf_folder, ids: ["file-#{@file1.id}"] } assert_response :forbidden end def test_copymove_target_folder - get :copymove, params: { id: @file1.project, folder_id: @file1.dmsf_folder, ids: ["file-#{@file1.id}"] } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get "/projects/#{@project1.id}/entries/copymove", + params: { folder_id: @file1.dmsf_folder, ids: ["file-#{@file1.id}"] } assert_response :success assert_template 'copymove' end def test_entries_copy - post :entries_operation, - params: { id: @file1.project, - dmsf_entries: { target_project_id: @folder1.project.id, target_folder_id: @folder1.id }, + post '/login', params: { username: 'jsmith', password: 'jsmith' } + post "/projects/#{@project1.id}/dmsf/entries", + params: { dmsf_entries: { target_project_id: @folder1.project.id, target_folder_id: @folder1.id }, ids: ["file-#{@file1.id}"], copy_entries: true } assert_response :redirect @@ -497,9 +557,9 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase end def test_entries_copy_to_the_same_folder - post :entries_operation, - params: { id: @file1.project, - dmsf_entries: { target_project_id: @file1.project.id, target_folder_id: @file1.dmsf_folder }, + post '/login', params: { username: 'jsmith', password: 'jsmith' } + post "/projects/#{@project1.id}/dmsf/entries", + params: { dmsf_entries: { target_project_id: @file1.project.id, target_folder_id: @file1.dmsf_folder }, ids: ["file-#{@file1.id}"], copy_entries: true } assert_response :redirect @@ -508,9 +568,9 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase def test_entries_move_recursion # Move a folder under the same folder - post :entries_operation, - params: { id: @folder1.project, - dmsf_entries: { target_project_id: @folder2.project.id, target_folder_id: @folder2.id }, + post '/login', params: { username: 'jsmith', password: 'jsmith' } + post "/projects/#{@project1.id}/dmsf/entries", + params: { dmsf_entries: { target_project_id: @folder2.project.id, target_folder_id: @folder2.id }, ids: ["folder-#{@folder1.id}"], move_entries: true } assert_response :redirect @@ -519,9 +579,9 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase def test_entries_move_infinity # Move the folder to itself - post :entries_operation, - params: { id: @folder1.project, - dmsf_entries: { target_project_id: @folder2.project.id, target_folder_id: @folder2.id }, + post '/login', params: { username: 'jsmith', password: 'jsmith' } + post "/projects/#{@project1.id}/dmsf/entries", + params: { dmsf_entries: { target_project_id: @folder2.project.id, target_folder_id: @folder2.id }, ids: ["folder-#{@folder2.id}"], move_entries: true } assert_response :redirect @@ -529,50 +589,50 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase end def test_entries_copy_to_locked_folder - @request.session[:user_id] = @admin.id - post :entries_operation, - params: { id: @folder1.project, - dmsf_entries: { target_project_id: @folder2.project.id, target_folder_id: @folder2.id }, + post '/login', params: { username: 'admin', password: 'admin' } + post "/projects/#{@project1.id}/dmsf/entries", + params: { dmsf_entries: { target_project_id: @folder2.project.id, target_folder_id: @folder2.id }, ids: ["file-#{@file1.id}"], move_entries: true } assert_response :forbidden end def test_entries_copy_to_dmsf_not_enabled + post '/login', params: { username: 'jsmith', password: 'jsmith' } @project2.disable_module! :dmsf - post :entries_operation, - params: { id: @project2.id, - dmsf_entries: { target_project_id: @project2.id }, + post "/projects/#{@project2.id}/dmsf/entries", + params: { dmsf_entries: { target_project_id: @project2.id }, ids: ["file-#{@file1.id}"], copy_entries: true } assert_response :forbidden end def test_entries_copy_to_dmsf_enabled - post :entries_operation, - params: { id: @project2.id, - dmsf_entries: { target_project_id: @project2.id }, + post '/login', params: { username: 'jsmith', password: 'jsmith' } + post "/projects/#{@project2.id}/dmsf/entries", + params: { dmsf_entries: { target_project_id: @project2.id }, ids: ["file-#{@file1.id}"], copy_entries: true } assert_response :redirect end def test_entries_copy_to_as_non_member - @request.session[:user_id] = @someone.id - post :entries_operation, - params: { id: @project2.id, - dmsf_entries: { target_project_id: @project2.id }, + post '/login', params: { username: 'someone', password: 'foo' } + post "/projects/#{@project2.id}/dmsf/entries", + params: { dmsf_entries: { target_project_id: @project2.id }, ids: ["file-#{@file1.id}"], copy_entries: true } assert_response :forbidden end def test_copymove_new_fast_links_enabled + post '/login', params: { username: 'jsmith', password: 'jsmith' } member = Member.find_by(user_id: @jsmith.id, project_id: @project1.id) assert member member.dmsf_fast_links = true member.save - get :copymove, params: { id: @file1.project, folder_id: @file1.dmsf_folder, ids: ["file-#{@file4.id}"] } + get "/projects/#{@project1.id}/entries/copymove", + params: { folder_id: @file1.dmsf_folder, ids: ["file-#{@file4.id}"] } assert_response :success assert_select 'label', { count: 0, text: l(:label_target_project) } assert_select 'label', { count: 0, text: "#{l(:label_target_folder)}#" } @@ -580,9 +640,9 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase def test_entries_move_fast_links_enabled # Target project is not given - post :entries_operation, - params: { id: @project1.id, - dmsf_entries: { target_folder_id: @folder1.id }, + post '/login', params: { username: 'jsmith', password: 'jsmith' } + post "/projects/#{@project1.id}/dmsf/entries", + params: { dmsf_entries: { target_folder_id: @folder1.id }, ids: ["file-#{@file1.id}"], move_entries: true } assert_response :redirect diff --git a/test/functional/dmsf_folder_permissions_controller_test.rb b/test/functional/dmsf_folder_permissions_controller_test.rb index 3db16004..35ed8ef2 100644 --- a/test/functional/dmsf_folder_permissions_controller_test.rb +++ b/test/functional/dmsf_folder_permissions_controller_test.rb @@ -26,30 +26,32 @@ class DmsfFolderPermissionsControllerTest < RedmineDmsf::Test::TestCase def setup super - @request.session[:user_id] = @jsmith.id + post '/login', params: { username: 'jsmith', password: 'jsmith' } end def test_new - get :new, params: { project_id: @project1, dmsf_folder_id: @folder7, format: 'js' }, xhr: true + get '/dmsf_folder_permissions/new', + params: { project_id: @project1.id, dmsf_folder_id: @folder7.id, format: 'js' }, + xhr: true assert_response :success assert_template 'new' assert @response.media_type.include?('text/javascript') end def test_autocomplete_for_user - get :autocomplete_for_user, - params: { project_id: @project1, dmsf_folder_id: @folder7, q: 'smi', format: 'js' }, + get '/dmsf_folder_permissions/autocomplete_for_user', + params: { project_id: @project1.id, dmsf_folder_id: @folder7.id, q: 'smi', format: 'js' }, xhr: true assert_response :success assert_include @jsmith.name, response.body end def test_append - get :new, - params: { project_id: @project1, dmsf_folder_id: @folder7, user_ids: [@jsmith.id], format: 'js' }, - xhr: true + post '/dmsf_folder_permissions/append', + params: { project_id: @project1.id, dmsf_folder_id: @folder7.id, user_ids: [@jsmith.id], format: 'js' }, + xhr: true assert_response :success - assert_template 'new' + assert_template 'append' assert @response.content_type.match?(%r{^text/javascript}) end end diff --git a/test/functional/dmsf_links_controller_test.rb b/test/functional/dmsf_links_controller_test.rb index eeeb5917..5379c71c 100644 --- a/test/functional/dmsf_links_controller_test.rb +++ b/test/functional/dmsf_links_controller_test.rb @@ -30,62 +30,66 @@ class DmsfLinksControllerTest < RedmineDmsf::Test::TestCase super @file_link = DmsfLink.find 1 @url_link = DmsfLink.find 5 - @request.session[:user_id] = @jsmith.id end def test_authorize_admin - @request.session[:user_id] = @admin.id - get :new, params: { project_id: @project1.id } + post '/login', params: { username: 'admin', password: 'admin' } + get '/dmsf_links/new', params: { project_id: @project1.id } assert_response :success assert_template 'new' end def test_authorize_non_member - @request.session[:user_id] = @someone.id - get :new, params: { project_id: @project2.id } + post '/login', params: { username: 'someone', password: 'foo' } + get '/dmsf_links/new', params: { project_id: @project2.id } assert_response :forbidden end def test_authorize_member_ok - @request.session[:user_id] = @jsmith.id - get :new, params: { project_id: @project1.id } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get '/dmsf_links/new', params: { project_id: @project1.id } assert_response :success end def test_authorize_member_no_module # Without the module + post '/login', params: { username: 'jsmith', password: 'jsmith' } @project1.disable_module! :dmsf - get :new, params: { project_id: @project1.id } + get '/dmsf_links/new', params: { project_id: @project1.id } assert_response :forbidden end def test_authorize_forbidden # Without permissions + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :file_manipulation - get :new, params: { project_id: @project1.id } + get '/dmsf_links/new', params: { project_id: @project1.id } assert_response :forbidden end def test_new - get :new, params: { project_id: @project1.id, type: 'link_to' } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get '/dmsf_links/new', params: { project_id: @project1.id, type: 'link_to' } assert_response :success assert_select 'label', { text: l(:label_target_project) } end def test_new_fast_links_enabled + post '/login', params: { username: 'jsmith', password: 'jsmith' } member = Member.find_by(user_id: @jsmith.id, project_id: @project1.id) assert member member.dmsf_fast_links = true member.save - get :new, params: { project_id: @project1.id, type: 'link_to' } + get '/dmsf_links/new', params: { project_id: @project1.id, type: 'link_to' } assert_response :success assert_select 'label', { count: 0, text: l(:label_target_project) } end def test_create_file_link_from_f1 + post '/login', params: { username: 'jsmith', password: 'jsmith' } # 1. File link in a folder from another folder assert_difference 'DmsfLink.count', +1 do - post :create, params: { dmsf_link: { + post '/dmsf_links', params: { dmsf_link: { project_id: @project1.id, target_project_id: @project2.id, dmsf_folder_id: @folder1.id, @@ -95,13 +99,14 @@ class DmsfLinksControllerTest < RedmineDmsf::Test::TestCase type: 'link_from' } } end - assert_redirected_to dmsf_folder_path(id: @project1, folder_id: @folder1) + assert_redirected_to dmsf_folder_path(id: @project1, folder_id: @folder1.id) end def test_create_file_link_from_f2 + post '/login', params: { username: 'jsmith', password: 'jsmith' } # 2. File link in a folder from another root folder assert_difference 'DmsfLink.count', +1 do - post :create, params: { dmsf_link: { + post '/dmsf_links', params: { dmsf_link: { project_id: @project1.id, dmsf_folder_id: @folder1.id, target_project_id: @project2.id, @@ -111,14 +116,15 @@ class DmsfLinksControllerTest < RedmineDmsf::Test::TestCase type: 'link_from' } } end - assert_redirected_to dmsf_folder_path(id: @project1, folder_id: @folder1) + assert_redirected_to dmsf_folder_path(id: @project1, folder_id: @folder1.id) end def test_create_file_link_from_f3 # 3. File link in a root folder from another folder + post '/login', params: { username: 'jsmith', password: 'jsmith' } assert_difference 'DmsfLink.count', +1 do - post :create, params: { dmsf_link: { - project_id: @project1, + post '/dmsf_links', params: { dmsf_link: { + project_id: @project1.id, target_project_id: @project2.id, target_file_id: @file6.id, target_folder_id: @folder3.id, @@ -131,9 +137,10 @@ class DmsfLinksControllerTest < RedmineDmsf::Test::TestCase def test_create_file_link_from_f4 # 4. File link in a root folder from another root folder + post '/login', params: { username: 'jsmith', password: 'jsmith' } assert_difference 'DmsfLink.count', +1 do - post :create, params: { dmsf_link: { - project_id: @project1, + post '/dmsf_links', params: { dmsf_link: { + project_id: @project1.id, target_project_id: @project2.id, target_file_id: @file2.id, name: 'file_link', @@ -145,38 +152,41 @@ class DmsfLinksControllerTest < RedmineDmsf::Test::TestCase def test_create_folder_link_from_d1 # 1. Folder link in a folder from another folder + post '/login', params: { username: 'jsmith', password: 'jsmith' } assert_difference 'DmsfLink.count', +1 do - post :create, params: { dmsf_link: { - project_id: @project1, - dmsf_folder_id: @folder1, + post '/dmsf_links', params: { dmsf_link: { + project_id: @project1.id, + dmsf_folder_id: @folder1.id, target_project_id: @project2.id, target_folder_id: @folder3.id, name: 'folder_link', type: 'link_from' } } end - assert_redirected_to dmsf_folder_path(id: @project1, folder_id: @folder1) + assert_redirected_to dmsf_folder_path(id: @project1, folder_id: @folder1.id) end def test_create_folder_link_from_d2 # 2. Folder link in a folder from another root folder + post '/login', params: { username: 'jsmith', password: 'jsmith' } assert_difference 'DmsfLink.count', +1 do - post :create, params: { dmsf_link: { - project_id: @project1, - dmsf_folder_id: @folder1, + post '/dmsf_links', params: { dmsf_link: { + project_id: @project1.id, + dmsf_folder_id: @folder1.id, target_project_id: @project2.id, name: 'folder_link', type: 'link_from' } } end - assert_redirected_to dmsf_folder_path(id: @project1, folder_id: @folder1) + assert_redirected_to dmsf_folder_path(id: @project1, folder_id: @folder1.id) end def test_create_folder_link_from_d3 # 3. Folder link in a root folder from another folder + post '/login', params: { username: 'jsmith', password: 'jsmith' } assert_difference 'DmsfLink.count', +1 do - post :create, params: { dmsf_link: { - project_id: @project1, + post '/dmsf_links', params: { dmsf_link: { + project_id: @project1.id, target_project_id: @project2.id, target_folder_id: @folder3.id, name: 'folder_link', @@ -188,9 +198,10 @@ class DmsfLinksControllerTest < RedmineDmsf::Test::TestCase def test_create_folder_link_from_d4 # 4. Folder link in a root folder from another root folder + post '/login', params: { username: 'jsmith', password: 'jsmith' } assert_difference 'DmsfLink.count', +1 do - post :create, params: { dmsf_link: { - project_id: @project1, + post '/dmsf_links', params: { dmsf_link: { + project_id: @project1.id, target_project_id: @project2.id, name: 'folder_link', type: 'link_from' @@ -201,25 +212,27 @@ class DmsfLinksControllerTest < RedmineDmsf::Test::TestCase def test_create_file_link_to_f1 # 1. File link to a root folder from another folder + post '/login', params: { username: 'jsmith', password: 'jsmith' } assert_difference 'DmsfLink.count', +1 do - post :create, params: { dmsf_link: { - project_id: @project1, - dmsf_file_id: @file1, + post '/dmsf_links', params: { dmsf_link: { + project_id: @project1.id, + dmsf_file_id: @file1.id, target_project_id: @project2.id, target_folder_id: @folder3.id, name: 'file_link', type: 'link_to' } } end - assert_redirected_to dmsf_file_path(@file1) + assert_redirected_to dmsf_file_path(@file1.id) end def test_create_file_link_to_f2 # 2. File link to a folder from another folder + post '/login', params: { username: 'jsmith', password: 'jsmith' } assert_difference 'DmsfLink.count', +1 do - post :create, params: { dmsf_link: { - project_id: @project2, - dmsf_folder_id: @folder3, + post '/dmsf_links', params: { dmsf_link: { + project_id: @project2.id, + dmsf_folder_id: @folder3.id, target_project_id: @project1.id, target_folder_id: @folder1.id, dmsf_file_id: @file6.id, @@ -227,27 +240,29 @@ class DmsfLinksControllerTest < RedmineDmsf::Test::TestCase type: 'link_to' } } end - assert_redirected_to dmsf_file_path(@file6) + assert_redirected_to dmsf_file_path(@file6.id) end def test_create_file_link_to_f3 # 3. File link to a root folder from another root folder + post '/login', params: { username: 'jsmith', password: 'jsmith' } assert_difference 'DmsfLink.count', +1 do - post :create, params: { dmsf_link: { - project_id: @project2, + post '/dmsf_links', params: { dmsf_link: { + project_id: @project2.id, target_project_id: @project1.id, dmsf_file_id: @file6.id, name: 'file_link', type: 'link_to' } } end - assert_redirected_to dmsf_file_path(@file6) + assert_redirected_to dmsf_file_path(@file6.id) end def test_create_file_link_to_f4 # 4. File link to a folder from another root folder + post '/login', params: { username: 'jsmith', password: 'jsmith' } assert_difference 'DmsfLink.count', +1 do - post :create, params: { dmsf_link: { + post '/dmsf_links', params: { dmsf_link: { project_id: @project2, dmsf_folder_id: @folder3, target_project_id: @project1.id, @@ -256,12 +271,13 @@ class DmsfLinksControllerTest < RedmineDmsf::Test::TestCase type: 'link_to' } } end - assert_redirected_to dmsf_file_path(@file6) + assert_redirected_to dmsf_file_path(@file6.id) end def test_create_external_link_from + post '/login', params: { username: 'jsmith', password: 'jsmith' } assert_difference 'DmsfLink.count', +1 do - post :create, params: { dmsf_link: { + post '/dmsf_links', params: { dmsf_link: { project_id: @project1, target_project_id: @project1.id, name: 'file_link', @@ -274,8 +290,9 @@ class DmsfLinksControllerTest < RedmineDmsf::Test::TestCase def test_create_folder_link_to_f1 # 1. Folder link to a root folder + post '/login', params: { username: 'jsmith', password: 'jsmith' } assert_difference 'DmsfLink.count', +1 do - post :create, params: { dmsf_link: { + post '/dmsf_links', params: { dmsf_link: { project_id: @project1.id, dmsf_folder_id: @folder1.id, target_project_id: @project2.id, @@ -283,13 +300,14 @@ class DmsfLinksControllerTest < RedmineDmsf::Test::TestCase type: 'link_to' } } end - assert_redirected_to dmsf_folder_path(id: @project1, folder_id: @folder1.dmsf_folder) + assert_redirected_to dmsf_folder_path(id: @project1, folder_id: @folder1.dmsf_folder_id) end def test_create_folder_link_to_f2 # 2. Folder link to a folder + post '/login', params: { username: 'jsmith', password: 'jsmith' } assert_difference 'DmsfLink.count', +1 do - post :create, params: { dmsf_link: { + post '/dmsf_links', params: { dmsf_link: { project_id: @project1.id, dmsf_folder_id: @folder1.id, target_project_id: @project2.id, @@ -298,35 +316,40 @@ class DmsfLinksControllerTest < RedmineDmsf::Test::TestCase type: 'link_to' } } end - assert_redirected_to dmsf_folder_path(id: @project1, folder_id: @folder1.dmsf_folder) + assert_redirected_to dmsf_folder_path(id: @project1, folder_id: @folder1.dmsf_folder_id) end def test_destroy + post '/login', params: { username: 'jsmith', password: 'jsmith' } assert_difference 'DmsfLink.visible.count', -1 do - delete :destroy, params: { project_id: @project1, id: @file_link } + delete "/dmsf_links/#{@file_link.id}", params: { project_id: @project1.id } end - assert_redirected_to dmsf_folder_path(id: @file_link.project, folder_id: @file_link.dmsf_folder) + assert_redirected_to dmsf_folder_path(id: @file_link.project, folder_id: @file_link.dmsf_folder_id) end def test_destroy_in_subfolder + post '/login', params: { username: 'jsmith', password: 'jsmith' } assert_difference 'DmsfLink.visible.count', -1 do - delete :destroy, params: { project_id: @url_link.project, id: @url_link, folder_id: @url_link.dmsf_folder } + delete "/dmsf_links/#{@url_link.id}", + params: { project_id: @url_link.project_id, folder_id: @url_link.dmsf_folder_id } end - assert_redirected_to dmsf_folder_path(id: @url_link.project, folder_id: @url_link.dmsf_folder) + assert_redirected_to dmsf_folder_path(id: @url_link.project, folder_id: @url_link.dmsf_folder_id) end def test_restore_forbidden # Missing permissions + post '/login', params: { username: 'jsmith', password: 'jsmith' } @request.env['HTTP_REFERER'] = trash_dmsf_path(id: @project1) @role_manager.remove_permission! :file_manipulation - get :restore, params: { project_id: @project1, id: @file_link } + get "/dmsf/links/#{@file_link.id}/restore", params: { project_id: @project1.id } assert_response :forbidden end def test_restore_ok # Permissions OK + post '/login', params: { username: 'jsmith', password: 'jsmith' } @request.env['HTTP_REFERER'] = trash_dmsf_path(id: @project1) - get :restore, params: { project_id: @project1, id: @file_link } + get "/dmsf/links/#{@file_link.id}/restore", params: { project_id: @project1.id } assert_response :redirect end end diff --git a/test/functional/dmsf_public_urls_controller_test.rb b/test/functional/dmsf_public_urls_controller_test.rb index c854a7f6..f6f870a1 100644 --- a/test/functional/dmsf_public_urls_controller_test.rb +++ b/test/functional/dmsf_public_urls_controller_test.rb @@ -25,17 +25,17 @@ class DmsfPublicUrlsControllerTest < RedmineDmsf::Test::TestCase fixtures :dmsf_public_urls, :dmsf_folders, :dmsf_files, :dmsf_file_revisions def test_show_valid_url - get :show, params: { token: 'd8d33e21914a433b280fdc94450ee212' } + get '/dmsf_public_urls', params: { token: 'd8d33e21914a433b280fdc94450ee212' } assert_response :success end def test_show_url_width_invalid_token - get :show, params: { token: 'f8d33e21914a433b280fdc94450ee212' } + get '/dmsf_public_urls', params: { token: 'f8d33e21914a433b280fdc94450ee212' } assert_response :not_found end def test_show_url_that_has_expired - get :show, params: { token: 'e8d33e21914a433b280fdc94450ee212' } + get '/dmsf_public_urls', params: { token: 'e8d33e21914a433b280fdc94450ee212' } assert_response :not_found end end diff --git a/test/functional/dmsf_state_controller_test.rb b/test/functional/dmsf_state_controller_test.rb index bf62e051..e6f47647 100644 --- a/test/functional/dmsf_state_controller_test.rb +++ b/test/functional/dmsf_state_controller_test.rb @@ -29,13 +29,14 @@ class DmsfStateControllerTest < RedmineDmsf::Test::TestCase def setup super @query401 = Query.find 401 - @request.session[:user_id] = @jsmith.id end def test_user_pref_save_member + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.add_permission! :user_preferences - post :user_pref_save, params: { id: @project1.id, email_notify: 1, title_format: '%t_%v', fast_links: 1, - act_as_attachable: 1, default_dmsf_query: @query401.id } + post "/projects/#{@project1.id}/dmsf/state", + params: { email_notify: 1, title_format: '%t_%v', fast_links: 1, act_as_attachable: 1, + default_dmsf_query: @query401.id } assert_redirected_to settings_project_path(@project1, tab: 'dmsf') assert_not_nil flash[:notice] assert_equal flash[:notice], l(:notice_your_preferences_were_saved) @@ -50,22 +51,23 @@ class DmsfStateControllerTest < RedmineDmsf::Test::TestCase end def test_user_pref_save_member_forbidden + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :user_preferences - post :user_pref_save, params: { id: @project1.id, email_notify: 1, title_format: '%t_%v' } + post "/projects/#{@project1.id}/dmsf/state", params: { email_notify: 1, title_format: '%t_%v' } assert_response :forbidden end def test_user_pref_save_none_member # Non Member - @request.session[:user_id] = @someone.id - post :user_pref_save, params: { id: @project1.id, email_notify: 1, title_format: '%t_%v' } + post '/login', params: { username: 'someone', password: 'foo' } + post "/projects/#{@project1.id}/dmsf/state", params: { email_notify: 1, title_format: '%t_%v' } assert_response :forbidden end def test_user_pref_save_admin # Admin - non member - @request.session[:user_id] = @admin.id - post :user_pref_save, params: { id: @project1.id, email_notify: 1, title_format: '%t_%v' } + post '/login', params: { username: 'admin', password: 'admin' } + post "/projects/#{@project1.id}/dmsf/state", params: { email_notify: 1, title_format: '%t_%v' } assert_redirected_to settings_project_path(@project1, tab: 'dmsf') assert_not_nil flash[:warning] assert_equal flash[:warning], l(:user_is_not_project_member) diff --git a/test/functional/dmsf_workflow_controller_test.rb b/test/functional/dmsf_workflow_controller_test.rb index d17edc19..f6c398c3 100644 --- a/test/functional/dmsf_workflow_controller_test.rb +++ b/test/functional/dmsf_workflow_controller_test.rb @@ -39,137 +39,151 @@ class DmsfWorkflowsControllerTest < RedmineDmsf::Test::TestCase @wfsa2 = DmsfWorkflowStepAssignment.find 2 @revision1 = DmsfFileRevision.find 1 @revision2 = DmsfFileRevision.find 2 - @request.env['HTTP_REFERER'] = dmsf_folder_path(id: @project1) - @request.session[:user_id] = @jsmith.id end def test_authorize_admin # Admin - @request.session[:user_id] = @admin.id - get :index + post '/login', params: { username: 'admin', password: 'admin' } + get '/dmsf_workflows' assert_response :success assert_template 'index' end def test_authorize_member # Non member - @request.session[:user_id] = @someone.id - get :index, params: { project_id: @project1.id } + post '/login', params: { username: 'someone', password: 'foo' } + get '/dmsf_workflows', params: { project_id: @project1.id } assert_response :forbidden end def test_authorize_administration # Administration - get :index + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get '/dmsf_workflows' assert_response :forbidden end def test_authorize_projects # Project - get :index, params: { project_id: @project1.id } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get '/dmsf_workflows', params: { project_id: @project1.id } assert_response :success assert_template 'index' end def test_authorize_manage_workflows_forbidden # Without permissions + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :manage_workflows - get :index, params: { project_id: @project1.id } + get '/dmsf_workflows', params: { project_id: @project1.id } assert_response :forbidden end def test_authorization_file_approval_ok + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.add_permission! :file_approval @revision2.dmsf_workflow_id = @wf1.id - get :start, params: { id: @revision2.dmsf_workflow_id, dmsf_file_revision_id: @revision2.id } + get "/dmsf_workflows/#{@revision2.dmsf_workflow_id}/start", params: { dmsf_file_revision_id: @revision2.id } assert_response :redirect end def test_authorization_file_approval_forbidden + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :file_approval @revision2.dmsf_workflow_id = @wf1.id - get :start, params: { id: @revision2.dmsf_workflow_id, dmsf_file_revision_id: @revision2.id } + get "/dmsf_workflows/#{@revision2.dmsf_workflow_id}/start", params: { dmsf_file_revision_id: @revision2.id } assert_response :forbidden end def test_authorization_no_module # Without the module + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.add_permission! :file_manipulation @project1.disable_module! :dmsf - get :index, params: { project_id: @project1.id } + get '/dmsf_workflows', params: { project_id: @project1.id } assert_response :forbidden end def test_index_administration - @request.session[:user_id] = @admin.id - get :index + post '/login', params: { username: 'admin', password: 'admin' } + get '/dmsf_workflows' assert_response :success assert_template 'index' end def test_index_project - get :index, params: { project_id: @project1.id } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get '/dmsf_workflows', params: { project_id: @project1.id } assert_response :success assert_template 'index' end def test_new - get :new, params: { project_id: @project1.id } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get '/dmsf_workflows/new', params: { project_id: @project1.id } assert_response :success assert_template 'new' end def test_lock - put :update, params: { id: @wf1.id, dmsf_workflow: { status: DmsfWorkflow::STATUS_LOCKED } } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + patch "/dmsf_workflows/#{@wf1.id}", params: { dmsf_workflow: { status: DmsfWorkflow::STATUS_LOCKED } } @wf1.reload assert @wf1.locked?, "#{@wf1.name} status is #{@wf1.status}" end def test_unlock - @request.session[:user_id] = @admin.id - put :update, params: { id: @wf3.id, dmsf_workflow: { status: DmsfWorkflow::STATUS_ACTIVE } } + post '/login', params: { username: 'admin', password: 'admin' } + patch "/dmsf_workflows/#{@wf3.id}", params: { dmsf_workflow: { status: DmsfWorkflow::STATUS_ACTIVE } } @wf3.reload assert @wf3.active?, "#{@wf3.name} status is #{@wf3.status}" end def test_show - get :show, params: { id: @wf1.id } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get "/dmsf_workflows/#{@wf1.id}" assert_response :success assert_template 'show' end def test_create + post '/login', params: { username: 'jsmith', password: 'jsmith' } assert_difference 'DmsfWorkflow.count', +1 do - post :create, params: { dmsf_workflow: { name: 'wf4', project_id: @project1.id } } + post '/dmsf_workflows', params: { dmsf_workflow: { name: 'wf4', project_id: @project1.id } } end assert_redirected_to settings_project_path(@project1, tab: 'dmsf_workflow') end def test_create_with_the_same_name + post '/login', params: { username: 'jsmith', password: 'jsmith' } assert_difference 'DmsfWorkflow.count', 0 do - post :create, params: { dmsf_workflow: { name: @wf1.name, project_id: @project1.id } } + post '/dmsf_workflows', params: { dmsf_workflow: { name: @wf1.name, project_id: @project1.id } } end assert_response :success assert_select_error(/#{l('activerecord.errors.messages.taken')}$/) end def test_update - put :update, params: { id: @wf1.id, dmsf_workflow: { name: 'wf1a' } } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + patch "/dmsf_workflows/#{@wf1.id}", params: { dmsf_workflow: { name: 'wf1a' } } @wf1.reload assert_equal 'wf1a', @wf1.name end def test_destroy + post '/login', params: { username: 'jsmith', password: 'jsmith' } assert_difference 'DmsfWorkflow.count', -1 do - delete :destroy, params: { id: @wf1.id } + delete "/dmsf_workflows/#{@wf1.id}" end assert_redirected_to settings_project_path(@project1, tab: 'dmsf_workflow') - assert_equal 0, DmsfWorkflowStep.where(dmsf_workflow_id: @wf1.id).all.count + assert_equal 0, DmsfWorkflowStep.where(dmsf_workflow_id: @wf1.id).all.size end def test_add_step + post '/login', params: { username: 'jsmith', password: 'jsmith' } assert_difference 'DmsfWorkflowStep.count', +1 do - post :add_step, params: { commit: l(:dmsf_or), step: 1, name: '1st step', id: @wf1.id, user_ids: [@someone.id] } + post "/dmsf_workflows/#{@wf1.id}/edit", + params: { commit: l(:dmsf_or), step: 1, name: '1st step', user_ids: [@someone.id] } end assert_response :success ws = DmsfWorkflowStep.order(id: :desc).first @@ -181,9 +195,10 @@ class DmsfWorkflowsControllerTest < RedmineDmsf::Test::TestCase end def test_remove_step - n = DmsfWorkflowStep.where(dmsf_workflow_id: @wf1.id, step: 1).count + post '/login', params: { username: 'jsmith', password: 'jsmith' } + n = DmsfWorkflowStep.where(dmsf_workflow_id: @wf1.id, step: @wfs1.step).count assert_difference 'DmsfWorkflowStep.count', -n do - delete :remove_step, params: { step: @wfs1.id, id: @wf1.id } + delete "/dmsf_workflows/#{@wf1.id}/edit", params: { step: @wfs1.id } end assert_response :redirect ws = DmsfWorkflowStep.where(dmsf_workflow_id: @wf1.id).order(id: :asc).first @@ -191,7 +206,8 @@ class DmsfWorkflowsControllerTest < RedmineDmsf::Test::TestCase end def test_reorder_steps_to_lower - put :reorder_steps, params: { step: 1, id: @wf1.id, dmsf_workflow: { position: 2 } } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + put "/dmsf_workflows/#{@wf1.id}/edit", params: { step: 1, dmsf_workflow: { position: 2 } } assert_response :success @wfs1.reload @wfs2.reload @@ -206,7 +222,8 @@ class DmsfWorkflowsControllerTest < RedmineDmsf::Test::TestCase end def test_reorder_steps_to_lowest - put :reorder_steps, params: { step: 1, id: @wf1.id, dmsf_workflow: { position: 3 } } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + put "/dmsf_workflows/#{@wf1.id}/edit", params: { step: 1, dmsf_workflow: { position: 3 } } assert_response :success @wfs1.reload @wfs2.reload @@ -221,7 +238,8 @@ class DmsfWorkflowsControllerTest < RedmineDmsf::Test::TestCase end def test_reorder_steps_to_higher - put :reorder_steps, params: { step: 3, id: @wf1.id, dmsf_workflow: { position: 2 } } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + put "/dmsf_workflows/#{@wf1.id}/edit", params: { step: 3, dmsf_workflow: { position: 2 } } assert_response :success @wfs1.reload @wfs2.reload @@ -236,7 +254,8 @@ class DmsfWorkflowsControllerTest < RedmineDmsf::Test::TestCase end def test_reorder_steps_to_highest - put :reorder_steps, params: { step: 3, id: @wf1.id, dmsf_workflow: { position: '1' } } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + put "/dmsf_workflows/#{@wf1.id}/edit", params: { step: 3, dmsf_workflow: { position: '1' } } assert_response :success @wfs1.reload @wfs2.reload @@ -251,64 +270,61 @@ class DmsfWorkflowsControllerTest < RedmineDmsf::Test::TestCase end def test_action_approve - post( - :new_action, params: { - commit: l(:button_submit), - id: @wf1.id, - dmsf_workflow_step_assignment_id: @wfsa2.id, - dmsf_file_revision_id: @revision1.id, - step_action: DmsfWorkflowStepAction::ACTION_APPROVE, - user_id: nil, - note: '' - } - ) + post '/login', params: { username: 'jsmith', password: 'jsmith' } + post "/dmsf_workflows/#{@wf1.id}/new_action", + params: { + commit: l(:button_submit), + dmsf_workflow_step_assignment_id: @wfsa2.id, + dmsf_file_revision_id: @revision1.id, + step_action: DmsfWorkflowStepAction::ACTION_APPROVE, + user_id: nil, + note: '' + } assert_redirected_to dmsf_folder_path(id: @project1) assert DmsfWorkflowStepAction.exists?(dmsf_workflow_step_assignment_id: @wfsa2.id, action: DmsfWorkflowStepAction::ACTION_APPROVE) end def test_action_reject - post( - :new_action, params: { - 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...' - } - ) + post '/login', params: { username: 'jsmith', password: 'jsmith' } + post "/dmsf_workflows/#{@wf1.id}/new_action", + params: { + commit: l(:button_submit), + 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.exists?(dmsf_workflow_step_assignment_id: @wfsa2.id, action: DmsfWorkflowStepAction::ACTION_REJECT) end def test_action - get( - :action, xhr: true, params: { - project_id: @project1.id, - id: @wf1.id, - dmsf_workflow_step_assignment_id: @wfsa2.id, - dmsf_file_revision_id: @revision2.id, - title: l(:title_waiting_for_approval) - } - ) + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get "/dmsf_workflows/#{@wf1.id}/action", + xhr: true, + params: { + project_id: @project1.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 - post( - :new_action, params: { - commit: l(:button_submit), - id: @wf1.id, - dmsf_workflow_step_assignment_id: @wfsa2.id, - dmsf_file_revision_id: @revision2.id, - step_action: @admin.id * 10, - note: 'Delegated because...' - } - ) + post '/login', params: { username: 'jsmith', password: 'jsmith' } + post "/dmsf_workflows/#{@wf1.id}/new_action", + params: { + commit: l(:button_submit), + dmsf_workflow_step_assignment_id: @wfsa2.id, + dmsf_file_revision_id: @revision2.id, + step_action: @admin.id * 10, + note: 'Delegated because...' + } assert_redirected_to dmsf_folder_path(id: @project1) assert DmsfWorkflowStepAction.exists?(dmsf_workflow_step_assignment_id: @wfsa2.id, action: DmsfWorkflowStepAction::ACTION_DELEGATE) @@ -317,41 +333,41 @@ class DmsfWorkflowsControllerTest < RedmineDmsf::Test::TestCase end def test_assign - get( - :assign, xhr: true, params: { - project_id: @project1.id, - id: @wf1.id, - dmsf_file_revision_id: @revision1.id, - title: l(:label_dmsf_wokflow_action_assign) - } - ) + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get "/dmsf_workflows/#{@project1.id}/assign", + xhr: true, + params: { + 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_start + post '/login', params: { username: 'jsmith', password: 'jsmith' } @revision2.dmsf_workflow_id = @wf1.id - get :start, params: { id: @revision2.dmsf_workflow_id, dmsf_file_revision_id: @revision2.id } + get "/dmsf_workflows/#{@revision2.dmsf_workflow_id}/start", params: { dmsf_file_revision_id: @revision2.id } assert_redirected_to dmsf_folder_path(id: @project1) end def test_assignment - post( - :assignment, params: { - commit: l(:button_submit), - id: @wf1.id, - dmsf_workflow_id: @wf1.id, - dmsf_file_revision_id: @revision2.id, - action: 'assignment', - project_id: @project1.id - } - ) + post '/login', params: { username: 'jsmith', password: 'jsmith' } + post "/dmsf_workflows/#{@project1.id}/assignment", + params: { + commit: l(:button_submit), + id: @wf1.id, + dmsf_workflow_id: @wf1.id, + dmsf_file_revision_id: @revision2.id, + action: 'assignment' + } assert_response :redirect end def test_update_step_name - put :update_step, params: { id: @wf1.id, step: @wfs2.step, dmsf_workflow: { step_name: 'new_name' } } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + put "/dmsf_workflows/#{@wf1.id}/update_step", params: { step: @wfs2.step, dmsf_workflow: { step_name: 'new_name' } } assert_response :redirect # All steps in the same step must be renamed @wfs2.reload @@ -364,66 +380,78 @@ class DmsfWorkflowsControllerTest < RedmineDmsf::Test::TestCase end def test_update_step_operators - put :update_step, params: { - id: @wf1, - step: '1', - operator_step: { @wfs1.id.to_s => DmsfWorkflowStep::OPERATOR_OR.to_s }, - assignee: { @wfs1.id.to_s => @wfs1.user_id.to_s } - } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + put "/dmsf_workflows/#{@wf1.id}/update_step", + params: { + step: '1', + operator_step: { @wfs1.id.to_s => DmsfWorkflowStep::OPERATOR_OR.to_s }, + assignee: { @wfs1.id.to_s => @wfs1.user_id.to_s } + } assert_response :redirect @wfs1.reload assert_equal @wfs1.operator, DmsfWorkflowStep::OPERATOR_OR end def test_update_step_assignee - put :update_step, params: { - id: @wf1, - step: '1', - operator_step: { @wfs1.id.to_s => DmsfWorkflowStep::OPERATOR_OR.to_s }, - assignee: { @wfs1.id.to_s => @someone.id.to_s } - } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + put "/dmsf_workflows/#{@wf1.id}/update_step", + params: { + step: '1', + operator_step: { @wfs1.id.to_s => DmsfWorkflowStep::OPERATOR_OR.to_s }, + assignee: { @wfs1.id.to_s => @someone.id.to_s } + } assert_response :redirect @wfs1.reload assert_equal @someone.id, @wfs1.user_id end def test_delete_step - name = @wfs2.name - assert_difference 'DmsfWorkflowStep.count', -1 do - delete :delete_step, params: { id: @wf1, step: @wfs2.id } + post '/login', params: { username: 'jsmith', password: 'jsmith' } + n = DmsfWorkflowStep.where(dmsf_workflow_id: @wf1.id, step: @wfs2.step).count + assert_difference 'DmsfWorkflowStep.count', -n do + delete "/dmsf_workflows/#{@wfs1.id}/edit", params: { step: @wfs2.id } end - @wfs3.reload - assert_equal @wfs3.name, name assert_response :redirect end def test_log_non_member - @request.session[:user_id] = @someone.id - get :log, params: { id: @wf1.id, project_id: @project1.id, dmsf_file_id: @file1.id, format: 'js' }, xhr: true + post '/login', params: { username: 'someone', password: 'foo' } + get "/dmsf_workflows/#{@wf1.id}/log", + params: { project_id: @project1.id, dmsf_file_id: @file1.id, format: 'js' }, + xhr: true assert_response :forbidden end def test_log_member_local_wf - get :log, params: { id: @wf1.id, project_id: @project1.id, dmsf_file_id: @file1.id, format: 'js' }, xhr: true + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get "/dmsf_workflows/#{@wf1.id}/log", + params: { project_id: @project1.id, dmsf_file_id: @file1.id, format: 'js' }, + xhr: true assert_response :success assert_template :log end def test_log_member_global_wf - get :log, params: { id: @wf3.id, project_id: @project1.id, dmsf_file_id: @file1.id, format: 'js' }, xhr: true + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get "/dmsf_workflows/#{@wf3.id}/log", + params: { project_id: @project1.id, dmsf_file_id: @file1.id, format: 'js' }, + xhr: true assert_response :success assert_template :log end def test_log_admin - @request.session[:user_id] = @admin.id - get :log, params: { id: @wf1.id, project_id: @project1.id, dmsf_file_id: @file1.id, format: 'js' }, xhr: true + post '/login', params: { username: 'admin', password: 'admin' } + get "/dmsf_workflows/#{@wf1.id}/log", + params: { project_id: @project1.id, dmsf_file_id: @file1.id, format: 'js' }, + xhr: true assert_response :success assert_template :log end def test_new_step - get :new_step, params: { id: @wf1.id, format: 'js' }, xhr: true + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get "/dmsf_workflows/#{@wf1.id}/new_step", params: { format: 'js' }, xhr: true assert_response :success assert_template :new_step end diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index b8190479..32982989 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -29,7 +29,7 @@ class IssuesControllerTest < RedmineDmsf::Test::TestCase def setup super @issue1 = Issue.find 1 - @request.session[:user_id] = @jsmith.id + post '/login', params: { username: 'jsmith', password: 'jsmith' } end def test_put_update_with_project_change @@ -41,11 +41,8 @@ class IssuesControllerTest < RedmineDmsf::Test::TestCase main_system_folder = @issue1.main_system_folder assert main_system_folder assert_equal @project1.id, main_system_folder.project_id - put :update, - params: { - id: @issue1.id, - issue: { project_id: @project2.id, tracker_id: '1', priority_id: '6', category_id: '3' } - } + patch "/issues/#{@issue1.id}", + params: { issue: { project_id: @project2.id, tracker_id: '1', priority_id: '6', category_id: '3' } } assert_redirected_to action: 'show', id: @issue1.id @issue1.reload assert_equal @project2.id, @issue1.project.id diff --git a/test/functional/my_controller_test.rb b/test/functional/my_controller_test.rb index 1c87d128..a89e5c0f 100644 --- a/test/functional/my_controller_test.rb +++ b/test/functional/my_controller_test.rb @@ -27,16 +27,12 @@ class MyControllerTest < RedmineDmsf::Test::TestCase 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 setup - super - @request.session[:user_id] = @jsmith.id - end - def test_page_with_open_approvals_one_approval + post '/login', params: { username: 'jsmith', password: 'jsmith' } DmsfFileRevision.where(id: 5).delete_all @jsmith.pref[:my_page_layout] = { 'top' => ['open_approvals'] } @jsmith.pref.save! - get :page + get '/my/page' assert_response :success return if defined?(EasyExtensions) @@ -46,9 +42,10 @@ class MyControllerTest < RedmineDmsf::Test::TestCase end def test_page_with_open_approvals_no_approval + post '/login', params: { username: 'jsmith', password: 'jsmith' } @jsmith.pref[:my_page_layout] = { 'top' => ['open_approvals'] } @jsmith.pref.save! - get :page + get '/my/page' assert_response :success return if defined?(EasyExtensions) @@ -58,10 +55,11 @@ class MyControllerTest < RedmineDmsf::Test::TestCase end def test_page_with_open_locked_documents + post '/login', params: { username: 'admin', password: 'admin' } @request.session[:user_id] = @admin.id @admin.pref[:my_page_layout] = { 'top' => ['locked_documents'] } @admin.pref.save! - get :page + get '/my/page' assert_response :success return if defined?(EasyExtensions) @@ -73,12 +71,13 @@ class MyControllerTest < RedmineDmsf::Test::TestCase end def test_page_with_open_watched_documents + post '/login', params: { username: 'jsmith', password: 'jsmith' } @jsmith.pref[:my_page_layout] = { 'top' => ['watched_documents'] } @jsmith.pref.save! @file1.add_watcher @jsmith @folder1.add_watcher @jsmith @project1.add_watcher @jsmith - get :page + get '/my/page' return if defined?(EasyExtensions) assert_response :success diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index 1455cfbd..7748e4c5 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -25,10 +25,10 @@ class ProjectsControllerTest < RedmineDmsf::Test::TestCase include Redmine::I18n def test_settings_dms_member - @request.session[:user_id] = @jsmith.id + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.add_permission! :user_preferences with_settings plugin_redmine_dmsf: { 'dmsf_act_as_attachable' => '1' } do - get :settings, params: { id: @project1.id, tab: 'dmsf' } + get "/projects/#{@project1.id}/settings", params: { tab: 'dmsf' } end assert_response :success assert_select 'fieldset legend', text: l(:link_user_preferences) @@ -36,33 +36,33 @@ class ProjectsControllerTest < RedmineDmsf::Test::TestCase end def test_settings_dms_member_no_permission - @request.session[:user_id] = @jsmith.id + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.remove_permission! :user_preferences - get :settings, params: { id: @project1.id, tab: 'dmsf' } + get "/projects/#{@project1.id}/settings", params: { tab: 'dmsf' } assert_response :success assert_select 'fieldset legend', text: l(:link_user_preferences), count: 0 end def test_settings_dms_non_member - @request.session[:user_id] = @admin.id - get :settings, params: { id: @project1.id, tab: 'dmsf' } + post '/login', params: { username: 'admin', password: 'admin' } + get "/projects/#{@project1.id}/settings", params: { tab: 'dmsf' } assert_response :success assert_select 'fieldset legend', text: l(:link_user_preferences), count: 0 end def test_settings_dms_member_no_act_as_attachments - @request.session[:user_id] = @jsmith.id + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.add_permission! :user_preferences - get :settings, params: { id: @project1.id, tab: 'dmsf' } + get "/projects/#{@project1.id}/settings", params: { tab: 'dmsf' } assert_response :success assert_select 'label', text: l(:label_act_as_attachable), count: 0 end def test_legacy_notifications - @request.session[:user_id] = @jsmith.id + post '/login', params: { username: 'jsmith', password: 'jsmith' } @role_manager.add_permission! :user_preferences with_settings notified_events: ['dmsf_legacy_notifications'] do - get :settings, params: { id: @project1.id, tab: 'dmsf' } + get "/projects/#{@project1.id}/settings", params: { tab: 'dmsf' } assert_response :success assert_select 'label', text: l(:label_notifications) end diff --git a/test/test_case.rb b/test/test_case.rb index 2ced8e40..0d2d4b90 100644 --- a/test/test_case.rb +++ b/test/test_case.rb @@ -4,7 +4,7 @@ # # Copyright © 2011 Vít Jonáš # Copyright © 2012 Daniel Munn -# Copyright © 2011-15 Karel Pičman +# Copyright © 2011-23 Karel Pičman # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -23,7 +23,7 @@ module RedmineDmsf module Test # Test case - class TestCase < ActionController::TestCase + 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. diff --git a/test/unit/custom_field_dmsf_file_format_test.rb b/test/unit/custom_field_dmsf_file_format_test.rb index 2c23b17c..5764a8ce 100644 --- a/test/unit/custom_field_dmsf_file_format_test.rb +++ b/test/unit/custom_field_dmsf_file_format_test.rb @@ -32,7 +32,7 @@ class CustomFieldDmsfFileFormatTest < RedmineDmsf::Test::UnitTest def test_possible_values_options n = @issue.project.dmsf_files.visible.all.size - DmsfFolder.visible(false).where(project_id: @issue.project.id).each do |f| + DmsfFolder.visible(false).where(project_id: @issue.project.id).find_each do |f| n += f.dmsf_files.visible.all.size end assert_equal n, @field.possible_values_options(@issue).size diff --git a/test/unit/lib/redmine_dmsf/dmsf_macros_test.rb b/test/unit/lib/redmine_dmsf/dmsf_macros_test.rb index a6c09951..5d67601d 100644 --- a/test/unit/lib/redmine_dmsf/dmsf_macros_test.rb +++ b/test/unit/lib/redmine_dmsf/dmsf_macros_test.rb @@ -35,7 +35,7 @@ class DmsfMacrosTest < RedmineDmsf::Test::HelperTest def setup super User.current = @jsmith - default_url_options[:host] = 'http://example.com' + default_url_options[:host] = 'www.example.com' @file1 = DmsfFile.find_by(id: 1) @file6 = DmsfFile.find_by(id: 6) # video @file7 = DmsfFile.find_by(id: 7) # image @@ -361,7 +361,7 @@ class DmsfMacrosTest < RedmineDmsf::Test::HelperTest link = link_to(img, url, target: '_blank', rel: 'noopener', title: h(@file7.last_revision.try(:tooltip)), - 'data-downloadurl': 'image/gif:test.gif:http://example.com/dmsf/files/7/test.gif') + 'data-downloadurl': 'image/gif:test.gif:http://www.example.com/dmsf/files/7/test.gif') assert_equal content_tag(:p, link + link), text end @@ -395,7 +395,7 @@ class DmsfMacrosTest < RedmineDmsf::Test::HelperTest link = link_to(img, url, target: '_blank', rel: 'noopener', title: h(@file7.last_revision.try(:tooltip)), - 'data-downloadurl': 'image/gif:test.gif:http://example.com/dmsf/files/7/test.gif') + 'data-downloadurl': 'image/gif:test.gif:http://www.example.com/dmsf/files/7/test.gif') assert_equal content_tag(:p, link), text width = '640' text = textilizable("{{dmsftn(#{@file7.id}, width=#{width})}}")