Dropped number from revision table. Also dropped timestamp. We will rely on autoincremented ID for sorting, and will for now store the time of last edit of the revision in revised_at. Later we will refactor content into a separate table (so as not to load the whole 300 kb of text and cached HTML every time we need page.revisions in code). Rake tests all pass, but watir tests indicate that some revision traversing links are still broken

This commit is contained in:
Alexey Verkhovsky 2005-08-14 22:26:54 +00:00
parent 476d7810f6
commit 052754b068
18 changed files with 116 additions and 112 deletions

View file

@ -140,7 +140,7 @@ class WikiController < ApplicationController
def pdf def pdf
page = wiki.read_page(@web_name, @page_name) page = wiki.read_page(@web_name, @page_name)
safe_page_name = @page.name.gsub(/\W/, '') safe_page_name = @page.name.gsub(/\W/, '')
file_name = "#{safe_page_name}-#{@web.address}-#{@page.created_at.strftime('%Y-%m-%d-%H-%M-%S')}" file_name = "#{safe_page_name}-#{@web.address}-#{@page.revised_on.strftime('%Y-%m-%d-%H-%M-%S')}"
file_path = File.join(@wiki.storage_path, file_name) file_path = File.join(@wiki.storage_path, file_name)
export_page_to_tex("#{file_path}.tex") unless FileTest.exists?("#{file_path}.tex") export_page_to_tex("#{file_path}.tex") unless FileTest.exists?("#{file_path}.tex")
@ -274,7 +274,8 @@ class WikiController < ApplicationController
end end
def get_page_and_revision def get_page_and_revision
@revision = @page.revisions[@params['rev'].to_i] @revision_number = @params['rev'].to_i
@revision = @page.revisions[@revision_number]
end end
def parse_category def parse_category
@ -312,8 +313,8 @@ class WikiController < ApplicationController
@pages_by_revision = @web.select.by_revision.first(limit) @pages_by_revision = @web.select.by_revision.first(limit)
else else
@pages_by_revision = @web.select.by_revision @pages_by_revision = @web.select.by_revision
@pages_by_revision.reject! { |page| page.created_at < start_date } if start_date @pages_by_revision.reject! { |page| page.revised_on < start_date } if start_date
@pages_by_revision.reject! { |page| page.created_at > end_date } if end_date @pages_by_revision.reject! { |page| page.revised_on > end_date } if end_date
end end
@hide_description = hide_description @hide_description = hide_description

View file

