From 1796fddd2b09ede4faefcf339cd33a0ae5ee35c4 Mon Sep 17 00:00:00 2001 From: Holger Just Date: Sun, 13 Mar 2011 16:53:09 +0100 Subject: [PATCH] [#275] Add requires_chiliproject. We now use the rubygems dependency syntax. --- lib/redmine/plugin.rb | 29 +++++++++++++++++++++++++++- test/unit/lib/redmine/plugin_test.rb | 23 ++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/lib/redmine/plugin.rb b/lib/redmine/plugin.rb index 5fdbb2f3..956617e0 100644 --- a/lib/redmine/plugin.rb +++ b/lib/redmine/plugin.rb @@ -101,9 +101,36 @@ module Redmine #:nodoc: self.id.to_s <=> plugin.id.to_s end - # Sets a requirement on Redmine version + # Sets a requirement on the ChiliProject version. + # Raises a PluginRequirementError exception if the requirement is not met. + # + # It uses the same syntax as rubygems requirements. + # Examples + # # Requires exactly ChiliProject 1.1.1 + # requires_chiliproject "1.1.1" + # requires_chiliproject "= 1.1.1" + + # # Requires ChiliProject 1.1.x + # requires_chiliproject "~> 1.1.0" + + # # Requires ChiliProject between 1.1.0 and 1.1.5 or higher + # requires_chiliproject ">= 1.1.0", "<= 1.1.5" + + def requires_chiliproject(*args) + required_version = Gem::Requirement.new(*args) + chili_version = Gem::Version.new(Redmine::VERSION.to_semver) + + unless required_version.satisfied_by? chili_version + raise PluginRequirementError.new("#{id} plugin requires ChiliProject version #{required_version} but current version is #{chili_version}.") + end + true + end + + # Sets a requirement on Redmine version. # Raises a PluginRequirementError exception if the requirement is not met # + # THIS IS A REDMINE COMPATIBILITY INTERFACE + # # Examples # # Requires Redmine 0.7.3 or higher # requires_redmine :version_or_higher => '0.7.3' diff --git a/test/unit/lib/redmine/plugin_test.rb b/test/unit/lib/redmine/plugin_test.rb index 4fdd45f9..24c24bba 100644 --- a/test/unit/lib/redmine/plugin_test.rb +++ b/test/unit/lib/redmine/plugin_test.rb @@ -71,6 +71,29 @@ class Redmine::PluginTest < ActiveSupport::TestCase end end + def test_requires_chiliproject + test = self + version = Redmine::VERSION.to_semver + + @klass.register :foo do + test.assert requires_chiliproject('>= 0.1') + test.assert requires_chiliproject(">= #{version}") + test.assert requires_chiliproject(version) + test.assert_raise Redmine::PluginRequirementError do + requires_chiliproject('>= 99.0.0') + end + test.assert_raise Redmine::PluginRequirementError do + requires_chiliproject('< 0.9') + end + requires_chiliproject('> 0.9', "<= 99.0.0") + test.assert_raise Redmine::PluginRequirementError do + requires_chiliproject('< 0.9', ">= 98.0.0") + end + + test.assert requires_chiliproject("~> #{Redmine::VERSION.to_semver.gsub(/\d+$/, '0')}") + end + end + def test_requires_redmine_plugin test = self other_version = '0.5.0'