summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-01-29 17:12:42 +0000
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-01-29 17:12:42 +0000
commita8b7ac91b44c83f6d53aaf30a460dd6717df1522 (patch)
treeecb6b3950a4ed560358b0044af8bba6a86a259a2
parent7ede227add897de1dfef306f73c13d8cdd32c410 (diff)
parentaa30088f6e02c761722d202bb741b7b51e9ec36e (diff)
downloadgitlab-ce-a8b7ac91b44c83f6d53aaf30a460dd6717df1522.tar.gz
Merge branch 'fix-viewing-wiki-page-lastest-version-via-version-id' into 'master'
Fix "old version" warning when viewing wiki page's latest version via version_id in URL Fixes #12712 See merge request !2627
-rw-r--r--app/models/wiki_page.rb2
-rw-r--r--spec/models/wiki_page_spec.rb32
2 files changed, 33 insertions, 1 deletions
diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb
index 2a65f0431c4..dbd70dc5a44 100644
--- a/app/models/wiki_page.rb
+++ b/app/models/wiki_page.rb
@@ -110,7 +110,7 @@ class WikiPage
# Returns boolean True or False if this instance
# is an old version of the page.
def historical?
- @page.historical?
+ @page.historical? && versions.first.sha != version.sha
end
# Returns boolean True or False if this instance
diff --git a/spec/models/wiki_page_spec.rb b/spec/models/wiki_page_spec.rb
index c1b03838aa9..ddc49495eda 100644
--- a/spec/models/wiki_page_spec.rb
+++ b/spec/models/wiki_page_spec.rb
@@ -189,6 +189,38 @@ describe WikiPage, models: true do
end
end
+ describe '#historical?' do
+ before do
+ create_page('Update', 'content')
+ @page = wiki.find_page('Update')
+ 3.times { |i| @page.update("content #{i}") }
+ end
+
+ after do
+ destroy_page('Update')
+ end
+
+ it 'returns true when requesting an old version' do
+ old_version = @page.versions.last.to_s
+ old_page = wiki.find_page('Update', old_version)
+
+ expect(old_page.historical?).to eq true
+ end
+
+ it 'returns false when requesting latest version' do
+ latest_version = @page.versions.first.to_s
+ latest_page = wiki.find_page('Update', latest_version)
+
+ expect(latest_page.historical?).to eq false
+ end
+
+ it 'returns false when version is nil' do
+ latest_page = wiki.find_page('Update', nil)
+
+ expect(latest_page.historical?).to eq false
+ end
+ end
+
private
def remove_temp_repo(path)