@ -1,9 +1,9 @@
class Page < ActiveRecord::Base class Page < ActiveRecord::Base
belongs_to :web belongs_to :web
has_many :revisions, :order => 'number' has_many :revisions, :order => 'id'
has_one :current_revision, :class_name => 'Revision', :order => 'number DESC' has_one :current_revision, :class_name => 'Revision', :order => 'id DESC'
def revise(content, created_at, author) def revise(content, time, author)
revisions_size = new_record? ? 0 : revisions.size revisions_size = new_record? ? 0 : revisions.size
if (revisions_size > 0) and content == current_revision.content if (revisions_size > 0) and content == current_revision.content
raise Instiki::ValidationError.new( raise Instiki::ValidationError.new(
@ -13,37 +13,49 @@ class Page < ActiveRecord::Base
author = Author.new(author.to_s) unless author.is_a?(Author) author = Author.new(author.to_s) unless author.is_a?(Author)
# Try to render content to make sure that markup engine can take it, # Try to render content to make sure that markup engine can take it,
# before addin a revision to the page Revision.new(:page => self, :content => content, :author => author, :revised_at => time).force_rendering
Revision.new(:page => self, :content => content, :created_at => created_at, :author => author).force_rendering
# A user may change a page, look at it and make some more changes - several times. # A user may change a page, look at it and make some more changes - several times.
# Not to record every such iteration as a new revision, if the previous revision was done # Not to record every such iteration as a new revision, if the previous revision was done
# by the same author, not more than 30 minutes ago, then update the last revision instead of # by the same author, not more than 30 minutes ago, then update the last revision instead of
# creating a new one # creating a new one
if (revisions_size > 0) && continous_revision?(created_at, author) if (revisions_size > 1) && continous_revision?(time, author)
current_revision.update_attributes(:created_at => created_at, :content => content) current_revision.update_attributes(:content => content, :revised_at => time)
else else
Revision.create(:page => self, :content => content, :created_at => created_at, :author => author) Revision.create(:page => self, :content => content, :author => author, :revised_at => time)
end end
self.created_at = created_at
save save
web.refresh_pages_with_references(name) if revisions_size == 0 web.refresh_pages_with_references(name) if revisions_size == 0
self self
end end
def rollback(revision_number, created_at, author_ip = nil) def rollback(revision_number, time, author_ip = nil)
roll_back_revision = Revision.find(:first, :conditions => ['page_id = ? AND number = ?', id, revision_number]) roll_back_revision = self.revisions[revision_number]
revise(roll_back_revision.content, created_at, Author.new(roll_back_revision.author, author_ip)) if roll_back_revision.nil?
raise Instiki::ValidationError.new("Revision #{revision_number} not found")
end
revise(roll_back_revision.content, time, Author.new(roll_back_revision.author, author_ip))
end end
def revisions? def revisions?
revisions.size > 1 revisions.size > 1
end end
def revised_on def previous_revision(revision)
created_on revision_index = revisions.each_with_index do |rev, index|
if rev.id == revision.id
break index
else
nil
end
end
if revision_index.nil? or revision_index == 0
nil
else
revisions[revision_index - 1]
end
end end
def in_category?(cat) def in_category?(cat)
@ -108,8 +120,8 @@ class Page < ActiveRecord::Base
private private
def continous_revision?(created_at, author) def continous_revision?(time, author)
current_revision.author == author && current_revision.created_at + 30.minutes > created_at (current_revision.author == author) && (revised_on + 30.minutes > time)
end end
# Forward method calls to the current revision, so the page responds to all revision calls # Forward method calls to the current revision, so the page responds to all revision calls

View file

@ -17,10 +17,9 @@ class PageSet < Array
end end
def most_recent_revision def most_recent_revision
self.map { |page| page.created_at }.max || Time.at(0) self.map { |page| page.revised_on }.max || Time.at(0)
end end
def by_name def by_name
PageSet.new(@web, sort_by { |page| page.name }) PageSet.new(@web, sort_by { |page| page.name })
end end
@ -28,7 +27,7 @@ class PageSet < Array
alias :sort :by_name alias :sort :by_name
def by_revision def by_revision
PageSet.new(@web, sort_by { |page| page.created_at }).reverse PageSet.new(@web, sort_by { |page| page.revised_on }).reverse
end end
def pages_that_reference(page_name) def pages_that_reference(page_name)

View file

@ -3,24 +3,13 @@ class Revision < ActiveRecord::Base
belongs_to :page belongs_to :page
composed_of :author, :mapping => [ %w(author name), %w(ip ip) ] composed_of :author, :mapping => [ %w(author name), %w(ip ip) ]
def created_on def revised_on
created_at.to_date revised_at
end end
def pretty_created_at # TODO this method belongs in the view helpers (only views use it)
# Must use DateTime because Time doesn't support %e on at least some platforms def pretty_created_on
DateTime.new( revised_on.to_date.strftime "%B %e, %Y %H:%M:%S"
created_at.year, created_at.mon, created_at.day, created_at.hour, created_at.min
).strftime "%B %e, %Y %H:%M"
end
# todo: drop next_revision, previuous_revision and number from here - unused code
def next_revision
Revision.find_by_number_and_page_id(number+1, page_id)
end
def previous_revision
@previous_revions ||= number > 0 ? Revision.find_by_number_and_page_id(number-1, page_id) : nil
end end
# Returns an array of all the WikiIncludes present in the content of this revision. # Returns an array of all the WikiIncludes present in the content of this revision.
@ -72,8 +61,14 @@ class Revision < ActiveRecord::Base
@display_cache @display_cache
end end
# TODO this probably doesn't belong in revision (because it has to call back the page)
def display_diff def display_diff
previous_revision ? HTMLDiff.diff(previous_revision.display_content, display_content) : display_content previous_revision = page.previous_revision(self)
if previous_revision
HTMLDiff.diff(previous_revision.display_content, display_content)
else
display_content
end
end end
def clear_display_cache def clear_display_cache
@ -112,18 +107,8 @@ class Revision < ActiveRecord::Base
end end
protected protected
before_create :set_revision_number, :set_timestamp
after_create :force_rendering after_create :force_rendering
after_save :clear_display_cache after_save :clear_display_cache
# TODO Refactor this away. Revisions collection should not rely on the revision number for
# sorting etc - revisions must be easy to delete (this helps fighting wiki spam)
def set_revision_number
self.number = self.class.count(['page_id = ?', page_id]) + 1
end
def set_timestamp
self.timestamp = (Time.now.to_f * 1000).to_i.to_s
end
end end

View file

@ -17,9 +17,9 @@ class Web < ActiveRecord::Base
self.brackets_only != brackets_only self.brackets_only != brackets_only
end end
def add_page(name, content, created_at, author) def add_page(name, content, time, author)
page = page(name) || Page.new(:web => self, :name => name) page = page(name) || Page.new(:web => self, :name => name)
page.revise(content, created_at, author) page.revise(content, time, author)
end end
def authors def authors

View file

@ -64,9 +64,9 @@ class Wiki
page.revise(content, revised_on, author) page.revise(content, revised_on, author)
end end
def rollback_page(web_address, page_name, revision_number, created_at, author_id = nil) def rollback_page(web_address, page_name, revision_number, time, author_id = nil)
page = read_page(web_address, page_name) page = read_page(web_address, page_name)
page.rollback(revision_number, created_at, author_id) page.rollback(revision_number, time, author_id)
end end
def setup(password, web_name, web_address) def setup(password, web_name, web_address)

View file

@ -12,7 +12,7 @@
<div id="changes" style="display: none"> <div id="changes" style="display: none">
<p style="background: #eee; padding: 3px; border: 1px solid silver"> <p style="background: #eee; padding: 3px; border: 1px solid silver">
<small> <small>
Showing changes from revision #<%= @page.number - 1 %> to #<%= @page.number %>: Showing changes from revision #<%= @page.revisions.size - 1 %> to #<%= @page.revisions.size %>:
<ins class="diffins">Added</ins> | <del class="diffdel">Removed</del> <ins class="diffins">Added</ins> | <del class="diffdel">Removed</del>
</small> </small>
</p> </p>
@ -22,7 +22,7 @@
<% end %> <% end %>
<div class="byline"> <div class="byline">
<%= @page.revisions? ? "Revised" : "Created" %> on <%= @page.pretty_created_at %> <%= @page.revisions? ? "Revised" : "Created" %> on <%= @page.pretty_created_on %>
by <%= @page.author_link %> by <%= @page.author_link %>
<%= "(#{@page.author.ip})" if @page.author.respond_to?(:ip) %> <%= "(#{@page.author.ip})" if @page.author.respond_to?(:ip) %>
<% if @web.count_pages? %> <% if @web.count_pages? %>

View file

@ -8,7 +8,7 @@
<%= @page.display_content_for_export %> <%= @page.display_content_for_export %>
<div class="byline"> <div class="byline">
<%= @page.revisions? ? "Revised" : "Created" %> on <%= @page.pretty_created_at %> <%= @page.revisions? ? "Revised" : "Created" %> on <%= @page.pretty_created_on %>
by by
<%= @page.author_link({ :mode => (@link_mode || :show) }) %> <%= @page.author_link({ :mode => (@link_mode || :show) }) %>
</div> </div>

View file

@ -17,7 +17,7 @@
<%= link_to_existing_page page %> <%= link_to_existing_page page %>
<div class="byline" style="margin-bottom: 0px"> <div class="byline" style="margin-bottom: 0px">
by <%= link_to_page(page.author) %> by <%= link_to_page(page.author) %>
at <%= page.created_at.strftime "%H:%M" %> at <%= page.current_revision.pretty_created_on %>
<%= "from #{page.author.ip}" if page.author.respond_to?(:ip) %> <%= "from #{page.author.ip}" if page.author.respond_to?(:ip) %>
</div> </div>
</li> </li>

View file

@ -1,4 +1,4 @@
<% @title = "#{@page.plain_name} (Rev ##{@revision.number})" %> <% @title = "#{@page.plain_name} (Rev ##{@revision_number})" %>
<div id="revision"> <div id="revision">
<%= @revision.display_content %> <%= @revision.display_content %>
@ -7,7 +7,7 @@
<div id="changes" style="display: none"> <div id="changes" style="display: none">
<p style="background: #eee; padding: 3px; border: 1px solid silver"> <p style="background: #eee; padding: 3px; border: 1px solid silver">
<small> <small>
Showing changes from revision #<%= @revision.number - 1 %> to #<%= @revision.number %>: Showing changes from revision #<%= @revision_number - 1 %> to #<%= @revision_number %>:
<ins class="diffins">Added</ins> | <del class="diffdel">Removed</del> <ins class="diffins">Added</ins> | <del class="diffdel">Removed</del>
</small> </small>
</p> </p>
@ -17,17 +17,17 @@
<div class="byline"> <div class="byline">
<%= "Revision from #{@revision.pretty_created_at} by" %> <%= "Revision from #{@revision.pretty_created_on} by" %>
<%= link_to_page @revision.author %> <%= link_to_page @revision.author %>
</div> </div>
<div class="navigation"> <div class="navigation">
<% if @revision.next_revision %> <% if @revision_number < @page.revisions.length - 1 %>
<% if @revision.next_revision.number < (@page.revisions.length - 1) %> <% if @revision_number < @page.revisions.length - 2 %>
<%= link_to('Forward in time', <%= link_to('Forward in time',
{:web => @web.address, :action => 'revision', :id => @page.name, {:web => @web.address, :action => 'revision', :id => @page.name,
:rev => @revision.next_revision.number}, :rev => @revision_number + 1},
{:class => 'navlink', :name => 'to_next_revision'}) {:class => 'navlink', :name => 'to_next_revision'})
%> %>
<% else %> <% else %>
@ -36,20 +36,20 @@
{:class => 'navlink', :name => 'to_next_revision'}) {:class => 'navlink', :name => 'to_next_revision'})
%> %>
<% end %> <% end %>
<small>(<%= @revision.page.revisions.length - @revision.next_revision.number %> more)</small> <small>(<%= @revision.page.revisions.length - @revision_number - 1 %> more)</small>
<% end %> <% end %>
<% if @revision.next_revision && @revision.previous_revision %> <% if @revision_number > 0 && @revision_number < @page.revisions.size - 1 %>
| |
<% end %> <% end %>
<% if @revision.previous_revision %> <% if @revision_number > 0 %>
<%= link_to('Back in time', <%= link_to('Back in time',
{:web => @web.address, :action => 'revision', :id => @page.name, {:web => @web.address, :action => 'revision', :id => @page.name,
:rev => @revision.previous_revision.number}, :rev => @revision_number - 1},
{:class => 'navlink', :name => 'to_previous_revision'}) {:class => 'navlink', :name => 'to_previous_revision'})
%> %>
<small>(<%= @revision.previous_revision.number + 1 %> more)</small> <small>(<%= @revision_number %> more)</small>
<% end %> <% end %>
| |
@ -57,7 +57,7 @@
{:class => 'navlink', :name => 'to_current_revision'}) {:class => 'navlink', :name => 'to_current_revision'})
%> %>
<% if @revision.previous_revision %> <% if @revision_number > 0 %>
<span id="show_changes"> <span id="show_changes">
| <a href="#" onClick="toggleChanges(); return false;">See changes</a> | <a href="#" onClick="toggleChanges(); return false;">See changes</a>
</span> </span>
@ -69,7 +69,7 @@
| |
<%= link_to('Rollback', <%= link_to('Rollback',
{:web => @web.address, :action => 'rollback', :id => @page.name, :rev => @revision.number}, {:web => @web.address, :action => 'rollback', :id => @page.name, :rev => @revision_number},
{:class => 'navlink', :name => 'rollback'}) {:class => 'navlink', :name => 'rollback'})
%> %>

