diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2018-10-17 17:07:55 +0000 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2018-10-17 17:07:55 +0000 |
commit | ab9cf561c230f1b6ec630215a9a9def53e14d764 (patch) | |
tree | 1b085bd694318da2bd362205fd2a0338725974bf /spec/models | |
parent | ed499b38e2e68e9e7979dfcce93175d8561007a0 (diff) | |
parent | d66066f7cb4a2981c74224ad2cb6ec3c00ca529e (diff) | |
download | gitlab-ce-ab9cf561c230f1b6ec630215a9a9def53e14d764.tar.gz |
Merge branch '52527-harden-wiki-against-missing-last-version' into 'master'
Harden the wiki against missing last_versions
Closes #52527
See merge request gitlab-org/gitlab-ce!22377
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/wiki_page_spec.rb | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/spec/models/wiki_page_spec.rb b/spec/models/wiki_page_spec.rb index b4732ec0cd5..821946a47e5 100644 --- a/spec/models/wiki_page_spec.rb +++ b/spec/models/wiki_page_spec.rb @@ -457,6 +457,12 @@ describe WikiPage do end describe '#historical?' do + let(:page) { wiki.find_page('Update') } + let(:old_version) { page.versions.last.id } + let(:old_page) { wiki.find_page('Update', old_version) } + let(:latest_version) { page.versions.first.id } + let(:latest_page) { wiki.find_page('Update', latest_version) } + before do create_page('Update', 'content') @page = wiki.find_page('Update') @@ -468,23 +474,27 @@ describe WikiPage do end it 'returns true when requesting an old version' do - old_version = @page.versions.last.id - old_page = wiki.find_page('Update', old_version) - - expect(old_page.historical?).to eq true + expect(old_page.historical?).to be_truthy end it 'returns false when requesting latest version' do - latest_version = @page.versions.first.id - latest_page = wiki.find_page('Update', latest_version) - - expect(latest_page.historical?).to eq false + expect(latest_page.historical?).to be_falsy end it 'returns false when version is nil' do - latest_page = wiki.find_page('Update', nil) + expect(latest_page.historical?).to be_falsy + end + + it 'returns false when the last version is nil' do + expect(old_page).to receive(:last_version) { nil } + + expect(old_page.historical?).to be_falsy + end + + it 'returns false when the version is nil' do + expect(old_page).to receive(:version) { nil } - expect(latest_page.historical?).to eq false + expect(old_page.historical?).to be_falsy end end |