summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/wiki_controller.rb2
-rw-r--r--app/models/wiki_content.rb10
-rw-r--r--app/views/wiki/show.html.erb8
-rw-r--r--test/fixtures/wiki_content_versions.yml24
-rw-r--r--test/unit/wiki_content_test.rb7
5 files changed, 46 insertions, 5 deletions
diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb
index 8713e91c4..2f4724f38 100644
--- a/app/controllers/wiki_controller.rb
+++ b/app/controllers/wiki_controller.rb
@@ -86,7 +86,7 @@ class WikiController < ApplicationController
end
@editable = editable?
@sections_editable = @editable && User.current.allowed_to?(:edit_wiki_pages, @page.project) &&
- @content.version == @page.content.version &&
+ @content.current_version? &&
Redmine::WikiFormatting.supports_section_edit?
render :action => 'show'
diff --git a/app/models/wiki_content.rb b/app/models/wiki_content.rb
index b1fe60fec..430e9a50e 100644
--- a/app/models/wiki_content.rb
+++ b/app/models/wiki_content.rb
@@ -45,6 +45,11 @@ class WikiContent < ActiveRecord::Base
notified.collect(&:mail)
end
+ # Return true if the content is the current page content
+ def current_version?
+ true
+ end
+
class Version
belongs_to :page, :class_name => '::WikiPage', :foreign_key => 'page_id'
belongs_to :author, :class_name => '::User', :foreign_key => 'author_id'
@@ -101,6 +106,11 @@ class WikiContent < ActiveRecord::Base
page.project
end
+ # Return true if the content is the current page content
+ def current_version?
+ page.content.version == self.version
+ end
+
# Returns the previous version or nil
def previous
@previous ||= WikiContent::Version.find(:first,
diff --git a/app/views/wiki/show.html.erb b/app/views/wiki/show.html.erb
index 22f3bab72..25dfc1062 100644
--- a/app/views/wiki/show.html.erb
+++ b/app/views/wiki/show.html.erb
@@ -1,19 +1,19 @@
<div class="contextual">
<% if @editable %>
-<%= link_to_if_authorized(l(:button_edit), {:action => 'edit', :id => @page.title}, :class => 'icon icon-edit', :accesskey => accesskey(:edit)) if @content.version == @page.content.version %>
+<%= link_to_if_authorized(l(:button_edit), {:action => 'edit', :id => @page.title}, :class => 'icon icon-edit', :accesskey => accesskey(:edit)) if @content.current_version? %>
<%= watcher_tag(@page, User.current) %>
<%= link_to_if_authorized(l(:button_lock), {:action => 'protect', :id => @page.title, :protected => 1}, :method => :post, :class => 'icon icon-lock') if !@page.protected? %>
<%= link_to_if_authorized(l(:button_unlock), {:action => 'protect', :id => @page.title, :protected => 0}, :method => :post, :class => 'icon icon-unlock') if @page.protected? %>
-<%= link_to_if_authorized(l(:button_rename), {:action => 'rename', :id => @page.title}, :class => 'icon icon-move') if @content.version == @page.content.version %>
+<%= link_to_if_authorized(l(:button_rename), {:action => 'rename', :id => @page.title}, :class => 'icon icon-move') if @content.current_version? %>
<%= link_to_if_authorized(l(:button_delete), {:action => 'destroy', :id => @page.title}, :method => :delete, :confirm => l(:text_are_you_sure), :class => 'icon icon-del') %>
-<%= link_to_if_authorized(l(:button_rollback), {:action => 'edit', :id => @page.title, :version => @content.version }, :class => 'icon icon-cancel') if @content.version < @page.content.version %>
+<%= link_to_if_authorized(l(:button_rollback), {:action => 'edit', :id => @page.title, :version => @content.version }, :class => 'icon icon-cancel') unless @content.current_version? %>
<% end %>
<%= link_to_if_authorized(l(:label_history), {:action => 'history', :id => @page.title}, :class => 'icon icon-history') %>
</div>
<%= wiki_page_breadcrumb(@page) %>
-<% if @content.version != @page.content.version %>
+<% unless @content.current_version? %>
<p>
<%= link_to(("\xc2\xab " + l(:label_previous)),
:action => 'show', :id => @page.title, :project_id => @page.project,
diff --git a/test/fixtures/wiki_content_versions.yml b/test/fixtures/wiki_content_versions.yml
index cdfeadd94..e7c0d4832 100644
--- a/test/fixtures/wiki_content_versions.yml
+++ b/test/fixtures/wiki_content_versions.yml
@@ -64,6 +64,8 @@ wiki_content_versions_005:
@WHATEVER@
Maecenas sed elit sit amet mi accumsan vestibulum non nec velit. Proin porta tincidunt lorem, consequat rhoncus dolor fermentum in.
+
+ Cras ipsum felis, ultrices at porttitor vel, faucibus eu nunc.
h2. Heading 2
@@ -75,4 +77,26 @@ wiki_content_versions_005:
version: 2
author_id: 1
comments:
+wiki_content_versions_006:
+ data: |-
+ h1. Title
+
+ Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
+
+ h2. Heading 1
+
+ @WHATEVER@
+
+ Maecenas sed elit sit amet mi accumsan vestibulum non nec velit. Proin porta tincidunt lorem, consequat rhoncus dolor fermentum in.
+
+ h2. Heading 2
+
+ Morbi facilisis accumsan orci non pharetra.
+ updated_on: 2007-03-08 00:18:07 +01:00
+ page_id: 11
+ wiki_content_id: 11
+ id: 6
+ version: 3
+ author_id: 1
+ comments:
diff --git a/test/unit/wiki_content_test.rb b/test/unit/wiki_content_test.rb
index 97c6b8ade..4900f48e2 100644
--- a/test/unit/wiki_content_test.rb
+++ b/test/unit/wiki_content_test.rb
@@ -85,4 +85,11 @@ class WikiContentTest < ActiveSupport::TestCase
page.reload
assert_equal 500.kilobyte, page.content.text.size
end
+
+ def test_current_version
+ content = WikiContent.find(11)
+ assert_equal true, content.current_version?
+ assert_equal true, content.versions.first(:order => 'version DESC').current_version?
+ assert_equal false, content.versions.first(:order => 'version ASC').current_version?
+ end
end