Controllers create renderer objects and pass them on to page.revise and page.rollback methods
This commit is contained in:
parent
4838f6e684
commit
7e500dfe57
|
@ -182,11 +182,11 @@ class WikiController < ApplicationController
|
|||
begin
|
||||
if @page
|
||||
wiki.revise_page(@web_name, @page_name, @params['content'], Time.now,
|
||||
Author.new(@params['author'], remote_ip))
|
||||
Author.new(@params['author'], remote_ip), PageRenderer.new)
|
||||
@page.unlock
|
||||
else
|
||||
wiki.write_page(@web_name, @page_name, @params['content'], Time.now,
|
||||
Author.new(@params['author'], remote_ip))
|
||||
Author.new(@params['author'], remote_ip), PageRenderer.new)
|
||||
end
|
||||
redirect_to_page @page_name
|
||||
rescue => e
|
||||
|
|
|
@ -3,7 +3,7 @@ class Page < ActiveRecord::Base
|
|||
has_many :revisions, :order => 'id'
|
||||
has_one :current_revision, :class_name => 'Revision', :order => 'id DESC'
|
||||
|
||||
def revise(content, time, author)
|
||||
def revise(content, time, author, renderer)
|
||||
revisions_size = new_record? ? 0 : revisions.size
|
||||
if (revisions_size > 0) and content == current_revision.content
|
||||
raise Instiki::ValidationError.new(
|
||||
|
@ -13,8 +13,9 @@ class Page < ActiveRecord::Base
|
|||
author = Author.new(author.to_s) unless author.is_a?(Author)
|
||||
|
||||
# Try to render content to make sure that markup engine can take it,
|
||||
r = Revision.new(:page => self, :content => content, :author => author, :revised_at => time)
|
||||
PageRenderer.new(r).force_rendering
|
||||
renderer.revision = Revision.new(
|
||||
:page => self, :content => content, :author => author, :revised_at => time)
|
||||
renderer.force_rendering
|
||||
|
||||
# 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
|
||||
|
@ -29,14 +30,15 @@ class Page < ActiveRecord::Base
|
|||
self
|
||||
end
|
||||
|
||||
def rollback(revision_number, time, author_ip = nil)
|
||||
def rollback(revision_number, time, author_ip, renderer)
|
||||
roll_back_revision = self.revisions[revision_number]
|
||||
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))
|
||||
author = Author.new(roll_back_revision.author.name, author_ip)
|
||||
revise(roll_back_revision.content, time, author, renderer)
|
||||
end
|
||||
|
||||
|
||||
def revisions?
|
||||
revisions.size > 1
|
||||
end
|
||||
|
|
|
@ -15,9 +15,9 @@ class Web < ActiveRecord::Base
|
|||
self.brackets_only != brackets_only
|
||||
end
|
||||
|
||||
def add_page(name, content, time, author)
|
||||
def add_page(name, content, time, author, renderer)
|
||||
page = page(name) || Page.new(:web => self, :name => name)
|
||||
page.revise(content, time, author)
|
||||
page.revise(content, time, author, renderer)
|
||||
end
|
||||
|
||||
def authors
|
||||
|
|
|
@ -58,9 +58,9 @@ class Wiki
|
|||
web.remove_pages(web.select.orphaned_pages)
|
||||
end
|
||||
|
||||
def revise_page(web_address, page_name, content, revised_at, author)
|
||||
def revise_page(web_address, page_name, content, revised_at, author, renderer)
|
||||
page = read_page(web_address, page_name)
|
||||
page.revise(content, revised_at, author)
|
||||
page.revise(content, revised_at, author, renderer)
|
||||
end
|
||||
|
||||
def rollback_page(web_address, page_name, revision_number, time, author_id = nil)
|
||||
|
@ -89,7 +89,7 @@ class Wiki
|
|||
self.class.storage_path
|
||||
end
|
||||
|
||||
def write_page(web_address, page_name, content, written_on, author)
|
||||
Web.find_by_address(web_address).add_page(page_name, content, written_on, author)
|
||||
def write_page(web_address, page_name, content, written_on, author, renderer)
|
||||
Web.find_by_address(web_address).add_page(page_name, content, written_on, author, renderer)
|
||||
end
|
||||
end
|
|
@ -4,7 +4,9 @@ require 'diff'
|
|||
|
||||
class PageRenderer
|
||||
|
||||
def initialize(revision)
|
||||
attr_accessor :revision
|
||||
|
||||
def initialize(revision = nil)
|
||||
@revision = revision
|
||||
end
|
||||
|
||||
|
|
205
rakefile.rb
205
rakefile.rb
|
@ -0,0 +1,205 @@
|
|||
require 'rake'
|
||||
require 'rake/testtask'
|
||||
require 'rake/rdoctask'
|
||||
|
||||
$VERBOSE = nil
|
||||
TEST_CHANGES_SINCE = Time.now - 600
|
||||
|
||||
desc "Run all the tests on a fresh test database"
|
||||
task :default => [ :test_units, :test_functional ]
|
||||
|
||||
|
||||
desc 'Require application environment.'
|
||||
task :environment do
|
||||
unless defined? RAILS_ROOT
|
||||
require File.dirname(__FILE__) + '/config/environment'
|
||||
end
|
||||
end
|
||||
|
||||
desc "Generate API documentation, show coding stats"
|
||||
task :doc => [ :appdoc, :stats ]
|
||||
|
||||
|
||||
# Look up tests for recently modified sources.
|
||||
def recent_tests(source_pattern, test_path, touched_since = 10.minutes.ago)
|
||||
FileList[source_pattern].map do |path|
|
||||
if File.mtime(path) > touched_since
|
||||
test = "#{test_path}/#{File.basename(path, '.rb')}_test.rb"
|
||||
test if File.exists?(test)
|
||||
end
|
||||
end.compact
|
||||
end
|
||||
|
||||
desc 'Test recent changes.'
|
||||
Rake::TestTask.new(:recent => [ :clone_structure_to_test ]) do |t|
|
||||
since = TEST_CHANGES_SINCE
|
||||
touched = FileList['test/**/*_test.rb'].select { |path| File.mtime(path) > since } +
|
||||
recent_tests('app/models/*.rb', 'test/unit', since) +
|
||||
recent_tests('app/controllers/*.rb', 'test/functional', since)
|
||||
|
||||
t.libs << 'test'
|
||||
t.verbose = true
|
||||
t.test_files = touched.uniq
|
||||
end
|
||||
task :test_recent => [ :clone_structure_to_test ]
|
||||
|
||||
desc "Run the unit tests in test/unit"
|
||||
Rake::TestTask.new("test_units") { |t|
|
||||
t.libs << "test"
|
||||
t.pattern = 'test/unit/**/*_test.rb'
|
||||
t.verbose = true
|
||||
}
|
||||
task :test_units => [ :clone_structure_to_test ]
|
||||
|
||||
desc "Run the functional tests in test/functional"
|
||||
Rake::TestTask.new("test_functional") { |t|
|
||||
t.libs << "test"
|
||||
t.pattern = 'test/functional/**/*_test.rb'
|
||||
t.verbose = true
|
||||
}
|
||||
task :test_functional => [ :clone_structure_to_test ]
|
||||
|
||||
desc "Generate documentation for the application"
|
||||
Rake::RDocTask.new("appdoc") { |rdoc|
|
||||
rdoc.rdoc_dir = 'doc/app'
|
||||
rdoc.title = "Rails Application Documentation"
|
||||
rdoc.options << '--line-numbers --inline-source'
|
||||
rdoc.rdoc_files.include('doc/README_FOR_APP')
|
||||
rdoc.rdoc_files.include('app/**/*.rb')
|
||||
}
|
||||
|
||||
desc "Generate documentation for the Rails framework"
|
||||
Rake::RDocTask.new("apidoc") { |rdoc|
|
||||
rdoc.rdoc_dir = 'doc/api'
|
||||
rdoc.template = "#{ENV['template']}.rb" if ENV['template']
|
||||
rdoc.title = "Rails Framework Documentation"
|
||||
rdoc.options << '--line-numbers --inline-source'
|
||||
rdoc.rdoc_files.include('README')
|
||||
rdoc.rdoc_files.include('CHANGELOG')
|
||||
rdoc.rdoc_files.include('vendor/rails/railties/CHANGELOG')
|
||||
rdoc.rdoc_files.include('vendor/rails/railties/MIT-LICENSE')
|
||||
rdoc.rdoc_files.include('vendor/rails/activerecord/README')
|
||||
rdoc.rdoc_files.include('vendor/rails/activerecord/CHANGELOG')
|
||||
rdoc.rdoc_files.include('vendor/rails/activerecord/lib/active_record/**/*.rb')
|
||||
rdoc.rdoc_files.exclude('vendor/rails/activerecord/lib/active_record/vendor/*')
|
||||
rdoc.rdoc_files.include('vendor/rails/actionpack/README')
|
||||
rdoc.rdoc_files.include('vendor/rails/actionpack/CHANGELOG')
|
||||
rdoc.rdoc_files.include('vendor/rails/actionpack/lib/action_controller/**/*.rb')
|
||||
rdoc.rdoc_files.include('vendor/rails/actionpack/lib/action_view/**/*.rb')
|
||||
rdoc.rdoc_files.include('vendor/rails/actionmailer/README')
|
||||
rdoc.rdoc_files.include('vendor/rails/actionmailer/CHANGELOG')
|
||||
rdoc.rdoc_files.include('vendor/rails/actionmailer/lib/action_mailer/base.rb')
|
||||
rdoc.rdoc_files.include('vendor/rails/actionwebservice/README')
|
||||
rdoc.rdoc_files.include('vendor/rails/actionwebservice/CHANGELOG')
|
||||
rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service.rb')
|
||||
rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/*.rb')
|
||||
rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/api/*.rb')
|
||||
rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/client/*.rb')
|
||||
rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/container/*.rb')
|
||||
rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/dispatcher/*.rb')
|
||||
rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/protocol/*.rb')
|
||||
rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/support/*.rb')
|
||||
rdoc.rdoc_files.include('vendor/rails/activesupport/README')
|
||||
rdoc.rdoc_files.include('vendor/rails/activesupport/CHANGELOG')
|
||||
rdoc.rdoc_files.include('vendor/rails/activesupport/lib/active_support/**/*.rb')
|
||||
}
|
||||
|
||||
desc "Report code statistics (KLOCs, etc) from the application"
|
||||
task :stats => [ :environment ] do
|
||||
require 'code_statistics'
|
||||
CodeStatistics.new(
|
||||
["Helpers", "app/helpers"],
|
||||
["Controllers", "app/controllers"],
|
||||
["APIs", "app/apis"],
|
||||
["Components", "components"],
|
||||
["Functionals", "test/functional"],
|
||||
["Models", "app/models"],
|
||||
["Units", "test/unit"]
|
||||
).to_s
|
||||
end
|
||||
|
||||
desc "Recreate the test databases from the development structure"
|
||||
task :clone_structure_to_test => [ :db_structure_dump, :purge_test_database ] do
|
||||
abcs = ActiveRecord::Base.configurations
|
||||
case abcs["test"]["adapter"]
|
||||
when "mysql"
|
||||
ActiveRecord::Base.establish_connection(:test)
|
||||
ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0')
|
||||
IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table|
|
||||
ActiveRecord::Base.connection.execute(table)
|
||||
end
|
||||
when "postgresql"
|
||||
ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"]
|
||||
ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"]
|
||||
ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"]
|
||||
`psql -U "#{abcs["test"]["username"]}" -f db/#{RAILS_ENV}_structure.sql #{abcs["test"]["database"]}`
|
||||
when "sqlite", "sqlite3"
|
||||
`#{abcs[RAILS_ENV]["adapter"]} #{abcs["test"]["dbfile"]} < db/#{RAILS_ENV}_structure.sql`
|
||||
when "sqlserver"
|
||||
`osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql`
|
||||
else
|
||||
raise "Unknown database adapter '#{abcs["test"]["adapter"]}'"
|
||||
end
|
||||
end
|
||||
|
||||
desc "Dump the database structure to a SQL file"
|
||||
task :db_structure_dump => :environment do
|
||||
abcs = ActiveRecord::Base.configurations
|
||||
case abcs[RAILS_ENV]["adapter"]
|
||||
when "mysql"
|
||||
ActiveRecord::Base.establish_connection(abcs[RAILS_ENV])
|
||||
File.open("db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
|
||||
when "postgresql"
|
||||
ENV['PGHOST'] = abcs[RAILS_ENV]["host"] if abcs[RAILS_ENV]["host"]
|
||||
ENV['PGPORT'] = abcs[RAILS_ENV]["port"].to_s if abcs[RAILS_ENV]["port"]
|
||||
ENV['PGPASSWORD'] = abcs[RAILS_ENV]["password"].to_s if abcs[RAILS_ENV]["password"]
|
||||
`pg_dump -U "#{abcs[RAILS_ENV]["username"]}" -s -x -O -f db/#{RAILS_ENV}_structure.sql #{abcs[RAILS_ENV]["database"]}`
|
||||
when "sqlite", "sqlite3"
|
||||
`#{abcs[RAILS_ENV]["adapter"]} #{abcs[RAILS_ENV]["dbfile"]} .schema > db/#{RAILS_ENV}_structure.sql`
|
||||
when "sqlserver"
|
||||
`scptxfr /s #{abcs[RAILS_ENV]["host"]} /d #{abcs[RAILS_ENV]["database"]} /I /f db\\#{RAILS_ENV}_structure.sql /q /A /r`
|
||||
`scptxfr /s #{abcs[RAILS_ENV]["host"]} /d #{abcs[RAILS_ENV]["database"]} /I /F db\ /q /A /r`
|
||||
else
|
||||
raise "Unknown database adapter '#{abcs["test"]["adapter"]}'"
|
||||
end
|
||||
end
|
||||
|
||||
desc "Empty the test database"
|
||||
task :purge_test_database => :environment do
|
||||
abcs = ActiveRecord::Base.configurations
|
||||
case abcs["test"]["adapter"]
|
||||
when "mysql"
|
||||
ActiveRecord::Base.establish_connection(:test)
|
||||
ActiveRecord::Base.connection.recreate_database(abcs["test"]["database"])
|
||||
when "postgresql"
|
||||
ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"]
|
||||
ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"]
|
||||
ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"]
|
||||
`dropdb -U "#{abcs["test"]["username"]}" #{abcs["test"]["database"]}`
|
||||
`createdb -T template0 -U "#{abcs["test"]["username"]}" #{abcs["test"]["database"]}`
|
||||
when "sqlite","sqlite3"
|
||||
File.delete(abcs["test"]["dbfile"]) if File.exist?(abcs["test"]["dbfile"])
|
||||
when "sqlserver"
|
||||
dropfkscript = "#{abcs["test"]["host"]}.#{abcs["test"]["database"]}.DP1".gsub(/\\/,'-')
|
||||
`osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{dropfkscript}`
|
||||
`osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql`
|
||||
else
|
||||
raise "Unknown database adapter '#{abcs["test"]["adapter"]}'"
|
||||
end
|
||||
end
|
||||
|
||||
desc "Clears all *.log files in log/"
|
||||
task :clear_logs => :environment do
|
||||
FileList["log/*.log"].each do |log_file|
|
||||
f = File.open(log_file, "w")
|
||||
f.close
|
||||
end
|
||||
end
|
||||
|
||||
desc "Migrate the database according to the migrate scripts in db/migrate (only supported on PG/MySQL). A specific version can be targetted with VERSION=x"
|
||||
task :migrate => :environment do
|
||||
ActiveRecord::Migrator.migrate(File.dirname(__FILE__) + '/db/migrate/', ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
|
||||
end
|
||||
|
||||
task :ft => :test_functional
|
||||
task :ut => :test_unit
|
|
@ -195,7 +195,7 @@ class AdminControllerTest < Test::Unit::TestCase
|
|||
orphan_page_linking_to_oak = @wiki.write_page('wiki1', 'Pine',
|
||||
"Refers to [[Oak]].\n" +
|
||||
"category: trees",
|
||||
Time.now, Author.new('TreeHugger', '127.0.0.2'))
|
||||
Time.now, Author.new('TreeHugger', '127.0.0.2'), test_renderer)
|
||||
|
||||
r = process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password_orphaned' => 'pswd')
|
||||
|
||||
|
|
|
@ -93,10 +93,11 @@ class FileControllerTest < Test::Unit::TestCase
|
|||
|
||||
def test_pic_upload_end_to_end
|
||||
# edit and re-render home page so that it has an "unknown file" link to 'rails-e2e.gif'
|
||||
@wiki.revise_page('wiki1', 'HomePage', '[[instiki-e2e.txt:file]]', Time.now, 'AnonymousBrave')
|
||||
@wiki.revise_page('wiki1', 'HomePage', '[[instiki-e2e.txt:file]]', Time.now, 'AnonymousBrave',
|
||||
test_renderer)
|
||||
assert_equal "<p><span class=\"newWikiWord\">instiki-e2e.txt" +
|
||||
"<a href=\"../file/instiki-e2e.txt\">?</a></span></p>",
|
||||
PageRenderer.new(@home.revisions.last).display_content
|
||||
test_renderer(@home.revisions.last).display_content
|
||||
|
||||
# rails-e2e.gif is unknown to the system, so pic action goes to the file [upload] form
|
||||
r = process 'file', 'web' => 'wiki1', 'id' => 'instiki-e2e.txt'
|
||||
|
@ -114,7 +115,7 @@ class FileControllerTest < Test::Unit::TestCase
|
|||
@home = Page.find(@home.id)
|
||||
assert_equal "<p><a class=\"existingWikiWord\" href=\"../file/instiki-e2e.txt\">" +
|
||||
"instiki-e2e.txt</a></p>",
|
||||
PageRenderer.new(@home.revisions.last).display_content
|
||||
test_renderer(@home.revisions.last).display_content
|
||||
end
|
||||
|
||||
def test_uploads_blocking
|
||||
|
|
|
@ -46,7 +46,7 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
def test_authors
|
||||
@wiki.write_page('wiki1', 'BreakSortingOrder',
|
||||
"This page breaks the accidentally correct sorting order of authors",
|
||||
Time.now, Author.new('BreakingTheOrder', '127.0.0.2'))
|
||||
Time.now, Author.new('BreakingTheOrder', '127.0.0.2'), test_renderer)
|
||||
|
||||
r = process('authors', 'web' => 'wiki1')
|
||||
|
||||
|
@ -92,9 +92,9 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_edit_page_with_special_symbols
|
||||
@wiki.write_page('wiki1', 'With : Special /> symbols',
|
||||
'This page has special symbols in the name',
|
||||
Time.now, Author.new('Special', '127.0.0.3'))
|
||||
@wiki.write_page('wiki1', 'With : Special /> symbols',
|
||||
'This page has special symbols in the name', Time.now, Author.new('Special', '127.0.0.3'),
|
||||
test_renderer)
|
||||
|
||||
r = process 'edit', 'web' => 'wiki1', 'id' => 'With : Special /> symbols'
|
||||
assert_success
|
||||
|
@ -104,7 +104,8 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_export_html
|
||||
@home.rollback(0, Time.now, 'Rick') # much simpler regex statement to match
|
||||
# rollback homepage to a version that is easier to match
|
||||
@home.rollback(0, Time.now, 'Rick', test_renderer)
|
||||
r = process 'export_html', 'web' => 'wiki1'
|
||||
|
||||
assert_success(bypass_body_parsing = true)
|
||||
|
@ -304,7 +305,7 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
page2 = @wiki.write_page('wiki1', 'Page2',
|
||||
"Page2 contents.\n" +
|
||||
"category: categorized",
|
||||
Time.now, Author.new('AnotherAuthor', '127.0.0.2'))
|
||||
Time.now, Author.new('AnotherAuthor', '127.0.0.2'), test_renderer)
|
||||
|
||||
r = process('recently_revised', 'web' => 'wiki1')
|
||||
assert_success
|
||||
|
@ -384,7 +385,7 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
|
||||
def test_rss_with_headlines
|
||||
@title_with_spaces = @wiki.write_page('wiki1', 'Title With Spaces',
|
||||
'About spaces', 1.hour.ago, Author.new('TreeHugger', '127.0.0.2'))
|
||||
'About spaces', 1.hour.ago, Author.new('TreeHugger', '127.0.0.2'), test_renderer)
|
||||
|
||||
@request.host = 'localhost'
|
||||
@request.port = 8080
|
||||
|
@ -486,7 +487,7 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
def test_rss_title_with_ampersand
|
||||
# was ticket:143
|
||||
@wiki.write_page('wiki1', 'Title&With&Ampersands',
|
||||
'About spaces', 1.hour.ago, Author.new('NitPicker', '127.0.0.3'))
|
||||
'About spaces', 1.hour.ago, Author.new('NitPicker', '127.0.0.3'), test_renderer)
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1'
|
||||
|
||||
|
@ -496,7 +497,8 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
|
||||
def test_rss_timestamp
|
||||
new_page = @wiki.write_page('wiki1', 'PageCreatedAtTheBeginningOfCtime',
|
||||
'Created on 1 Jan 1970 at 0:00:00 Z', Time.at(0), Author.new('NitPicker', '127.0.0.3'))
|
||||
'Created on 1 Jan 1970 at 0:00:00 Z', Time.at(0), Author.new('NitPicker', '127.0.0.3'),
|
||||
test_renderer)
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1'
|
||||
assert_template_xpath_match '/rss/channel/item/pubDate[9]', "Thu, 01 Jan 1970 00:00:00 Z"
|
||||
|
@ -588,7 +590,7 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
|
||||
def test_show_page_with_multiple_revisions
|
||||
@wiki.write_page('wiki1', 'HomePage', 'Second revision of the HomePage end', Time.now,
|
||||
Author.new('AnotherAuthor', '127.0.0.2'))
|
||||
Author.new('AnotherAuthor', '127.0.0.2'), test_renderer)
|
||||
|
||||
r = process('show', 'id' => 'HomePage', 'web' => 'wiki1')
|
||||
|
||||
|
|
|
@ -35,12 +35,17 @@ class Test::Unit::TestCase
|
|||
ActiveRecord::Base.silence do
|
||||
(1..30).each do |i|
|
||||
@wiki.write_page('wiki1', "page#{i}", "Test page #{i}\ncategory: test",
|
||||
Time.local(1976, 10, i, 12, 00, 00), Author.new('Dema', '127.0.0.2'))
|
||||
Time.local(1976, 10, i, 12, 00, 00), Author.new('Dema', '127.0.0.2'),
|
||||
test_renderer)
|
||||
end
|
||||
end
|
||||
@web = Web.find(@web.id)
|
||||
end
|
||||
|
||||
def test_renderer(revision = nil)
|
||||
PageRenderer.new(revision)
|
||||
end
|
||||
|
||||
def use_blank_wiki
|
||||
Revision.destroy_all
|
||||
Page.destroy_all
|
||||
|
|
|
@ -12,14 +12,14 @@ class PageRendererTest < Test::Unit::TestCase
|
|||
|
||||
def test_wiki_word_linking
|
||||
@web.add_page('SecondPage', 'Yo, yo. Have you EverBeenHated',
|
||||
Time.now, 'DavidHeinemeierHansson')
|
||||
Time.now, 'DavidHeinemeierHansson', test_renderer)
|
||||
|
||||
assert_equal('<p>Yo, yo. Have you <span class="newWikiWord">Ever Been Hated' +
|
||||
'<a href="../show/EverBeenHated">?</a></span></p>',
|
||||
rendered_content(@web.page("SecondPage")))
|
||||
|
||||
@web.add_page('EverBeenHated', 'Yo, yo. Have you EverBeenHated', Time.now,
|
||||
'DavidHeinemeierHansson')
|
||||
'DavidHeinemeierHansson', test_renderer)
|
||||
assert_equal('<p>Yo, yo. Have you <a class="existingWikiWord" ' +
|
||||
'href="../show/EverBeenHated">Ever Been Hated</a></p>',
|
||||
rendered_content(@web.page("SecondPage")))
|
||||
|
@ -71,18 +71,18 @@ class PageRendererTest < Test::Unit::TestCase
|
|||
|
||||
def test_wiki_words
|
||||
assert_equal %w( HisWay MyWay SmartEngine SmartEngineGUI ThatWay ),
|
||||
PageRenderer.new(@revision).wiki_words.sort
|
||||
test_renderer(@revision).wiki_words.sort
|
||||
|
||||
@wiki.write_page('wiki1', 'NoWikiWord', 'hey you!', Time.now, 'Me')
|
||||
assert_equal [], PageRenderer.new(@wiki.read_page('wiki1', 'NoWikiWord').revisions.last).wiki_words
|
||||
@wiki.write_page('wiki1', 'NoWikiWord', 'hey you!', Time.now, 'Me', test_renderer)
|
||||
assert_equal [], test_renderer(@wiki.read_page('wiki1', 'NoWikiWord').revisions.last).wiki_words
|
||||
end
|
||||
|
||||
def test_existing_pages
|
||||
assert_equal %w( MyWay SmartEngine ThatWay ), PageRenderer.new(@revision).existing_pages.sort
|
||||
assert_equal %w( MyWay SmartEngine ThatWay ), test_renderer(@revision).existing_pages.sort
|
||||
end
|
||||
|
||||
def test_unexisting_pages
|
||||
assert_equal %w( HisWay SmartEngineGUI ), PageRenderer.new(@revision).unexisting_pages.sort
|
||||
assert_equal %w( HisWay SmartEngineGUI ), test_renderer(@revision).unexisting_pages.sort
|
||||
end
|
||||
|
||||
def test_content_with_wiki_links
|
||||
|
@ -94,7 +94,7 @@ class PageRendererTest < Test::Unit::TestCase
|
|||
'<a class="existingWikiWord" href="../show/SmartEngine">Smart Engine</a> in that ' +
|
||||
'<span class="newWikiWord">Smart Engine GUI' +
|
||||
'<a href="../show/SmartEngineGUI">?</a></span></p>',
|
||||
PageRenderer.new(@revision).display_content
|
||||
test_renderer(@revision).display_content
|
||||
end
|
||||
|
||||
def test_markdown
|
||||
|
@ -173,7 +173,7 @@ class PageRendererTest < Test::Unit::TestCase
|
|||
|
||||
assert_equal "<tt>hello</tt> that <span class=\"newWikiWord\">Smart Engine GUI" +
|
||||
"<a href=\"../show/SmartEngineGUI\">?</a></span>\n\n",
|
||||
PageRenderer.new(@revision).display_content
|
||||
test_renderer(@revision).display_content
|
||||
end
|
||||
|
||||
def test_content_with_auto_links
|
||||
|
@ -271,36 +271,36 @@ class PageRendererTest < Test::Unit::TestCase
|
|||
|
||||
def test_content_for_export
|
||||
assert_equal '<p><span class="newWikiWord">His Way</span> would be ' +
|
||||
'<a class="existingWikiWord" href="MyWay.html">My Way</a> in kinda ' +
|
||||
'<a class="existingWikiWord" href="ThatWay.html">That Way</a> in ' +
|
||||
'<span class="newWikiWord">His Way</span> though ' +
|
||||
'<a class="existingWikiWord" href="MyWay.html">My Way</a> OverThere—see ' +
|
||||
'<a class="existingWikiWord" href="SmartEngine.html">Smart Engine</a> in that ' +
|
||||
'<span class="newWikiWord">Smart Engine GUI</span></p>',
|
||||
PageRenderer.new(@revision).display_content_for_export
|
||||
'<a class="existingWikiWord" href="MyWay.html">My Way</a> in kinda ' +
|
||||
'<a class="existingWikiWord" href="ThatWay.html">That Way</a> in ' +
|
||||
'<span class="newWikiWord">His Way</span> though ' +
|
||||
'<a class="existingWikiWord" href="MyWay.html">My Way</a> OverThere—see ' +
|
||||
'<a class="existingWikiWord" href="SmartEngine.html">Smart Engine</a> in that ' +
|
||||
'<span class="newWikiWord">Smart Engine GUI</span></p>',
|
||||
test_renderer(@revision).display_content_for_export
|
||||
end
|
||||
|
||||
def test_double_replacing
|
||||
@revision.content = "VersionHistory\r\n\r\ncry VersionHistory"
|
||||
assert_equal '<p><span class="newWikiWord">Version History' +
|
||||
"<a href=\"../show/VersionHistory\">?</a></span></p>\n\n\n\t<p>cry " +
|
||||
'<span class="newWikiWord">Version History<a href="../show/VersionHistory">?</a>' +
|
||||
'</span></p>',
|
||||
PageRenderer.new(@revision).display_content
|
||||
"<a href=\"../show/VersionHistory\">?</a></span></p>\n\n\n\t<p>cry " +
|
||||
'<span class="newWikiWord">Version History<a href="../show/VersionHistory">?</a>' +
|
||||
'</span></p>',
|
||||
test_renderer(@revision).display_content
|
||||
|
||||
@revision.content = "f\r\nVersionHistory\r\n\r\ncry VersionHistory"
|
||||
assert_equal "<p>f<br /><span class=\"newWikiWord\">Version History" +
|
||||
"<a href=\"../show/VersionHistory\">?</a></span></p>\n\n\n\t<p>cry " +
|
||||
"<span class=\"newWikiWord\">Version History<a href=\"../show/VersionHistory\">?</a>" +
|
||||
"</span></p>",
|
||||
PageRenderer.new(@revision).display_content
|
||||
"<a href=\"../show/VersionHistory\">?</a></span></p>\n\n\n\t<p>cry " +
|
||||
"<span class=\"newWikiWord\">Version History<a href=\"../show/VersionHistory\">?</a>" +
|
||||
"</span></p>",
|
||||
test_renderer(@revision).display_content
|
||||
end
|
||||
|
||||
def test_difficult_wiki_words
|
||||
@revision.content = "[[It's just awesome GUI!]]"
|
||||
assert_equal "<p><span class=\"newWikiWord\">It's just awesome GUI!" +
|
||||
"<a href=\"../show/It%27s+just+awesome+GUI%21\">?</a></span></p>",
|
||||
PageRenderer.new(@revision).display_content
|
||||
"<a href=\"../show/It%27s+just+awesome+GUI%21\">?</a></span></p>",
|
||||
test_renderer(@revision).display_content
|
||||
end
|
||||
|
||||
def test_revisions_diff
|
||||
|
@ -311,7 +311,7 @@ class PageRendererTest < Test::Unit::TestCase
|
|||
|
||||
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 " +
|
||||
"today</ins></p>", PageRenderer.new(@page.revisions.last).display_diff
|
||||
"today</ins></p>", test_renderer(@page.revisions.last).display_diff
|
||||
end
|
||||
|
||||
def test_link_to_file
|
||||
|
@ -373,18 +373,18 @@ class PageRendererTest < Test::Unit::TestCase
|
|||
|
||||
def add_sample_pages
|
||||
@in_love = @web.add_page('EverBeenInLove', 'Who am I me',
|
||||
Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson')
|
||||
Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson', test_renderer)
|
||||
@hated = @web.add_page('EverBeenHated', 'I am me EverBeenHated',
|
||||
Time.local(2004, 4, 4, 16, 51), 'DavidHeinemeierHansson')
|
||||
Time.local(2004, 4, 4, 16, 51), 'DavidHeinemeierHansson', test_renderer)
|
||||
end
|
||||
|
||||
def assert_markup_parsed_as(expected_output, input)
|
||||
revision = Revision.new(:page => @page, :content => input, :author => Author.new('AnAuthor'))
|
||||
assert_equal expected_output, PageRenderer.new(revision).display_content, 'Rendering output not as expected'
|
||||
assert_equal expected_output, test_renderer(revision).display_content, 'Rendering output not as expected'
|
||||
end
|
||||
|
||||
def rendered_content(page)
|
||||
PageRenderer.new(page.revisions.last).display_content
|
||||
test_renderer(page.revisions.last).display_content
|
||||
end
|
||||
|
||||
end
|
|
@ -31,36 +31,43 @@ class PageTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
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', test_renderer)
|
||||
@page.reload
|
||||
|
||||
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 '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'
|
||||
end
|
||||
|
||||
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', test_renderer)
|
||||
@page.reload
|
||||
assert_equal 2, @page.revisions.length
|
||||
assert_equal 'HisWay would be MyWay in kinda lame', @page.content
|
||||
|
||||
# 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', test_renderer)
|
||||
@page.reload
|
||||
assert_equal 2, @page.revisions.length
|
||||
assert_equal 'HisWay would be MyWay in kinda update', @page.content
|
||||
assert_equal Time.local(2004, 4, 4, 16, 57), @page.revised_at
|
||||
|
||||
# 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', test_renderer)
|
||||
@page.reload
|
||||
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', test_renderer)
|
||||
@page.reload
|
||||
assert_equal 4, @page.revisions.length
|
||||
end
|
||||
|
@ -70,7 +77,7 @@ class PageTest < Test::Unit::TestCase
|
|||
revisions_number_before = @page.revisions.size
|
||||
|
||||
assert_raises(Instiki::ValidationError) {
|
||||
@page.revise(@page.current_revision.content, Time.now, 'AlexeyVerkhovsky')
|
||||
@page.revise(@page.current_revision.content, Time.now, 'AlexeyVerkhovsky', test_renderer)
|
||||
}
|
||||
|
||||
assert_equal last_revision_before, @page.current_revision(true)
|
||||
|
@ -78,11 +85,11 @@ class PageTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_rollback
|
||||
@page.revise("spot two", Time.now, "David")
|
||||
@page.revise("spot three", Time.now + 2000, "David")
|
||||
@page.revise("spot two", Time.now, "David", test_renderer)
|
||||
@page.revise("spot three", Time.now + 2000, "David", test_renderer)
|
||||
assert_equal 3, @page.revisions(true).length, "Should have three revisions"
|
||||
@page.current_revision(true)
|
||||
@page.rollback(0, Time.now)
|
||||
@page.rollback(0, Time.now, '127.0.0.1', test_renderer)
|
||||
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
|
||||
|
|
|
@ -61,9 +61,9 @@ class WebTest < Test::Unit::TestCase
|
|||
def test_new_page_linked_from_mother_page
|
||||
# this was a bug in revision 204
|
||||
home = @web.add_page('HomePage', 'This page refers to AnotherPage',
|
||||
Time.local(2004, 4, 4, 16, 50), 'Alexey Verkhovsky')
|
||||
Time.local(2004, 4, 4, 16, 50), 'Alexey Verkhovsky', test_renderer)
|
||||
@web.add_page('AnotherPage', 'This is \AnotherPage',
|
||||
Time.local(2004, 4, 4, 16, 51), 'Alexey Verkhovsky')
|
||||
Time.local(2004, 4, 4, 16, 51), 'Alexey Verkhovsky', test_renderer)
|
||||
|
||||
@web.pages(true)
|
||||
assert_equal [home], @web.select.pages_that_link_to('AnotherPage')
|
||||
|
@ -73,13 +73,13 @@ class WebTest < Test::Unit::TestCase
|
|||
add_sample_pages
|
||||
home = @web.add_page('HomePage',
|
||||
'This is a home page, it should not be an orphan',
|
||||
Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky')
|
||||
Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky', test_renderer)
|
||||
author = @web.add_page('AlexeyVerkhovsky',
|
||||
'This is an author page, it should not be an orphan',
|
||||
Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky')
|
||||
Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky', test_renderer)
|
||||
self_linked = @web.add_page('SelfLinked',
|
||||
'I am me SelfLinked and link to EverBeenInLove',
|
||||
Time.local(2004, 4, 4, 16, 50), 'AnonymousCoward')
|
||||
Time.local(2004, 4, 4, 16, 50), 'AnonymousCoward', test_renderer)
|
||||
|
||||
# page that links to itself, and nobody else links to it must be an orphan
|
||||
assert_equal ['EverBeenHated', 'SelfLinked'],
|
||||
|
@ -90,8 +90,8 @@ class WebTest < Test::Unit::TestCase
|
|||
|
||||
def add_sample_pages
|
||||
@in_love = @web.add_page('EverBeenInLove', 'Who am I me',
|
||||
Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson')
|
||||
Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson', test_renderer)
|
||||
@hated = @web.add_page('EverBeenHated', 'I am me EverBeenHated',
|
||||
Time.local(2004, 4, 4, 16, 51), 'DavidHeinemeierHansson')
|
||||
Time.local(2004, 4, 4, 16, 51), 'DavidHeinemeierHansson', test_renderer)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue