From 1e6b5a1e4d76784ef31f78a3074854930ecd56ab Mon Sep 17 00:00:00 2001 From: erwanlr Date: Wed, 30 Jul 2014 12:11:04 +0100 Subject: [PATCH] Improves the version comparison --- lib/common/version_compare.rb | 4 ++++ spec/lib/common/version_compare_spec.rb | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/common/version_compare.rb b/lib/common/version_compare.rb index 098ed603..3e0ded85 100644 --- a/lib/common/version_compare.rb +++ b/lib/common/version_compare.rb @@ -10,6 +10,10 @@ class VersionCompare # # @return [ Boolean ] def self.lesser_or_equal?(version1, version2) + # Prepend a '0' if the version starts with a '.' + version1 = "0#{version1}" if version1 && version1[0,1] == '.' + version2 = "0#{version2}" if version2 && version2[0,1] == '.' + return true if (version1 == version2) # Both versions must be set return false unless (version1 and version2) diff --git a/spec/lib/common/version_compare_spec.rb b/spec/lib/common/version_compare_spec.rb index f89d7445..0a62b74f 100644 --- a/spec/lib/common/version_compare_spec.rb +++ b/spec/lib/common/version_compare_spec.rb @@ -36,6 +36,11 @@ describe 'VersionCompare' do @version1 = '0.4.2b' @version2 = '2.3.3' end + + it 'returns true' do + @version1 = '.47' + @version2 = '.50.3' + end end context 'version checked is older' do @@ -60,6 +65,11 @@ describe 'VersionCompare' do @version1 = '1.6.3.7.3.4' @version2 = '1.2.4.567.679.8.e' end + + it 'returns false' do + @version1 = '.47' + @version2 = '.46.3' + end end context 'version checked is the same' do