diff options
Diffstat (limited to 'spec/helpers/whats_new_helper_spec.rb')
-rw-r--r-- | spec/helpers/whats_new_helper_spec.rb | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/spec/helpers/whats_new_helper_spec.rb b/spec/helpers/whats_new_helper_spec.rb index 1c8684de75c..017826921ff 100644 --- a/spec/helpers/whats_new_helper_spec.rb +++ b/spec/helpers/whats_new_helper_spec.rb @@ -3,22 +3,22 @@ require 'spec_helper' RSpec.describe WhatsNewHelper do - let(:fixture_dir_glob) { Dir.glob(File.join('spec', 'fixtures', 'whats_new', '*.yml')) } - describe '#whats_new_storage_key' do subject { helper.whats_new_storage_key } context 'when version exist' do + let(:release_item) { double(:item) } + before do - allow(Dir).to receive(:glob).with(Rails.root.join('data', 'whats_new', '*.yml')).and_return(fixture_dir_glob) + allow(ReleaseHighlight).to receive(:versions).and_return([84.0]) end - it { is_expected.to eq('display-whats-new-notification-01.05') } + it { is_expected.to eq('display-whats-new-notification-84.0') } end - context 'when recent release items do NOT exist' do + context 'when most recent release highlights do NOT exist' do before do - allow(helper).to receive(:whats_new_release_items).and_return(nil) + allow(ReleaseHighlight).to receive(:versions).and_return(nil) end it { is_expected.to be_nil } @@ -30,31 +30,28 @@ RSpec.describe WhatsNewHelper do context 'when recent release items exist' do it 'returns the count from the most recent file' do - expect(Dir).to receive(:glob).with(Rails.root.join('data', 'whats_new', '*.yml')).and_return(fixture_dir_glob) + allow(ReleaseHighlight).to receive(:most_recent_item_count).and_return(1) expect(subject).to eq(1) end end context 'when recent release items do NOT exist' do - before do - allow(YAML).to receive(:safe_load).and_raise + it 'returns nil' do + allow(ReleaseHighlight).to receive(:most_recent_item_count).and_return(nil) - expect(Gitlab::ErrorTracking).to receive(:track_exception) - end - - it 'fails gracefully and logs an error' do expect(subject).to be_nil end end end - # Testing this important private method here because the request spec required multiple confusing mocks and felt wrong and overcomplicated - describe '#whats_new_items_cache_key' do - it 'returns a key containing the most recent file name and page parameter' do - allow(Dir).to receive(:glob).with(Rails.root.join('data', 'whats_new', '*.yml')).and_return(fixture_dir_glob) + describe '#whats_new_versions' do + let(:versions) { [84.0] } + + it 'returns ReleaseHighlight.versions' do + expect(ReleaseHighlight).to receive(:versions).and_return(versions) - expect(helper.send(:whats_new_items_cache_key, 2)).to eq('whats_new:release_items:file-20201225_01_05:page-2') + expect(helper.whats_new_versions).to eq(versions) end end end |