# frozen_string_literal: true require 'spec_helper' 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$/) } before do allow(Dir).to receive(:glob).with(Rails.root.join('data', 'whats_new', '*.yml')).and_return(fixture_dir_glob) end after do ReleaseHighlight.instance_variable_set(:@file_paths, nil) end describe '.for_version' do subject { ReleaseHighlight.for_version(version: version) } let(:version) { '1.1' } context 'with version param that exists' do it 'returns items from that version' do expect(subject.items.first['title']).to eq("It's gonna be a bright") end end context 'with version param that does NOT exist' do let(:version) { '84.0' } it 'returns nil' do expect(subject).to be_nil end end end describe '.paginated' do let(:dot_com) { false } before do allow(Gitlab).to receive(:com?).and_return(dot_com) end context 'with page param' do subject { ReleaseHighlight.paginated(page: page) } context 'when there is another page of results' do let(:page) { 2 } it 'responds with paginated results' do expect(subject[:items].first['title']).to eq('bright') expect(subject[:next_page]).to eq(3) end end context 'when there is NOT another page of results' do let(:page) { 3 } it 'responds with paginated results and no next_page' do expect(subject[:items].first['title']).to eq("It's gonna be a bright") expect(subject[:next_page]).to eq(nil) end end context 'when that specific page does not exist' do let(:page) { 84 } it 'returns nil' do expect(subject).to be_nil end end end context 'with no page param' do subject { ReleaseHighlight.paginated } it 'uses multiple levels of cache' do expect(Rails.cache).to receive(:fetch).with("release_highlight:items:page-1:#{Gitlab.revision}", { expires_in: described_class::CACHE_DURATION }).and_call_original expect(Rails.cache).to receive(:fetch).with("release_highlight:file_paths:#{Gitlab.revision}", { expires_in: described_class::CACHE_DURATION }).and_call_original subject end it 'returns platform specific items' do expect(subject[:items].count).to eq(1) expect(subject[:items].first['title']).to eq("bright and sunshinin' day") expect(subject[:next_page]).to eq(2) end it 'parses the body as markdown and returns html' do expect(subject[:items].first['body']).to match("