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:
- 12898 Bytes
1 | #!/usr/bin/env ruby |
2 | |
3 | require File.expand_path(File.dirname(__FILE__) + '/../test_helper') |
4 | require 'admin_controller' |
5 | |
6 | # Raise errors beyond the default web-based presentation |
7 | class AdminController; def rescue_action(e) logger.error(e); raise e end; end |
8 | |
9 | class AdminControllerTest < ActionController::TestCase |
10 | fixtures :webs, :pages, :revisions, :system, :wiki_references |
11 | |
12 | def setup |
13 | require 'action_controller/test_process' |
14 | @controller = AdminController.new |
15 | @request = ActionController::TestRequest.new |
16 | @response = ActionController::TestResponse.new |
17 | class << @request.session |
18 | attr_accessor :dbman |
19 | end |
20 | # simulate a cookie session store |
21 | @request.session.dbman = FakeSessionDbMan |
22 | @wiki = Wiki.new |
23 | @oak = pages(:oak) |
24 | @liquor = pages(:liquor) |
25 | @elephant = pages(:elephant) |
26 | @web = webs(:test_wiki) |
27 | @home = @page = pages(:home_page) |
28 | FileUtils.rm_rf("#{RAILS_ROOT}/webs/renamed_wiki1") |
29 | end |
30 | |
31 | def test_create_system_form_displayed |
32 | use_blank_wiki |
33 | process('create_system') |
34 | assert_response :success |
35 | end |
36 | |
37 | def test_create_system_form_submitted |
38 | use_blank_wiki |
39 | assert !@wiki.setup? |
40 | |
41 | process('create_system', 'password' => 'a_password', 'web_name' => 'My Wiki', |
42 | 'web_address' => 'my_wiki') |
43 | |
44 | assert_redirected_to :web => 'my_wiki', :controller => 'wiki', :action => 'new', |
45 | :id => 'HomePage' |
46 | assert @wiki.setup? |
47 | assert_equal 'a_password', @wiki.system[:password] |
48 | assert_equal 1, @wiki.webs.size |
49 | new_web = @wiki.webs['my_wiki'] |
50 | assert_equal 'My Wiki', new_web.name |
51 | assert_equal 'my_wiki', new_web.address |
52 | end |
53 | |
54 | def test_create_system_form_submitted_and_wiki_already_initialized |
55 | wiki_before = @wiki |
56 | old_size = @wiki.webs.size |
57 | assert @wiki.setup? |
58 | |
59 | process 'create_system', 'password' => 'a_password', 'web_name' => 'My Wiki', |
60 | 'web_address' => 'my_wiki' |
61 | |
62 | assert_redirected_to :web => @wiki.webs.keys.first, :controller => 'wiki', :action => 'show', :id => 'HomePage' |
63 | assert_equal wiki_before, @wiki |
64 | # and no new web should be created either |
65 | assert_equal old_size, @wiki.webs.size |
66 | assert(@response.has_flash_object?(:error)) |
67 | end |
68 | |
69 | def test_create_system_no_form_and_wiki_already_initialized |
70 | assert @wiki.setup? |
71 | process('create_system') |
72 | assert_redirected_to :web => @wiki.webs.keys.first, :controller => 'wiki', :action => 'show', :id => 'HomePage' |
73 | assert(@response.has_flash_object?(:error)) |
74 | end |
75 | |
76 | |
77 | def test_create_web |
78 | @wiki.system.update_attribute(:password, 'pswd') |
79 | |
80 | process 'create_web', 'system_password' => 'pswd', 'name' => 'Wiki Two', 'address' => 'wiki2' |
81 | |
82 | assert_redirected_to :web => 'wiki2', :controller => 'wiki', :action => 'new', :id => 'HomePage' |
83 | wiki2 = @wiki.webs['wiki2'] |
84 | assert wiki2 |
85 | assert_equal 'Wiki Two', wiki2.name |
86 | assert_equal 'wiki2', wiki2.address |
87 | end |
88 | |
89 | def test_create_web_default_password |
90 | @wiki.system.update_attribute(:password, nil) |
91 | |
92 | process 'create_web', 'system_password' => 'instiki', 'name' => 'Wiki Two', 'address' => 'wiki2' |
93 | |
94 | assert_redirected_to :web => 'wiki2', :controller => 'wiki', :action => 'new', :id => 'HomePage' |
95 | end |
96 | |
97 | def test_create_web_failed_authentication |
98 | @wiki.system.update_attribute(:password, 'pswd') |
99 | |
100 | process 'create_web', 'system_password' => 'wrong', 'name' => 'Wiki Two', 'address' => 'wiki2' |
101 | |
102 | assert_redirected_to :controller => 'admin', :action => 'create_web' |
103 | assert_nil @wiki.webs['wiki2'] |
104 | end |
105 | |
106 | def test_create_web_no_form_submitted |
107 | @wiki.system.update_attribute(:password, 'pswd') |
108 | process 'create_web' |
109 | assert_response :success |
110 | end |
111 | |
112 | def test_edit_web_no_form |
113 | process 'edit_web', 'web' => 'wiki1' |
114 | # this action simply renders a form |
115 | assert_response :success |
116 | end |
117 | |
118 | def test_edit_web_form_submitted |
119 | @wiki.system.update_attribute(:password, 'pswd') |
120 | @web.save |
121 | |
122 | process('edit_web', 'system_password' => 'pswd', |
123 | 'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1', |
124 | 'markup' => 'markdown', 'color' => 'blue', 'additional_style' => 'whatever', |
125 | 'safe_mode' => 'on', 'password' => 'new_password', 'password_check' => 'new_password', 'published' => 'on', |
126 | 'brackets_only' => 'on', 'count_pages' => 'on', 'allow_uploads' => 'on', |
127 | 'max_upload_size' => '300') |
128 | |
129 | assert_redirected_to :web => 'renamed_wiki1', :controller => 'wiki', :action => 'show', :id => 'HomePage' |
130 | @web = Web.find(@web.id) |
131 | assert_equal 'renamed_wiki1', @web.address |
132 | assert_equal 'Renamed Wiki1', @web.name |
133 | assert_equal :markdown, @web.markup |
134 | assert_equal 'blue', @web.color |
135 | assert @web.safe_mode? |
136 | assert_equal 'new_password', @web.password |
137 | assert @web.published? |
138 | assert @web.brackets_only? |
139 | assert @web.count_pages? |
140 | assert @web.allow_uploads? |
141 | assert_equal 300, @web.max_upload_size |
142 | assert File.directory? Rails.root.join("webs", "renamed_wiki1", "files") |
143 | assert !File.exist?(Rails.root.join("webs", "renamed_wiki1", "wiki1")) |
144 | assert !File.exist?(Rails.root.join("webs", "wiki1")) |
145 | end |
146 | |
147 | def test_edit_web_web_password_mismatch |
148 | @wiki.system.update_attribute(:password, 'pswd') |
149 | @web.save |
150 | |
151 | process('edit_web', 'system_password' => 'pswd', |
152 | 'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1', |
153 | 'markup' => 'markdown', 'color' => 'blue', 'additional_style' => 'whatever', |
154 | 'safe_mode' => 'on', 'password' => 'new_password', 'password_check' => 'old_password', 'published' => 'on', |
155 | 'brackets_only' => 'on', 'count_pages' => 'on', 'allow_uploads' => 'on', |
156 | 'max_upload_size' => '300') |
157 | |
158 | assert_response :success |
159 | assert @response.has_template_object?('error') |
160 | assert File.directory? Rails.root.join("webs", "wiki1", "files") |
161 | assert !File.exist?(Rails.root.join("webs", "renamed_wiki1", "wiki1")) |
162 | assert !File.exist?(Rails.root.join("webs", "renamed_wiki1")) |
163 | end |
164 | |
165 | def test_edit_web_opposite_values |
166 | @wiki.system.update_attribute(:password, 'pswd') |
167 | @web.save |
168 | |
169 | process('edit_web', 'system_password' => 'pswd', |
170 | 'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1', |
171 | 'markup' => 'markdown', 'color' => 'blue', 'additional_style' => 'whatever', |
172 | 'password' => 'new_password', 'password_check' => 'new_password') |
173 | # safe_mode, published, brackets_only, count_pages, allow_uploads not set |
174 | # and should become false |
175 | |
176 | assert_redirected_to :web => 'renamed_wiki1', :controller => 'wiki', :action => 'show', :id => 'HomePage' |
177 | @web = Web.find(@web.id) |
178 | assert !@web.safe_mode? |
179 | assert !@web.published? |
180 | assert !@web.brackets_only? |
181 | assert !@web.count_pages? |
182 | assert !@web.allow_uploads? |
183 | assert File.directory? Rails.root.join("webs", "renamed_wiki1", "files") |
184 | assert !File.exist?(Rails.root.join("webs", "renamed_wiki1", "wiki1")) |
185 | assert !File.exist?(Rails.root.join("webs", "wiki1")) |
186 | end |
187 | |
188 | def test_edit_web_wrong_password |
189 | process('edit_web', 'system_password' => 'wrong', |
190 | 'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1', |
191 | 'markup' => 'markdown', 'color' => 'blue', 'additional_style' => 'whatever', |
192 | 'password' => 'new_password') |
193 | |
194 | #returns to the same form |
195 | assert_response :success |
196 | assert @response.has_template_object?('error') |
197 | end |
198 | |
199 | def test_edit_web_rename_to_already_existing_web_name |
200 | @wiki.system.update_attribute(:password, 'pswd') |
201 | |
202 | @wiki.create_web('Another', 'another') |
203 | process('edit_web', 'system_password' => 'pswd', |
204 | 'web' => 'wiki1', 'address' => 'another', 'name' => 'Renamed Wiki1', |
205 | 'markup' => 'markdown', 'color' => 'blue', 'additional_style' => 'whatever', |
206 | 'password' => 'new_password', 'password_check' => 'new_password') |
207 | |
208 | #returns to the same form |
209 | assert_response :success |
210 | assert @response.has_template_object?('error') |
211 | end |
212 | |
213 | def test_edit_web_empty_password |
214 | process('edit_web', 'system_password' => '', |
215 | 'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1', |
216 | 'markup' => 'markdown', 'color' => 'blue', 'additional_style' => 'whatever', |
217 | 'password' => 'new_password') |
218 | |
219 | #returns to the same form |
220 | assert_response :success |
221 | assert @response.has_template_object?('error') |
222 | end |
223 | |
224 | |
225 | def test_remove_orphaned_pages |
226 | @wiki.system.update_attribute(:password, 'pswd') |
227 | page_order = [@home, pages(:my_way), @oak, pages(:smart_engine), pages(:that_way), @liquor] |
228 | x_test_renderer(@web.page('liquor').revisions.last).display_content(true) |
229 | orphan_page_linking_to_oak_and_redirecting_to_liquor = @wiki.write_page('wiki1', 'Pine', |
230 | "Refers to [[Oak]] and to [[booze]].\n" + |
231 | "category: trees", |
232 | Time.now, Author.new('TreeHugger', '127.0.0.2'), x_test_renderer) |
233 | |
234 | r = process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password_orphaned' => 'pswd') |
235 | |
236 | assert_redirected_to :controller => 'wiki', :web => 'wiki1', :action => 'list' |
237 | @web.pages(true) |
238 | assert_equal page_order, @web.select.sort, |
239 | "Pages are not as expected: #{@web.select.sort.map {|p| p.name}.inspect}" |
240 | |
241 | # Oak is now orphan, second pass should remove it |
242 | r = process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password_orphaned' => 'pswd') |
243 | assert_redirected_to :controller => 'wiki', :web => 'wiki1', :action => 'list' |
244 | @web.pages(true) |
245 | page_order.delete(@oak) |
246 | page_order.delete(@liquor) |
247 | assert_equal page_order, @web.select.sort, |
248 | "Pages are not as expected: #{@web.select.sort.map {|p| p.name}.inspect}" |
249 | |
250 | # third pass does not destroy HomePage |
251 | r = process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password_orphaned' => 'pswd') |
252 | assert_redirected_to :web => 'wiki1', :controller => 'wiki', :action => 'list' |
253 | @web.pages(true) |
254 | assert_equal page_order, @web.select.sort, |
255 | "Pages are not as expected: #{@web.select.sort.map {|p| p.name}.inspect}" |
256 | end |
257 | |
258 | def test_remove_orphaned_pages_in_category |
259 | @wiki.system.update_attribute(:password, 'pswd') |
260 | page_order = [pages(:elephant), pages(:first_page), @home, pages(:my_way), pages(:no_wiki_word), |
261 | @oak, pages(:smart_engine), pages(:that_way), @liquor] |
262 | orphan_page_linking_to_oak = @wiki.write_page('wiki1', 'Pine', |
263 | "Refers to [[Oak]].\n" + |
264 | "category: trees", |
265 | Time.now, Author.new('TreeHugger', '127.0.0.2'), x_test_renderer) |
266 | |
267 | r = process('remove_orphaned_pages_in_category', 'web' => 'wiki1', 'category' => 'trees','system_password_orphaned_in_category' => 'pswd') |
268 | |
269 | assert_redirected_to :controller => 'wiki', :web => 'wiki1', :action => 'list' |
270 | @web.pages(true) |
271 | assert_equal page_order, @web.select.sort, |
272 | "Pages are not as expected: #{@web.select.sort.map {|p| p.name}.inspect}" |
273 | |
274 | # Oak is now orphan, but it's not in the 'animals' category, |
275 | # so the second pass should not remove it |
276 | r = process('remove_orphaned_pages_in_category', 'web' => 'wiki1', 'category' => 'animals', 'system_password_orphaned_in_category' => 'pswd') |
277 | assert_redirected_to :controller => 'wiki', :web => 'wiki1', :action => 'list' |
278 | @web.pages(true) |
279 | page_order.delete(pages(:elephant)) |
280 | assert_equal page_order, @web.select.sort, |
281 | "Pages are not as expected: #{@web.select.sort.map {|p| p.name}.inspect}" |
282 | |
283 | # third pass does does nothing, since there are no pages in the |
284 | # 'leaves' category. |
285 | r = process('remove_orphaned_pages_in_category', 'web' => 'wiki1', 'category' => 'leaves', 'system_password_orphaned_in_category' => 'pswd') |
286 | assert_redirected_to :controller => 'wiki', :web => 'wiki1', :action => 'list' |
287 | @web.pages(true) |
288 | assert_equal page_order, @web.select.sort, |
289 | "Pages are not as expected: #{@web.select.sort.map {|p| p.name}.inspect}" |
290 | |
291 | # fourth pass destroys Oak |
292 | r = process('remove_orphaned_pages_in_category', 'web' => 'wiki1', 'category' => 'trees', 'system_password_orphaned_in_category' => 'pswd') |
293 | assert_redirected_to :controller => 'wiki', :web => 'wiki1', :action => 'list' |
294 | @web.pages(true) |
295 | page_order.delete(@oak) |
296 | assert_equal page_order, @web.select.sort, |
297 | "Pages are not as expected: #{@web.select.sort.map {|p| p.name}.inspect}" |
298 | end |
299 | |
300 | def test_remove_orphaned_pages_empty_or_wrong_password |
301 | @wiki.system[:password] = 'pswd' |
302 | |
303 | process('remove_orphaned_pages', 'web' => 'wiki1') |
304 | assert_redirected_to(:controller => 'admin', :action => 'edit_web', :web => 'wiki1') |
305 | assert @response.flash[:error] |
306 | |
307 | process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password_orphaned' => 'wrong') |
308 | assert_redirected_to(:controller => 'admin', :action => 'edit_web', :web => 'wiki1') |
309 | assert @response.flash[:error] |
310 | end |
311 | end |