summaryrefslogtreecommitdiff
path: root/spec/models/wiki_page_spec.rb
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2018-10-15 20:07:02 +0100
committerNick Thomas <nick@gitlab.com>2018-10-17 13:24:52 +0100
commitd66066f7cb4a2981c74224ad2cb6ec3c00ca529e (patch)
treee416f31d864631ad9b231870eb8bae46d2234aac /spec/models/wiki_page_spec.rb
parente657c9a9e6d9877a4bf0b3fb39a0f4bff0dc5470 (diff)
downloadgitlab-ce-d66066f7cb4a2981c74224ad2cb6ec3c00ca529e.tar.gz
Harden the wiki against missing last_versions
Currently, we assume a "last_version" always exists for a wiki page. In production, this is not always true. So, guard uses of it with a null check.
Diffstat (limited to 'spec/models/wiki_page_spec.rb')
-rw-r--r--spec/models/wiki_page_spec.rb30
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