mirror of
https://github.com/discourse/discourse.git
synced 2024-12-15 06:16:02 +08:00
271d6319ce
Adds a new rake task `plugin:checkout_compatible_all` and `plugin:checkout_compatible[plugin-name]` that check out compatible plugin versions. Supports a .discourse-compatibility file in the root of plugins and themes that list out a plugin's compatibility with certain discourse versions: eg: .discourse-compatibility ``` 2.5.0.beta6: some-git-hash 2.4.4.beta4: some-git-tag 2.2.0: git-reference ``` This ensures older Discourse installs are able to find and install older versions of plugins without intervention, through the manifest only. It iterates through the versions in descending order. If the current Discourse version matches an item in the manifest, it checks out the listed plugin target. If the Discourse version is greater than an item in the manifest, it checks out the next highest version listed in the manifest. If no versions match, it makes no change.
107 lines
4.1 KiB
Ruby
107 lines
4.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
|
|
|
|
context "compatible_resource" do
|
|
after do
|
|
# Cleanup versions
|
|
::Discourse::VERSION::STRING = [::Discourse::VERSION::MAJOR, ::Discourse::VERSION::MINOR, ::Discourse::VERSION::TINY, ::Discourse::VERSION::PRE].compact.join('.')
|
|
end
|
|
|
|
shared_examples "test compatible resource" do
|
|
it "returns nil when the current version is above all pinned versions" do
|
|
::Discourse::VERSION::STRING = "2.6.0"
|
|
expect(Discourse.find_compatible_resource(version_list)).to be_nil
|
|
end
|
|
|
|
it "returns the correct version if matches exactly" do
|
|
::Discourse::VERSION::STRING = "2.5.0.beta4"
|
|
expect(Discourse.find_compatible_resource(version_list)).to eq("twofivebetafour")
|
|
end
|
|
|
|
it "returns the closest matching version" do
|
|
::Discourse::VERSION::STRING = "2.4.6.beta12"
|
|
expect(Discourse.find_compatible_resource(version_list)).to eq("twofivebetatwo")
|
|
end
|
|
|
|
it "returns the lowest version possible when using an older version" do
|
|
::Discourse::VERSION::STRING = "1.4.6.beta12"
|
|
expect(Discourse.find_compatible_resource(version_list)).to eq("twofourtwobetaone")
|
|
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
|
|
end
|