##// END OF EJS Templates
Adds a combo to select parent on wiki page rename (#5136)....
Jean-Philippe Lang -
r4261:666c54e86c2a
parent child
Show More
@@ -1,69 +1,69
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 module WikiHelper
18 module WikiHelper
19
19
20 def wiki_page_options_for_select(pages, selected = nil, parent = nil, level = 0)
20 def wiki_page_options_for_select(pages, selected = nil, parent = nil, level = 0)
21 s = ''
21 s = ''
22 pages.select {|p| p.parent == parent}.each do |page|
22 pages.select {|p| p.parent == parent}.each do |page|
23 attrs = "value='#{page.id}'"
23 attrs = "value='#{page.id}'"
24 attrs << " selected='selected'" if selected == page
24 attrs << " selected='selected'" if selected == page
25 indent = (level > 0) ? ('&nbsp;' * level * 2 + '&#187; ') : nil
25 indent = (level > 0) ? ('&nbsp;' * level * 2 + '&#187; ') : nil
26
26
27 s << "<option value='#{page.id}'>#{indent}#{h page.pretty_title}</option>\n" +
27 s << "<option #{attrs}>#{indent}#{h page.pretty_title}</option>\n" +
28 wiki_page_options_for_select(pages, selected, page, level + 1)
28 wiki_page_options_for_select(pages, selected, page, level + 1)
29 end
29 end
30 s
30 s
31 end
31 end
32
32
33 def html_diff(wdiff)
33 def html_diff(wdiff)
34 words = wdiff.words.collect{|word| h(word)}
34 words = wdiff.words.collect{|word| h(word)}
35 words_add = 0
35 words_add = 0
36 words_del = 0
36 words_del = 0
37 dels = 0
37 dels = 0
38 del_off = 0
38 del_off = 0
39 wdiff.diff.diffs.each do |diff|
39 wdiff.diff.diffs.each do |diff|
40 add_at = nil
40 add_at = nil
41 add_to = nil
41 add_to = nil
42 del_at = nil
42 del_at = nil
43 deleted = ""
43 deleted = ""
44 diff.each do |change|
44 diff.each do |change|
45 pos = change[1]
45 pos = change[1]
46 if change[0] == "+"
46 if change[0] == "+"
47 add_at = pos + dels unless add_at
47 add_at = pos + dels unless add_at
48 add_to = pos + dels
48 add_to = pos + dels
49 words_add += 1
49 words_add += 1
50 else
50 else
51 del_at = pos unless del_at
51 del_at = pos unless del_at
52 deleted << ' ' + h(change[2])
52 deleted << ' ' + h(change[2])
53 words_del += 1
53 words_del += 1
54 end
54 end
55 end
55 end
56 if add_at
56 if add_at
57 words[add_at] = '<span class="diff_in">' + words[add_at]
57 words[add_at] = '<span class="diff_in">' + words[add_at]
58 words[add_to] = words[add_to] + '</span>'
58 words[add_to] = words[add_to] + '</span>'
59 end
59 end
60 if del_at
60 if del_at
61 words.insert del_at - del_off + dels + words_add, '<span class="diff_out">' + deleted + '</span>'
61 words.insert del_at - del_off + dels + words_add, '<span class="diff_out">' + deleted + '</span>'
62 dels += 1
62 dels += 1
63 del_off += words_del
63 del_off += words_del
64 words_del = 0
64 words_del = 0
65 end
65 end
66 end
66 end
67 simple_format_without_paragraph(words.join(' '))
67 simple_format_without_paragraph(words.join(' '))
68 end
68 end
69 end
69 end
@@ -1,12 +1,12
1 <h2><%= l(:button_rename) %>: <%= @original_title %></h2>
1 <h2><%= l(:button_rename) %>: <%= @original_title %></h2>
2
2
3 <%= error_messages_for 'page' %>
3 <%= error_messages_for 'page' %>
4
4
5 <% labelled_tabular_form_for :wiki_page, @page, :url => { :action => 'rename' } do |f| %>
5 <% labelled_tabular_form_for :wiki_page, @page, :url => { :action => 'rename' } do |f| %>
6 <div class="box">
6 <div class="box">
7 <p><%= f.text_field :title, :required => true, :size => 100 %></p>
7 <p><%= f.text_field :title, :required => true, :size => 100 %></p>
8 <p><%= f.check_box :redirect_existing_links %></p>
8 <p><%= f.check_box :redirect_existing_links %></p>
9 <p><%= f.text_field :parent_title, :size => 100 %></p>
9 <p><%= f.select :parent_id, "<option value=''></option>" + wiki_page_options_for_select(@wiki.pages.all(:include => :parent) - @page.self_and_descendants, @page.parent), :label => :field_parent_title %></p>
10 </div>
10 </div>
11 <%= submit_tag l(:button_rename) %>
11 <%= submit_tag l(:button_rename) %>
12 <% end %>
12 <% end %>
@@ -1,365 +1,413
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'wiki_controller'
19 require 'wiki_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class WikiController; def rescue_action(e) raise e end; end
22 class WikiController; def rescue_action(e) raise e end; end
23
23
24 class WikiControllerTest < ActionController::TestCase
24 class WikiControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :attachments
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :attachments
26
26
27 def setup
27 def setup
28 @controller = WikiController.new
28 @controller = WikiController.new
29 @request = ActionController::TestRequest.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
30 @response = ActionController::TestResponse.new
31 User.current = nil
31 User.current = nil
32 end
32 end
33
33
34 def test_show_start_page
34 def test_show_start_page
35 get :show, :project_id => 'ecookbook'
35 get :show, :project_id => 'ecookbook'
36 assert_response :success
36 assert_response :success
37 assert_template 'show'
37 assert_template 'show'
38 assert_tag :tag => 'h1', :content => /CookBook documentation/
38 assert_tag :tag => 'h1', :content => /CookBook documentation/
39
39
40 # child_pages macro
40 # child_pages macro
41 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
41 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
42 :child => { :tag => 'li',
42 :child => { :tag => 'li',
43 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
43 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
44 :content => 'Page with an inline image' } }
44 :content => 'Page with an inline image' } }
45 end
45 end
46
46
47 def test_show_page_with_name
47 def test_show_page_with_name
48 get :show, :project_id => 1, :id => 'Another_page'
48 get :show, :project_id => 1, :id => 'Another_page'
49 assert_response :success
49 assert_response :success
50 assert_template 'show'
50 assert_template 'show'
51 assert_tag :tag => 'h1', :content => /Another page/
51 assert_tag :tag => 'h1', :content => /Another page/
52 # Included page with an inline image
52 # Included page with an inline image
53 assert_tag :tag => 'p', :content => /This is an inline image/
53 assert_tag :tag => 'p', :content => /This is an inline image/
54 assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3',
54 assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3',
55 :alt => 'This is a logo' }
55 :alt => 'This is a logo' }
56 end
56 end
57
57
58 def test_show_with_sidebar
58 def test_show_with_sidebar
59 page = Project.find(1).wiki.pages.new(:title => 'Sidebar')
59 page = Project.find(1).wiki.pages.new(:title => 'Sidebar')
60 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
60 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
61 page.save!
61 page.save!
62
62
63 get :show, :project_id => 1, :id => 'Another_page'
63 get :show, :project_id => 1, :id => 'Another_page'
64 assert_response :success
64 assert_response :success
65 assert_tag :tag => 'div', :attributes => {:id => 'sidebar'},
65 assert_tag :tag => 'div', :attributes => {:id => 'sidebar'},
66 :content => /Side bar content for test_show_with_sidebar/
66 :content => /Side bar content for test_show_with_sidebar/
67 end
67 end
68
68
69 def test_show_unexistent_page_without_edit_right
69 def test_show_unexistent_page_without_edit_right
70 get :show, :project_id => 1, :id => 'Unexistent page'
70 get :show, :project_id => 1, :id => 'Unexistent page'
71 assert_response 404
71 assert_response 404
72 end
72 end
73
73
74 def test_show_unexistent_page_with_edit_right
74 def test_show_unexistent_page_with_edit_right
75 @request.session[:user_id] = 2
75 @request.session[:user_id] = 2
76 get :show, :project_id => 1, :id => 'Unexistent page'
76 get :show, :project_id => 1, :id => 'Unexistent page'
77 assert_response :success
77 assert_response :success
78 assert_template 'edit'
78 assert_template 'edit'
79 end
79 end
80
80
81 def test_create_page
81 def test_create_page
82 @request.session[:user_id] = 2
82 @request.session[:user_id] = 2
83 put :update, :project_id => 1,
83 put :update, :project_id => 1,
84 :id => 'New page',
84 :id => 'New page',
85 :content => {:comments => 'Created the page',
85 :content => {:comments => 'Created the page',
86 :text => "h1. New page\n\nThis is a new page",
86 :text => "h1. New page\n\nThis is a new page",
87 :version => 0}
87 :version => 0}
88 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page'
88 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page'
89 page = Project.find(1).wiki.find_page('New page')
89 page = Project.find(1).wiki.find_page('New page')
90 assert !page.new_record?
90 assert !page.new_record?
91 assert_not_nil page.content
91 assert_not_nil page.content
92 assert_equal 'Created the page', page.content.comments
92 assert_equal 'Created the page', page.content.comments
93 end
93 end
94
94
95 def test_create_page_with_attachments
95 def test_create_page_with_attachments
96 @request.session[:user_id] = 2
96 @request.session[:user_id] = 2
97 assert_difference 'WikiPage.count' do
97 assert_difference 'WikiPage.count' do
98 assert_difference 'Attachment.count' do
98 assert_difference 'Attachment.count' do
99 put :update, :project_id => 1,
99 put :update, :project_id => 1,
100 :id => 'New page',
100 :id => 'New page',
101 :content => {:comments => 'Created the page',
101 :content => {:comments => 'Created the page',
102 :text => "h1. New page\n\nThis is a new page",
102 :text => "h1. New page\n\nThis is a new page",
103 :version => 0},
103 :version => 0},
104 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
104 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
105 end
105 end
106 end
106 end
107 page = Project.find(1).wiki.find_page('New page')
107 page = Project.find(1).wiki.find_page('New page')
108 assert_equal 1, page.attachments.count
108 assert_equal 1, page.attachments.count
109 assert_equal 'testfile.txt', page.attachments.first.filename
109 assert_equal 'testfile.txt', page.attachments.first.filename
110 end
110 end
111
111
112 def test_preview
112 def test_preview
113 @request.session[:user_id] = 2
113 @request.session[:user_id] = 2
114 xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation',
114 xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation',
115 :content => { :comments => '',
115 :content => { :comments => '',
116 :text => 'this is a *previewed text*',
116 :text => 'this is a *previewed text*',
117 :version => 3 }
117 :version => 3 }
118 assert_response :success
118 assert_response :success
119 assert_template 'common/_preview'
119 assert_template 'common/_preview'
120 assert_tag :tag => 'strong', :content => /previewed text/
120 assert_tag :tag => 'strong', :content => /previewed text/
121 end
121 end
122
122
123 def test_preview_new_page
123 def test_preview_new_page
124 @request.session[:user_id] = 2
124 @request.session[:user_id] = 2
125 xhr :post, :preview, :project_id => 1, :id => 'New page',
125 xhr :post, :preview, :project_id => 1, :id => 'New page',
126 :content => { :text => 'h1. New page',
126 :content => { :text => 'h1. New page',
127 :comments => '',
127 :comments => '',
128 :version => 0 }
128 :version => 0 }
129 assert_response :success
129 assert_response :success
130 assert_template 'common/_preview'
130 assert_template 'common/_preview'
131 assert_tag :tag => 'h1', :content => /New page/
131 assert_tag :tag => 'h1', :content => /New page/
132 end
132 end
133
133
134 def test_history
134 def test_history
135 get :history, :project_id => 1, :id => 'CookBook_documentation'
135 get :history, :project_id => 1, :id => 'CookBook_documentation'
136 assert_response :success
136 assert_response :success
137 assert_template 'history'
137 assert_template 'history'
138 assert_not_nil assigns(:versions)
138 assert_not_nil assigns(:versions)
139 assert_equal 3, assigns(:versions).size
139 assert_equal 3, assigns(:versions).size
140 assert_select "input[type=submit][name=commit]"
140 assert_select "input[type=submit][name=commit]"
141 end
141 end
142
142
143 def test_history_with_one_version
143 def test_history_with_one_version
144 get :history, :project_id => 1, :id => 'Another_page'
144 get :history, :project_id => 1, :id => 'Another_page'
145 assert_response :success
145 assert_response :success
146 assert_template 'history'
146 assert_template 'history'
147 assert_not_nil assigns(:versions)
147 assert_not_nil assigns(:versions)
148 assert_equal 1, assigns(:versions).size
148 assert_equal 1, assigns(:versions).size
149 assert_select "input[type=submit][name=commit]", false
149 assert_select "input[type=submit][name=commit]", false
150 end
150 end
151
151
152 def test_diff
152 def test_diff
153 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => 2, :version_from => 1
153 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => 2, :version_from => 1
154 assert_response :success
154 assert_response :success
155 assert_template 'diff'
155 assert_template 'diff'
156 assert_tag :tag => 'span', :attributes => { :class => 'diff_in'},
156 assert_tag :tag => 'span', :attributes => { :class => 'diff_in'},
157 :content => /updated/
157 :content => /updated/
158 end
158 end
159
159
160 def test_annotate
160 def test_annotate
161 get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2
161 get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2
162 assert_response :success
162 assert_response :success
163 assert_template 'annotate'
163 assert_template 'annotate'
164 # Line 1
164 # Line 1
165 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1' },
165 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1' },
166 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/ },
166 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/ },
167 :child => { :tag => 'td', :content => /h1\. CookBook documentation/ }
167 :child => { :tag => 'td', :content => /h1\. CookBook documentation/ }
168 # Line 2
168 # Line 2
169 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '2' },
169 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '2' },
170 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/ },
170 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/ },
171 :child => { :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ }
171 :child => { :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ }
172 end
172 end
173
174 def test_get_rename
175 @request.session[:user_id] = 2
176 get :rename, :project_id => 1, :id => 'Another_page'
177 assert_response :success
178 assert_template 'rename'
179 assert_tag 'option',
180 :attributes => {:value => ''},
181 :content => '',
182 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
183 assert_no_tag 'option',
184 :attributes => {:selected => 'selected'},
185 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
186 end
187
188 def test_get_rename_child_page
189 @request.session[:user_id] = 2
190 get :rename, :project_id => 1, :id => 'Child_1'
191 assert_response :success
192 assert_template 'rename'
193 assert_tag 'option',
194 :attributes => {:value => ''},
195 :content => '',
196 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
197 assert_tag 'option',
198 :attributes => {:value => '2', :selected => 'selected'},
199 :content => /Another page/,
200 :parent => {
201 :tag => 'select',
202 :attributes => {:name => 'wiki_page[parent_id]'}
203 }
204 end
173
205
174 def test_rename_with_redirect
206 def test_rename_with_redirect
175 @request.session[:user_id] = 2
207 @request.session[:user_id] = 2
176 post :rename, :project_id => 1, :id => 'Another_page',
208 post :rename, :project_id => 1, :id => 'Another_page',
177 :wiki_page => { :title => 'Another renamed page',
209 :wiki_page => { :title => 'Another renamed page',
178 :redirect_existing_links => 1 }
210 :redirect_existing_links => 1 }
179 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
211 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
180 wiki = Project.find(1).wiki
212 wiki = Project.find(1).wiki
181 # Check redirects
213 # Check redirects
182 assert_not_nil wiki.find_page('Another page')
214 assert_not_nil wiki.find_page('Another page')
183 assert_nil wiki.find_page('Another page', :with_redirect => false)
215 assert_nil wiki.find_page('Another page', :with_redirect => false)
184 end
216 end
185
217
186 def test_rename_without_redirect
218 def test_rename_without_redirect
187 @request.session[:user_id] = 2
219 @request.session[:user_id] = 2
188 post :rename, :project_id => 1, :id => 'Another_page',
220 post :rename, :project_id => 1, :id => 'Another_page',
189 :wiki_page => { :title => 'Another renamed page',
221 :wiki_page => { :title => 'Another renamed page',
190 :redirect_existing_links => "0" }
222 :redirect_existing_links => "0" }
191 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
223 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
192 wiki = Project.find(1).wiki
224 wiki = Project.find(1).wiki
193 # Check that there's no redirects
225 # Check that there's no redirects
194 assert_nil wiki.find_page('Another page')
226 assert_nil wiki.find_page('Another page')
195 end
227 end
196
228
229 def test_rename_with_parent_assignment
230 @request.session[:user_id] = 2
231 post :rename, :project_id => 1, :id => 'Another_page',
232 :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' }
233 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
234 assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent
235 end
236
237 def test_rename_with_parent_unassignment
238 @request.session[:user_id] = 2
239 post :rename, :project_id => 1, :id => 'Child_1',
240 :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' }
241 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1'
242 assert_nil WikiPage.find_by_title('Child_1').parent
243 end
244
197 def test_destroy_child
245 def test_destroy_child
198 @request.session[:user_id] = 2
246 @request.session[:user_id] = 2
199 delete :destroy, :project_id => 1, :id => 'Child_1'
247 delete :destroy, :project_id => 1, :id => 'Child_1'
200 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
248 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
201 end
249 end
202
250
203 def test_destroy_parent
251 def test_destroy_parent
204 @request.session[:user_id] = 2
252 @request.session[:user_id] = 2
205 assert_no_difference('WikiPage.count') do
253 assert_no_difference('WikiPage.count') do
206 delete :destroy, :project_id => 1, :id => 'Another_page'
254 delete :destroy, :project_id => 1, :id => 'Another_page'
207 end
255 end
208 assert_response :success
256 assert_response :success
209 assert_template 'destroy'
257 assert_template 'destroy'
210 end
258 end
211
259
212 def test_destroy_parent_with_nullify
260 def test_destroy_parent_with_nullify
213 @request.session[:user_id] = 2
261 @request.session[:user_id] = 2
214 assert_difference('WikiPage.count', -1) do
262 assert_difference('WikiPage.count', -1) do
215 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify'
263 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify'
216 end
264 end
217 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
265 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
218 assert_nil WikiPage.find_by_id(2)
266 assert_nil WikiPage.find_by_id(2)
219 end
267 end
220
268
221 def test_destroy_parent_with_cascade
269 def test_destroy_parent_with_cascade
222 @request.session[:user_id] = 2
270 @request.session[:user_id] = 2
223 assert_difference('WikiPage.count', -3) do
271 assert_difference('WikiPage.count', -3) do
224 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy'
272 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy'
225 end
273 end
226 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
274 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
227 assert_nil WikiPage.find_by_id(2)
275 assert_nil WikiPage.find_by_id(2)
228 assert_nil WikiPage.find_by_id(5)
276 assert_nil WikiPage.find_by_id(5)
229 end
277 end
230
278
231 def test_destroy_parent_with_reassign
279 def test_destroy_parent_with_reassign
232 @request.session[:user_id] = 2
280 @request.session[:user_id] = 2
233 assert_difference('WikiPage.count', -1) do
281 assert_difference('WikiPage.count', -1) do
234 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1
282 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1
235 end
283 end
236 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
284 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
237 assert_nil WikiPage.find_by_id(2)
285 assert_nil WikiPage.find_by_id(2)
238 assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent
286 assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent
239 end
287 end
240
288
241 def test_index
289 def test_index
242 get :index, :project_id => 'ecookbook'
290 get :index, :project_id => 'ecookbook'
243 assert_response :success
291 assert_response :success
244 assert_template 'index'
292 assert_template 'index'
245 pages = assigns(:pages)
293 pages = assigns(:pages)
246 assert_not_nil pages
294 assert_not_nil pages
247 assert_equal Project.find(1).wiki.pages.size, pages.size
295 assert_equal Project.find(1).wiki.pages.size, pages.size
248
296
249 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
297 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
250 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' },
298 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' },
251 :content => 'CookBook documentation' },
299 :content => 'CookBook documentation' },
252 :child => { :tag => 'ul',
300 :child => { :tag => 'ul',
253 :child => { :tag => 'li',
301 :child => { :tag => 'li',
254 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
302 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
255 :content => 'Page with an inline image' } } } },
303 :content => 'Page with an inline image' } } } },
256 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' },
304 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' },
257 :content => 'Another page' } }
305 :content => 'Another page' } }
258 end
306 end
259
307
260 context "GET :export" do
308 context "GET :export" do
261 context "with an authorized user to export the wiki" do
309 context "with an authorized user to export the wiki" do
262 setup do
310 setup do
263 @request.session[:user_id] = 2
311 @request.session[:user_id] = 2
264 get :export, :project_id => 'ecookbook'
312 get :export, :project_id => 'ecookbook'
265 end
313 end
266
314
267 should_respond_with :success
315 should_respond_with :success
268 should_assign_to :pages
316 should_assign_to :pages
269 should_respond_with_content_type "text/html"
317 should_respond_with_content_type "text/html"
270 should "export all of the wiki pages to a single html file" do
318 should "export all of the wiki pages to a single html file" do
271 assert_select "a[name=?]", "CookBook_documentation"
319 assert_select "a[name=?]", "CookBook_documentation"
272 assert_select "a[name=?]", "Another_page"
320 assert_select "a[name=?]", "Another_page"
273 assert_select "a[name=?]", "Page_with_an_inline_image"
321 assert_select "a[name=?]", "Page_with_an_inline_image"
274 end
322 end
275
323
276 end
324 end
277
325
278 context "with an unauthorized user" do
326 context "with an unauthorized user" do
279 setup do
327 setup do
280 get :export, :project_id => 'ecookbook'
328 get :export, :project_id => 'ecookbook'
281
329
282 should_respond_with :redirect
330 should_respond_with :redirect
283 should_redirect_to('wiki index') { {:action => 'show', :project_id => @project, :id => nil} }
331 should_redirect_to('wiki index') { {:action => 'show', :project_id => @project, :id => nil} }
284 end
332 end
285 end
333 end
286 end
334 end
287
335
288 context "GET :date_index" do
336 context "GET :date_index" do
289 setup do
337 setup do
290 get :date_index, :project_id => 'ecookbook'
338 get :date_index, :project_id => 'ecookbook'
291 end
339 end
292
340
293 should_respond_with :success
341 should_respond_with :success
294 should_assign_to :pages
342 should_assign_to :pages
295 should_assign_to :pages_by_date
343 should_assign_to :pages_by_date
296 should_render_template 'wiki/date_index'
344 should_render_template 'wiki/date_index'
297
345
298 end
346 end
299
347
300 def test_not_found
348 def test_not_found
301 get :show, :project_id => 999
349 get :show, :project_id => 999
302 assert_response 404
350 assert_response 404
303 end
351 end
304
352
305 def test_protect_page
353 def test_protect_page
306 page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
354 page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
307 assert !page.protected?
355 assert !page.protected?
308 @request.session[:user_id] = 2
356 @request.session[:user_id] = 2
309 post :protect, :project_id => 1, :id => page.title, :protected => '1'
357 post :protect, :project_id => 1, :id => page.title, :protected => '1'
310 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
358 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
311 assert page.reload.protected?
359 assert page.reload.protected?
312 end
360 end
313
361
314 def test_unprotect_page
362 def test_unprotect_page
315 page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
363 page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
316 assert page.protected?
364 assert page.protected?
317 @request.session[:user_id] = 2
365 @request.session[:user_id] = 2
318 post :protect, :project_id => 1, :id => page.title, :protected => '0'
366 post :protect, :project_id => 1, :id => page.title, :protected => '0'
319 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation'
367 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation'
320 assert !page.reload.protected?
368 assert !page.reload.protected?
321 end
369 end
322
370
323 def test_show_page_with_edit_link
371 def test_show_page_with_edit_link
324 @request.session[:user_id] = 2
372 @request.session[:user_id] = 2
325 get :show, :project_id => 1
373 get :show, :project_id => 1
326 assert_response :success
374 assert_response :success
327 assert_template 'show'
375 assert_template 'show'
328 assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
376 assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
329 end
377 end
330
378
331 def test_show_page_without_edit_link
379 def test_show_page_without_edit_link
332 @request.session[:user_id] = 4
380 @request.session[:user_id] = 4
333 get :show, :project_id => 1
381 get :show, :project_id => 1
334 assert_response :success
382 assert_response :success
335 assert_template 'show'
383 assert_template 'show'
336 assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
384 assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
337 end
385 end
338
386
339 def test_edit_unprotected_page
387 def test_edit_unprotected_page
340 # Non members can edit unprotected wiki pages
388 # Non members can edit unprotected wiki pages
341 @request.session[:user_id] = 4
389 @request.session[:user_id] = 4
342 get :edit, :project_id => 1, :id => 'Another_page'
390 get :edit, :project_id => 1, :id => 'Another_page'
343 assert_response :success
391 assert_response :success
344 assert_template 'edit'
392 assert_template 'edit'
345 end
393 end
346
394
347 def test_edit_protected_page_by_nonmember
395 def test_edit_protected_page_by_nonmember
348 # Non members can't edit protected wiki pages
396 # Non members can't edit protected wiki pages
349 @request.session[:user_id] = 4
397 @request.session[:user_id] = 4
350 get :edit, :project_id => 1, :id => 'CookBook_documentation'
398 get :edit, :project_id => 1, :id => 'CookBook_documentation'
351 assert_response 403
399 assert_response 403
352 end
400 end
353
401
354 def test_edit_protected_page_by_member
402 def test_edit_protected_page_by_member
355 @request.session[:user_id] = 2
403 @request.session[:user_id] = 2
356 get :edit, :project_id => 1, :id => 'CookBook_documentation'
404 get :edit, :project_id => 1, :id => 'CookBook_documentation'
357 assert_response :success
405 assert_response :success
358 assert_template 'edit'
406 assert_template 'edit'
359 end
407 end
360
408
361 def test_history_of_non_existing_page_should_return_404
409 def test_history_of_non_existing_page_should_return_404
362 get :history, :project_id => 1, :id => 'Unknown_page'
410 get :history, :project_id => 1, :id => 'Unknown_page'
363 assert_response 404
411 assert_response 404
364 end
412 end
365 end
413 end
General Comments 0
You need to be logged in to leave comments. Login now