Commit dc25a083 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'jswain_whats_new_dont_cache_root_path' into 'master'

Dont cache root path in file_paths method

See merge request gitlab-org/gitlab!68081
parents 38e1a5ee a38f7c8e
...@@ -49,8 +49,12 @@ class ReleaseHighlight ...@@ -49,8 +49,12 @@ class ReleaseHighlight
end end
def self.file_paths def self.file_paths
@file_paths ||= Rails.cache.fetch(self.cache_key('file_paths'), expires_in: CACHE_DURATION) do @file_paths ||= self.relative_file_paths.map { |path| path.prepend(Rails.root.to_s) }
Dir.glob(FILES_PATH).sort.reverse end
def self.relative_file_paths
Rails.cache.fetch(self.cache_key('file_paths'), expires_in: CACHE_DURATION) do
Dir.glob(FILES_PATH).sort.reverse.map { |path| path.delete_prefix(Rails.root.to_s) }
end end
end end
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe ReleaseHighlight, :clean_gitlab_redis_cache do RSpec.describe ReleaseHighlight, :clean_gitlab_redis_cache do
let(:fixture_dir_glob) { Dir.glob(File.join('spec', 'fixtures', 'whats_new', '*.yml')).grep(/\d*\_(\d*\_\d*)\.yml$/) } let(:fixture_dir_glob) { Dir.glob(File.join(Rails.root, 'spec', 'fixtures', 'whats_new', '*.yml')).grep(/\d*\_(\d*\_\d*)\.yml$/) }
let(:starter_plan) { create(:license, plan: License::STARTER_PLAN) } let(:starter_plan) { create(:license, plan: License::STARTER_PLAN) }
let(:premium_plan) { create(:license, plan: License::PREMIUM_PLAN) } let(:premium_plan) { create(:license, plan: License::PREMIUM_PLAN) }
let(:ultimate_plan) { create(:license, plan: License::ULTIMATE_PLAN) } let(:ultimate_plan) { create(:license, plan: License::ULTIMATE_PLAN) }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe ReleaseHighlight, :clean_gitlab_redis_cache do RSpec.describe ReleaseHighlight, :clean_gitlab_redis_cache do
let(:fixture_dir_glob) { Dir.glob(File.join('spec', 'fixtures', 'whats_new', '*.yml')).grep(/\d*\_(\d*\_\d*)\.yml$/) } let(:fixture_dir_glob) { Dir.glob(File.join(Rails.root, 'spec', 'fixtures', 'whats_new', '*.yml')).grep(/\d*\_(\d*\_\d*)\.yml$/) }
before do before do
allow(Dir).to receive(:glob).with(Rails.root.join('data', 'whats_new', '*.yml')).and_return(fixture_dir_glob) allow(Dir).to receive(:glob).with(Rails.root.join('data', 'whats_new', '*.yml')).and_return(fixture_dir_glob)
...@@ -193,4 +193,12 @@ RSpec.describe ReleaseHighlight, :clean_gitlab_redis_cache do ...@@ -193,4 +193,12 @@ RSpec.describe ReleaseHighlight, :clean_gitlab_redis_cache do
expect(subject).to eq('Free') expect(subject).to eq('Free')
end end
end end
describe '.file_paths' do
it 'joins relative file paths with the root path to avoid caching the root url' do
allow(described_class).to receive(:relative_file_paths).and_return([+'/a.yml'])
expect(described_class.file_paths.first).to eq("#{Rails.root}/a.yml")
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment