All tests pass, including Watir suite

This commit is contained in:
Alexey Verkhovsky 2006-03-19 07:54:54 +00:00
parent b49bc6a31d
commit 6f0434bf83
7 changed files with 154 additions and 123 deletions

View file

@ -224,15 +224,18 @@ class WikiController < ApplicationController
def save
render(:status => 404, :text => 'Undefined page name') and return if @page_name.nil?
cookies['author'] = { :value => @params['author'], :expires => Time.utc(2030) }
author_name = @params['author']
author_name = 'AnonymousCoward' if author_name =~ /^\s*$/
cookies['author'] = { :value => author_name, :expires => Time.utc(2030) }
begin
if @page
wiki.revise_page(@web_name, @page_name, @params['content'], Time.now,
Author.new(@params['author'], remote_ip), PageRenderer.new)
Author.new(author_name, remote_ip), PageRenderer.new)
@page.unlock
else
wiki.write_page(@web_name, @page_name, @params['content'], Time.now,
Author.new(@params['author'], remote_ip), PageRenderer.new)
Author.new(author_name, remote_ip), PageRenderer.new)
end
redirect_to_page @page_name
rescue => e
@ -336,7 +339,7 @@ class WikiController < ApplicationController
def get_page_and_revision
@revision_number = @params['rev'].to_i
@revision = @page.revisions[@revision_number]
@revision = @page.revisions[@revision_number - 1]
end
def parse_category

View file

@ -0,0 +1,89 @@
module WikiHelper
def navigation_menu_for_revision
menu = []
menu << forward
menu << back_for_revision if @revision_number > 1
menu << current_revision
menu << see_or_hide_changes_for_revision if @revision_number > 1
menu << rollback
menu
end
def navigation_menu_for_page
menu = []
menu << edit_page
menu << edit_web if @page.name == "HomePage"
if @page.revisions.length > 1
menu << back_for_page
menu << see_or_hide_changes_for_page
end
menu
end
def edit_page
link_text = (@page.name == "HomePage" ? 'Edit Page' : 'Edit')
link_to(link_text, {:web => @web.address, :action => 'edit', :id => @page.name},
{:class => 'navlink', :accesskey => 'E', :name => 'edit'})
end
def edit_web
link_to('Edit Web', {:web => @web.address, :action => 'edit_web'},
{:class => 'navlink', :accesskey => 'W', :name => 'edit_web'})
end
def forward
if @revision_number < @page.revisions.length - 1
link_to('Forward in time',
{:web => @web.address, :action => 'revision', :id => @page.name, :rev => @revision_number + 1},
{:class => 'navlink', :accesskey => 'F', :name => 'to_next_revision'}) +
" <small>(#{@revision.page.revisions.length - @revision_number} more)</small> "
else
link_to('Forward in time', {:web => @web.address, :action => 'show', :id => @page.name},
{:class => 'navlink', :accesskey => 'F', :name => 'to_next_revision'}) +
" <small> (to current)</small>"
end
end
def back_for_revision
link_to('Back in time',
{:web => @web.address, :action => 'revision', :id => @page.name, :rev => @revision_number - 1},
{:class => 'navlink', :name => 'to_previous_revision'}) +
" <small>(#{@revision_number - 1} more)</small>"
end
def back_for_page
link_to('Back in time',
{:web => @web.address, :action => 'revision', :id => @page.name,
:rev => @page.revisions.length - 1},
{:class => 'navlink', :accesskey => 'B', :name => 'to_previous_revision'}) +
" <small>(#{@page.revisions.length - 1} #{@page.revisions.length - 1 == 1 ? 'revision' : 'revisions'})</small>"
end
def current_revision
link_to('See current', {:web => @web.address, :action => 'show', :id => @page.name},
{:class => 'navlink', :name => 'to_current_revision'})
end
def see_or_hide_changes_for_revision
link_to(@show_diff ? 'Hide changes' : 'See changes',
{:web => @web.address, :action => 'revision', :id => @page.name, :rev => @revision_number,
:mode => (@show_diff ? nil : 'diff') },
{:class => 'navlink', :accesskey => 'C', :name => 'see_changes'})
end
def see_or_hide_changes_for_page
link_to(@show_diff ? 'Hide changes' : 'See changes',
{:web => @web.address, :action => 'show', :id => @page.name, :mode => (@show_diff ? nil : 'diff') },
{:class => 'navlink', :accesskey => 'C', :name => 'see_changes'})
end
def rollback
link_to('Rollback',
{:web => @web.address, :action => 'rollback', :id => @page.name, :rev => @revision_number},
{:class => 'navlink', :name => 'rollback'})
end
end

