From b5d483c8238655193e10857bb953effb6fa2bc05 Mon Sep 17 00:00:00 2001 From: Alexander Meindl Date: Sun, 10 Nov 2024 19:29:59 +0100 Subject: [PATCH] working on redmine 6 support --- .github/workflows/tests.yml | 7 +-- .rubocop.yml | 3 +- CHANGELOG.md | 2 + Gemfile | 7 ++- README.md | 19 +++--- additionals.gemspec | 32 ---------- app/helpers/additionals_icons_helper.rb | 16 +---- app/jobs/additionals_job.rb | 17 ------ app/models/additionals_application_record.rb | 7 --- app/models/dashboard.rb | 2 +- app/models/dashboard_role.rb | 2 +- app/overrides/wiki_edit.rb | 18 ++---- app/overrides/wiki_show.rb | 21 ++----- .../additionals/_export_options.html.slim | 2 +- app/views/additionals_journals/update.js.erb | 3 +- app/views/projects/show.html.slim | 6 +- init.rb | 8 +-- lib/additionals.rb | 32 ++-------- lib/additionals/gemify.rb | 59 ------------------- lib/additionals/job_wrapper.rb | 11 ---- lib/additionals/patches/project_patch.rb | 2 +- lib/additionals/plugin_version.rb | 7 --- test/global_test_helper.rb | 5 -- test/test_helper.rb | 18 +----- test/unit/project_test.rb | 6 +- test/unit/wiki_formating/common_mark_test.rb | 10 +--- test/unit/wiki_formating/markdown_test.rb | 50 ---------------- test/unit/wiki_formating/textile_test.rb | 30 ++++------ 28 files changed, 64 insertions(+), 338 deletions(-) delete mode 100644 additionals.gemspec delete mode 100644 app/jobs/additionals_job.rb delete mode 100644 app/models/additionals_application_record.rb delete mode 100644 lib/additionals/gemify.rb delete mode 100644 lib/additionals/job_wrapper.rb delete mode 100644 lib/additionals/plugin_version.rb delete mode 100644 test/unit/wiki_formating/markdown_test.rb diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c1da7661..8bb6580f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,12 +10,9 @@ jobs: strategy: matrix: - ruby: ['3.1', '3.2'] - redmine: ['5.0-stable', '5.1-stable', 'master'] + ruby: ['3.1', '3.2', '3.3'] + redmine: ['6.0-stable', 'master'] db: ['postgres', 'mysql'] - exclude: - - ruby: '3.2' - redmine: 5.0-stable fail-fast: false services: diff --git a/.rubocop.yml b/.rubocop.yml index acbe0138..58c70a1f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,7 +5,7 @@ require: AllCops: TargetRubyVersion: 3.1 - TargetRailsVersion: 6.1 + TargetRailsVersion: 7.2 NewCops: enable ActiveSupportExtensionsEnabled: true @@ -82,7 +82,6 @@ Style/AutoResourceCleanup: Style/ExpandPathArguments: Enabled: true Exclude: - - additionals.gemspec - test/**/* Style/FrozenStringLiteralComment: diff --git a/CHANGELOG.md b/CHANGELOG.md index 52b46906..934b6425 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ## 4.0.0 - Support for Redmine 6 +- Redmine 5 support dropped +- Gemify support dropped ## 3.4.0 diff --git a/Gemfile b/Gemfile index 64c6688a..c754fee4 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,10 @@ # frozen_string_literal: true -# Specify your gem's dependencies in additionals.gemspec -gemspec +gem 'redmine_plugin_kit' +gem 'render_async' +gem 'rss' +gem 'slim-rails' +gem 'tanuki_emoji', '~> 0.13.0' # this is only used for local development. # if you want to use it, do: diff --git a/README.md b/README.md index 51b65518..652f5da2 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,9 @@ Additionals is a `Redmine` plugin for customizing Redmine, providing wiki macros | Name | requirement | | -------------------|----------------------------------| -| `Redmine` version | >= 5.0 | +| `Redmine` version | >= 6.0 | | `Ruby` version | >= 3.1 | -| Database version | MySQL >= 8.0 or PostgreSQL >= 10 | +| Database version | MySQL >= 8.0 or PostgreSQL >= 14 | > **_NOTE:_** If you use MySQL, make sure all database tables using the same storage engine (InnoDB is recommended) and character set (utf8mb4 is recommended). > **_NOTE:_** For more information use the official [Redmine install documentation](https://www.redmine.org/projects/redmine/wiki/RedmineInstall) @@ -30,7 +30,7 @@ Install `additionals` plugin for `Redmine`. bundle exec rake redmine:plugins:migrate RAILS_ENV=production ``` -Restart your application server (apache with passenger, nginx with passenger, unicorn, puma, etc.) and *Additionals* is ready to use. +Restart your application server (apache with passenger, nginx with passenger, unicorn, puma, etc.) and `additionals` is ready to use. More information about installation of Redmine plugins, you can find in the official [Redmine plugin documentation](https://www.redmine.org/projects/redmine/wiki/Plugins>). @@ -55,7 +55,6 @@ Uninstall `additionals` plugin. ```shell cd $REDMINE_ROOT bundle exec rake redmine:plugins:migrate NAME=additionals VERSION=0 RAILS_ENV=production - rm -rf plugins/additionals public/plugin_assets/additionals ``` ## Features @@ -101,7 +100,7 @@ Uninstall `additionals` plugin. * anonymize referrer for external urls * hide role in project memberbox * limitation of the number of attachments that are displayed as a preview in the issue -* Auto watch option *Issues assigned to me* +* Auto watch option _Issues assigned to me_ * change issue author * create issue on user profile * "assign to me" link on issue @@ -161,7 +160,7 @@ The following modules are available : * mermaid * select2 -### Redmine Plugins, which are using *additionals* +### Redmine Plugins, which are using _additionals_ * [additional_tags](https://github.com/alphanodes/additional_tags) * [redmine_automation](https://alphanodes.com/redmine-automation) @@ -179,11 +178,11 @@ The following modules are available : * [redmine_sudo](https://github.com/alphanodes/redmine_sudo) * [redmine_wiki_guide](https://alphanodes.com/redmine-wiki-guide) -If you know other plugins, which are using *additionals*, please let us know or create a [PR](https://github.com/alphanodes/additionals/pulls). +If you know other plugins, which are using `additionals`, please let us know or create a [PR](https://github.com/alphanodes/additionals/pulls). ## You need a feature -*additionals* is [Open-source](https://opensource.org/osd) and it is available at +`additionals` is [Open-source](https://opensource.org/osd) and it is available at If you want to implement new features in it or if you want to change something, you can provide a pull request. @@ -193,7 +192,7 @@ We are an `Open-source`_ service company from Munich. Among other things, we off ## Additionals plugin manual -The plugin configuration takes place in the administration area by a user with administration permission. Go to *Plugins / Additionals* to open it. +The plugin configuration takes place in the administration area by a user with administration permission. Go to _Plugins / Additionals_ to open it. The additionals plugin configuration is divided into several sections, described below. @@ -265,7 +264,7 @@ Global wiki sidebar Redmine macros can be used in the Wiki of a project or in the text area of an issue. For more information on how to add macros use the Redmine help documentation. -The *Macros section* of the additionals plugin lists all available macros that the logged in user can use with the *macro button* of the wiki toolbar. If you leave them deactivated they are all available to your users for selection. +The _Macros section_ of the additionals plugin lists all available macros that the logged in user can use with the _macro button_ of the wiki toolbar. If you leave them deactivated they are all available to your users for selection. Macros marked here are not offered for selection. This allows you to limit the scope of the list for a better usability. diff --git a/additionals.gemspec b/additionals.gemspec deleted file mode 100644 index 075d1a86..00000000 --- a/additionals.gemspec +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -lib = File.expand_path '../lib', __FILE__ -$LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib -require 'additionals/plugin_version' - -Gem::Specification.new do |spec| - spec.name = 'additionals' - spec.version = Additionals::PluginVersion::VERSION - spec.authors = ['AlphaNodes'] - spec.email = ['alex@alphanodes.com'] - spec.metadata = { 'rubygems_mfa_required' => 'true' } - - spec.summary = 'Redmine plugin for adding dashboard functionality, wiki macros and libraries for other Redmine plugins' - spec.description = 'Redmine plugin for adding dashboard functionality, wiki macros and libraries for other Redmine plugins' - spec.homepage = 'https://github.com/alphanodes/alphanodes' - spec.license = 'GPL-2.0' - - spec.files = Dir['**/*'].reject do |f| - f.match %r{^((contrib|test|node_modules)/|Gemfile|Gemfile\.lock|additionals\.gemspec|package\.json|yarn\.lock)} - end - spec.require_paths = ['lib'] - spec.required_ruby_version = '>= 3.1' - - spec.add_dependency 'redmine_plugin_kit' - spec.add_dependency 'render_async' - spec.add_dependency 'rss' - spec.add_dependency 'slim-rails' - # TODO: tanuki_emoji 0.11.0 is not compatible with Redmine 5.0 - # we should switch to latest version after dropping Redmine 5.0 support - spec.add_dependency 'tanuki_emoji', '~> 0.10.0' -end diff --git a/app/helpers/additionals_icons_helper.rb b/app/helpers/additionals_icons_helper.rb index a975fbe9..09b24943 100644 --- a/app/helpers/additionals_icons_helper.rb +++ b/app/helpers/additionals_icons_helper.rb @@ -41,21 +41,7 @@ def svg_icon_tag(icon_name, end def additionals_asset_path(file) - plugin_id = 'additionals' - - if Additionals.redmine6? - asset_path "plugin_assets/#{plugin_id}/#{file}" - else - "#{additionals_image_path plugin_id}/#{file}" - end - end - - def additionals_image_path(plugin_id) - return asset_path if Additionals.redmine6? - return @additionals_image_path if defined? @additionals_image_path - - relative_url = Redmine::Utils.relative_url_root - @additionals_image_path = "#{relative_url}/plugin_assets/#{plugin_id}/images" + asset_path "plugin_assets/additionals/#{file}" end private diff --git a/app/jobs/additionals_job.rb b/app/jobs/additionals_job.rb deleted file mode 100644 index d022f3e0..00000000 --- a/app/jobs/additionals_job.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -if Additionals.redmine6? - class AdditionalsJob < ApplicationJob - end -else - class AdditionalsJob < ActiveJob::Base - # Automatically retry jobs that encountered a deadlock - # retry_on ActiveRecord::Deadlocked - - # Most jobs are safe to ignore if the underlying records are no longer available - # discard_on ActiveJob::DeserializationError - - include Additionals::JobWrapper - around_enqueue :keep_current_user - end -end diff --git a/app/models/additionals_application_record.rb b/app/models/additionals_application_record.rb deleted file mode 100644 index f034d94d..00000000 --- a/app/models/additionals_application_record.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -# NOTE: this file is used for compatibility with Redmine 5.x and Redmine 6 - -class AdditionalsApplicationRecord < (defined?(ApplicationRecord) == 'constant' ? ApplicationRecord : ActiveRecord::Base) - self.abstract_class = true -end diff --git a/app/models/dashboard.rb b/app/models/dashboard.rb index cb1c7d03..065b1f43 100644 --- a/app/models/dashboard.rb +++ b/app/models/dashboard.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Dashboard < AdditionalsApplicationRecord +class Dashboard < ApplicationRecord include Redmine::I18n include Redmine::SafeAttributes include Additionals::EntityMethods diff --git a/app/models/dashboard_role.rb b/app/models/dashboard_role.rb index b19bec0c..bf575f2c 100644 --- a/app/models/dashboard_role.rb +++ b/app/models/dashboard_role.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class DashboardRole < AdditionalsApplicationRecord +class DashboardRole < ApplicationRecord include Redmine::SafeAttributes belongs_to :dashboard diff --git a/app/overrides/wiki_edit.rb b/app/overrides/wiki_edit.rb index 5579b1a7..b3c0b256 100644 --- a/app/overrides/wiki_edit.rb +++ b/app/overrides/wiki_edit.rb @@ -1,17 +1,9 @@ # frozen_string_literal: true module WikiEdit - if Additionals.redmine6? - Deface::Override.new virtual_path: 'wiki/edit', - name: 'wiki-edit', - insert_before: 'fieldset', - original: '8c202edfea8a0a74e4c3c0c4ae53e129b1d2b1ee', - partial: 'hooks/view_wiki_form_bottom' - else - Deface::Override.new virtual_path: 'wiki/edit', - name: 'wiki-edit', - insert_before: 'fieldset', - original: 'ededb6cfd5adfe8a9723d00ce0ee23575c7cc44c', - partial: 'hooks/view_wiki_form_bottom' - end + Deface::Override.new virtual_path: 'wiki/edit', + name: 'wiki-edit', + insert_before: 'fieldset', + original: '8c202edfea8a0a74e4c3c0c4ae53e129b1d2b1ee', + partial: 'hooks/view_wiki_form_bottom' end diff --git a/app/overrides/wiki_show.rb b/app/overrides/wiki_show.rb index 73c2b951..b38cd71a 100644 --- a/app/overrides/wiki_show.rb +++ b/app/overrides/wiki_show.rb @@ -1,19 +1,10 @@ # frozen_string_literal: true module WikiShow - if Redmine::VERSION.to_s < '5.1' - Deface::Override.new virtual_path: 'wiki/show', - name: 'wiki-show', - sequence: 1, - insert_before: 'p.wiki-update-info', - original: 'd9f52aa98f1cb335314570d3f5403690f1b29145', - partial: 'hooks/view_wiki_show_bottom' - else - Deface::Override.new virtual_path: 'wiki/show', - name: 'wiki-show', - sequence: 1, - insert_before: 'p.wiki-update-info', - original: '39c0ff8f0b6a468264526af5046c3c6db7e94997', - partial: 'hooks/view_wiki_show_bottom' - end + Deface::Override.new virtual_path: 'wiki/show', + name: 'wiki-show', + sequence: 1, + insert_before: 'p.wiki-update-info', + original: '39c0ff8f0b6a468264526af5046c3c6db7e94997', + partial: 'hooks/view_wiki_show_bottom' end diff --git a/app/views/additionals/_export_options.html.slim b/app/views/additionals/_export_options.html.slim index 69b6d7e7..7d4e4b02 100644 --- a/app/views/additionals/_export_options.html.slim +++ b/app/views/additionals/_export_options.html.slim @@ -25,7 +25,7 @@ = column.caption = export_csv_encoding_select_tag - = export_csv_separator_select_tag if Redmine::VERSION.to_s >= '5.1' + = export_csv_separator_select_tag - if @issue_count && @issue_count > Setting.issues_export_limit.to_i || \ @query_count && query.export_limit && @query_count > query.export_limit diff --git a/app/views/additionals_journals/update.js.erb b/app/views/additionals_journals/update.js.erb index 80838d17..0af47458 100644 --- a/app/views/additionals_journals/update.js.erb +++ b/app/views/additionals_journals/update.js.erb @@ -5,7 +5,7 @@ $("#journal-<%= @journal.id %>-notes").replaceWith('<%= escape_javascript(render_notes(nil, @journal)) %>'); $("#journal-<%= @journal.id %>-notes").show(); $("#journal-<%= @journal.id %>-form").remove(); - <% if Redmine::VERSION.to_s >= '5.1' %> + var journal_header = $("#change-<%= @journal.id %> h4"); var journal_updated_info = journal_header.find("span.update-info"); if (journal_updated_info.length > 0) { @@ -13,5 +13,4 @@ } else { journal_header.append('<%= escape_javascript(render_journal_update_info(@journal)) %>'); } - <% end %> <% end %> diff --git a/app/views/projects/show.html.slim b/app/views/projects/show.html.slim index e652c935..339ff6a9 100644 --- a/app/views/projects/show.html.slim +++ b/app/views/projects/show.html.slim @@ -16,12 +16,12 @@ = link_to l(:label_subproject_new), new_project_path(parent_id: @project), class: 'icon icon-add' - if User.current.allowed_to? :close_project, @project - if @project.active? - - confirm_msg = Redmine::VERSION.to_s >= '5.1' ? l(:text_project_close_confirmation, @project.to_s) : l(:text_are_you_sure) + - confirm_msg = l :text_project_close_confirmation, @project.to_s = link_to l(:button_close), close_project_path(@project), data: { confirm: - confirm_msg }, method: :post, class: 'icon icon-lock' - else - - confirm_msg = Redmine::VERSION.to_s >= '5.1' ? l(:text_project_reopen_confirmation, @project.to_s) : l(:text_are_you_sure) + - confirm_msg = l :text_project_reopen_confirmation, @project.to_s = link_to l(:button_reopen), reopen_project_path(@project), data: { confirm: confirm_msg }, method: :post, class: 'icon icon-unlock' @@ -32,7 +32,7 @@ unarchive_project_path(@project, status: params[:status]), method: :post, class: 'icon icon-unlock' - else - - confirm_msg = Redmine::VERSION.to_s >= '5.1' ? l(:text_project_archive_confirmation, @project.to_s) : l(:text_are_you_sure) + - confirm_msg = l :text_project_archive_confirmation, @project.to_s = link_to l(:button_archive), archive_project_path(@project, status: params[:status]), data: { confirm: confirm_msg }, method: :post, class: 'icon icon-lock' diff --git a/init.rb b/init.rb index 2e6c0677..909979ee 100644 --- a/init.rb +++ b/init.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'additionals/plugin_version' - loader = RedminePluginKit::Loader.new plugin_id: 'additionals' Redmine::Plugin.register :additionals do @@ -9,10 +7,9 @@ author 'AlphaNodes GmbH' description 'Customizing Redmine, providing dashboards, wiki macros and other functions for better usability.' \ ' As well as acting as a library/function provider for other Redmine plugins' - version Additionals::PluginVersion::VERSION + version Additionals::VERSION author_url 'https://alphanodes.com/' url 'https://github.com/alphanodes/additionals' - directory File.dirname(__FILE__) settings default: loader.default_settings, partial: 'additionals/settings/additionals' @@ -42,8 +39,7 @@ permission :log_time_on_closed_issues, {} end - # required redmine version - requires_redmine version_or_higher: '5.0' + requires_redmine version_or_higher: '5.1' # redmine 6.0 is required, but version is not set in redmine source yet menu :admin_menu, :additionals, { controller: 'settings', action: 'plugin', id: 'additionals' }, caption: :label_additionals end diff --git a/lib/additionals.rb b/lib/additionals.rb index 03d255a2..28a055be 100644 --- a/lib/additionals.rb +++ b/lib/additionals.rb @@ -3,6 +3,8 @@ require 'redmine_plugin_kit' module Additionals + VERSION = '4.0.0-main' + MAX_CUSTOM_MENU_ITEMS = 5 DEFAULT_MODAL_WIDTH = '350px' GOTO_LIST = " \xc2\xbb" @@ -19,6 +21,10 @@ def class_prefix(klass) klass_name.underscore.tr '/', '_' end + def uri_parser + defined?(::URI::RFC2396_PARSER) ? ::URI::RFC2396_PARSER : ::URI::DEFAULT_PARSE + end + def now_with_user_time_zone(user = User.current) if user.time_zone.nil? Time.current @@ -94,10 +100,6 @@ def debug(message = 'running', console: false) end end - def redmine6? - Redmine::VERSION.to_s >= '5.1' && Redmine::VERSION::BRANCH == 'devel' - end - private def setup @@ -163,28 +165,6 @@ def setup loader.load_view_hooks! end end - - # Run the classic redmine plugin initializer after rails boot - class Plugin < ::Rails::Engine - require 'tanuki_emoji' - require 'render_async' - require 'rss' - require 'slim' - - config.after_initialize do - # engine_name could be used (additionals_plugin), but can - # create some side effencts - plugin_id = 'additionals' - - # if plugin is already in plugins directory, use this and leave here - next if Redmine::Plugin.installed? plugin_id - - # gem is used as redmine plugin - require File.expand_path '../init', __dir__ - Additionals::Gemify.install_assets plugin_id - Additionals::Gemify.create_plugin_hint plugin_id - end - end end class String diff --git a/lib/additionals/gemify.rb b/lib/additionals/gemify.rb deleted file mode 100644 index 3c518646..00000000 --- a/lib/additionals/gemify.rb +++ /dev/null @@ -1,59 +0,0 @@ -# frozen_string_literal: true - -module Additionals - class Gemify - class << self - # install assets from gem (without asset pipline) - def install_assets(plugin_id = 'additionals') - return unless Gem.loaded_specs[plugin_id] - - source = File.join Gem.loaded_specs[plugin_id].full_gem_path, 'assets' - destination = File.join Dir.pwd, 'public', 'plugin_assets', plugin_id - return unless File.directory? source - - source_files = Dir["#{source}/**/*"] - source_dirs = source_files.select { |d| File.directory? d } - source_files -= source_dirs - - unless source_files.empty? - base_target_dir = File.join destination, File.dirname(source_files.first).gsub(source, '') - begin - FileUtils.mkdir_p base_target_dir - rescue StandardError => e - raise "Could not create directory #{base_target_dir}: " + e.message - end - end - - source_dirs.each do |dir| - target_dir = File.join destination, dir.gsub(source, '') - begin - FileUtils.mkdir_p target_dir - rescue StandardError => e - raise "Could not create directory #{target_dir}: " + e.message - end - end - - source_files.each do |file| - target = File.join destination, file.gsub(source, '') - FileUtils.cp file, target unless File.exist?(target) && FileUtils.identical?(file, target) - rescue StandardError => e - raise "Could not copy #{file} to #{target}: " + e.message - end - end - - # Create text file to Redmine's plugins directory. - # The purpose is telling plugins directory to users. - def create_plugin_hint(plugin_id = 'additionals') - plugins_dir = File.join Bundler.root, 'plugins' - path = File.join plugins_dir, plugin_id - return if File.exist? path - - File.write path, - "This plugin was installed as gem wrote to Gemfile.local instead of putting Redmine's plugin directory.\n" \ - "See #{plugin_id} gem installed directory.\n" - rescue Errno::EACCES => e - Rails.logger.warn "Could not create plugin hint file: #{e.message}" - end - end - end -end diff --git a/lib/additionals/job_wrapper.rb b/lib/additionals/job_wrapper.rb deleted file mode 100644 index 4c5e68d6..00000000 --- a/lib/additionals/job_wrapper.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -module Additionals - module JobWrapper - def keep_current_user - current_user = User.current - yield - User.current = current_user - end - end -end diff --git a/lib/additionals/patches/project_patch.rb b/lib/additionals/patches/project_patch.rb index 020a3221..06bd22b7 100644 --- a/lib/additionals/patches/project_patch.rb +++ b/lib/additionals/patches/project_patch.rb @@ -35,7 +35,7 @@ def available_status_ids def available_statuses statuses = USABLE_STATUSES.dup statuses[Project::STATUS_ARCHIVED] = :archived - statuses[Project::STATUS_SCHEDULED_FOR_DELETION] = :scheduled_for_deletion if Redmine::VERSION.to_s >= '5.1' + statuses[Project::STATUS_SCHEDULED_FOR_DELETION] = :scheduled_for_deletion statuses end diff --git a/lib/additionals/plugin_version.rb b/lib/additionals/plugin_version.rb deleted file mode 100644 index 1d01effa..00000000 --- a/lib/additionals/plugin_version.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -module Additionals - module PluginVersion - VERSION = '4.0.0-main' unless defined? Additionals::PluginVersion::VERSION - end -end diff --git a/test/global_test_helper.rb b/test/global_test_helper.rb index f08507fa..0f0f9680 100644 --- a/test/global_test_helper.rb +++ b/test/global_test_helper.rb @@ -209,11 +209,6 @@ def columns_in_projects_list css_select('table.projects thead th').map(&:text) end - # should be dropped after dropping Rails 6.x support / Redmine 5.1 support - def self.fixture_date_format(date) - date.try(:to_fs, :db) || date.to_s(:db) - end - def WikiPage.generate(**options) content = options.delete(:content) || 'Example text' diff --git a/test/test_helper.rb b/test/test_helper.rb index c719bcb6..0280d064 100755 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -37,24 +37,8 @@ def prepare_tests end end - def smiley_test_span(text) - "#{text}" - end - - def svg_test_icon - '' - end - - # for tanuki_emoji 0.11.0 or newer - # NOTE: tanuki_emoji 0.11.0 can only be used, if Redmine 5.0 suppord dropped - # (depenceny for i18n version) - def emoji_heart_tag_new - '❤️' - end - def emoji_heart_tag - '' + '❤️' end end diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index 73430839..d8142dd4 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -169,10 +169,6 @@ def test_sql_for_usable_status def test_available_status_ids ids = Project.available_status_ids - if Redmine::VERSION.to_s < '5.1' - assert_equal 3, ids.count - else - assert_operator ids.count, :>, 3 - end + assert_operator ids.count, :>, 3 end end diff --git a/test/unit/wiki_formating/common_mark_test.rb b/test/unit/wiki_formating/common_mark_test.rb index cb78e219..2f163922 100644 --- a/test/unit/wiki_formating/common_mark_test.rb +++ b/test/unit/wiki_formating/common_mark_test.rb @@ -13,13 +13,9 @@ def setup def test_smileys with_plugin_settings 'additionals', legacy_smiley_support: 1, emoji_support: 0 do - input = <<~HTML - A small test :) with an smiley - HTML - expected = <<~HTML - A small test #{smiley_test_span svg_test_icon} with an smiley - HTML - assert_equal expected, smiley_filter(input) + + assert smiley_filter('A small test :) with an smiley').include?('#icon--smiley-smiley') + assert smiley_filter('A small test :) with an smiley').include?('a-s18 a-svg-icon smiley') end end diff --git a/test/unit/wiki_formating/markdown_test.rb b/test/unit/wiki_formating/markdown_test.rb deleted file mode 100644 index e16a7beb..00000000 --- a/test/unit/wiki_formating/markdown_test.rb +++ /dev/null @@ -1,50 +0,0 @@ -# frozen_string_literal: true - -require File.expand_path '../../../test_helper', __FILE__ - -module WikiFormatting - class MarkdownTest < ActionView::TestCase - include Additionals::TestHelper - - def setup - skip 'Redcarpet is not installed' unless Object.const_defined? :Redcarpet - - @formatter = Redmine::WikiFormatting::Markdown::Formatter - end - - def test_smileys - with_plugin_settings 'additionals', legacy_smiley_support: 1, - emoji_support: 0 do - text = 'A small test :) with an smilie' - - assert_equal "

