Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 2
- Log:
Initial import of Instiki 0.11.0 sources from a downloaded Tarball.
Instiki is a Ruby On Rails based Wiki clone.
- Author:
- adh
- Date:
- Sat Jul 22 14:54:51 +0100 2006
- Size:
- 5306 Bytes
1 | ENV['RAILS_ENV'] = 'test' |
2 | |
3 | # Expand the path to environment so that Ruby does not load it multiple times |
4 | # File.expand_path can be removed if Ruby 1.9 is in use. |
5 | require File.expand_path(File.dirname(__FILE__) + '/../config/environment') |
6 | require 'application' |
7 | |
8 | require 'test/unit' |
9 | require 'active_record/fixtures' |
10 | require 'action_controller/test_process' |
11 | require 'action_web_service/test_invoke' |
12 | require 'breakpoint' |
13 | require 'wiki_content' |
14 | require 'url_generator' |
15 | |
16 | # Uncomment these and hang on, because the tests will be FAST |
17 | #Test::Unit::TestCase.pre_loaded_fixtures = false |
18 | #Test::Unit::TestCase.use_transactional_fixtures = true |
19 | |
20 | Test::Unit::TestCase.use_instantiated_fixtures = false |
21 | Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/" |
22 | |
23 | # activate PageObserver |
24 | PageObserver.instance |
25 | |
26 | class Test::Unit::TestCase |
27 | def create_fixtures(*table_names) |
28 | Fixtures.create_fixtures(File.dirname(__FILE__) + "/fixtures", table_names) |
29 | end |
30 | |
31 | # Add more helper methods to be used by all tests here... |
32 | def set_web_property(property, value) |
33 | @web.update_attribute(property, value) |
34 | @page = Page.find(@page.id) |
35 | @wiki.webs[@web.name] = @web |
36 | end |
37 | |
38 | def setup_wiki_with_30_pages |
39 | ActiveRecord::Base.silence do |
40 | (1..30).each do |i| |
41 | @wiki.write_page('wiki1', "page#{i}", "Test page #{i}\ncategory: test", |
42 | Time.local(1976, 10, i, 12, 00, 00), Author.new('Dema', '127.0.0.2'), |
43 | test_renderer) |
44 | end |
45 | end |
46 | @web = Web.find(@web.id) |
47 | end |
48 | |
49 | def test_renderer(revision = nil) |
50 | PageRenderer.setup_url_generator(StubUrlGenerator.new) |
51 | PageRenderer.new(revision) |
52 | end |
53 | |
54 | def use_blank_wiki |
55 | Revision.destroy_all |
56 | Page.destroy_all |
57 | Web.destroy_all |
58 | end |
59 | end |
60 | |
61 | # This module is to be included in unit tests that involve matching chunks. |
62 | # It provides a easy way to test whether a chunk matches a particular string |
63 | # and any the values of any fields that should be set after a match. |
64 | class ContentStub < String |
65 | include ChunkManager |
66 | def initialize(str) |
67 | super |
68 | init_chunk_manager |
69 | end |
70 | def page_link(*); end |
71 | end |
72 | |
73 | module ChunkMatch |
74 | |
75 | # Asserts a number of tests for the given type and text. |
76 | def match(chunk_type, test_text, expected_chunk_state) |
77 | if chunk_type.respond_to? :pattern |
78 | assert_match(chunk_type.pattern, test_text) |
79 | end |
80 | |
81 | content = ContentStub.new(test_text) |
82 | chunk_type.apply_to(content) |
83 | |
84 | # Test if requested parts are correct. |
85 | expected_chunk_state.each_pair do |a_method, expected_value| |
86 | assert content.chunks.last.kind_of?(chunk_type) |
87 | assert_respond_to(content.chunks.last, a_method) |
88 | assert_equal(expected_value, content.chunks.last.send(a_method.to_sym), |
89 | "Wrong #{a_method} value") |
90 | end |
91 | end |
92 | |
93 | # Asserts that test_text doesn't match the chunk_type |
94 | def no_match(chunk_type, test_text) |
95 | if chunk_type.respond_to? :pattern |
96 | assert_no_match(chunk_type.pattern, test_text) |
97 | end |
98 | end |
99 | end |
100 | |
101 | class StubUrlGenerator < AbstractUrlGenerator |
102 | |
103 | def initialize |
104 | super(:doesnt_need_controller) |
105 | end |
106 | |
107 | def file_link(mode, name, text, web_name, known_file) |
108 | link = CGI.escape(name) |
109 | case mode |
110 | when :export |
111 | if known_file then %{<a class="existingWikiWord" href="#{link}.html">#{text}</a>} |
112 | else %{<span class="newWikiWord">#{text}</span>} end |
113 | when :publish |
114 | if known_file then %{<a class="existingWikiWord" href="../published/#{link}">#{text}</a>} |
115 | else %{<span class=\"newWikiWord\">#{text}</span>} end |
116 | else |
117 | if known_file |
118 | %{<a class=\"existingWikiWord\" href=\"../file/#{link}\">#{text}</a>} |
119 | else |
120 | %{<span class=\"newWikiWord\">#{text}<a href=\"../file/#{link}\">?</a></span>} |
121 | end |
122 | end |
123 | end |
124 | |
125 | def page_link(mode, name, text, web_address, known_page) |
126 | link = CGI.escape(name) |
127 | case mode.to_sym |
128 | when :export |
129 | if known_page then %{<a class="existingWikiWord" href="#{link}.html">#{text}</a>} |
130 | else %{<span class="newWikiWord">#{text}</span>} end |
131 | when :publish |
132 | if known_page then %{<a class="existingWikiWord" href="../published/#{link}">#{text}</a>} |
133 | else %{<span class="newWikiWord">#{text}</span>} end |
134 | else |
135 | if known_page |
136 | %{<a class="existingWikiWord" href="../show/#{link}">#{text}</a>} |
137 | else |
138 | %{<span class="newWikiWord">#{text}<a href="../show/#{link}">?</a></span>} |
139 | end |
140 | end |
141 | end |
142 | |
143 | def pic_link(mode, name, text, web_name, known_pic) |
144 | link = CGI.escape(name) |
145 | case mode.to_sym |
146 | when :export |
147 | if known_pic then %{<img alt="#{text}" src="#{link}" />} |
148 | else %{<img alt="#{text}" src="no image" />} end |
149 | when :publish |
150 | if known_pic then %{<img alt="#{text}" src="#{link}" />} |
151 | else %{<span class="newWikiWord">#{text}</span>} end |
152 | else |
153 | if known_pic then %{<img alt="#{text}" src="../file/#{link}" />} |
154 | else %{<span class="newWikiWord">#{text}<a href="../file/#{link}">?</a></span>} end |
155 | end |
156 | end |
157 | end |
158 | |
159 | module Test |
160 | module Unit |
161 | module Assertions |
162 | def assert_success(bypass_body_parsing = false) |
163 | assert_response :success |
164 | unless bypass_body_parsing |
165 | assert_nothing_raised(@response.body) { REXML::Document.new(@response.body) } |
166 | end |
167 | end |
168 | end |
169 | end |
170 | end |