View file

@ -1,5 +1,5 @@
<% <%
@title = "Rollback to #{@page.plain_name} Rev ##{@revision.number}" @title = "Rollback to #{@page.plain_name} Rev ##{@revision_number}"
@content_width = 720 @content_width = 720
@hide_navigation = true @hide_navigation = true
%> %>

View file

@ -12,7 +12,7 @@
<% unless @hide_description %> <% unless @hide_description %>
<description><%= h page.display_content %></description> <description><%= h page.display_content %></description>
<% end %> <% end %>
<pubDate><%= page.created_at.getgm.strftime "%a, %d %b %Y %H:%M:%S Z" %></pubDate> <pubDate><%= page.revised_on.getgm.strftime "%a, %d %b %Y %H:%M:%S Z" %></pubDate>
<guid><%= url_for :only_path => false, :web => @web_name, :action => @link_action, :id => page.name %></guid> <guid><%= url_for :only_path => false, :web => @web_name, :action => @link_action, :id => page.name %></guid>
<link><%= url_for :only_path => false, :web => @web_name, :action => @link_action, :id => page.name %></link> <link><%= url_for :only_path => false, :web => @web_name, :action => @link_action, :id => page.name %></link>
<dc:creator><%= WikiWords.separate(page.author) %></dc:creator> <dc:creator><%= WikiWords.separate(page.author) %></dc:creator>

