diff --git a/app/models/category_featured_topic.rb b/app/models/category_featured_topic.rb index e78dab86e4..2e454effca 100644 --- a/app/models/category_featured_topic.rb +++ b/app/models/category_featured_topic.rb @@ -74,7 +74,7 @@ class CategoryFeaturedTopic < ActiveRecord::Base results.each_with_index do |topic_id, idx| begin c.category_featured_topics.create(topic_id: topic_id, rank: idx) - rescue PG::UniqueViolation, ActiveRecord::RecordNotUnique + rescue PG::UniqueViolation # If another process features this topic, just ignore it end end diff --git a/lib/version.rb b/lib/version.rb index ed96d4c2bd..addca5b5e7 100644 --- a/lib/version.rb +++ b/lib/version.rb @@ -4,8 +4,6 @@ module Discourse VERSION_REGEXP ||= /\A\d+\.\d+\.\d+(\.beta\d+)?\z/ VERSION_COMPATIBILITY_FILENAME ||= ".discourse-compatibility" - VERSION_COMPATIBILITY_FILENAME = ".discourse-compatibility" - # work around reloader unless defined? ::Discourse::VERSION module VERSION #:nodoc: @@ -57,40 +55,4 @@ module Discourse compat_resource, std_error, s = Open3.capture3("git -C '#{path}' show HEAD@{upstream}:#{Discourse::VERSION_COMPATIBILITY_FILENAME}") Discourse.find_compatible_resource(compat_resource) if s.success? end - - # lookup an external resource (theme/plugin)'s best compatible version - # compatible resource files are YAML, in the format: - # `discourse_version: plugin/theme git reference.` For example: - # 2.5.0.beta6: c4a6c17 - # 2.5.0.beta4: d1d2d3f - # 2.5.0.beta2: bbffee - # 2.4.4.beta6: some-other-branch-ref - # 2.4.2.beta1: v1-tag - def self.find_compatible_resource(version_list) - - return unless version_list - - version_list = YAML.load(version_list).sort_by { |version, pin| Gem::Version.new(version) }.reverse - - # If plugin compat version is listed as less than current Discourse version, take the version/hash listed before. - checkout_version = nil - version_list.each do |core_compat, target| - if Gem::Version.new(core_compat) == Gem::Version.new(::Discourse::VERSION::STRING) # Exact version match - return it - checkout_version = target - break - elsif Gem::Version.new(core_compat) < Gem::Version.new(::Discourse::VERSION::STRING) # Core is on a higher version than listed, use a later version - break - end - checkout_version = target - end - - checkout_version - end - - # Find a compatible resource from a git repo - def self.find_compatible_git_resource(path) - return unless File.directory?("#{path}/.git") - compat_resource, std_error, s = Open3.capture3("git -C '#{path}' show HEAD@{upstream}:#{Discourse::VERSION_COMPATIBILITY_FILENAME}") - Discourse.find_compatible_resource(compat_resource) if s.success? - end end diff --git a/spec/components/version_spec.rb b/spec/components/version_spec.rb index 52c78959b7..aba3461f77 100644 --- a/spec/components/version_spec.rb +++ b/spec/components/version_spec.rb @@ -94,61 +94,4 @@ describe Discourse::VERSION do include_examples "test compatible resource" 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