Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 344
- Log:
Massive changeset which brings the old, ROOL customised Instiki
version up to date, but without any ROOL customisations in this
latest checked-in version (which is 0.19.1). This is deliberate,
so that it's easy to see the changes made for the ROOL version
in a subsequent changeset. The 'app/views/shared' directory is not
part of Instiki but is kept to maintain the change history with
updated ROOL customisations, some of which involve the same files
in that same directory.
- Author:
- rool
- Date:
- Sat Mar 19 19:52:13 +0000 2011
- Size:
- 6927 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.join(File.dirname(__FILE__), '..', 'config', 'environment')) |
6 | |
7 | require 'test_help' |
8 | require 'wiki_content' |
9 | require 'url_generator' |
10 | require 'digest/sha1' |
11 | |
12 | # simulates cookie session store |
13 | class FakeSessionDbMan |
14 | def self.generate_digest(data) |
15 | Digest::SHA1.hexdigest("secure") |
16 | end |
17 | end |
18 | |
19 | class ActiveSupport::TestCase |
20 | self.pre_loaded_fixtures = false |
21 | self.use_transactional_fixtures = true |
22 | self.use_instantiated_fixtures = false |
23 | self.fixture_path = Rails.root.join('test', 'fixtures', '') |
24 | end |
25 | |
26 | # activate PageObserver |
27 | PageObserver.instance |
28 | |
29 | class Test::Unit::TestCase |
30 | def create_fixtures(*table_names) |
31 | Fixtures.create_fixtures(Rails.root.join('test', 'fixtures'), table_names) |
32 | end |
33 | |
34 | # Add more helper methods to be used by all tests here... |
35 | def set_web_property(property, value) |
36 | @web.update_attribute(property, value) |
37 | @page = Page.find(@page.id) |
38 | @wiki.webs[@web.name] = @web |
39 | end |
40 | |
41 | def setup_wiki_with_30_pages |
42 | ActiveRecord::Base.silence do |
43 | (1..30).each do |i| |
44 | @wiki.write_page('wiki1', "page#{i}", "Test page #{i}\ncategory: test", |
45 | Time.local(1976, 10, i, 12, 00, 00), Author.new('Dema', '127.0.0.2'), |
46 | x_test_renderer) |
47 | end |
48 | end |
49 | @web = Web.find(@web.id) |
50 | end |
51 | |
52 | def x_test_renderer(revision = nil) |
53 | PageRenderer.setup_url_generator(StubUrlGenerator.new) |
54 | PageRenderer.new(revision) |
55 | end |
56 | |
57 | def use_blank_wiki |
58 | Revision.destroy_all |
59 | Page.destroy_all |
60 | Web.destroy_all |
61 | end |
62 | end |
63 | |
64 | # This module is to be included in unit tests that involve matching chunks. |
65 | # It provides a easy way to test whether a chunk matches a particular string |
66 | # and any the values of any fields that should be set after a match. |
67 | class ContentStub < String |
68 | |
69 | attr_reader :web |
70 | |
71 | include ChunkManager |
72 | def initialize(str) |
73 | super |
74 | init_chunk_manager |
75 | @web = Object.new |
76 | class << @web |
77 | def address |
78 | 'wiki1' |
79 | end |
80 | end |
81 | end |
82 | |
83 | def url_generator |
84 | StubUrlGenerator.new |
85 | end |
86 | |
87 | def page_link(*); end |
88 | end |
89 | |
90 | module ChunkMatch |
91 | |
92 | # Asserts a number of tests for the given type and text. |
93 | def match(chunk_type, test_text, expected_chunk_state) |
94 | if chunk_type.respond_to? :pattern |
95 | assert_match(chunk_type.pattern, test_text) |
96 | end |
97 | |
98 | content = ContentStub.new(test_text) |
99 | chunk_type.apply_to(content) |
100 | |
101 | # Test if requested parts are correct. |
102 | expected_chunk_state.each_pair do |a_method, expected_value| |
103 | assert content.chunks.last.kind_of?(chunk_type) |
104 | assert_respond_to(content.chunks.last, a_method) |
105 | assert_equal(expected_value, content.chunks.last.send(a_method.to_sym), |
106 | "Wrong #{a_method} value") |
107 | end |
108 | end |
109 | |
110 | # Asserts that test_text doesn't match the chunk_type |
111 | def no_match(chunk_type, test_text) |
112 | if chunk_type.respond_to? :pattern |
113 | assert_no_match(chunk_type.pattern, test_text) |
114 | end |
115 | end |
116 | end |
117 | |
118 | class StubUrlGenerator < AbstractUrlGenerator |
119 | |
120 | def initialize |
121 | super(:doesnt_need_controller) |
122 | end |
123 | |
124 | def url_for(hash = {}) |
125 | if(hash[:action] == 'list') |
126 | "/#{hash[:web]}/list" |
127 | else |
128 | '../files/pngs' |
129 | end |
130 | end |
131 | |
132 | def file_link(mode, name, text, web_name, known_file, description) |
133 | link = CGI.escape(name) |
134 | case mode |
135 | when :export |
136 | if known_file then %{<a class="existingWikiWord" title="#{description}" href="#{link}.html">#{text}</a>} |
137 | else %{<span class="newWikiWord">#{text}</span>} end |
138 | when :publish |
139 | if known_file then %{<a class="existingWikiWord" title="#{description}" href="../published/#{link}">#{text}</a>} |
140 | else %{<span class=\"newWikiWord\">#{text}</span>} end |
141 | else |
142 | if known_file |
143 | %{<a class=\"existingWikiWord\" title="#{description}" href=\"../file/#{link}\">#{text}</a>} |
144 | else |
145 | %{<span class=\"newWikiWord\">#{text}<a href=\"../file/#{link}\">?</a></span>} |
146 | end |
147 | end |
148 | end |
149 | |
150 | def page_link(mode, name, text, web_address, known_page) |
151 | link = CGI.escape(name) |
152 | title = web_address == 'wiki1' ? '' : " title='#{web_address}'" |
153 | case mode |
154 | when :export |
155 | if known_page then %{<a class="existingWikiWord" href="#{link}.html">#{text}</a>} |
156 | else %{<span class="newWikiWord">#{text}</span>} end |
157 | when :publish |
158 | if known_page then %{<a class="existingWikiWord" href="../published/#{link}"#{title}>#{text}</a>} |
159 | else %{<span class="newWikiWord">#{text}</span>} end |
160 | else |
161 | if known_page |
162 | if web_address == 'instiki' |
163 | %{<a class="existingWikiWord" href="../../#{web_address}/show/#{link}"#{title}>#{text}</a>} |
164 | else |
165 | %{<a class="existingWikiWord" href="../show/#{link}"#{title}>#{text}</a>} |
166 | end |
167 | else |
168 | if web_address == 'instiki' |
169 | %{<span class="newWikiWord">#{text}<a href="../../#{web_address}/show/#{link}">?</a></span>} |
170 | else |
171 | %{<span class="newWikiWord">#{text}<a href="../show/#{link}">?</a></span>} |
172 | end |
173 | end |
174 | end |
175 | end |
176 | |
177 | def pic_link(mode, name, text, web_name, known_pic) |
178 | link = CGI.escape(name) |
179 | text = CGI.escapeHTML(CGI.unescapeHTML(text || :description)) |
180 | case mode.to_sym |
181 | when :export |
182 | if known_pic then %{<img alt="#{text}" src="#{link}" />} |
183 | else %{<img alt="#{text}" src="no image" />} end |
184 | when :publish |
185 | if known_pic then %{<img alt="#{text}" src="../file/#{link}" />} |
186 | else %{<span class="newWikiWord">#{text}</span>} end |
187 | else |
188 | if known_pic then %{<img alt="#{text}" src="../file/#{link}" />} |
189 | else %{<span class="newWikiWord">#{text}<a href="../file/#{link}">?</a></span>} end |
190 | end |
191 | end |
192 | end |
193 | |
194 | def media_link(mode, name, text, web_address, known_media, media_type) |
195 | link = CGI.escape(name) |
196 | text = CGI.escapeHTML(CGI.unescapeHTML(text || :description)) |
197 | case mode.to_sym |
198 | when :export |
199 | if known_media |
200 | %{<#{media_type} src="#{CGI.escape(name)}" controls="controls">#{text}</#{media_type}>} |
201 | else |
202 | text |
203 | end |
204 | when :publish |
205 | if known_media |
206 | %{<#{media_type} src="../file/#{link}" controls="controls">#{text}</#{media_type}>} |
207 | else |
208 | %{<span class="newWikiWord">#{text}</span>} |
209 | end |
210 | else |
211 | if known_media |
212 | %{<#{media_type} src="../file/#{link}" controls="controls">#{text}</#{media_type}>} |
213 | else |
214 | %{<span class="newWikiWord">#{text}<a href="../file/#{link}">?</a></span>} |
215 | end |
216 | end |
217 | end |
218 | |
219 | module Test |
220 | module Unit |
221 | module Assertions |
222 | def assert_success(bypass_body_parsing = false) |
223 | assert_response :success |
224 | unless bypass_body_parsing |
225 | assert_nothing_raised(@response.body) { REXML::Document.new(@response.body) } |
226 | end |
227 | end |
228 | end |
229 | end |
230 | end |