View file

@ -3,10 +3,14 @@ CREATE TABLE revisions (
created_at <%= @datetime %> NOT NULL, created_at <%= @datetime %> NOT NULL,
updated_at <%= @datetime %> NOT NULL, updated_at <%= @datetime %> NOT NULL,
timestamp CHAR(13) NOT NULL, -- note that continuous edits change the existing last revision, instead of creating one
-- revised_at is the timestamp of last edit of this revision
-- unlike updated_at is can be set explicitly in a call to Revision.create
-- besides, it should not be updated when Revision row changes for any other reason than
-- changing content
revised_at <%= @datetime %> NOT NULL,
page_id INTEGER NOT NULL, page_id INTEGER NOT NULL,
content TEXT NOT NULL, content TEXT NOT NULL,
author VARCHAR(60), author VARCHAR(60),
ip VARCHAR(60), ip VARCHAR(60)
number INTEGER
) <%= create_options %>; ) <%= create_options %>;

View file

@ -2,9 +2,8 @@ home_page_first_revision:
id: 1 id: 1
created_at: <%= Time.local(2004, 4, 4, 15, 50).to_formatted_s(:db) %> created_at: <%= Time.local(2004, 4, 4, 15, 50).to_formatted_s(:db) %>
updated_at: <%= Time.local(2004, 4, 4, 15, 50).to_formatted_s(:db) %> updated_at: <%= Time.local(2004, 4, 4, 15, 50).to_formatted_s(:db) %>
timestamp: <%= (Time.local(2004, 4, 4, 15, 50).to_f * 1000).to_i %> revised_at: <%= Time.local(2004, 4, 4, 15, 50).to_formatted_s(:db) %>
page_id: 1 page_id: 1
number: 1
content: First revision of the HomePage end content: First revision of the HomePage end
author: AnAuthor author: AnAuthor
ip: 127.0.0.1 ip: 127.0.0.1
@ -13,9 +12,8 @@ my_way_first_revision:
id: 2 id: 2
created_at: <%= 9.days.ago.to_formatted_s(:db) %> created_at: <%= 9.days.ago.to_formatted_s(:db) %>
updated_at: <%= 9.days.ago.to_formatted_s(:db) %> updated_at: <%= 9.days.ago.to_formatted_s(:db) %>
timestamp: <%= (9.days.ago.to_f * 1000).to_i %> revised_at: <%= 9.days.ago.to_formatted_s(:db) %>
page_id: 2 page_id: 2
number: 1
content: MyWay content: MyWay
author: Me author: Me
@ -23,9 +21,8 @@ smart_engine_first_revision:
id: 3 id: 3
created_at: <%= 8.days.ago.to_formatted_s(:db) %> created_at: <%= 8.days.ago.to_formatted_s(:db) %>
updated_at: <%= 8.days.ago.to_formatted_s(:db) %> updated_at: <%= 8.days.ago.to_formatted_s(:db) %>
timestamp: <%= (8.days.ago.to_f * 1000).to_i %> revised_at: <%= 8.days.ago.to_formatted_s(:db) %>
page_id: 3 page_id: 3
number: 1
content: SmartEngine content: SmartEngine
author: Me author: Me
@ -33,9 +30,8 @@ that_way_first_revision:
id: 4 id: 4
created_at: <%= 7.days.ago.to_formatted_s(:db) %> created_at: <%= 7.days.ago.to_formatted_s(:db) %>
updated_at: <%= 7.days.ago.to_formatted_s(:db) %> updated_at: <%= 7.days.ago.to_formatted_s(:db) %>
timestamp: <%= (7.days.ago.to_f * 1000).to_i %> revised_at: <%= 7.days.ago.to_formatted_s(:db) %>
page_id: 4 page_id: 4
number: 1
content: ThatWay content: ThatWay
author: Me author: Me
@ -43,9 +39,8 @@ no_wiki_word_first_revision:
id: 5 id: 5
created_at: <%= 6.days.ago.to_formatted_s(:db) %> created_at: <%= 6.days.ago.to_formatted_s(:db) %>
updated_at: <%= 6.days.ago.to_formatted_s(:db) %> updated_at: <%= 6.days.ago.to_formatted_s(:db) %>
timestamp: <%= (6.days.ago.to_f * 1000).to_i %> revised_at: <%= 6.days.ago.to_formatted_s(:db) %>
page_id: 5 page_id: 5
number: 1
content: hey you content: hey you
author: Me author: Me
@ -53,9 +48,8 @@ home_page_second_revision:
id: 6 id: 6
created_at: <%= Time.local(2004, 4, 4, 16, 50).to_formatted_s(:db) %> created_at: <%= Time.local(2004, 4, 4, 16, 50).to_formatted_s(:db) %>
updated_at: <%= Time.local(2004, 4, 4, 16, 50).to_formatted_s(:db) %> updated_at: <%= Time.local(2004, 4, 4, 16, 50).to_formatted_s(:db) %>
timestamp: <%= (Time.local(2004, 4, 4, 16, 50).to_f * 1000).to_i %> revised_at: <%= Time.local(2004, 4, 4, 16, 50).to_formatted_s(:db) %>
page_id: 1 page_id: 1
number: 2
content: HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \OverThere -- see SmartEngine in that SmartEngineGUI content: HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \OverThere -- see SmartEngine in that SmartEngineGUI
author: DavidHeinemeierHansson author: DavidHeinemeierHansson
@ -63,9 +57,8 @@ first_page_first_revision:
id: 7 id: 7
created_at: <%= Time.local(2004, 4, 4, 16, 55).to_formatted_s(:db) %> created_at: <%= Time.local(2004, 4, 4, 16, 55).to_formatted_s(:db) %>
updated_at: <%= Time.local(2004, 4, 4, 16, 55).to_formatted_s(:db) %> updated_at: <%= Time.local(2004, 4, 4, 16, 55).to_formatted_s(:db) %>
timestamp: <%= (Time.local(2004, 4, 4, 16, 55).to_f * 1000).to_i %> revised_at: <%= Time.local(2004, 4, 4, 16, 55).to_formatted_s(:db) %>
page_id: 6 page_id: 6
number: 1
content: HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \\OverThere -- see SmartEngine in that SmartEngineGUI content: HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \\OverThere -- see SmartEngine in that SmartEngineGUI
author: DavidHeinemeierHansson author: DavidHeinemeierHansson
@ -73,9 +66,8 @@ oak_first_revision:
id: 8 id: 8
created_at: <%= 5.days.ago.to_formatted_s(:db) %> created_at: <%= 5.days.ago.to_formatted_s(:db) %>
updated_at: <%= 5.days.ago.to_formatted_s(:db) %> updated_at: <%= 5.days.ago.to_formatted_s(:db) %>
timestamp: <%= (5.days.ago.to_f * 1000).to_i %> revised_at: <%= 5.days.ago.to_formatted_s(:db) %>
page_id: 7 page_id: 7
number: 1
content: "All about oak.\ncategory: trees" content: "All about oak.\ncategory: trees"
author: TreeHugger author: TreeHugger
ip: 127.0.0.2 ip: 127.0.0.2
@ -84,9 +76,8 @@ elephant_first_revision:
id: 9 id: 9
created_at: <%= 10.minutes.ago.to_formatted_s(:db) %> created_at: <%= 10.minutes.ago.to_formatted_s(:db) %>
updated_at: <%= 10.minutes.ago.to_formatted_s(:db) %> updated_at: <%= 10.minutes.ago.to_formatted_s(:db) %>
timestamp: <%= (10.minutes.ago.to_f * 1000).to_i %> revised_at: <%= 10.minutes.ago.to_formatted_s(:db) %>
page_id: 8 page_id: 8
number: 1
content: "All about elephants.\ncategory: animals" content: "All about elephants.\ncategory: animals"
author: Guest author: Guest
ip: 127.0.0.2 ip: 127.0.0.2

View file

@ -104,7 +104,7 @@ class WikiControllerTest < Test::Unit::TestCase
end end
def test_export_html def test_export_html
@home.rollback(1, Time.now, 'Rick') # much simpler regex statement to match @home.rollback(0, Time.now, 'Rick') # much simpler regex statement to match
r = process 'export_html', 'web' => 'wiki1' r = process 'export_html', 'web' => 'wiki1'
assert_response :success assert_response :success

View file

@ -32,27 +32,37 @@ class PageTest < Test::Unit::TestCase
def test_revise def test_revise
@page.revise('HisWay would be MyWay in kinda lame', Time.local(2004, 4, 4, 16, 55), 'MarianneSyhler') @page.revise('HisWay would be MyWay in kinda lame', Time.local(2004, 4, 4, 16, 55), 'MarianneSyhler')
assert_equal 2, @page.revisions(true).length, 'Should have two revisions' @page.reload
assert_equal 'MarianneSyhler', @page.current_revision(true).author.to_s, 'Mary should be the author now'
assert_equal 2, @page.revisions.length, 'Should have two revisions'
assert_equal 'MarianneSyhler', @page.current_revision.author.to_s, 'Mary should be the author now'
assert_equal 'DavidHeinemeierHansson', @page.revisions.first.author.to_s, 'David was the first author' assert_equal 'DavidHeinemeierHansson', @page.revisions.first.author.to_s, 'David was the first author'
end end
def test_revise_continous_revision def test_revise_continous_revision
@page.revise('HisWay would be MyWay in kinda lame', Time.local(2004, 4, 4, 16, 55), 'MarianneSyhler') @page.revise('HisWay would be MyWay in kinda lame', Time.local(2004, 4, 4, 16, 55), 'MarianneSyhler')
assert_equal 2, @page.revisions(true).length @page.reload
assert_equal 2, @page.revisions.length
assert_equal 'HisWay would be MyWay in kinda lame', @page.content
@page.current_revision(true) # consecutive revision by the same author within 30 minutes doesn't create a new revision
@page.revise('HisWay would be MyWay in kinda update', Time.local(2004, 4, 4, 16, 57), 'MarianneSyhler') @page.revise('HisWay would be MyWay in kinda update', Time.local(2004, 4, 4, 16, 57), 'MarianneSyhler')
assert_equal 2, @page.revisions(true).length @page.reload
assert_equal 'HisWay would be MyWay in kinda update', @page.revisions.last.content assert_equal 2, @page.revisions.length
assert_equal Time.local(2004, 4, 4, 16, 57), @page.revisions.last.created_at assert_equal 'HisWay would be MyWay in kinda update', @page.content
assert_equal Time.local(2004, 4, 4, 16, 57), @page.revised_on
# but consecutive revision by another author results in a new revision
@page.revise('HisWay would be MyWay in the house', Time.local(2004, 4, 4, 16, 58), 'DavidHeinemeierHansson') @page.revise('HisWay would be MyWay in the house', Time.local(2004, 4, 4, 16, 58), 'DavidHeinemeierHansson')
assert_equal 3, @page.revisions(true).length @page.reload
assert_equal 'HisWay would be MyWay in the house', @page.revisions.last.content assert_equal 3, @page.revisions.length
assert_equal 'HisWay would be MyWay in the house', @page.content
# consecutive update after 30 minutes since the last one also creates a new revision,
# even when it is by the same author
@page.revise('HisWay would be MyWay in my way', Time.local(2004, 4, 4, 17, 30), 'DavidHeinemeierHansson') @page.revise('HisWay would be MyWay in my way', Time.local(2004, 4, 4, 17, 30), 'DavidHeinemeierHansson')
assert_equal 4, @page.revisions(true).length @page.reload
assert_equal 4, @page.revisions.length
end end
def test_revise_content_unchanged def test_revise_content_unchanged
@ -72,7 +82,7 @@ class PageTest < Test::Unit::TestCase
@page.revise("spot three", Time.now + 2000, "David") @page.revise("spot three", Time.now + 2000, "David")
assert_equal 3, @page.revisions(true).length, "Should have three revisions" assert_equal 3, @page.revisions(true).length, "Should have three revisions"
@page.current_revision(true) @page.current_revision(true)
@page.rollback(1, Time.now) @page.rollback(0, Time.now)
assert_equal "HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \\\\OverThere -- see SmartEngine in that SmartEngineGUI", @page.current_revision(true).content assert_equal "HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \\\\OverThere -- see SmartEngine in that SmartEngineGUI", @page.current_revision(true).content
end end
end end

