2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-28 01:06:53 +08:00
|
|
|
require "version"
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe Discourse::VERSION do
|
2022-07-28 00:14:14 +08:00
|
|
|
describe ".has_needed_version?" do
|
2015-04-28 01:06:53 +08:00
|
|
|
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 15:52:33 +08:00
|
|
|
it "works for beta comparisons when current_version is beta" do
|
2015-04-28 01:06:53 +08: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 15:52:33 +08: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-28 01:06:53 +08:00
|
|
|
end
|
2020-07-07 05:48:00 +08:00
|
|
|
|
2022-07-28 00:14:14 +08:00
|
|
|
describe ".find_compatible_resource" do
|
2020-07-07 05:48:00 +08:00
|
|
|
shared_examples "test compatible resource" do
|
|
|
|
it "returns nil when the current version is above all pinned versions" do
|
2020-07-10 02:57:27 +08:00
|
|
|
expect(Discourse.find_compatible_resource(version_list, "2.6.0")).to be_nil
|
2020-07-07 05:48:00 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the correct version if matches exactly" do
|
2020-07-10 02:57:27 +08:00
|
|
|
expect(Discourse.find_compatible_resource(version_list, "2.5.0.beta4")).to eq(
|
|
|
|
"twofivebetafour",
|
|
|
|
)
|
2020-07-07 05:48:00 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the closest matching version" do
|
2020-07-10 02:57:27 +08:00
|
|
|
expect(Discourse.find_compatible_resource(version_list, "2.4.6.beta12")).to eq(
|
|
|
|
"twofivebetatwo",
|
|
|
|
)
|
2020-07-07 05:48:00 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the lowest version possible when using an older version" do
|
2020-07-10 02:57:27 +08:00
|
|
|
expect(Discourse.find_compatible_resource(version_list, "1.4.6.beta12")).to eq(
|
|
|
|
"twofourtwobetaone",
|
|
|
|
)
|
2020-07-07 05:48:00 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns nil when nil" do
|
|
|
|
expect(Discourse.find_compatible_resource(nil)).to be_nil
|
|
|
|
end
|
|
|
|
|
2022-02-23 16:44:37 +08:00
|
|
|
it "returns nil when empty" do
|
|
|
|
expect(Discourse.find_compatible_resource("")).to be_nil
|
|
|
|
end
|
|
|
|
|
2020-10-13 00:25:06 +08:00
|
|
|
it "raises an error on invalid input" do
|
|
|
|
expect { Discourse.find_compatible_resource("1.0.0.beta1 12f82d5") }.to raise_error(
|
|
|
|
Discourse::InvalidVersionListError,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2020-07-07 05:48:00 +08:00
|
|
|
context "with a regular compatible list" do
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
let(:version_list) { <<~YML }
|
2020-07-07 05:48:00 +08:00
|
|
|
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
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
YML
|
2020-07-07 05:48:00 +08:00
|
|
|
include_examples "test compatible resource"
|
|
|
|
end
|
|
|
|
|
2022-07-28 00:14:14 +08:00
|
|
|
context "when handling a compatible resource out of order" do
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
let(:version_list) { <<~YML }
|
2020-07-07 05:48:00 +08:00
|
|
|
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
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
YML
|
2020-07-07 05:48:00 +08:00
|
|
|
include_examples "test compatible resource"
|
|
|
|
end
|
|
|
|
end
|
2020-10-13 00:25:06 +08:00
|
|
|
|
2022-07-28 00:14:14 +08:00
|
|
|
describe ".find_compatible_git_resource" do
|
2020-10-13 00:25:06 +08:00
|
|
|
let!(:git_directory) do
|
|
|
|
path = nil
|
|
|
|
|
|
|
|
capture_stdout do
|
|
|
|
# Note the lack of colon between version and hash
|
|
|
|
path = setup_git_repo(".discourse-compatibility" => "1.0.0.beta1 12f82d5")
|
|
|
|
|
|
|
|
# Simulate a remote upstream
|
|
|
|
`cd #{path} && git remote add origin #{path}/.git && git fetch -q`
|
2020-10-13 04:54:56 +08:00
|
|
|
`cd #{path} && git branch -u origin/$(git rev-parse --abbrev-ref HEAD)`
|
2020-10-13 00:25:06 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
path
|
|
|
|
end
|
|
|
|
|
|
|
|
after { FileUtils.remove_entry(git_directory) }
|
|
|
|
|
|
|
|
it "gracefully handles invalid input" do
|
|
|
|
output =
|
|
|
|
capture_stderr { expect(Discourse.find_compatible_git_resource(git_directory)).to be_nil }
|
|
|
|
|
|
|
|
expect(output).to include("Invalid version list")
|
|
|
|
end
|
|
|
|
end
|
2015-04-28 01:06:53 +08:00
|
|
|
end
|