Improves the version comparison

This commit is contained in:
erwanlr
2014-07-30 12:11:04 +01:00
parent 12d275c26b
commit 1e6b5a1e4d
2 changed files with 14 additions and 0 deletions

View File

@@ -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)

View File

@@ -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