2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2015-04-27 13:06:53 -04:00
|
|
|
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
|
|
|
|
|
2020-06-29 03:52:33 -04:00
|
|
|
it "works for beta comparisons when current_version is beta" do
|
2015-04-27 13:06:53 -04:00
|
|
|
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
|
|
|
|
|
2020-06-29 03:52:33 -04:00
|
|
|
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
|
|
|
|
|
2015-04-27 13:06:53 -04:00
|
|
|
end
|
2020-07-06 17:48:00 -04:00
|
|
|
|
|
|
|
context "compatible_resource" do
|
|
|
|
shared_examples "test compatible resource" do
|
|
|
|
it "returns nil when the current version is above all pinned versions" do
|
2020-07-09 14:57:27 -04:00
|
|
|
expect(Discourse.find_compatible_resource(version_list, "2.6.0")).to be_nil
|
2020-07-06 17:48:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the correct version if matches exactly" do
|
2020-07-09 14:57:27 -04:00
|
|
|
expect(Discourse.find_compatible_resource(version_list, "2.5.0.beta4")).to eq("twofivebetafour")
|
2020-07-06 17:48:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the closest matching version" do
|
2020-07-09 14:57:27 -04:00
|
|
|
expect(Discourse.find_compatible_resource(version_list, "2.4.6.beta12")).to eq("twofivebetatwo")
|
2020-07-06 17:48:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the lowest version possible when using an older version" do
|
2020-07-09 14:57:27 -04:00
|
|
|
expect(Discourse.find_compatible_resource(version_list, "1.4.6.beta12")).to eq("twofourtwobetaone")
|
2020-07-06 17:48:00 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns nil when nil" do
|
|
|
|
expect(Discourse.find_compatible_resource(nil)).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a regular compatible list" do
|
|
|
|
let(:version_list) { <<~VERSION_LIST
|
|
|
|
2.5.0.beta6: twofivebetasix
|
|
|
|
2.5.0.beta4: twofivebetafour
|
|
|
|
2.5.0.beta2: twofivebetatwo
|
|
|
|
2.4.4.beta6: twofourfourbetasix
|
|
|
|
2.4.2.beta1: twofourtwobetaone
|
|
|
|
VERSION_LIST
|
|
|
|
}
|
|
|
|
include_examples "test compatible resource"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "handle a compatible resource out of order" do
|
|
|
|
let(:version_list) { <<~VERSION_LIST
|
|
|
|
2.4.2.beta1: twofourtwobetaone
|
|
|
|
2.5.0.beta4: twofivebetafour
|
|
|
|
2.5.0.beta6: twofivebetasix
|
|
|
|
2.5.0.beta2: twofivebetatwo
|
|
|
|
2.4.4.beta6: twofourfourbetasix
|
|
|
|
VERSION_LIST
|
|
|
|
}
|
|
|
|
include_examples "test compatible resource"
|
|
|
|
end
|
|
|
|
end
|
2015-04-27 13:06:53 -04:00
|
|
|
end
|