View file

@ -5,7 +5,17 @@
%>
<div id="revision">
<%= @show_diff ? @renderer.display_diff : @renderer.display_content %>
<% if @show_diff %>
<p style="background: #eee; padding: 3px; border: 1px solid silver">
<small>
Showing changes from revision #<%= @page.revisions.size - 1 %> to #<%= @page.revisions.size %>:
<ins class="diffins">Added</ins> | <del class="diffdel">Removed</del>
</small>
</p>
<%= @renderer.display_diff %>
<% else %>
<%= @renderer.display_content %>
<% end %>
</div>
<div class="byline">
@ -19,38 +29,8 @@
</div>
<div class="navigation">
<% if @page.name == "HomePage" %>
<%= link_to('Edit Page',
{:web => @web.address, :action => 'edit', :id => @page.name},
{:class => 'navlink', :accesskey => 'E', :name => 'edit'})
%>
|
<%= link_to('Edit Web',
{:web => @web.address, :action => 'edit_web'},
{:class => 'navlink', :name => 'edit_web'})
%>
<% else %>
<%= link_to('Edit',
{:web => @web.address, :action => 'edit', :id => @page.name},
{:class => 'navlink', :accesskey => 'E', :name => 'edit'})
%>
<% end %>
<% if @page.revisions.length > 1 %>
|
<%= link_to('Back in time',
{:web => @web.address, :action => 'revision', :id => @page.name,
:rev => @page.revisions.length - 2},
{:class => 'navlink', :accesskey => 'R', :name => 'to_previous_revision'})
%>
<small>(<%= @page.revisions.length - 1 %> revisions)</small>
|
<%= link_to(@show_diff ? 'Hide changes' : 'See changes',
{ :web => @web.address, :action => 'show', :id => @page.name,
:mode => (@show_diff ? nil : 'diff') },
{ :class => 'navlink', :accesskey => 'C', :name => 'see_changes' })
%>
<% end %>
<%= navigation_menu_for_page.join(' | ') %>
<small>
| Views:

View file

@ -4,7 +4,17 @@
<div id="revision">
<%= @show_diff ? @renderer.display_diff : @renderer.display_content %>
<% if @show_diff %>
<p style="background: #eee; padding: 3px; border: 1px solid silver">
<small>
Showing changes from revision #<%= @revision_number - 1 %> to #<%= @revision_number %>:
<ins class="diffins">Added</ins> | <del class="diffdel">Removed</del>
</small>
</p>
<%= @renderer.display_diff %>
<% else %>
<%= @renderer.display_content %>
<% end %>
</div>
<div class="byline">
@ -13,73 +23,6 @@
</div>
<div class="navigation">
<% if @revision_number < @page.revisions.length - 1 %>
<% if @revision_number < @page.revisions.length - 2 %>
<%= link_to('Forward in time',
{:web => @web.address, :action => 'revision', :id => @page.name,
:rev => @revision_number + 1},
{:class => 'navlink', :name => 'to_next_revision'})
%>
<% else %>
<%= link_to('Forward in time',
{:web => @web.address, :action => 'show', :id => @page.name},
{:class => 'navlink', :name => 'to_next_revision'})
%>
<% end %>
<small>(<%= @revision.page.revisions.length - @revision_number - 1 %> more)</small>
<% end %>
<% if @revision_number > 0 && @revision_number < @page.revisions.size - 1 %>
|
<% end %>
<% if @revision_number > 0 %>
<%= link_to('Back in time',
{:web => @web.address, :action => 'revision', :id => @page.name,
:rev => @revision_number - 1},
{:class => 'navlink', :name => 'to_previous_revision'})
%>
<small>(<%= @revision_number %> more)</small>
<% end %>
|
<%= link_to('See current', {:web => @web.address, :action => 'show', :id => @page.name},
{:class => 'navlink', :name => 'to_current_revision'})
%>
<% if @revision_number > 0 %>
|
<%= link_to(@show_diff ? 'Hide changes' : 'See changes',
{:web => @web.address, :action => 'revision', :id => @page.name,
:rev => @revision_number, :mode => (@show_diff ? nil : 'diff') },
{:class => 'navlink', :accesskey => 'C', :name => 'see_changes'})
%>
<% end %>
|
<%= link_to('Rollback',
{:web => @web.address, :action => 'rollback', :id => @page.name, :rev => @revision_number},
{:class => 'navlink', :name => 'rollback'})
%>
<%= navigation_menu_for_revision.join(' | ') %>
<%= render :partial => 'inbound_links' %>
</div>
<script language="Javascript">
function toggleChanges() {
if (document.getElementById("changes").style.display == "none") {
document.getElementById("changes").style.display = "block";
document.getElementById("revision").style.display = "none";
document.getElementById("show_changes").style.display = "none";
document.getElementById("hide_changes").style.display = "inline";
} else {
document.getElementById("changes").style.display = "none";
document.getElementById("revision").style.display = "block";
document.getElementById("show_changes").style.display = "inline";
document.getElementById("hide_changes").style.display = "none";
}
}
</script>

View file

@ -360,7 +360,7 @@ class WikiControllerTest < Test::Unit::TestCase
def test_revision
r = process 'revision', 'web' => 'wiki1', 'id' => 'HomePage', 'rev' => '0'
r = process 'revision', 'web' => 'wiki1', 'id' => 'HomePage', 'rev' => '1'
assert_success
assert_equal @home, r.template_objects['page']
@ -371,7 +371,7 @@ class WikiControllerTest < Test::Unit::TestCase
def test_rollback
# rollback shows a form where a revision can be edited.
# its assigns the same as or revision
r = process 'rollback', 'web' => 'wiki1', 'id' => 'HomePage', 'rev' => '0'
r = process 'rollback', 'web' => 'wiki1', 'id' => 'HomePage', 'rev' => '1'
assert_success
assert_equal @home, r.template_objects['page']
@ -565,6 +565,19 @@ class WikiControllerTest < Test::Unit::TestCase
assert !@home.locked?(Time.now), 'HomePage should be unlocked if an edit was unsuccessful'
end
def test_save_blank_author
r = process 'save', 'web' => 'wiki1', 'id' => 'NewPage', 'content' => 'Contents of a new page',
'author' => ''
new_page = @wiki.read_page('wiki1', 'NewPage')
assert_equal 'AnonymousCoward', new_page.author
r = process 'save', 'web' => 'wiki1', 'id' => 'AnotherPage', 'content' => 'Contents of a new page',
'author' => ' '
another_page = @wiki.read_page('wiki1', 'AnotherPage')
assert_equal 'AnonymousCoward', another_page.author
end
def test_search
r = process 'search', 'web' => 'wiki1', 'query' => '\s[A-Z]ak'

View file

@ -111,7 +111,6 @@ class PageTest < Test::Unit::TestCase
assert_equal WikiReference::WANTED_PAGE, references[1].link_type
end
def test_rollback
@page.revise("spot two", Time.now, "David", test_renderer)
@page.revise("spot three", Time.now + 2000, "David", test_renderer)

View file

