From 26c046cdfa1d62151c4fe271590b37f97037ec0a Mon Sep 17 00:00:00 2001
From: Rick Okin Markup engine has failed to render this page, raising the following error: #{message} All content: <%= total_chars %> chars / <%= sprintf("%-.1f", (total_chars / 2275 )) %> pages His Way? ' +
+ 'would be My Way in kinda ' +
+ 'That Way in ' +
+ 'His Way? ' +
+ 'though My Way OverThere—see ' +
+ 'Smart Engine in that ' +
+ 'Smart Engine GUI' +
+ '? that } +
+ %{Smart Engine GUI? This is a code block: Nice! h2. Textile heading some text with -styles- Markdown heading some text with some text with http://www.loudthinking.com/ ' +
+ 'points to That Way from ' +
+ 'david@loudthinking.com Would a clever motor' +
+ ' go by any other name? should we go ' +
+ 'That Way or This Way?' +
+ ' That is some Stylish Emphasis WikiWord A #{self.content}
+ EOL
+ clear_display_cache
+ raise e
+ end
+ end
+
+ protected
+ before_create :set_revision_number
+ after_create :force_rendering
+ after_save :clear_display_cache
+
+ def set_revision_number
+ self.number = self.class.count(['page_id = ?', page_id]) + 1
+ end
+end
diff --git a/app/models/system.rb b/app/models/system.rb
new file mode 100644
index 00000000..7ac1ad08
--- /dev/null
+++ b/app/models/system.rb
@@ -0,0 +1,4 @@
+class System < ActiveRecord::Base
+ set_table_name 'system'
+ validates_presence_of :password
+end
\ No newline at end of file
diff --git a/app/models/web.rb b/app/models/web.rb
index 2c31bf8f..5ca077d5 100644
--- a/app/models/web.rb
+++ b/app/models/web.rb
@@ -1,3 +1,173 @@
+require 'cgi'
+
class Web < ActiveRecord::Base
- has_many :pages
-end
\ No newline at end of file
+ has_many :pages#, :include => [:current_revision, :web]
+
+ def wiki
+ Wiki.new
+ end
+
+ def file_yard
+ @file_yard ||= FileYard.new("#{Wiki.storage_path}/#{address}", max_upload_size)
+ end
+
+ def settings_changed?(markup, safe_mode, brackets_only)
+ self.markup != markup ||
+ self.safe_mode != safe_mode ||
+ self.brackets_only != brackets_only
+ end
+
+ def add_page(name, content, created_at, author)
+ page = page(name) || Page.new(:web => self, :name => name)
+ page.revise(content, created_at, author)
+ end
+
+ def authors
+ select.authors
+ end
+
+ def categories
+ select.map { |page| page.categories }.flatten.uniq.sort
+ end
+
+ def page(name)
+ pages.find(:first, :conditions => ['name = ?', name])
+ end
+
+ def has_page?(name)
+ Page.count(['web_id = ? AND name = ?', id, name]) > 0
+ end
+
+ def has_file?(name)
+ wiki.file_yard(self).has_file?(name)
+ end
+
+ def markup
+ read_attribute('markup').to_sym
+ end
+
+ def make_file_link(mode, name, text, base_url)
+ link = CGI.escape(name)
+ case mode
+ when :export
+ if has_file?(name) then "#{text}"
+ else "#{text}" end
+ when :publish
+ if has_file?(name) then "#{text}"
+ else "#{text}" end
+ else
+ if has_file?(name)
+ "#{text}"
+ else
+ "#{text}?"
+ end
+ end
+ end
+
+ # Create a link for the given page name and link text based
+ # on the render mode in options and whether the page exists
+ # in the this web.
+ # The links a relative, and will work only if displayed on another WikiPage.
+ # It should not be used in menus, templates and such - instead, use link_to_page helper
+ def make_link(name, text = nil, options = {})
+ text = CGI.escapeHTML(text || WikiWords.separate(name))
+ mode = options[:mode] || :show
+ base_url = options[:base_url] || '..'
+ link_type = options[:link_type] || :show
+ case link_type.to_sym
+ when :show
+ make_page_link(mode, name, text, base_url)
+ when :file
+ make_file_link(mode, name, text, base_url)
+ when :pic
+ make_pic_link(mode, name, text, base_url)
+ else
+ raise "Unknown link type: #{link_type}"
+ end
+ end
+
+ def make_page_link(mode, name, text, base_url)
+ link = CGI.escape(name)
+ case mode.to_sym
+ when :export
+ if has_page?(name) then %{#{text}}
+ else %{#{text}} end
+ when :publish
+ if has_page?(name) then %{#{text}}
+ else %{#{text}} end
+ else
+ if has_page?(name)
+ %{#{text}}
+ else
+ %{#{text}?}
+ end
+ end
+ end
+
+ def make_pic_link(mode, name, text, base_url)
+ link = CGI.escape(name)
+ case mode.to_sym
+ when :export
+ if has_file?(name) then %{}
+ else %{} end
+ when :publish
+ if has_file?(name) then %{}
+ else %{#{text}} end
+ else
+ if has_file?(name) then %{}
+ else %{#{text}?} end
+ end
+ end
+
+ # Clears the display cache for all the pages with references to
+ def refresh_pages_with_references(page_name)
+ #select.pages_that_reference(page_name).each { |page|
+ # page.revisions.each { |revision| revision.clear_display_cache }
+ #}
+ end
+
+ def refresh_revisions
+ select.each { |page| page.revisions.each { |revision| revision.clear_display_cache } }
+ end
+
+ def remove_pages(pages_to_be_removed)
+ pages_to_be_removed.each { |p| p.destroy }
+ end
+
+ def revised_on
+ select.most_recent_revision
+ end
+
+ def select(&condition)
+ PageSet.new(self, pages, condition)
+ end
+
+ private
+
+ # Returns an array of all the wiki words in any current revision
+ def wiki_words
+ pages.inject([]) { |wiki_words, page| wiki_words << page.wiki_words }.flatten.uniq
+ end
+
+ # Returns an array of all the page names on this web
+ def page_names
+ pages.map { |p| p.name }
+ end
+
+ protected
+ before_save :sanitize_markup
+ before_validation :validate_address
+ validates_uniqueness_of :address
+ validates_length_of :color, :in => 3..6
+
+ def sanitize_markup
+ self.markup = markup.to_s
+ end
+
+ def validate_address
+ unless address == CGI.escape(address)
+ self.errors.add(:address, 'should contain only valid URI characters')
+ raise Instiki::ValidationError.new("#{self.class.human_attribute_name('address')} #{errors.on(:address)}")
+ end
+ end
+end
diff --git a/app/views/wiki/list.rhtml b/app/views/wiki/list.rhtml
index 34a93798..d891f5a2 100644
--- a/app/views/wiki/list.rhtml
+++ b/app/views/wiki/list.rhtml
@@ -17,7 +17,7 @@
<% end %>
-<% if @web.count_pages %>
+<% if @web.count_pages? %>
<% total_chars = @pages_in_category.characters %>
chunk456categorychunk
"
+ # inside_chunks(Literal::Pre) ==> yield 456
+ def inside_chunks(chunk_types)
+ chunk_types.each{|chunk_type| chunk_type.apply_to(self) }
+
+ chunk_types.each{|chunk_type| @chunks_by_type[chunk_type].each{|hide_chunk|
+ scan_chunkid(hide_chunk.text){|id| yield id }
+ }
+ }
+ end
+end
+
+class WikiContent < String
+
+ include ChunkManager
+
+ DEFAULT_OPTS = {
+ :active_chunks => ACTIVE_CHUNKS,
+ :engine => Engines::Textile,
+ :engine_opts => [],
+ :mode => :show
+ }.freeze
+
+ attr_reader :web, :options, :revision, :not_rendered, :pre_rendered
+
+ # Create a new wiki content string from the given one.
+ # The options are explained at the top of this file.
+ def initialize(revision, options = {})
+ @revision = revision
+ @web = @revision.page.web
+
+ @options = DEFAULT_OPTS.dup.merge(options)
+ @options[:engine] = Engines::MAP[@web.markup]
+ @options[:engine_opts] = [:filter_html, :filter_styles] if @web.safe_mode?
+ @options[:active_chunks] = (ACTIVE_CHUNKS - [WikiChunk::Word] ) if @web.brackets_only?
+
+ @not_rendered = @pre_rendered = nil
+
+ super(@revision.content)
+ init_chunk_manager
+ build_chunks
+ @not_rendered = String.new(self)
+ end
+
+ # Call @web.page_link using current options.
+ def page_link(name, text, link_type)
+ @options[:link_type] = (link_type || :show)
+ @web.make_link(name, text, @options)
+ end
+
+ def build_chunks
+ # create and mask Includes and "active_chunks" chunks
+ Include.apply_to(self)
+ @options[:active_chunks].each{|chunk_type| chunk_type.apply_to(self)}
+
+ # Handle hiding contexts like "pre" and "code" etc..
+ # The markup (textile, rdoc etc) can produce such contexts with its own syntax.
+ # To reveal them, we work on a copy of the content.
+ # The copy is rendered and used to detect the chunks that are inside protecting context
+ # These chunks are reverted on the original content string.
+
+ copy = WikiContentStub.new(self, @options)
+ @options[:engine].apply_to(copy)
+
+ copy.inside_chunks(HIDE_CHUNKS) do |id|
+ @chunks_by_id[id].revert
+ end
+ end
+
+ def pre_render!
+ unless @pre_rendered
+ @chunks_by_type[Include].each{|chunk| chunk.unmask }
+ @pre_rendered = String.new(self)
+ end
+ @pre_rendered
+ end
+
+ def render!
+ pre_render!
+ @options[:engine].apply_to(self)
+ # unmask in one go. $~[1] is the chunk id
+ gsub!(MASK_RE[ACTIVE_CHUNKS]){
+ if chunk = @chunks_by_id[$~[1]]
+ chunk.unmask_text
+ # if we match a chunkmask that existed in the original content string
+ # just keep it as it is
+ else
+ $~[0]
+ end}
+ self
+ end
+
+ def page_name
+ @revision.page.name
+ end
+
+ def page_id
+ @revision.page.id
+ end
+
+end
+
diff --git a/lib/wiki_words.rb b/lib/wiki_words.rb
new file mode 100644
index 00000000..8f2b154f
--- /dev/null
+++ b/lib/wiki_words.rb
@@ -0,0 +1,23 @@
+# Contains all the methods for finding and replacing wiki words
+module WikiWords
+ # In order of appearance: Latin, greek, cyrillian, armenian
+ I18N_HIGHER_CASE_LETTERS =
+ "ÀÃ?ÂÃÄÅĀĄĂÆÇĆČĈĊĎÄ?ÃˆÃ‰ÃŠÃ‹Ä’Ä˜ÄšÄ”Ä–ÄœÄžÄ Ä¢Ä¤Ä¦ÃŒÃ?ÃŽÃ?ĪĨĬĮİIJĴĶÅ?ĽĹĻĿÑŃŇŅŊÒÓÔÕÖØŌÅ?ŎŒŔŘŖŚŠŞŜȘŤŢŦȚÙÚÛÜŪŮŰŬŨŲŴÃ?ŶŸŹŽŻ" +
+ "ΑΒΓΔΕΖΗΘΙΚΛΜÎ?ΞΟΠΡΣΤΥΦΧΨΩ" +
+ "ΆΈΉΊΌΎÎ?Ñ Ñ¢Ñ¤Ñ¦Ñ¨ÑªÑ¬Ñ®Ñ°Ñ²Ñ´Ñ¶Ñ¸ÑºÑ¼Ñ¾Ò€ÒŠÒŒÒŽÒ?Ò’Ò”Ò–Ò˜ÒšÒœÒžÒ Ò¢Ò¤Ò¦Ò¨ÒªÒ¬Ò®Ò°Ò²Ò´Ò¶Ò¸ÒºÒ¼Ò¾Ó?ÓƒÓ…Ó‡Ó‰Ó‹Ó?Ó?Ó’Ó”Ó–Ó˜ÓšÓœÓžÓ Ó¢Ó¤Ó¦Ó¨ÓªÓ¬Ó®Ó°Ó²Ó´Ó¸Ð–" +
+ "Ô±Ô²Ô³Ô´ÔµÔ¶Ô·Ô¸Ô¹ÔºÔ»Ô¼Ô½Ô¾Ô¿Õ€Õ?Õ‚ÕƒÕ„Õ…Õ†Õ‡ÕˆÕ‰ÕŠÕ‹ÕŒÕ?Õ?Õ?Õ‘Õ’Õ“Õ”Õ•Õ–"
+
+ I18N_LOWER_CASE_LETTERS =
+ "à áâãäåÄ?ąăæçćÄ?ĉċÄ?đèéêëēęěĕėƒÄ?ğġģĥħìÃîïīĩÄįıijĵķĸłľĺļŀñńňņʼnŋòóôõöøÅ?Å‘Å?œŕřŗśšşÅ?șťţŧțùúûüūůűÅũųŵýÿŷžżźÞþßſÃ?ð" +
+ "άÎήίΰαβγδεζηθικλμνξοπÏ?ςστυφχψωϊϋόÏ?ÏŽÎ?" +
+ "абвгдежзийклмнопрÑ?туфхцчшщъыьÑ?ÑŽÑ?Ñ?ёђѓєѕіїјљћќÑ?ўџѡѣѥѧѩѫÑѯѱѳѵѷѹѻѽѿÒ?Ò‹Ò?Ò?Ò‘Ò“Ò•Ò—Ò™Ò›Ò?ÒŸÒ¡Ò£Ò¥Ò§Ò©Ò«ÒүұҳҵҷҹһҽҿӀӂӄӆӈӊӌӎӑӓӕӗәӛÓ?ÓŸÓ¡Ó£Ó¥Ó§Ó©Ó«ÓÓ¯Ó±Ó³ÓµÓ¹" +
+ "Õ¡Õ¢Õ£Õ¤Õ¥Õ¦Õ§Õ¨Õ©ÕªÕ«Õ¬ÕÕ®Õ¯Õ°Õ±Õ²Õ³Õ´ÕµÕ¶Õ·Õ¸Õ¹ÕºÕ»Õ¼Õ½Õ¾Õ¿Ö€Ö?Ö‚ÖƒÖ„Ö…Ö†Ö‡"
+
+ WIKI_WORD_PATTERN = '[A-Z' + I18N_HIGHER_CASE_LETTERS + '][a-z' + I18N_LOWER_CASE_LETTERS + ']+[A-Z' + I18N_HIGHER_CASE_LETTERS + ']\w+'
+ CAMEL_CASED_WORD_BORDER = /([a-z#{I18N_LOWER_CASE_LETTERS}])([A-Z#{I18N_HIGHER_CASE_LETTERS}])/u
+
+ def self.separate(wiki_word)
+ wiki_word.gsub(CAMEL_CASED_WORD_BORDER, '\1 \2')
+ end
+
+end
diff --git a/rakefile.rb b/rakefile.rb
index 1495f84e..e69de29b 100755
--- a/rakefile.rb
+++ b/rakefile.rb
@@ -1,134 +0,0 @@
-require 'rake'
-require 'rake/clean'
-require 'rake/testtask'
-require 'rake/rdoctask'
-require 'rake/packagetask'
-
-$VERBOSE = nil
-
-# Standard Rails tasks
-
-desc 'Run all tests'
-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 documentatio, show coding stats'
-task :doc => [ :appdoc, :stats ]
-
-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
-}
-
-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
-}
-
-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.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/activesupport/README')
- 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'],
- ['Functionals', 'test/functional'],
- ['Models', 'app/models'],
- ['Units', 'test/unit'],
- ['Miscellaneous (lib)', 'lib']
- ).to_s
-end
-
-# Additional tasks (not standard Rails)
-
-CLEAN << 'pkg' << 'storage' << 'doc' << 'html'
-
-begin
- require 'rubygems'
- require 'rake/gempackagetask'
-rescue Exception => e
- nil
-end
-
-if defined? Rake::GemPackageTask
- gemspec = eval(File.read('instiki.gemspec'))
- Rake::GemPackageTask.new(gemspec) do |p|
- p.gem_spec = gemspec
- p.need_tar = true
- p.need_zip = true
- end
-
- Rake::PackageTask.new('instiki', gemspec.version) do |p|
- p.need_tar = true
- p.need_zip = true
- # the list of glob expressions for files comes from instiki.gemspec
- p.package_files.include($__instiki_source_patterns)
- end
-
- # Create a task to build the RDOC documentation tree.
- rd = Rake::RDocTask.new("rdoc") { |rdoc|
- rdoc.rdoc_dir = 'html'
- rdoc.title = 'Instiki -- The Wiki'
- rdoc.options << '--line-numbers --inline-source --main README'
- rdoc.rdoc_files.include(gemspec.files)
- rdoc.main = 'README'
- }
-else
- puts 'Warning: without Rubygems packaging tasks are not available'
-end
-
-# Shorthand aliases
-desc 'Shorthand for test_units'
-task :tu => :test_units
-desc 'Shorthand for test_units'
-task :ut => :test_units
-
-desc 'Shorthand for test_functional'
-task :tf => :test_functional
-desc 'Shorthand for test_functional'
-task :ft => :test_functional
diff --git a/script/console b/script/console
new file mode 100644
index 00000000..eece24a9
--- /dev/null
+++ b/script/console
@@ -0,0 +1,23 @@
+#!/usr/local/bin/ruby
+irb = RUBY_PLATFORM =~ /mswin32/ ? 'irb.bat' : 'irb'
+
+require 'optparse'
+options = { :sandbox => false, :irb => irb }
+OptionParser.new do |opt|
+ opt.on('-s', '--sandbox', 'Rollback database modifications on exit.') { |options[:sandbox]| }
+ opt.on("--irb=[#{irb}]", 'Invoke a different irb.') { |options[:irb]| }
+ opt.parse!(ARGV)
+end
+
+libs = " -r irb/completion"
+libs << " -r #{File.dirname(__FILE__)}/../config/environment"
+libs << " -r console_sandbox" if options[:sandbox]
+
+ENV['RAILS_ENV'] = ARGV.first || 'development'
+if options[:sandbox]
+ puts "Loading #{ENV['RAILS_ENV']} environment in sandbox."
+ puts "Any modifications you make will be rolled back on exit."
+else
+ puts "Loading #{ENV['RAILS_ENV']} environment."
+end
+exec "#{options[:irb]} #{libs} --prompt-mode simple"
diff --git a/script/create_db b/script/create_db
index b421fb8c..642b0d03 100644
--- a/script/create_db
+++ b/script/create_db
@@ -12,7 +12,7 @@ config = ActiveRecord::Base.configurations
ENV['RAILS_ENV'] = target
load APP_ROOT + 'config/environment.rb'
puts "Creating tables for #{target}..."
-
+
db_structure(config[target]['adapter']).split(/\s*;\s*/).each do |sql|
ActiveRecord::Base.connection.execute(sql)
end
diff --git a/script/server b/script/server
index 0da05085..487d1fd9 100755
--- a/script/server
+++ b/script/server
@@ -1,93 +1,49 @@
-#!/usr/bin/ruby
+#!/usr/local/bin/ruby
require 'webrick'
require 'optparse'
-require 'fileutils'
-
-pwd = File.expand_path(File.dirname(__FILE__) + "/..")
OPTIONS = {
- # Overridable options
- :port => 2500,
- :ip => '0.0.0.0',
- :environment => 'production',
- :server_root => File.expand_path(File.dirname(__FILE__) + '/../public/'),
- :server_type => WEBrick::SimpleServer,
- :storage => "#{File.expand_path(FileUtils.pwd)}/storage",
+ :port => 3000,
+ :ip => "0.0.0.0",
+ :environment => "development",
+ :server_root => File.expand_path(File.dirname(__FILE__) + "/../public/"),
+ :server_type => WEBrick::SimpleServer
}
ARGV.options do |opts|
script_name = File.basename($0)
opts.banner = "Usage: ruby #{script_name} [options]"
- opts.separator ''
+ opts.separator ""
- opts.on('-p', '--port=port', Integer,
- 'Runs Instiki on the specified port.',
- 'Default: 2500') { |OPTIONS[:port]| }
- opts.on('-b', '--binding=ip', String,
- 'Binds Rails to the specified ip.',
- 'Default: 0.0.0.0') { |OPTIONS[:ip]| }
- opts.on('-e', '--environment=name', String,
- 'Specifies the environment to run this server under (test/development/production).',
- 'Default: production') { |OPTIONS[:environment]| }
- opts.on('-d', '--daemon',
- 'Make Instiki run as a Daemon (only works if fork is available -- meaning on *nix).'
+ opts.on("-p", "--port=port", Integer,
+ "Runs Rails on the specified port.",
+ "Default: 3000") { |OPTIONS[:port]| }
+ opts.on("-b", "--binding=ip", String,
+ "Binds Rails to the specified ip.",
+ "Default: 0.0.0.0") { |OPTIONS[:ip]| }
+ opts.on("-e", "--environment=name", String,
+ "Specifies the environment to run this server under (test/development/production).",
+ "Default: development") { |OPTIONS[:environment]| }
+ opts.on("-d", "--daemon",
+ "Make Rails run as a Daemon (only works if fork is available -- meaning on *nix)."
) { OPTIONS[:server_type] = WEBrick::Daemon }
- opts.on('-s', '--simple', '--simple-server',
- '[deprecated] Forces Instiki not to run as a Daemon if fork is available.',
- 'Since version 0.10.0 this option is ignored.'
- ) { puts "Warning: -s (--simple) option is deprecated. See instiki --help for details." }
- opts.on('-t', '--storage=storage', String,
- 'Makes Instiki use the specified directory for storage.',
- 'Default: ./storage/[port]') { |OPTIONS[:storage]| }
- opts.on('-x', '--notex',
- 'Blocks wiki exports to TeX and PDF, even when pdflatex is available.'
- ) { |OPTIONS[:notex]| }
- opts.on('-v', '--verbose',
- 'Enables debug-level logging'
- ) { OPTIONS[:verbose] = true }
- opts.separator ''
+ opts.separator ""
- opts.on('-h', '--help',
- 'Show this help message.') { puts opts; exit }
+ opts.on("-h", "--help",
+ "Show this help message.") { puts opts; exit }
opts.parse!
end
-if OPTIONS[:environment] == 'production'
- storage_path = "#{OPTIONS[:storage]}/#{OPTIONS[:port]}"
-else
- storage_path = "#{OPTIONS[:storage]}/#{OPTIONS[:environment]}/#{OPTIONS[:port]}"
-end
-FileUtils.mkdir_p(storage_path)
+ENV["RAILS_ENV"] = OPTIONS[:environment]
+require File.dirname(__FILE__) + "/../config/environment"
+require 'webrick_server'
-ENV['RAILS_ENV'] = OPTIONS[:environment]
-$instiki_debug_logging = OPTIONS[:verbose]
-require File.expand_path(File.dirname(__FILE__) + '/../config/environment')
-WikiService.storage_path = storage_path
+OPTIONS['working_directory'] = File.expand_path(RAILS_ROOT)
-if OPTIONS[:notex]
- OPTIONS[:pdflatex] = false
-else
- begin
- OPTIONS[:pdflatex] = system "pdflatex -version"
- rescue Errno::ENOENT
- OPTIONS[:pdflatex] = false
- end
-end
-
-if defined? INSTIKI_BATCH_JOB
- require 'application'
-else
- puts "=> Starting Instiki on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"
- puts "=> Data files are stored in #{storage_path}"
-
- require 'webrick_server'
- require_dependency 'application'
-
- OPTIONS[:index_controller] = 'wiki'
- ApplicationController.wiki = WikiService.instance
- DispatchServlet.dispatch(OPTIONS)
-end
+puts "=> Rails application started on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"
+puts "=> Ctrl-C to shutdown server; call with --help for options" if OPTIONS[:server_type] == WEBrick::SimpleServer
+DispatchServlet.dispatch(OPTIONS)
diff --git a/test/fixtures/pages.yml b/test/fixtures/pages.yml
index 2c62113c..f7add425 100644
--- a/test/fixtures/pages.yml
+++ b/test/fixtures/pages.yml
@@ -1,5 +1,55 @@
home_page:
id: 1
- created_at: 2004-08-01
- updated_at: 2005-08-01
- web_id: 1
\ No newline at end of file
+ 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) %>
+ web_id: 1
+ name: HomePage
+
+my_way:
+ id: 2
+ created_at: <%= 9.days.ago.to_formatted_s(:db) %>
+ updated_at: <%= 9.days.ago.to_formatted_s(:db) %>
+ web_id: 1
+ name: MyWay
+
+smart_engine:
+ id: 3
+ created_at: <%= 8.days.ago.to_formatted_s(:db) %>
+ updated_at: <%= 8.days.ago.to_formatted_s(:db) %>
+ web_id: 1
+ name: SmartEngine
+
+that_way:
+ id: 4
+ created_at: <%= 7.days.ago.to_formatted_s(:db) %>
+ updated_at: <%= 7.days.ago.to_formatted_s(:db) %>
+ web_id: 1
+ name: ThatWay
+
+no_wiki_word:
+ id: 5
+ created_at: <%= 6.days.ago.to_formatted_s(:db) %>
+ updated_at: <%= 6.days.ago.to_formatted_s(:db) %>
+ web_id: 1
+ name: NoWikiWord
+
+first_page:
+ id: 6
+ 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) %>
+ web_id: 1
+ name: FirstPage
+
+oak:
+ id: 7
+ created_at: <%= 5.days.ago.to_formatted_s(:db) %>
+ updated_at: <%= 5.days.ago.to_formatted_s(:db) %>
+ web_id: 1
+ name: Oak
+
+elephant:
+ id: 8
+ created_at: <%= 10.minutes.ago.to_formatted_s(:db) %>
+ updated_at: <%= 10.minutes.ago.to_formatted_s(:db) %>
+ web_id: 1
+ name: Elephant
\ No newline at end of file
diff --git a/test/fixtures/revisions.yml b/test/fixtures/revisions.yml
index 9d43eb26..eb5eff5b 100644
--- a/test/fixtures/revisions.yml
+++ b/test/fixtures/revisions.yml
@@ -1,6 +1,84 @@
home_page_first_revision:
id: 1
- created_at: 2004-08-01
- updated_at: 2005-08-01
+ 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) %>
page_id: 1
- content: some text
\ No newline at end of file
+ number: 1
+ content: First revision of the HomePage end
+ author: AnAuthor
+ ip: 127.0.0.1
+
+my_way_first_revision:
+ id: 2
+ created_at: <%= 9.days.ago.to_formatted_s(:db) %>
+ updated_at: <%= 9.days.ago.to_formatted_s(:db) %>
+ page_id: 2
+ number: 1
+ content: MyWay
+ author: Me
+
+smart_engine_first_revision:
+ id: 3
+ created_at: <%= 8.days.ago.to_formatted_s(:db) %>
+ updated_at: <%= 8.days.ago.to_formatted_s(:db) %>
+ page_id: 3
+ number: 1
+ content: SmartEngine
+ author: Me
+
+that_way_first_revision:
+ id: 4
+ created_at: <%= 7.days.ago.to_formatted_s(:db) %>
+ updated_at: <%= 7.days.ago.to_formatted_s(:db) %>
+ page_id: 4
+ number: 1
+ content: ThatWay
+ author: Me
+
+no_wiki_word_first_revision:
+ id: 5
+ created_at: <%= 6.days.ago.to_formatted_s(:db) %>
+ updated_at: <%= 6.days.ago.to_formatted_s(:db) %>
+ page_id: 5
+ number: 1
+ content: hey you
+ author: Me
+
+home_page_second_revision:
+ id: 6
+ 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) %>
+ page_id: 1
+ number: 2
+ content: HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \OverThere -- see SmartEngine in that SmartEngineGUI
+ author: DavidHeinemeierHansson
+
+first_page_first_revision:
+ id: 7
+ 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) %>
+ page_id: 6
+ number: 1
+ content: HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \\OverThere -- see SmartEngine in that SmartEngineGUI
+ author: DavidHeinemeierHansson
+
+oak_first_revision:
+ id: 8
+ created_at: <%= 5.days.ago.to_formatted_s(:db) %>
+ updated_at: <%= 5.days.ago.to_formatted_s(:db) %>
+ page_id: 7
+ number: 1
+ content: "All about oak.\ncategory: trees"
+ author: TreeHugger
+ ip: 127.0.0.2
+
+elephant_first_revision:
+ id: 9
+ created_at: <%= 10.minutes.ago.to_formatted_s(:db) %>
+ updated_at: <%= 10.minutes.ago.to_formatted_s(:db) %>
+ page_id: 8
+ number: 1
+ content: "All about elephants.\ncategory: animals"
+ author: Guest
+ ip: 127.0.0.2
+
diff --git a/test/fixtures/system.yml b/test/fixtures/system.yml
new file mode 100644
index 00000000..1b17f2fc
--- /dev/null
+++ b/test/fixtures/system.yml
@@ -0,0 +1,2 @@
+system:
+ password: test_password
diff --git a/test/fixtures/webs.yml b/test/fixtures/webs.yml
index 7276bb65..29c89566 100644
--- a/test/fixtures/webs.yml
+++ b/test/fixtures/webs.yml
@@ -2,5 +2,14 @@ test_wiki:
id: 1
created_at: 2004-08-01
updated_at: 2005-08-01
- name: wiki
- address: wiki
\ No newline at end of file
+ name: wiki1
+ address: wiki1
+ markup: textile
+
+instiki:
+ id: 2
+ created_at: 2004-08-01
+ updated_at: 2005-08-01
+ name: Instiki
+ address: instiki
+ markup: textile
\ No newline at end of file
diff --git a/test/functional/admin_controller_test.rb b/test/functional/admin_controller_test.rb
index 7aed5c70..a24cf8c0 100644
--- a/test/functional/admin_controller_test.rb
+++ b/test/functional/admin_controller_test.rb
@@ -1,70 +1,73 @@
-#!/bin/env ruby -w
+#!/bin/env ruby
-require File.dirname(__FILE__) + '/../test_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
require 'admin_controller'
# Raise errors beyond the default web-based presentation
class AdminController; def rescue_action(e) logger.error(e); raise e end; end
class AdminControllerTest < Test::Unit::TestCase
+ fixtures :webs, :pages, :revisions, :system
def setup
- setup_test_wiki
- setup_controller_test
+ @controller = AdminController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ @wiki = Wiki.new
+ @oak = pages(:oak)
+ @elephant = pages(:elephant)
+ @web = webs(:test_wiki)
+ @home = @page = pages(:home_page)
end
- def tear_down
- tear_down_wiki
- end
-
-
def test_create_system_form_displayed
- ApplicationController.wiki = WikiServiceWithNoPersistence.new
+ use_blank_wiki
process('create_system')
- assert_success
+ assert_response :success
end
def test_create_system_form_submitted
- ApplicationController.wiki = WikiServiceWithNoPersistence.new
- assert !ApplicationController.wiki.setup?
+ use_blank_wiki
+ assert !@wiki.setup?
process('create_system', 'password' => 'a_password', 'web_name' => 'My Wiki',
'web_address' => 'my_wiki')
assert_redirected_to :web => 'my_wiki', :controller => 'wiki', :action => 'new',
:id => 'HomePage'
- assert ApplicationController.wiki.setup?
- assert_equal 'a_password', ApplicationController.wiki.system[:password]
- assert_equal 1, ApplicationController.wiki.webs.size
- new_web = ApplicationController.wiki.webs['my_wiki']
+ assert @wiki.setup?
+ assert_equal 'a_password', @wiki.system[:password]
+ assert_equal 1, @wiki.webs.size
+ new_web = @wiki.webs['my_wiki']
assert_equal 'My Wiki', new_web.name
assert_equal 'my_wiki', new_web.address
end
def test_create_system_form_submitted_and_wiki_already_initialized
- wiki_before = ApplicationController.wiki
- assert ApplicationController.wiki.setup?
+ wiki_before = @wiki
+ old_size = @wiki.webs.size
+ assert @wiki.setup?
process 'create_system', 'password' => 'a_password', 'web_name' => 'My Wiki',
'web_address' => 'my_wiki'
- assert_redirected_to :web => 'wiki1', :action => 'show', :id => 'HomePage'
- assert_equal wiki_before, ApplicationController.wiki
+ assert_redirected_to :web => @wiki.webs.keys.first, :action => 'show', :id => 'HomePage'
+ assert_equal wiki_before, @wiki
# and no new web should be created either
- assert_equal 1, ApplicationController.wiki.webs.size
+ assert_equal old_size, @wiki.webs.size
assert_flash_has :error
end
def test_create_system_no_form_and_wiki_already_initialized
assert @wiki.setup?
process('create_system')
- assert_redirected_to :web => 'wiki1', :action => 'show', :id => 'HomePage'
+ assert_redirected_to :web => @wiki.webs.keys.first, :action => 'show', :id => 'HomePage'
assert_flash_has :error
end
def test_create_web
- @wiki.system[:password] = 'pswd'
+ @wiki.system.update_attribute(:password, 'pswd')
process 'create_web', 'system_password' => 'pswd', 'name' => 'Wiki Two', 'address' => 'wiki2'
@@ -76,7 +79,7 @@ class AdminControllerTest < Test::Unit::TestCase
end
def test_create_web_default_password
- @wiki.system[:password] = nil
+ @wiki.system.update_attribute(:password, nil)
process 'create_web', 'system_password' => 'instiki', 'name' => 'Wiki Two', 'address' => 'wiki2'
@@ -84,7 +87,7 @@ class AdminControllerTest < Test::Unit::TestCase
end
def test_create_web_failed_authentication
- @wiki.system[:password] = 'pswd'
+ @wiki.system.update_attribute(:password, 'pswd')
process 'create_web', 'system_password' => 'wrong', 'name' => 'Wiki Two', 'address' => 'wiki2'
@@ -93,20 +96,20 @@ class AdminControllerTest < Test::Unit::TestCase
end
def test_create_web_no_form_submitted
- @wiki.system[:password] = 'pswd'
+ @wiki.system.update_attribute(:password, 'pswd')
process 'create_web'
- assert_success
+ assert_response :success
end
def test_edit_web_no_form
process 'edit_web', 'web' => 'wiki1'
# this action simply renders a form
- assert_success
+ assert_response :success
end
def test_edit_web_form_submitted
- @wiki.system[:password] = 'pswd'
+ @wiki.system.update_attribute(:password, 'pswd')
process('edit_web', 'system_password' => 'pswd',
'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1',
@@ -116,21 +119,22 @@ class AdminControllerTest < Test::Unit::TestCase
'max_upload_size' => '300')
assert_redirected_to :web => 'renamed_wiki1', :action => 'show', :id => 'HomePage'
+ @web = Web.find(@web.id)
assert_equal 'renamed_wiki1', @web.address
assert_equal 'Renamed Wiki1', @web.name
assert_equal :markdown, @web.markup
assert_equal 'blue', @web.color
- assert @web.safe_mode
+ assert @web.safe_mode?
assert_equal 'new_password', @web.password
- assert @web.published
- assert @web.brackets_only
- assert @web.count_pages
- assert @web.allow_uploads
+ assert @web.published?
+ assert @web.brackets_only?
+ assert @web.count_pages?
+ assert @web.allow_uploads?
assert_equal 300, @web.max_upload_size
end
def test_edit_web_opposite_values
- @wiki.system[:password] = 'pswd'
+ @wiki.system.update_attribute(:password, 'pswd')
process('edit_web', 'system_password' => 'pswd',
'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1',
@@ -140,11 +144,12 @@ class AdminControllerTest < Test::Unit::TestCase
# and should become false
assert_redirected_to :web => 'renamed_wiki1', :action => 'show', :id => 'HomePage'
- assert !@web.safe_mode
- assert !@web.published
- assert !@web.brackets_only
- assert !@web.count_pages
- assert !@web.allow_uploads
+ @web = Web.find(@web.id)
+ assert !@web.safe_mode?
+ assert !@web.published?
+ assert !@web.brackets_only?
+ assert !@web.count_pages?
+ assert !@web.allow_uploads?
end
def test_edit_web_wrong_password
@@ -154,12 +159,12 @@ class AdminControllerTest < Test::Unit::TestCase
'password' => 'new_password')
#returns to the same form
- assert_success
+ assert_response :success
assert @response.has_template_object?('error')
end
def test_edit_web_rename_to_already_existing_web_name
- @wiki.system[:password] = 'pswd'
+ @wiki.system.update_attribute(:password, 'pswd')
@wiki.create_web('Another', 'another')
process('edit_web', 'system_password' => 'pswd',
@@ -168,7 +173,7 @@ class AdminControllerTest < Test::Unit::TestCase
'password' => 'new_password')
#returns to the same form
- assert_success
+ assert_response :success
assert @response.has_template_object?('error')
end
@@ -179,15 +184,15 @@ class AdminControllerTest < Test::Unit::TestCase
'password' => 'new_password')
#returns to the same form
- assert_success
+ assert_response :success
assert @response.has_template_object?('error')
end
def test_remove_orphaned_pages
- setup_wiki_with_three_pages
- @wiki.system[:password] = 'pswd'
- orhan_page_linking_to_oak = @wiki.write_page('wiki1', 'Pine',
+ @wiki.system.update_attribute(:password, 'pswd')
+ page_order = [@home, pages(:my_way), @oak, pages(:smart_engine), pages(:that_way)]
+ 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'))
@@ -195,25 +200,28 @@ class AdminControllerTest < Test::Unit::TestCase
r = process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password_orphaned' => 'pswd')
assert_redirected_to :controller => 'wiki', :web => 'wiki1', :action => 'list'
- assert_equal [@home, @oak], @web.select.sort,
+ @web.pages(true)
+ assert_equal page_order, @web.select.sort,
"Pages are not as expected: #{@web.select.sort.map {|p| p.name}.inspect}"
# Oak is now orphan, second pass should remove it
r = process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password_orphaned' => 'pswd')
assert_redirected_to :controller => 'wiki', :web => 'wiki1', :action => 'list'
- assert_equal [@home], @web.select.sort,
+ @web.pages(true)
+ page_order.delete(@oak)
+ assert_equal page_order, @web.select.sort,
"Pages are not as expected: #{@web.select.sort.map {|p| p.name}.inspect}"
# third pass does not destroy HomePage
r = process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password_orphaned' => 'pswd')
assert_redirected_to :action => 'list'
- assert_equal [@home], @web.select.sort,
+ @web.pages(true)
+ assert_equal page_order, @web.select.sort,
"Pages are not as expected: #{@web.select.sort.map {|p| p.name}.inspect}"
end
def test_remove_orphaned_pages_empty_or_wrong_password
- setup_wiki_with_three_pages
@wiki.system[:password] = 'pswd'
process('remove_orphaned_pages', 'web' => 'wiki1')
@@ -224,5 +232,4 @@ class AdminControllerTest < Test::Unit::TestCase
assert_redirected_to(:controller => 'admin', :action => 'edit_web', :web => 'wiki1')
assert @response.flash[:error]
end
-
end
diff --git a/test/functional/application_test.rb b/test/functional/application_test.rb
index 3a33df74..c32f8b23 100755
--- a/test/functional/application_test.rb
+++ b/test/functional/application_test.rb
@@ -8,24 +8,23 @@ require 'rexml/document'
class WikiController; def rescue_action(e) logger.error(e); raise e end; end
class ApplicationTest < Test::Unit::TestCase
-
+ fixtures :webs, :pages, :revisions, :system
+
def setup
- setup_test_wiki
- setup_controller_test(WikiController)
+ @controller = WikiController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ @wiki = Wiki.new
end
-
- def tear_down
- tear_down_wiki
- end
-
+
def test_utf8_header
- r = process('show', 'web' => 'wiki1', 'id' => 'HomePage')
- assert_equal 'text/html; charset=UTF-8', r.headers['Content-Type']
+ get :show, :web => 'wiki1', :id => 'HomePage'
+ assert_equal 'text/html; charset=UTF-8', @response.headers['Content-Type']
end
def test_connect_to_model_unknown_wiki
- r = process('show', 'web' => 'unknown_wiki', 'id' => 'HomePage')
- assert_equal 404, r.response_code
+ get :show, :web => 'unknown_wiki', :id => 'HomePage'
+ assert_response :missing
end
end
diff --git a/test/functional/file_controller_test.rb b/test/functional/file_controller_test.rb
index 23f18c42..cea3aa81 100755
--- a/test/functional/file_controller_test.rb
+++ b/test/functional/file_controller_test.rb
@@ -1,4 +1,4 @@
-#!/bin/env ruby -w
+#!/bin/env ruby
require File.dirname(__FILE__) + '/../test_helper'
require 'file_controller'
@@ -8,24 +8,26 @@ require 'fileutils'
class FileController; def rescue_action(e) logger.error(e); raise e end; end
class FileControllerTest < Test::Unit::TestCase
+ fixtures :webs, :pages, :revisions, :system
- FILE_AREA = RAILS_ROOT + '/storage/test/wiki1'
+ Wiki.storage_path += "test/"
+ FILE_AREA = Wiki.storage_path + 'wiki1'
FileUtils.mkdir_p(FILE_AREA) unless File.directory?(FILE_AREA)
FileUtils.rm(Dir["#{FILE_AREA}/*"])
def setup
- setup_test_wiki
- setup_controller_test
- end
-
- def tear_down
- tear_down_wiki
+ @controller = FileController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ @wiki = Wiki.new
+ @web = webs(:test_wiki)
+ @home = @page = pages(:home_page)
end
def test_file
process 'file', 'web' => 'wiki1', 'id' => 'foo.tgz'
- assert_success
+ assert_response :success
assert_rendered_file 'file/file'
end
@@ -34,7 +36,7 @@ class FileControllerTest < Test::Unit::TestCase
r = process 'file', 'web' => 'wiki1', 'id' => 'foo.txt'
- assert_success
+ assert_response :success
assert_equal "aaa\nbbb\n", r.binary_content
assert_equal 'text/plain', r.headers['Content-Type']
end
@@ -44,7 +46,7 @@ class FileControllerTest < Test::Unit::TestCase
r = process 'file', 'web' => 'wiki1', 'id' => 'foo.pdf'
- assert_success
+ assert_response :success
assert_equal "aaa\nbbb\n", r.binary_content
assert_equal 'application/pdf', r.headers['Content-Type']
end
@@ -54,14 +56,14 @@ class FileControllerTest < Test::Unit::TestCase
r = process 'pic', 'web' => 'wiki1', 'id' => 'rails.gif'
- assert_success
+ assert_response :success
assert_equal File.size("#{FILE_AREA}/rails.gif"), r.binary_content.size
end
def test_pic_unknown_pic
r = process 'pic', 'web' => 'wiki1', 'id' => 'non-existant.gif'
- assert_success
+ assert_response :success
assert_rendered_file 'file/file'
end
@@ -74,7 +76,7 @@ class FileControllerTest < Test::Unit::TestCase
# rails-e2e.gif is unknown to the system, so pic action goes to the file [upload] form
r = process 'pic', 'web' => 'wiki1', 'id' => 'rails-e2e.gif'
- assert_success
+ assert_response :success
assert_rendered_file 'file/file'
# User uploads the picture
@@ -98,7 +100,7 @@ class FileControllerTest < Test::Unit::TestCase
# 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'
- assert_success
+ assert_response :success
assert_rendered_file 'file/file'
# User uploads the picture
@@ -109,17 +111,18 @@ class FileControllerTest < Test::Unit::TestCase
assert_equal(file, File.read("#{RAILS_ROOT}/storage/test/wiki1/instiki-e2e.txt"))
# this should refresh the page display content (cached)
+ @home = Page.find(@home.id)
assert_equal "",
@home.display_content
end
def test_uploads_blocking
- @web.allow_uploads = true
+ set_web_property :allow_uploads, true
r = process 'file', 'web' => 'wiki1', 'id' => 'filename'
- assert_success
+ assert_response :success
- @web.allow_uploads = false
+ set_web_property :allow_uploads, false
r = process 'file', 'web' => 'wiki1', 'id' => 'filename'
assert_equal '403 Forbidden', r.headers['Status']
end
diff --git a/test/functional/routes_test.rb b/test/functional/routes_test.rb
index 2e338bd0..c2334ef7 100644
--- a/test/functional/routes_test.rb
+++ b/test/functional/routes_test.rb
@@ -1,4 +1,4 @@
-#!/bin/env ruby -w
+#!/bin/env ruby
require File.dirname(__FILE__) + '/../test_helper'
diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb
index bc79a8bf..b799ad3b 100755
--- a/test/functional/wiki_controller_test.rb
+++ b/test/functional/wiki_controller_test.rb
@@ -1,10 +1,10 @@
-#!/bin/env ruby -w
+#!/bin/env ruby
# Uncomment the line below to enable pdflatex tests; don't forget to comment them again
# commiting to SVN
# $INSTIKI_TEST_PDFLATEX = true
-require File.dirname(__FILE__) + '/../test_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
require 'wiki_controller'
require 'rexml/document'
require 'tempfile'
@@ -14,63 +14,60 @@ require 'zip/zipfilesystem'
class WikiController; def rescue_action(e) logger.error(e); raise e end; end
class WikiControllerTest < Test::Unit::TestCase
-
+ fixtures :webs, :pages, :revisions, :system
+
def setup
- setup_test_wiki
- setup_controller_test
+ @controller = WikiController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ @wiki = Wiki.new
+ @web = webs(:test_wiki)
+ @home = @page = pages(:home_page)
+ @oak = pages(:oak)
+ @elephant = pages(:elephant)
end
- def tear_down
- tear_down_wiki
- end
-
-
def test_authenticate
- @web.password = 'pswd'
+ set_web_property :password, 'pswd'
- r = process('authenticate', 'web' => 'wiki1', 'password' => 'pswd')
+ get :authenticate, :web => 'wiki1', :password => 'pswd'
assert_redirected_to :web => 'wiki1', :action => 'show', :id => 'HomePage'
- assert_equal ['pswd'], r.cookies['web_address']
+ assert_equal ['pswd'], @response.cookies['web_address']
end
def test_authenticate_wrong_password
- @web.password = 'pswd'
+ set_web_property :password, 'pswd'
r = process('authenticate', 'web' => 'wiki1', 'password' => 'wrong password')
assert_redirected_to :action => 'login', :web => 'wiki1'
assert_nil r.cookies['web_address']
end
-
def test_authors
- setup_wiki_with_three_pages
@wiki.write_page('wiki1', 'BreakSortingOrder',
"This page breaks the accidentally correct sorting order of authors",
Time.now, Author.new('BreakingTheOrder', '127.0.0.2'))
r = process('authors', 'web' => 'wiki1')
- assert_success
- assert_equal ['AnAuthor', 'BreakingTheOrder', 'Guest', 'TreeHugger'],
+ assert_response :success
+ assert_equal %w(AnAuthor BreakingTheOrder DavidHeinemeierHansson Guest Me TreeHugger),
r.template_objects['authors']
end
-
def test_cancel_edit
- setup_wiki_with_three_pages
@oak.lock(Time.now, 'Locky')
assert @oak.locked?(Time.now)
r = process('cancel_edit', 'web' => 'wiki1', 'id' => 'Oak')
assert_redirected_to :action => 'show', :id => 'Oak'
- assert !@oak.locked?(Time.now)
+ assert !Page.find(@oak.id).locked?(Time.now)
end
-
def test_edit
r = process 'edit', 'web' => 'wiki1', 'id' => 'HomePage'
- assert_success
+ assert_response :success
assert_equal @wiki.read_page('wiki1', 'HomePage'), r.template_objects['page']
end
@@ -83,7 +80,8 @@ class WikiControllerTest < Test::Unit::TestCase
def test_edit_page_break_lock
@home.lock(Time.now, 'Locky')
process 'edit', 'web' => 'wiki1', 'id' => 'HomePage', 'break_lock' => 'y'
- assert_success
+ assert_response :success
+ @home = Page.find(@home.id)
assert @home.locked?(Time.now)
end
@@ -99,19 +97,17 @@ class WikiControllerTest < Test::Unit::TestCase
Time.now, Author.new('Special', '127.0.0.3'))
r = process 'edit', 'web' => 'wiki1', 'id' => 'With : Special /> symbols'
- assert_success
+ assert_response :success
xml = REXML::Document.new(r.body)
form = REXML::XPath.first(xml, '//form')
assert_equal '/wiki1/save/With+%3A+Special+%2F%3E+symbols', form.attributes['action']
end
-
def test_export_html
- setup_wiki_with_three_pages
-
+ @home.rollback(1, Time.now, 'Rick') # much simpler regex statement to match
r = process 'export_html', 'web' => 'wiki1'
- assert_success
+ assert_response :success
assert_equal 'application/zip', r.headers['Content-Type']
assert_match /attachment; filename="wiki1-html-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.zip"/,
r.headers['Content-Disposition']
@@ -124,7 +120,7 @@ class WikiControllerTest < Test::Unit::TestCase
begin
File.open(@tempfile_path, 'wb') { |f| f.write(content); @exported_file = f.path }
Zip::ZipFile.open(@exported_file) do |zip|
- assert_equal %w(Elephant.html HomePage.html Oak.html index.html), zip.dir.entries('.').sort
+ assert_equal %w(Elephant.html FirstPage.html HomePage.html MyWay.html NoWikiWord.html Oak.html SmartEngine.html ThatWay.html index.html), zip.dir.entries('.').sort
assert_match /.*/,
zip.file.read('Elephant.html').gsub(/\s+/, ' ')
assert_match /.*/,
@@ -138,12 +134,10 @@ class WikiControllerTest < Test::Unit::TestCase
end
end
- def test_export_html_no_layout
- setup_wiki_with_three_pages
-
+ def test_export_html_no_layout
r = process 'export_html', 'web' => 'wiki1', 'layout' => 'no'
- assert_success
+ assert_response :success
assert_equal 'application/zip', r.headers['Content-Type']
assert_match /attachment; filename="wiki1-html-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.zip"/,
r.headers['Content-Disposition']
@@ -155,7 +149,7 @@ class WikiControllerTest < Test::Unit::TestCase
def test_export_markup
r = process 'export_markup', 'web' => 'wiki1'
- assert_success
+ assert_response :success
assert_equal 'application/zip', r.headers['Content-Type']
assert_match /attachment; filename="wiki1-textile-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.zip"/,
r.headers['Content-Disposition']
@@ -168,7 +162,7 @@ class WikiControllerTest < Test::Unit::TestCase
def test_export_pdf
r = process 'export_pdf', 'web' => 'wiki1'
- assert_success
+ assert_response :success
assert_equal 'application/pdf', r.headers['Content-Type']
assert_match /attachment; filename="wiki1-tex-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.pdf"/,
r.headers['Content-Disposition']
@@ -183,13 +177,10 @@ class WikiControllerTest < Test::Unit::TestCase
puts ' $INSTIKI_TEST_PDFLATEX to enable them.'
end
-
- def test_export_tex
- setup_wiki_with_three_pages
-
+ def test_export_tex
r = process 'export_tex', 'web' => 'wiki1'
- assert_success
+ assert_response :success
assert_equal 'application/octet-stream', r.headers['Content-Type']
assert_match /attachment; filename="wiki1-tex-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.tex"/,
r.headers['Content-Disposition']
@@ -202,6 +193,8 @@ class WikiControllerTest < Test::Unit::TestCase
end
def test_index
+ # delete extra web fixture
+ webs(:instiki).destroy
process('index')
assert_redirected_to :web => 'wiki1', :action => 'show', :id => 'HomePage'
end
@@ -219,41 +212,39 @@ class WikiControllerTest < Test::Unit::TestCase
end
def test_index_wiki_not_initialized
- ApplicationController.wiki = WikiServiceWithNoPersistence.new
+ use_blank_wiki
process('index')
assert_redirected_to :controller => 'admin', :action => 'create_system'
end
def test_list
- setup_wiki_with_three_pages
-
r = process('list', 'web' => 'wiki1')
assert_equal ['animals', 'trees'], r.template_objects['categories']
assert_nil r.template_objects['category']
- assert_equal [@elephant, @home, @oak], r.template_objects['pages_in_category']
+ assert_equal [@elephant, pages(:first_page), @home, pages(:my_way), pages(:no_wiki_word), @oak, pages(:smart_engine), pages(:that_way)], r.template_objects['pages_in_category']
end
def test_locked
@home.lock(Time.now, 'Locky')
r = process('locked', 'web' => 'wiki1', 'id' => 'HomePage')
- assert_success
+ assert_response :success
assert_equal @home, r.template_objects['page']
end
def test_login
r = process 'login', 'web' => 'wiki1'
- assert_success
+ assert_response :success
# this action goes straight to the templates
end
def test_new
r = process('new', 'id' => 'NewPage', 'web' => 'wiki1')
- assert_success
+ assert_response :success
assert_equal 'AnonymousCoward', r.template_objects['author']
assert_equal 'NewPage', r.template_objects['page_name']
end
@@ -264,7 +255,7 @@ class WikiControllerTest < Test::Unit::TestCase
def test_pdf
assert RedClothForTex.available?, 'Cannot do test_pdf when pdflatex is not available'
r = process('pdf', 'web' => 'wiki1', 'id' => 'HomePage')
- assert_success
+ assert_response :success
content = r.binary_content
@@ -282,23 +273,23 @@ class WikiControllerTest < Test::Unit::TestCase
def test_print
r = process('print', 'web' => 'wiki1', 'id' => 'HomePage')
- assert_success
+ assert_response :success
assert_equal :show, r.template_objects['link_mode']
end
def test_published
- @web.published = true
+ set_web_property :published, true
r = process('published', 'web' => 'wiki1', 'id' => 'HomePage')
- assert_success
+ assert_response :success
assert_equal @home, r.template_objects['page']
end
def test_published_web_not_published
- @web.published = false
+ set_web_property :published, false
r = process('published', 'web' => 'wiki1', 'id' => 'HomePage')
@@ -308,11 +299,11 @@ class WikiControllerTest < Test::Unit::TestCase
def test_recently_revised
r = process('recently_revised', 'web' => 'wiki1')
- assert_success
+ assert_response :success
- assert_equal [], r.template_objects['categories']
+ assert_equal %w(animals trees), r.template_objects['categories']
assert_nil r.template_objects['category']
- assert_equal [@home], r.template_objects['pages_in_category']
+ assert_equal [@elephant, pages(:first_page), @home, pages(:my_way), pages(:no_wiki_word), @oak, pages(:smart_engine), pages(:that_way)], r.template_objects['pages_in_category']
assert_equal 'the web', r.template_objects['set_name']
end
@@ -323,37 +314,33 @@ class WikiControllerTest < Test::Unit::TestCase
Time.now, Author.new('AnotherAuthor', '127.0.0.2'))
r = process('recently_revised', 'web' => 'wiki1')
- assert_success
+ assert_response :success
- assert_equal ['categorized'], r.template_objects['categories']
+ assert_equal %w(animals categorized trees), r.template_objects['categories']
# no category is specified in params
assert_nil r.template_objects['category']
- assert_equal [@home, page2], r.template_objects['pages_in_category'],
+ assert_equal [@elephant, pages(:first_page), @home, pages(:my_way), pages(:no_wiki_word), @oak, page2, pages(:smart_engine), pages(:that_way)], r.template_objects['pages_in_category'],
"Pages are not as expected: " +
r.template_objects['pages_in_category'].map {|p| p.name}.inspect
assert_equal 'the web', r.template_objects['set_name']
end
def test_recently_revised_with_categorized_page_multiple_categories
- setup_wiki_with_three_pages
-
r = process('recently_revised', 'web' => 'wiki1')
- assert_success
+ assert_response :success
assert_equal ['animals', 'trees'], r.template_objects['categories']
# no category is specified in params
assert_nil r.template_objects['category']
- assert_equal [@elephant, @home, @oak], r.template_objects['pages_in_category'],
+ assert_equal [@elephant, pages(:first_page), @home, pages(:my_way), pages(:no_wiki_word), @oak, pages(:smart_engine), pages(:that_way)], r.template_objects['pages_in_category'],
"Pages are not as expected: " +
r.template_objects['pages_in_category'].map {|p| p.name}.inspect
assert_equal 'the web', r.template_objects['set_name']
end
def test_recently_revised_with_specified_category
- setup_wiki_with_three_pages
-
r = process('recently_revised', 'web' => 'wiki1', 'category' => 'animals')
- assert_success
+ assert_response :success
assert_equal ['animals', 'trees'], r.template_objects['categories']
# no category is specified in params
@@ -366,7 +353,7 @@ class WikiControllerTest < Test::Unit::TestCase
def test_revision
r = process 'revision', 'web' => 'wiki1', 'id' => 'HomePage', 'rev' => '0'
- assert_success
+ assert_response :success
assert_equal @home, r.template_objects['page']
assert_equal @home.revisions[0], r.template_objects['revision']
end
@@ -377,27 +364,24 @@ class WikiControllerTest < Test::Unit::TestCase
# its assigns the same as or revision
r = process 'rollback', 'web' => 'wiki1', 'id' => 'HomePage', 'rev' => '0'
- assert_success
+ assert_response :success
assert_equal @home, r.template_objects['page']
assert_equal @home.revisions[0], r.template_objects['revision']
end
def test_rss_with_content
- setup_wiki_with_three_pages
-
r = process 'rss_with_content', 'web' => 'wiki1'
- assert_success
+ assert_response :success
pages = r.template_objects['pages_by_revision']
- assert_equal [@home, @oak, @elephant], pages,
+ assert_equal [@elephant, @oak, pages(:no_wiki_word), pages(:that_way), pages(:smart_engine), pages(:my_way), pages(:first_page), @home], pages,
"Pages are not as expected: #{pages.map {|p| p.name}.inspect}"
assert !r.template_objects['hide_description']
end
def test_rss_with_content_when_blocked
- setup_wiki_with_three_pages
- @web.password = 'aaa'
- @web.published = false
+ @web.update_attributes(:password => 'aaa', :published => false)
+ @web = Web.find(@web.id)
r = process 'rss_with_content', 'web' => 'wiki1'
@@ -406,7 +390,6 @@ class WikiControllerTest < Test::Unit::TestCase
def test_rss_with_headlines
- setup_wiki_with_three_pages
@title_with_spaces = @wiki.write_page('wiki1', 'Title With Spaces',
'About spaces', 1.hour.ago, Author.new('TreeHugger', '127.0.0.2'))
@@ -415,19 +398,24 @@ class WikiControllerTest < Test::Unit::TestCase
r = process 'rss_with_headlines', 'web' => 'wiki1'
- assert_success
+ assert_response :success
pages = r.template_objects['pages_by_revision']
- assert_equal [@home, @oak, @elephant, @title_with_spaces], pages,
- "Pages are not as expected: #{pages.map {|p| p.name}.inspect}"
+ assert_equal [@elephant, @title_with_spaces, @oak, pages(:no_wiki_word), pages(:that_way), pages(:smart_engine), pages(:my_way), pages(:first_page), @home], pages, "Pages are not as expected: #{pages.map {|p| p.name}.inspect}"
assert r.template_objects['hide_description']
xml = REXML::Document.new(r.body)
expected_page_links =
- ['http://localhost:8080/wiki1/show/HomePage',
+ ['http://localhost:8080/wiki1/show/Elephant',
+ 'http://localhost:8080/wiki1/show/Title+With+Spaces',
'http://localhost:8080/wiki1/show/Oak',
- 'http://localhost:8080/wiki1/show/Elephant',
- 'http://localhost:8080/wiki1/show/Title+With+Spaces']
+ 'http://localhost:8080/wiki1/show/NoWikiWord',
+ 'http://localhost:8080/wiki1/show/ThatWay',
+ 'http://localhost:8080/wiki1/show/SmartEngine',
+ 'http://localhost:8080/wiki1/show/MyWay',
+ 'http://localhost:8080/wiki1/show/FirstPage',
+ 'http://localhost:8080/wiki1/show/HomePage',
+ ]
assert_template_xpath_match '/rss/channel/link',
'http://localhost:8080/wiki1/show/HomePage'
@@ -436,22 +424,26 @@ class WikiControllerTest < Test::Unit::TestCase
end
def test_rss_switch_links_to_published
- setup_wiki_with_three_pages
- @web.password = 'aaa'
- @web.published = true
+ @web.update_attributes(:password => 'aaa', :published => true)
+ @web = Web.find(@web.id)
@request.host = 'foo.bar.info'
@request.port = 80
r = process 'rss_with_headlines', 'web' => 'wiki1'
- assert_success
+ assert_response :success
xml = REXML::Document.new(r.body)
expected_page_links =
- ['http://foo.bar.info/wiki1/published/HomePage',
+ ['http://foo.bar.info/wiki1/published/Elephant',
'http://foo.bar.info/wiki1/published/Oak',
- 'http://foo.bar.info/wiki1/published/Elephant']
+ 'http://foo.bar.info/wiki1/published/NoWikiWord',
+ 'http://foo.bar.info/wiki1/published/ThatWay',
+ 'http://foo.bar.info/wiki1/published/SmartEngine',
+ 'http://foo.bar.info/wiki1/published/MyWay',
+ 'http://foo.bar.info/wiki1/published/FirstPage',
+ 'http://foo.bar.info/wiki1/published/HomePage']
assert_template_xpath_match '/rss/channel/link',
'http://foo.bar.info/wiki1/published/HomePage'
@@ -463,45 +455,43 @@ class WikiControllerTest < Test::Unit::TestCase
setup_wiki_with_30_pages
r = process 'rss_with_headlines', 'web' => 'wiki1'
- assert_success
+ assert_response :success
pages = r.template_objects['pages_by_revision']
assert_equal 15, pages.size, 15
r = process 'rss_with_headlines', 'web' => 'wiki1', 'limit' => '5'
- assert_success
+ assert_response :success
pages = r.template_objects['pages_by_revision']
assert_equal 5, pages.size
r = process 'rss_with_headlines', 'web' => 'wiki1', 'limit' => '25'
- assert_success
+ assert_response :success
pages = r.template_objects['pages_by_revision']
assert_equal 25, pages.size
r = process 'rss_with_headlines', 'web' => 'wiki1', 'limit' => 'all'
- assert_success
+ assert_response :success
pages = r.template_objects['pages_by_revision']
- assert_equal 31, pages.size
+ assert_equal 38, pages.size
r = process 'rss_with_headlines', 'web' => 'wiki1', 'start' => '1976-10-16'
- assert_success
+ assert_response :success
pages = r.template_objects['pages_by_revision']
- assert_equal 16, pages.size
+ assert_equal 23, pages.size
r = process 'rss_with_headlines', 'web' => 'wiki1', 'end' => '1976-10-16'
- assert_success
+ assert_response :success
pages = r.template_objects['pages_by_revision']
assert_equal 15, pages.size
r = process 'rss_with_headlines', 'web' => 'wiki1', 'start' => '1976-10-01', 'end' => '1976-10-06'
- assert_success
+ assert_response :success
pages = r.template_objects['pages_by_revision']
assert_equal 5, pages.size
end
def test_rss_title_with_ampersand
- # was ticket:143
- setup_wiki_with_three_pages
-
+ # was ticket:143
@wiki.write_page('wiki1', 'Title&With&Ampersands',
'About spaces', 1.hour.ago, Author.new('NitPicker', '127.0.0.3'))
@@ -511,15 +501,12 @@ class WikiControllerTest < Test::Unit::TestCase
assert r.body.include?('My Headline
\n\n
\n\ndef a_method(arg)\n} +
+ %{return ThatWay\n
Markdown heading
\n\n" +
+ "\n
",
+ textile_and_markdown)
+
+ set_web_property :markup, :textile
+ assert_markup_parsed_as(
+ "
================Textile heading
" +
+ "\n\n\n\tstyles\n\t
",
+ textile_and_markdown)
+
+ set_web_property :markup, :mixed
+ assert_markup_parsed_as(
+ "Markdown heading
\n\n\n\tTextile heading
\n\n\n\t" +
+ "styles\n\t
",
+ textile_and_markdown)
+ end
+
+ def test_rdoc
+ set_web_property :markup, :rdoc
+
+ @revision = Revision.new(:page => @page, :content => '+hello+ that SmartEngineGUI',
+ :author => Author.new('DavidHeinemeierHansson'))
+
+ assert_equal "hello that Smart Engine GUI" +
+ "?\n\n", @revision.display_content
+ end
+
+ def test_content_with_auto_links
+ assert_markup_parsed_as(
+ 'class SmartEngine end
would not mark up CodeBlocks
class SmartEngine end
would not mark up CodeBlocks') + end + + def test_content_with_autolink_in_parentheses + assert_markup_parsed_as( + '
The W3C body (' + + 'http://www.w3c.org) sets web standards
', + 'The W3C body (http://www.w3c.org) sets web standards') + end + + def test_content_with_link_in_parentheses + assert_markup_parsed_as( + '', + '("What is a wiki?":http://wiki.org/wiki.cgi?WhatIsWiki)') + end + + def test_content_with_image_link + assert_markup_parsed_as( + 'This is a Textile image link.
', + 'This !http://hobix.com/sample.jpg! is a Textile image link.') + end + + def test_content_with_inlined_img_tag + assert_markup_parsed_as( + 'This is an inline image link.
', + 'This is an inline image link.') + + assert_markup_parsed_as( + 'This is an inline image link.
', + 'This is an inline image link.') + end + + def test_nowiki_tag + assert_markup_parsed_as( + 'Do not mark up [[this text]] or http://www.thislink.com.
', + 'Do not mark upDo not mark \n up [[this text]] \nand http://this.url.com but markup " + + 'this?
', + "Do notThis is a WikiWord and a tricky name ' + + 'Sperberg-McQueen?.
', + 'This is a WikiWord and a tricky name [[Sperberg-McQueen]].') + end + + def test_content_for_export + assert_equal 'His Way would be ' + + 'My Way in kinda ' + + 'That Way in ' + + 'His Way though ' + + 'My Way OverThere—see ' + + 'Smart Engine in that ' + + 'Smart Engine GUI
', + @revision.display_content_for_export + end + + def test_double_replacing + @revision.content = "VersionHistory\r\n\r\ncry VersionHistory" + assert_equal 'Version History' + + "?
\n\n\n\tcry " + + 'Version History?' + + '
', + @revision.display_content + + @revision.clear_display_cache + + @revision.content = "f\r\nVersionHistory\r\n\r\ncry VersionHistory" + assert_equal "f
Version History" +
+ "?
cry " + + "Version History?" + + "
", + @revision.display_content + end + + def test_difficult_wiki_words + @revision.content = "[[It's just awesome GUI!]]" + assert_equal "It's just awesome GUI!" + + "?
", + @revision.display_content + end + + 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 red and lovely morning today', :author => Author.new('DavidHeinemeierHansson')) + + assert_equal "What a blue red " +
+ "and lovely morningmorning " +
+ "today
doc.pdf?
', + '[[doc.pdf:file]]') + end + + def test_link_to_pic + FileUtils.mkdir_p "#{RAILS_ROOT}/storage/test/wiki1" + FileUtils.rm(Dir["#{RAILS_ROOT}/storage/test/wiki1/*"]) + @wiki.file_yard(@web).upload_file('square.jpg', StringIO.new('')) + assert_markup_parsed_as( + '', + '[[square.jpg|Square:pic]]') + assert_markup_parsed_as( + '', + '[[square.jpg:pic]]') + end + + def test_link_to_non_existant_pic + assert_markup_parsed_as( + 'NonExistant?' + + '
', + '[[NonExistant.jpg|NonExistant:pic]]') + assert_markup_parsed_as( + 'NonExistant.jpg?' + + '
', + '[[NonExistant.jpg:pic]]') + end + + def test_wiki_link_with_colon + assert_markup_parsed_as( + 'With:Colon?
', + '[[With:Colon]]') + end + + # TODO Remove the leading underscores from this test when upgrading to RedCloth 3.0.1; + # also add a test for the "Unhappy Face" problem (another interesting RedCloth bug) + def test_list_with_tildas + list_with_tildas = <<-EOL + * "a":~b + * c~ d + EOL + + assert_markup_parsed_as( + "\nss
", + "!http://google.com!\r\nss") + end + + def assert_markup_parsed_as(expected_output, input) + revision = Revision.new(:page => @page, :content => input, :author => Author.new('AnAuthor')) + assert_equal expected_output, revision.display_content, 'Textile output not as expected' + end end diff --git a/test/unit/uri_test.rb b/test/unit/uri_test.rb index 9cef4a23..4affbd60 100755 --- a/test/unit/uri_test.rb +++ b/test/unit/uri_test.rb @@ -1,4 +1,4 @@ -#!/bin/env ruby -w +#!/bin/env ruby require File.dirname(__FILE__) + '/../test_helper' require 'chunks/uri' diff --git a/test/unit/web_test.rb b/test/unit/web_test.rb index 2e504e0c..433b579f 100644 --- a/test/unit/web_test.rb +++ b/test/unit/web_test.rb @@ -1,7 +1,158 @@ -require File.dirname(__FILE__) + '/../test_helper' +require File.expand_path(File.dirname(__FILE__) + '/../test_helper') class WebTest < Test::Unit::TestCase - - fixtures 'webs', 'pages', 'revisions' + fixtures :webs, :pages, :revisions, :system + def setup + @web = webs(:instiki) + end + + def test_wiki_word_linking + @web.add_page('SecondPage', 'Yo, yo. Have you EverBeenHated', + Time.now, 'DavidHeinemeierHansson') + + assert_equal('Yo, yo. Have you Ever Been Hated' + + '?
', + @web.page("SecondPage").display_content) + + @web.add_page('EverBeenHated', 'Yo, yo. Have you EverBeenHated', Time.now, + 'DavidHeinemeierHansson') + assert_equal('Yo, yo. Have you Ever Been Hated
', + @web.page("SecondPage").display_content) + end + + def test_pages_by_revision + add_sample_pages + assert_equal 'EverBeenHated', @web.select.by_revision.first.name + end + + def test_pages_by_match + add_sample_pages + assert_equal 2, @web.select { |page| page.content =~ /me/i }.length + assert_equal 1, @web.select { |page| page.content =~ /Who/i }.length + assert_equal 0, @web.select { |page| page.content =~ /none/i }.length + end + + def test_references + add_sample_pages + assert_equal 1, @web.select.pages_that_reference('EverBeenHated').length + assert_equal 0, @web.select.pages_that_reference('EverBeenInLove').length + end + + def test_delete + add_sample_pages + assert_equal 2, @web.pages.length + @web.remove_pages([ @web.page('EverBeenInLove') ]) + assert_equal 1, @web.pages(true).length + end + + def test_make_link + add_sample_pages + + existing_page_wiki_url = + 'Ever Been In Love' + existing_page_published_url = + 'Ever Been In Love' + existing_page_static_url = + 'Ever Been In Love' + new_page_wiki_url = + 'Unknown Word?' + new_page_published_url = + new_page_static_url = + 'Unknown Word' + + # no options + assert_equal existing_page_wiki_url, @web.make_link('EverBeenInLove') + + # :mode => :export + assert_equal existing_page_static_url, @web.make_link('EverBeenInLove', nil, :mode => :export) + + # :mode => :publish + assert_equal existing_page_published_url, + @web.make_link('EverBeenInLove', nil, :mode => :publish) + + # new page, no options + assert_equal new_page_wiki_url, @web.make_link('UnknownWord') + + # new page, :mode => :export + assert_equal new_page_static_url, @web.make_link('UnknownWord', nil, :mode => :export) + + # new page, :mode => :publish + assert_equal new_page_published_url, @web.make_link('UnknownWord', nil, :mode => :publish) + + # Escaping special characters in the name + assert_equal( + 'Smith & Wesson?', + @web.make_link('Smith & Wesson')) + + # optionally using text as the link text + assert_equal( + existing_page_published_url.sub(/>Ever Been In Love, ">Haven't you ever been in love?<"), + @web.make_link('EverBeenInLove', "Haven't you ever been in love?", :mode => :publish)) + + end + + def test_initialize + web = Web.new(:name => 'Wiki2', :address => 'wiki2', :password => '123') + + assert_equal 'Wiki2', web.name + assert_equal 'wiki2', web.address + assert_equal '123', web.password + + # new web should be set for maximum features enabled + assert_equal :textile, web.markup + assert_equal '008B26', web.color + assert !web.safe_mode? + assert_equal([], web.pages) + assert web.allow_uploads? + assert_nil web.additional_style + assert !web.published? + assert !web.brackets_only? + assert !web.count_pages? + assert_equal 100, web.max_upload_size + end + + def test_initialize_invalid_name + assert_raises(Instiki::ValidationError) { + Web.create(:name => 'Wiki2', :address => "wiki\234", :password => '123') + } + end + + 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') + @web.add_page('AnotherPage', 'This is \AnotherPage', + Time.local(2004, 4, 4, 16, 51), 'Alexey Verkhovsky') + + @web.pages(true) + assert_equal [home], @web.select.pages_that_link_to('AnotherPage') + end + + def test_orphaned_pages + 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') + author = @web.add_page('AlexeyVerkhovsky', + 'This is an author page, it should not be an orphan', + Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky') + self_linked = @web.add_page('SelfLinked', + 'I am me SelfLinked and link to EverBeenInLove', + Time.local(2004, 4, 4, 16, 50), 'AnonymousCoward') + + # page that links to itself, and nobody else links to it must be an orphan + assert_equal ['EverBeenHated', 'SelfLinked'], + @web.select.orphaned_pages.collect{ |page| page.name }.sort + end + + private + + def add_sample_pages + @in_love = @web.add_page('EverBeenInLove', 'Who am I me', + Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson') + @hated = @web.add_page('EverBeenHated', 'I am me EverBeenHated', + Time.local(2004, 4, 4, 16, 51), 'DavidHeinemeierHansson') + end end diff --git a/test/unit/wiki_words_test.rb b/test/unit/wiki_words_test.rb index a1aa1ff9..93bc5d12 100755 --- a/test/unit/wiki_words_test.rb +++ b/test/unit/wiki_words_test.rb @@ -1,6 +1,6 @@ -#!/bin/env ruby -w +#!/bin/env ruby -require File.dirname(__FILE__) + '/../test_helper' +require File.expand_path(File.dirname(__FILE__) + '/../test_helper') require 'wiki_words' class WikiWordsTest < Test::Unit::TestCase