Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorSato Hiroyuki <sathiroyuki@gmail.com>2013-05-08 09:19:51 +0400
committerSato Hiroyuki <sathiroyuki@gmail.com>2013-05-08 12:36:48 +0400
commit862e0ff6b846d9207c3adf9e86b5b84420595935 (patch)
treed06940ebe66d59a59550229004f10b8d25d0682e /spec/lib
parent2e9599b746d5858eea0e4edcd5db4969b74c885c (diff)
Add Gitlab::VersionInfo class to fix and simplify version check.
It returns "yes" if required version is "1.7.10" and current version is "1.6.10", because the patch version of current version equals to that of required version.
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/version_info_spec.rb69
1 files changed, 69 insertions, 0 deletions
diff --git a/spec/lib/gitlab/version_info_spec.rb b/spec/lib/gitlab/version_info_spec.rb
new file mode 100644
index 00000000000..94dccf7a4e5
--- /dev/null
+++ b/spec/lib/gitlab/version_info_spec.rb
@@ -0,0 +1,69 @@
+require 'spec_helper'
+
+describe 'Gitlab::VersionInfo', no_db: true do
+ before do
+ @unknown = Gitlab::VersionInfo.new
+ @v0_0_1 = Gitlab::VersionInfo.new(0, 0, 1)
+ @v0_1_0 = Gitlab::VersionInfo.new(0, 1, 0)
+ @v1_0_0 = Gitlab::VersionInfo.new(1, 0, 0)
+ @v1_0_1 = Gitlab::VersionInfo.new(1, 0, 1)
+ @v1_1_0 = Gitlab::VersionInfo.new(1, 1, 0)
+ @v2_0_0 = Gitlab::VersionInfo.new(2, 0, 0)
+ end
+
+ context '>' do
+ it { @v2_0_0.should > @v1_1_0 }
+ it { @v1_1_0.should > @v1_0_1 }
+ it { @v1_0_1.should > @v1_0_0 }
+ it { @v1_0_0.should > @v0_1_0 }
+ it { @v0_1_0.should > @v0_0_1 }
+ end
+
+ context '>=' do
+ it { @v2_0_0.should >= Gitlab::VersionInfo.new(2, 0, 0) }
+ it { @v2_0_0.should >= @v1_1_0 }
+ end
+
+ context '<' do
+ it { @v0_0_1.should < @v0_1_0 }
+ it { @v0_1_0.should < @v1_0_0 }
+ it { @v1_0_0.should < @v1_0_1 }
+ it { @v1_0_1.should < @v1_1_0 }
+ it { @v1_1_0.should < @v2_0_0 }
+ end
+
+ context '<=' do
+ it { @v0_0_1.should <= Gitlab::VersionInfo.new(0, 0, 1) }
+ it { @v0_0_1.should <= @v0_1_0 }
+ end
+
+ context '==' do
+ it { @v0_0_1.should == Gitlab::VersionInfo.new(0, 0, 1) }
+ it { @v0_1_0.should == Gitlab::VersionInfo.new(0, 1, 0) }
+ it { @v1_0_0.should == Gitlab::VersionInfo.new(1, 0, 0) }
+ end
+
+ context '!=' do
+ it { @v0_0_1.should_not == @v0_1_0 }
+ end
+
+ context 'unknown' do
+ it { @unknown.should_not be @v0_0_1 }
+ it { @unknown.should_not be Gitlab::VersionInfo.new }
+ it { expect{@unknown > @v0_0_1}.to raise_error(ArgumentError) }
+ it { expect{@unknown < @v0_0_1}.to raise_error(ArgumentError) }
+ end
+
+ context 'parse' do
+ it { Gitlab::VersionInfo.parse("1.0.0").should == @v1_0_0 }
+ it { Gitlab::VersionInfo.parse("1.0.0.1").should == @v1_0_0 }
+ it { Gitlab::VersionInfo.parse("git 1.0.0b1").should == @v1_0_0 }
+ it { Gitlab::VersionInfo.parse("git 1.0b1").should_not be_valid }
+ end
+
+ context 'to_s' do
+ it { @v1_0_0.to_s.should == "1.0.0" }
+ it { @unknown.to_s.should == "Unknown" }
+ end
+end
+