View file

@ -245,8 +245,10 @@ class RevisionTest < Test::Unit::TestCase
end end
def test_revisions_diff def test_revisions_diff
Revision.create(:page => @page, :content => 'What a blue and lovely morning', :author => Author.new('DavidHeinemeierHansson')) Revision.create(:page => @page, :content => 'What a blue and lovely morning',
Revision.create(:page => @page, :content => 'What a red and lovely morning today', :author => Author.new('DavidHeinemeierHansson')) :author => Author.new('DavidHeinemeierHansson'), :revised_at => Time.now)
Revision.create(:page => @page, :content => 'What a red and lovely morning today',
:author => Author.new('DavidHeinemeierHansson'), :revised_at => Time.now)
assert_equal "<p>What a <del class=\"diffmod\">blue </del><ins class=\"diffmod\">red " + assert_equal "<p>What a <del class=\"diffmod\">blue </del><ins class=\"diffmod\">red " +
"</ins>and lovely <del class=\"diffmod\">morning</del><ins class=\"diffmod\">morning " + "</ins>and lovely <del class=\"diffmod\">morning</del><ins class=\"diffmod\">morning " +

View file

@ -248,7 +248,7 @@ class E2EInstikiTest < Test::Unit::TestCase
def date_pattern def date_pattern
'(January|February|March|April|May|June|July|August|September|October|November|December) ' + '(January|February|March|April|May|June|July|August|September|October|November|December) ' +
'\d\d?, \d\d\d\d \d\d:\d\d' '\d\d?, \d\d\d\d \d\d:\d\d:\d\d'
end end
def enter_markup(page, content, author = nil) def enter_markup(page, content, author = nil)