@ -98,22 +98,21 @@ class E2EInstikiTest < Test::Unit::TestCase
assert_match Regexp.new('Revised on ' + date_pattern + ' by Author\?'), ie.text
link_to_previous_revision = ie.link(:name, 'to_previous_revision')
assert_equal url(:revision, 'TestEditPage', 0), link_to_previous_revision.href
assert_equal url(:revision, 'TestEditPage', 1), link_to_previous_revision.href
assert_equal 'Back in time', link_to_previous_revision.text
assert_match /Edit \| Back in time \(1 revisions\) \| See changes/, ie.text
assert_match /Edit \| Back in time \(1 revision\) \| See changes/, ie.text
# another anonymous revision
enter_markup('TestEditPage', 'Test Edit Page, revision 3')
assert_match /Test Edit Page, revision 3/, ie.text
assert_match /Edit \| Back in time \(2 revisions\) \| See changes \| Hide changes /, ie.text
assert_match /Edit \| Back in time \(2 revisions\) \| See changes /, ie.text
end
def test_00040_traversing_revisions
ie.goto url(:revision, 'TestEditPage', 1)
ie.goto url(:revision, 'TestEditPage', 2)
assert_match /Test Edit Page, revision 2/, ie.text
assert_match(Regexp.new(
'Forward in time \(1 more\) \| Back in time \(1 more\) \| ' +
'See current \| See changes \| Hide changes \| Rollback'),
'Forward in time \(to current\) \| Back in time \(1 more\) \| See current \| See changes \| Rollback'),
ie.text)
ie.link(:name, 'to_previous_revision').click
@ -128,10 +127,10 @@ class E2EInstikiTest < Test::Unit::TestCase
end
def test_00050_rollback
ie.goto url(:revision, 'TestEditPage', 1)
ie.goto url(:revision, 'TestEditPage', 2)
assert_match /Test Edit Page, revision 2/, ie.text
ie.link(:name, 'rollback').click
assert_equal url(:rollback, 'TestEditPage', 1), ie.url
assert_equal url(:rollback, 'TestEditPage', 2), ie.url
assert_equal 'Test Edit Page, revision 2', ie.text_field(:name, 'content').value
ie.text_field(:name, 'content').set('Test Edit Page, revision 2, rolled back')
@ -143,13 +142,12 @@ class E2EInstikiTest < Test::Unit::TestCase
def test_0060_see_changes
ie.goto url(:show, 'TestEditPage')
assert ie.html.include?('<P>Test Edit Page, revision <DEL class=diffmod>2</DEL>' +
'<INS class=diffmod>2, rolled back</INS></P>')
assert_match /Test Edit Page, revision 2, rolled back/, ie.text
ie.link(:text, 'See changes').click
assert_match /Showing changes from revision #1 to #2: Added \| Removed/, ie.text
assert_match /Showing changes from revision #2 to #3: Added \| Removed/, ie.text
assert_match /Test Edit Page, revision 22, rolled back/, ie.text
ie.link(:text, 'Hide changes').click
@ -168,11 +166,17 @@ class E2EInstikiTest < Test::Unit::TestCase
expected_page_links = ['Another Wiki Page', 'Home Page', 'Test Edit Page', '?',
'Another Wiki Page', 'Test Edit Page']
assert_equal expected_page_links, page_links[-6..-1]
links_sequence = 'All Pages.*Another Wiki Page.*Home Page.*Test Edit Page.*' +
links_sequence =
'All Pages.*Another Wiki Page.*Home Page.*Test Edit Page.*' +
'Wanted Pages.*Non Existant Page\? wanted by Another Wiki Page.*'+
'Orphaned Pages.*Test Edit Page.*'
assert_match Regexp.new(links_sequence, Regexp::MULTILINE), ie.text
# and before that, we have the tail of the main menu
require 'breakpoint'; breakpoint
assert_equal 'Export', page_links[-7]
end
@ -332,7 +336,7 @@ class InstikiController
def self.clear_database
ENV['RAILS_ENV'] = 'development'
require INSTIKI_ROOT + '/config/environment.rb'
[Revision, Page, Web, System].each { |entity| entity.delete_all }
[WikiReference, Revision, Page, WikiFile, Web, System].each { |entity| entity.delete_all }
end
def initialize(pid)