Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

replace legacy spec

ulferts6a821ed820e1
diff --git a/lib/redmine/plugin.rb b/lib/redmine/plugin.rb
index b5e19256f52..fcf26063bd7 100644
--- a/lib/redmine/plugin.rb
+++ b/lib/redmine/plugin.rb
@@ -127,13 +127,7 @@ module Redmine # :nodoc:
# find circular dependencies
raise PluginCircularDependency.new(id) if dependencies_for(e.plugin_id).include?(id)
- if RedminePluginLocator.instance.has_plugin? e.plugin_id
- # The required plugin is going to be loaded later, defer loading this plugin
- (deferred_plugins[e.plugin_id] ||= []) << [id, block]
- p
- else
- raise
- end
+ raise
end
def name(*args)
diff --git a/spec/lib/redmine/i18n_spec.rb b/spec/lib/redmine/i18n_spec.rb
index 165dcca05e2..c1d91b48348 100644
--- a/spec/lib/redmine/i18n_spec.rb
+++ b/spec/lib/redmine/i18n_spec.rb
@@ -86,7 +86,7 @@ module OpenProject
end
it 'returns no js language as they are duplicates of the rest of the other language' do
- expect(all_languages.any? { |l| /\Ajs-/.match(l.to_s) }).to be_falsey
+ expect(all_languages).not_to be_any { |l| /\Ajs-/.match(l.to_s) }
end
# it is OK if more languages exist
@@ -117,8 +117,8 @@ module OpenProject
Setting.all_languages.each do |lang|
it "sets I18n.locale to #{lang}" do
- allow(I18n).to receive(:locale=)
- expect(I18n).to receive(:locale=).with(lang)
+ allow(described_class).to receive(:locale=)
+ expect(described_class).to receive(:locale=).with(lang)
set_language_if_valid(lang)
end
@@ -127,7 +127,7 @@ module OpenProject
it 'does not set I18n.locale to an invalid language' do
allow(Setting).to receive(:available_languages).and_return([:en])
- expect(I18n).not_to receive(:locale=).with(:de)
+ expect(described_class).not_to receive(:locale=).with(:de)
end
end
@@ -200,7 +200,7 @@ module OpenProject
context 'without a date_format setting', with_settings: { date_format: '' } do
it 'uses the locale formate' do
expect(format_date(Date.today))
- .to eql I18n.l(Date.today)
+ .to eql described_class.l(Date.today)
end
end
@@ -210,6 +210,195 @@ module OpenProject
.to eql Date.today.strftime('%d %m %Y')
end
end
+
+ valid_languages.each do |lang|
+ context "for lang #{lang}" do
+ it 'raises no error' do
+ described_class.with_locale lang do
+ expect { format_date(Date.today) }
+ .not_to raise_error
+ end
+ end
+ end
+ end
+ end
+
+ describe '#numer_to_human_size' do
+ valid_languages.each do |lang|
+ context "for locale #{lang}" do
+ it 'does not raise an error' do
+ described_class.with_locale lang do
+ expect { number_to_human_size(1024 * 1024 * 4) }
+ .not_to raise_error
+ end
+ end
+ end
+ end
+ end
+
+ describe '#format_time', with_settings: {
+ time_format: '%H %M',
+ date_format: '%d %m %Y'
+ } do
+ let!(:now) { Time.parse('2011-02-20 15:45:22') }
+
+ it 'with date and hours' do
+ expect(format_time(now))
+ .to eql now.strftime('%d %m %Y %H %M')
+ end
+
+ it 'with only hours' do
+ expect(format_time(now, false))
+ .to eql now.strftime('%H %M')
+ end
+
+ it 'with a utc to date and hours' do
+ expect(format_time(now.utc))
+ .to eql now.localtime.strftime('%d %m %Y %H %M')
+ end
+
+ it 'with a utce to only hours' do
+ expect(format_time(now.utc, false))
+ .to eql now.localtime.strftime('%H %M')
+ end
+
+ context 'with a different format defined', with_settings: {
+ time_format: '%H:%M',
+ date_format: '%Y-%m-%d'
+ } do
+ it 'renders date and hours' do
+ expect(format_time(now))
+ .to eql '2011-02-20 15:45'
+ end
+
+ it 'renders only hours' do
+ expect(format_time(now, false))
+ .to eql '15:45'
+ end
+ end
+
+ context 'without time and date format', with_settings: {
+ time_format: '',
+ date_format: ''
+ } do
+ it 'falls back to default for date and hours' do
+ expect(format_time(now))
+ .to eql '02/20/2011 03:45 PM'
+ end
+
+ it 'falls back to default for only hours' do
+ expect(format_time(now, false))
+ .to eql '03:45 PM'
+ end
+
+ valid_languages.each do |lang|
+ context "for lang #{lang}" do
+ it 'raises no error for date and hours' do
+ described_class.with_locale lang do
+ expect { format_time(now) }
+ .not_to raise_error
+ end
+ end
+
+ it 'raises no error for only hours' do
+ described_class.with_locale lang do
+ expect { format_time(now, false) }
+ .not_to raise_error
+ end
+ end
+ end
+ end
+ end
+
+ context 'without time format', with_settings: {
+ time_format: '',
+ date_format: '%Y-%m-%d'
+ } do
+ it 'falls back to default for date and hours' do
+ expect(format_time(now))
+ .to eql '2011-02-20 03:45 PM'
+ end
+
+ it 'falls back to default for only hours' do
+ expect(format_time(now, false))
+ .to eql '03:45 PM'
+ end
+ end
+
+ context 'without date format', with_settings: {
+ time_format: '%H:%M',
+ date_format: ''
+ } do
+ it 'falls back to default for date and hours' do
+ expect(format_time(now))
+ .to eql '02/20/2011 15:45'
+ end
+
+ it 'falls back to default for only hours' do
+ expect(format_time(now, false))
+ .to eql '15:45'
+ end
+ end
+ end
+
+ describe 'day names' do
+ valid_languages.each do |lang|
+ context "for locale #{lang}" do
+ it 'is an array' do
+ described_class.with_locale lang do
+ expect(described_class.t('date.day_names'))
+ .to be_a Array
+ end
+ end
+
+ it 'has 7 elements' do
+ described_class.with_locale lang do
+ expect(described_class.t('date.day_names').size)
+ .to eq 7
+ end
+ end
+ end
+ end
+ end
+
+ describe 'month names' do
+ valid_languages.each do |lang|
+ context "for locale #{lang}" do
+ it 'is an array' do
+ described_class.with_locale lang do
+ expect(described_class.t('date.month_names'))
+ .to be_a Array
+ end
+ end
+
+ it 'has 13 elements' do
+ described_class.with_locale lang do
+ expect(described_class.t('date.month_names').size)
+ .to eq 13
+ end
+ end
+ end
+ end
+ end
+
+ describe '.l' do
+ valid_languages.each do |lang|
+ context "for locale #{lang}" do
+ it 'is not \'default\' for a date' do
+ described_class.with_locale lang do
+ expect(described_class.l(Date.today, format: :default))
+ .not_to eq 'default'
+ end
+ end
+
+ it 'is not \'default\' for a time' do
+ described_class.with_locale lang do
+ expect(described_class.l(Time.zone.now, format: :default))
+ .not_to eq 'time'
+ end
+ end
+ end
+ end
end
end
end
diff --git a/spec/lib/redmine/plugin_spec.rb b/spec/lib/redmine/plugin_spec.rb
new file mode 100644
index 00000000000..f9dfe28d6d1
--- /dev/null
+++ b/spec/lib/redmine/plugin_spec.rb
@@ -0,0 +1,238 @@
+# --copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2022 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+# ++
+
+require 'spec_helper'
+
+describe Redmine::Plugin do
+ let!(:registered_plugins) { described_class.instance_variable_get(:@registered_plugins) }
+
+ before do
+ described_class.clear
+ end
+
+ after do
+ described_class.instance_variable_set(:@registered_plugins, registered_plugins)
+ end
+
+ describe '.register' do
+ context 'for a plugin with properties' do
+ before do
+ described_class.register :foo do
+ name 'Foo plugin'
+ url 'https://example.net/plugins/foo'
+ author 'John Smith'
+ author_url 'https://example.net/jsmith'
+ description 'This is a test plugin'
+ version '0.0.1'
+ settings default: { 'sample_setting' => 'value', 'foo' => 'bar' },
+ partial: 'foo/settings'
+ end
+ end
+
+ subject { described_class.find(:foo) }
+
+ it 'has the provided id' do
+ expect(subject.id)
+ .to eq :foo
+ end
+
+ it 'has the provided url' do
+ expect(subject.url)
+ .to eq 'https://example.net/plugins/foo'
+ end
+
+ it 'has the provided author' do
+ expect(subject.author)
+ .to eq 'John Smith'
+ end
+
+ it 'has the provided author url' do
+ expect(subject.author_url)
+ .to eq 'https://example.net/jsmith'
+ end
+
+ it 'has the provided description' do
+ expect(subject.description)
+ .to eq 'This is a test plugin'
+ end
+
+ it 'has the provided version' do
+ expect(subject.version)
+ .to eq '0.0.1'
+ end
+
+ it 'adds a setting' do
+ expect(Setting['plugin_foo'])
+ .to eq('sample_setting' => 'value', 'foo' => 'bar')
+ end
+ end
+ end
+
+ describe '.register with #requires_openproject' do
+ it 'allows registering with a version requirement lower than the op version' do
+ expect do
+ described_class.register(:foo) do
+ requires_openproject(">= #{OpenProject::VERSION.to_semver.gsub(/\A\d+/) { |num| num.to_i - 1 }}")
+ end
+ end.not_to raise_error
+ end
+
+ it 'allows registering with a version requirement to be the op version as a minumum' do
+ expect do
+ described_class.register(:foo) { requires_openproject(">= #{OpenProject::VERSION.to_semver}") }
+ end.not_to raise_error
+ end
+
+ it 'allows registering with a version requirement equal to the op version' do
+ expect do
+ described_class.register(:foo) { requires_openproject(OpenProject::VERSION.to_semver) }
+ end.not_to raise_error
+ end
+
+ it 'allows registering with a version requirement equal to the minor op version' do
+ expect do
+ described_class.register(:foo) { requires_openproject("~> #{OpenProject::VERSION.to_semver.gsub(/\d+\z/, '0')}") }
+ end.not_to raise_error
+ end
+
+ it 'allows registering with a version requirement between two versions' do
+ expect do
+ described_class.register(:foo) do
+ requires_openproject("> #{OpenProject::VERSION.to_semver.gsub(/\A\d+/) { |num| num.to_i - 1 }}",
+ "<= #{OpenProject::VERSION.to_semver.gsub(/\d+\z/) { |num| num.to_i + 1 }}")
+ end
+ end.not_to raise_error
+ end
+
+ it 'raises when registering with a minimum version requirement not met' do
+ expect do
+ described_class.register(:foo) do
+ requires_openproject(">= #{OpenProject::VERSION.to_semver.next}")
+ end
+ end.to raise_error Redmine::PluginRequirementError
+ end
+
+ it 'raises when registering with a maximum version requirement not met' do
+ expect do
+ described_class.register(:foo) do
+ requires_openproject("< #{OpenProject::VERSION.to_semver}")
+ end
+ end.to raise_error Redmine::PluginRequirementError
+ end
+
+ it 'raises registering with a minimum and maximum version requirement which are both not met' do
+ expect do
+ described_class.register(:foo) do
+ requires_openproject("< #{OpenProject::VERSION.to_semver}",
+ ">= #{OpenProject::VERSION.to_semver.next}")
+ end
+ end.to raise_error Redmine::PluginRequirementError
+ end
+ end
+
+ describe '.register with #requires_redmine_plugin' do
+ before do
+ described_class.register :other do
+ name 'Other'
+ version '0.5.0'
+ end
+ end
+
+ it 'allows registering with a version requirement lower than the plugin version' do
+ expect do
+ described_class.register(:foo) do
+ requires_redmine_plugin(:other, "0.4.0")
+ end
+ end.not_to raise_error
+ end
+
+ it 'allows registering with a version requirement equal to the plugin version' do
+ expect do
+ described_class.register(:foo) do
+ requires_redmine_plugin(:other, "0.5.0")
+ end
+ end.not_to raise_error
+ end
+
+ it 'raises an error when registering with a version requirement higher than the plugin version' do
+ expect do
+ described_class.register(:foo) do
+ requires_redmine_plugin(:other, "0.5.1")
+ end
+ end.to raise_error Redmine::PluginRequirementError
+ end
+
+ it 'allows registering with a version requirement that is exactly the plugin version' do
+ expect do
+ described_class.register(:foo) do
+ requires_redmine_plugin(:other, version: "0.5.0")
+ end
+ end.not_to raise_error
+ end
+
+ it 'allows registering with a version requirement that is exactly the plugin version from a list of allowed' do
+ expect do
+ described_class.register(:foo) do
+ requires_redmine_plugin(:other, version: %w[0.5.0 99.9.9])
+ end
+ end.not_to raise_error
+ end
+
+ it 'raises an error when registering with a version requirement that is not exactly the specified one' do
+ expect do
+ described_class.register(:foo) do
+ requires_redmine_plugin(:other, version: "0.4.0")
+ end
+ end.to raise_error Redmine::PluginRequirementError
+ end
+
+ it 'raises an error when registering with a version requirement that is not one of the exactly specified ones' do
+ expect do
+ described_class.register(:foo) do
+ requires_redmine_plugin(:other, version: %w[0.4.0 0.5.1 0.9.9])
+ end
+ end.to raise_error Redmine::PluginRequirementError
+ end
+
+ it 'raises for a missing plugin with an exact version specification' do
+ expect do
+ described_class.register(:foo) do
+ requires_redmine_plugin(:missing, version_or_higher: "0.4.0")
+ end
+ end.to raise_error Redmine::PluginNotFound
+ end
+
+ it 'raises for a missing plugin with a minimum version specification' do
+ expect do
+ described_class.register(:foo) do
+ requires_redmine_plugin(:missing, version_or_higher: %w[0.4.0 0.5.1 0.9.9])
+ end
+ end.to raise_error Redmine::PluginNotFound
+ end
+ end
+end
diff --git a/spec_legacy/unit/lib/redmine/i18n_spec.rb b/spec_legacy/unit/lib/redmine/i18n_spec.rb
deleted file mode 100644
index 59b48d72e4e..00000000000
--- a/spec_legacy/unit/lib/redmine/i18n_spec.rb
+++ /dev/null
@@ -1,105 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2022 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-require_relative '../../../legacy_spec_helper'
-
-describe Redmine::I18n do
- include Redmine::I18n
- include ActionView::Helpers::NumberHelper
-
- it 'dates and time for each language' do
- Setting.date_format = ''
- valid_languages.each do |lang|
- set_language_if_valid lang
- expect do
- format_date(Date.today)
- format_time(Time.now)
- format_time(Time.now, false)
- refute_equal 'default', ::I18n.l(Date.today, format: :default), "date.formats.default missing in #{lang}"
- refute_equal 'time', ::I18n.l(Time.now, format: :time), "time.formats.time missing in #{lang}"
- end.not_to raise_error
- assert I18n.t('date.day_names').is_a?(Array)
- assert_equal 7, I18n.t('date.day_names').size
-
- assert I18n.t('date.month_names').is_a?(Array)
- assert_equal 13, I18n.t('date.month_names').size
- end
- end
-
- it 'times format' do
- set_language_if_valid 'en'
- now = Time.parse('2011-02-20 15:45:22')
- Setting.time_format = '%H:%M'
- Setting.date_format = '%Y-%m-%d'
- assert_equal '2011-02-20 15:45', format_time(now)
- assert_equal '15:45', format_time(now, false)
-
- Setting.date_format = ''
- assert_equal '02/20/2011 15:45', format_time(now)
- assert_equal '15:45', format_time(now, false)
- end
-
- it 'times format default' do
- set_language_if_valid 'en'
- now = Time.parse('2011-02-20 15:45:22')
- Setting.time_format = ''
- Setting.date_format = '%Y-%m-%d'
- assert_equal '2011-02-20 03:45 PM', format_time(now)
- assert_equal '03:45 PM', format_time(now, false)
-
- Setting.date_format = ''
- assert_equal '02/20/2011 03:45 PM', format_time(now)
- assert_equal '03:45 PM', format_time(now, false)
- end
-
- it 'times format' do
- set_language_if_valid 'en'
- now = Time.now
- Setting.time_format = '%H %M'
- Setting.date_format = '%d %m %Y'
- assert_equal now.strftime('%d %m %Y %H %M'), format_time(now)
- assert_equal now.strftime('%H %M'), format_time(now, false)
- end
-
- it 'utcs time format' do
- set_language_if_valid 'en'
- now = Time.now
- Setting.time_format = '%H %M'
- Setting.date_format = '%d %m %Y'
- assert_equal now.localtime.strftime('%d %m %Y %H %M'), format_time(now.utc)
- assert_equal now.localtime.strftime('%H %M'), format_time(now.utc, false)
- end
-
- it 'numbers to human size for each language' do
- valid_languages.each do |lang|
- set_language_if_valid lang
- expect do
- number_to_human_size(1024 * 1024 * 4)
- end.not_to raise_error
- end
- end
-end
diff --git a/spec_legacy/unit/lib/redmine/plugin_spec.rb b/spec_legacy/unit/lib/redmine/plugin_spec.rb
deleted file mode 100644
index 65ca1e11abe..00000000000
--- a/spec_legacy/unit/lib/redmine/plugin_spec.rb
+++ /dev/null
@@ -1,125 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2022 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-require_relative '../../../legacy_spec_helper'
-
-describe Redmine::Plugin do
- before do
- @klass = Redmine::Plugin
- # In case some real plugins are installed
- @klass.clear
- end
-
- after do
- @klass.clear
- end
-
- it 'registers' do
- @klass.register :foo do
- name 'Foo plugin'
- url 'http://example.net/plugins/foo'
- author 'John Smith'
- author_url 'http://example.net/jsmith'
- description 'This is a test plugin'
- version '0.0.1'
- settings default: { 'sample_setting' => 'value', 'foo' => 'bar' }, partial: 'foo/settings'
- end
-
- assert_equal 1, @klass.all.size
-
- plugin = @klass.find('foo')
- assert plugin.is_a?(Redmine::Plugin)
- assert_equal :foo, plugin.id
- assert_equal 'Foo plugin', plugin.name
- assert_equal 'http://example.net/plugins/foo', plugin.url
- assert_equal 'John Smith', plugin.author
- assert_equal 'http://example.net/jsmith', plugin.author_url
- assert_equal 'This is a test plugin', plugin.description
- assert_equal '0.0.1', plugin.version
- end
-
- it 'requireses openproject' do
- test = self
- version = OpenProject::VERSION.to_semver
-
- @klass.register :foo do
- test.assert requires_openproject('>= 0.1')
- test.assert requires_openproject(">= #{version}")
- test.assert requires_openproject(version)
- test.assert_raises Redmine::PluginRequirementError do
- requires_openproject('>= 99.0.0')
- end
- test.assert_raises Redmine::PluginRequirementError do
- requires_openproject('< 0.9')
- end
- requires_openproject('> 0.9', '<= 99.0.0')
- test.assert_raises Redmine::PluginRequirementError do
- requires_openproject('< 0.9', '>= 98.0.0')
- end
-
- test.assert requires_openproject("~> #{OpenProject::VERSION.to_semver.gsub(/\d+\z/, '0')}")
- end
- end
-
- it 'requireses redmine plugin' do
- test = self
- other_version = '0.5.0'
-
- @klass.register :other do
- name 'Other'
- version other_version
- end
-
- @klass.register :foo do
- test.assert requires_redmine_plugin(:other, version_or_higher: '0.1.0')
- test.assert requires_redmine_plugin(:other, version_or_higher: other_version)
- test.assert requires_redmine_plugin(:other, other_version)
- test.assert_raises Redmine::PluginRequirementError do
- requires_redmine_plugin(:other, version_or_higher: '99.0.0')
- end
-
- test.assert requires_redmine_plugin(:other, version: other_version)
- test.assert requires_redmine_plugin(:other, version: [other_version, '99.0.0'])
- test.assert_raises Redmine::PluginRequirementError do
- requires_redmine_plugin(:other, version: '99.0.0')
- end
- test.assert_raises Redmine::PluginRequirementError do
- requires_redmine_plugin(:other, version: ['98.0.0', '99.0.0'])
- end
- # Missing plugin
- test.assert_raises Redmine::PluginNotFound do
- requires_redmine_plugin(:missing, version_or_higher: '0.1.0')
- end
- test.assert_raises Redmine::PluginNotFound do
- requires_redmine_plugin(:missing, '0.1.0')
- end
- test.assert_raises Redmine::PluginNotFound do
- requires_redmine_plugin(:missing, version: '0.1.0')
- end
- end
- end
-end