mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 09:23:44 +08:00
0edffcc47d
* FIX: Correct version comparison logic when comparing stable to beta For example, version 1.3.0 should be considered higher than 1.3.0.beta3. So `Discourse.has_needed_version?('1.3.0', '1.3.0.beta3')` should return true * Switch to use Gem::Version to compare versions
50 lines
2.1 KiB
Ruby
50 lines
2.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
require 'version'
|
|
|
|
describe Discourse::VERSION do
|
|
|
|
context "has_needed_version?" do
|
|
|
|
it "works for major comparisons" do
|
|
expect(Discourse.has_needed_version?('1.0.0', '1.0.0')).to eq(true)
|
|
expect(Discourse.has_needed_version?('2.0.0', '1.0.0')).to eq(true)
|
|
expect(Discourse.has_needed_version?('0.0.1', '1.0.0')).to eq(false)
|
|
end
|
|
|
|
it "works for minor comparisons" do
|
|
expect(Discourse.has_needed_version?('1.1.0', '1.1.0')).to eq(true)
|
|
expect(Discourse.has_needed_version?('1.2.0', '1.1.0')).to eq(true)
|
|
expect(Discourse.has_needed_version?('2.0.0', '1.1.0')).to eq(true)
|
|
expect(Discourse.has_needed_version?('0.1.0', '0.1.0')).to eq(true)
|
|
|
|
expect(Discourse.has_needed_version?('1.0.0', '1.1.0')).to eq(false)
|
|
expect(Discourse.has_needed_version?('0.0.1', '0.1.0')).to eq(false)
|
|
end
|
|
|
|
it "works for tiny comparisons" do
|
|
expect(Discourse.has_needed_version?('2.0.0', '2.0.0')).to eq(true)
|
|
expect(Discourse.has_needed_version?('2.0.1', '2.0.0')).to eq(true)
|
|
expect(Discourse.has_needed_version?('1.12.0', '2.0.0')).to eq(false)
|
|
expect(Discourse.has_needed_version?('1.12.0', '2.12.5')).to eq(false)
|
|
end
|
|
|
|
it "works for beta comparisons when current_version is beta" do
|
|
expect(Discourse.has_needed_version?('1.3.0.beta3', '1.2.9')).to eq(true)
|
|
expect(Discourse.has_needed_version?('1.3.0.beta3', '1.3.0.beta1')).to eq(true)
|
|
expect(Discourse.has_needed_version?('1.3.0.beta3', '1.3.0.beta4')).to eq(false)
|
|
expect(Discourse.has_needed_version?('1.3.0.beta3', '1.3.0')).to eq(false)
|
|
end
|
|
|
|
it "works for beta comparisons when needed_version is beta" do
|
|
expect(Discourse.has_needed_version?('1.2.0', '1.3.0.beta3')).to eq(false)
|
|
expect(Discourse.has_needed_version?('1.2.9', '1.3.0.beta3')).to eq(false)
|
|
expect(Discourse.has_needed_version?('1.3.0.beta1', '1.3.0.beta3')).to eq(false)
|
|
expect(Discourse.has_needed_version?('1.3.0.beta4', '1.3.0.beta3')).to eq(true)
|
|
expect(Discourse.has_needed_version?('1.3.0', '1.3.0.beta3')).to eq(true)
|
|
end
|
|
|
|
end
|
|
end
|