A small test #{smiley_test_span svg_test_icon} with an smilie

", - @formatter.new(text).to_html.strip - end - end - - def test_emojies - with_plugin_settings 'additionals', legacy_smiley_support: 0, - emoji_support: 1 do - text = 'A test with a :heart: emoji' - - assert_equal "

A test with a #{emoji_heart_tag} emoji

", - @formatter.new(text).to_html.strip - end - end - - def test_smileys_and_emojies - with_plugin_settings 'additionals', legacy_smiley_support: 1, - emoji_support: 1 do - text = ':heart: and :)' - - assert_equal "

#{emoji_heart_tag} and #{smiley_test_span svg_test_icon}

", - @formatter.new(text).to_html.strip - - text = ' :) and :heart:' - - assert_equal "

#{smiley_test_span svg_test_icon} and #{emoji_heart_tag}

", - @formatter.new(text).to_html.strip - end - end - end -end diff --git a/test/unit/wiki_formating/textile_test.rb b/test/unit/wiki_formating/textile_test.rb index f5d32728..0348cd44 100644 --- a/test/unit/wiki_formating/textile_test.rb +++ b/test/unit/wiki_formating/textile_test.rb @@ -18,9 +18,8 @@ def test_smileys # this is required, because inline_smileys are activated with controller action @formatter::RULES << :inline_smileys - @to_test['A test with a :) smiley'] = - "A test with a #{smiley_test_span svg_test_icon} smiley" - @to_test[':) :)'] = "#{smiley_test_span svg_test_icon} #{smiley_test_span svg_test_icon}" + @to_test['A test with a :) smiley'] = ['#icon--smiley-smiley', 'a-s18 a-svg-icon smiley'] + @to_test[':) :)'] = ['#icon--smiley-smiley', 'a-s18 a-svg-icon smiley'] assert_html_output @to_test end @@ -31,8 +30,7 @@ def test_emojies emoji_support: 1 do @formatter::RULES.delete :inline_smileys - str = 'A test with a :heart: emoji and a :) smiley' - @to_test[str] = "A test with a #{emoji_heart_tag} emoji and a :) smiley" + @to_test['A test with a :heart: emoji and a :) smiley'] = 'additionals-emoji' assert_html_output @to_test end @@ -44,8 +42,8 @@ def test_smileys_and_emojies # this is required, because inline_smileys are activated with controller action @formatter::RULES << :inline_smileys - @to_test[':heart: and :)'] = "#{emoji_heart_tag} and #{smiley_test_span svg_test_icon}" - @to_test[':) and :heart:'] = "#{smiley_test_span svg_test_icon} and #{emoji_heart_tag}" + @to_test[':heart: and :)'] = ['#icon--smiley-smiley', 'additionals-emoji'] + @to_test[':) and :heart:'] = ['#icon--smiley-smiley', 'additionals-emoji'] assert_html_output @to_test end @@ -53,18 +51,14 @@ def test_smileys_and_emojies private - def assert_html_output(to_test, expect_paragraph: true) - to_test.each do |text, expected| - assert_equal( - (expect_paragraph ? "

#{expected}

" : expected), - @formatter.new(text).to_html, - "Formatting the following text failed:\n===\n#{text}\n===\n" - ) - end - end + def assert_html_output(to_test) + to_test.each do |text, patterns| + formated_text = @formatter.new(text).to_html - def to_html(text) - @formatter.new(text).to_html + Array(patterns).each do |pattern| + assert_includes formated_text, pattern + end + end end end end