##// END OF EJS Templates
Merged r5186 from trunk....
Jean-Philippe Lang -
r5456:b43ebcbdc4a4
parent child
Show More
@@ -1,33 +1,33
1 <div class="contextual">
1 <div class="contextual">
2 <%= watcher_tag(@wiki, User.current) %>
2 <%= watcher_tag(@wiki, User.current) %>
3 </div>
3 </div>
4
4
5 <h2><%= l(:label_index_by_date) %></h2>
5 <h2><%= l(:label_index_by_date) %></h2>
6
6
7 <% if @pages.empty? %>
7 <% if @pages.empty? %>
8 <p class="nodata"><%= l(:label_no_data) %></p>
8 <p class="nodata"><%= l(:label_no_data) %></p>
9 <% end %>
9 <% end %>
10
10
11 <% @pages_by_date.keys.sort.reverse.each do |date| %>
11 <% @pages_by_date.keys.sort.reverse.each do |date| %>
12 <h3><%= format_date(date) %></h3>
12 <h3><%= format_date(date) %></h3>
13 <ul>
13 <ul>
14 <% @pages_by_date[date].each do |page| %>
14 <% @pages_by_date[date].each do |page| %>
15 <li><%= link_to page.pretty_title, :action => 'show', :id => page.title, :project_id => page.project %></li>
15 <li><%= link_to page.pretty_title, :action => 'show', :id => page.title, :project_id => page.project %></li>
16 <% end %>
16 <% end %>
17 </ul>
17 </ul>
18 <% end %>
18 <% end %>
19
19
20 <% content_for :sidebar do %>
20 <% content_for :sidebar do %>
21 <%= render :partial => 'sidebar' %>
21 <%= render :partial => 'sidebar' %>
22 <% end %>
22 <% end %>
23
23
24 <% unless @pages.empty? %>
24 <% unless @pages.empty? %>
25 <% other_formats_links do |f| %>
25 <% other_formats_links do |f| %>
26 <%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'show', :id => @project, :show_wiki_edits => 1, :key => User.current.rss_key} %>
26 <%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'index', :id => @project, :show_wiki_edits => 1, :key => User.current.rss_key} %>
27 <%= f.link_to('HTML', :url => {:action => 'export'}) if User.current.allowed_to?(:export_wiki_pages, @project) %>
27 <%= f.link_to('HTML', :url => {:action => 'export'}) if User.current.allowed_to?(:export_wiki_pages, @project) %>
28 <% end %>
28 <% end %>
29 <% end %>
29 <% end %>
30
30
31 <% content_for :header_tags do %>
31 <% content_for :header_tags do %>
32 <%= auto_discovery_link_tag(:atom, :controller => 'activities', :action => 'show', :id => @project, :show_wiki_edits => 1, :format => 'atom', :key => User.current.rss_key) %>
32 <%= auto_discovery_link_tag(:atom, :controller => 'activities', :action => 'index', :id => @project, :show_wiki_edits => 1, :format => 'atom', :key => User.current.rss_key) %>
33 <% end %>
33 <% end %>
@@ -1,26 +1,26
1 <div class="contextual">
1 <div class="contextual">
2 <%= watcher_tag(@wiki, User.current) %>
2 <%= watcher_tag(@wiki, User.current) %>
3 </div>
3 </div>
4
4
5 <h2><%= l(:label_index_by_title) %></h2>
5 <h2><%= l(:label_index_by_title) %></h2>
6
6
7 <% if @pages.empty? %>
7 <% if @pages.empty? %>
8 <p class="nodata"><%= l(:label_no_data) %></p>
8 <p class="nodata"><%= l(:label_no_data) %></p>
9 <% end %>
9 <% end %>
10
10
11 <%= render_page_hierarchy(@pages_by_parent_id) %>
11 <%= render_page_hierarchy(@pages_by_parent_id) %>
12
12
13 <% content_for :sidebar do %>
13 <% content_for :sidebar do %>
14 <%= render :partial => 'sidebar' %>
14 <%= render :partial => 'sidebar' %>
15 <% end %>
15 <% end %>
16
16
17 <% unless @pages.empty? %>
17 <% unless @pages.empty? %>
18 <% other_formats_links do |f| %>
18 <% other_formats_links do |f| %>
19 <%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'show', :id => @project, :show_wiki_edits => 1, :key => User.current.rss_key} %>
19 <%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'index', :id => @project, :show_wiki_edits => 1, :key => User.current.rss_key} %>
20 <%= f.link_to('HTML', :url => {:action => 'export'}) if User.current.allowed_to?(:export_wiki_pages, @project) %>
20 <%= f.link_to('HTML', :url => {:action => 'export'}) if User.current.allowed_to?(:export_wiki_pages, @project) %>
21 <% end %>
21 <% end %>
22 <% end %>
22 <% end %>
23
23
24 <% content_for :header_tags do %>
24 <% content_for :header_tags do %>
25 <%= auto_discovery_link_tag(:atom, :controller => 'activities', :action => 'show', :id => @project, :show_wiki_edits => 1, :format => 'atom', :key => User.current.rss_key) %>
25 <%= auto_discovery_link_tag(:atom, :controller => 'activities', :action => 'index', :id => @project, :show_wiki_edits => 1, :format => 'atom', :key => User.current.rss_key) %>
26 <% end %>
26 <% end %>
@@ -1,495 +1,503
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.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
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_update_page
112 def test_update_page
113 @request.session[:user_id] = 2
113 @request.session[:user_id] = 2
114 assert_no_difference 'WikiPage.count' do
114 assert_no_difference 'WikiPage.count' do
115 assert_no_difference 'WikiContent.count' do
115 assert_no_difference 'WikiContent.count' do
116 assert_difference 'WikiContent::Version.count' do
116 assert_difference 'WikiContent::Version.count' do
117 put :update, :project_id => 1,
117 put :update, :project_id => 1,
118 :id => 'Another_page',
118 :id => 'Another_page',
119 :content => {
119 :content => {
120 :comments => "my comments",
120 :comments => "my comments",
121 :text => "edited",
121 :text => "edited",
122 :version => 1
122 :version => 1
123 }
123 }
124 end
124 end
125 end
125 end
126 end
126 end
127 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
127 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
128
128
129 page = Wiki.find(1).pages.find_by_title('Another_page')
129 page = Wiki.find(1).pages.find_by_title('Another_page')
130 assert_equal "edited", page.content.text
130 assert_equal "edited", page.content.text
131 assert_equal 2, page.content.version
131 assert_equal 2, page.content.version
132 assert_equal "my comments", page.content.comments
132 assert_equal "my comments", page.content.comments
133 end
133 end
134
134
135 def test_update_page_with_failure
135 def test_update_page_with_failure
136 @request.session[:user_id] = 2
136 @request.session[:user_id] = 2
137 assert_no_difference 'WikiPage.count' do
137 assert_no_difference 'WikiPage.count' do
138 assert_no_difference 'WikiContent.count' do
138 assert_no_difference 'WikiContent.count' do
139 assert_no_difference 'WikiContent::Version.count' do
139 assert_no_difference 'WikiContent::Version.count' do
140 put :update, :project_id => 1,
140 put :update, :project_id => 1,
141 :id => 'Another_page',
141 :id => 'Another_page',
142 :content => {
142 :content => {
143 :comments => 'a' * 300, # failure here, comment is too long
143 :comments => 'a' * 300, # failure here, comment is too long
144 :text => 'edited',
144 :text => 'edited',
145 :version => 1
145 :version => 1
146 }
146 }
147 end
147 end
148 end
148 end
149 end
149 end
150 assert_response :success
150 assert_response :success
151 assert_template 'edit'
151 assert_template 'edit'
152
152
153 assert_error_tag :descendant => {:content => /Comment is too long/}
153 assert_error_tag :descendant => {:content => /Comment is too long/}
154 assert_tag :tag => 'textarea', :attributes => {:id => 'content_text'}, :content => 'edited'
154 assert_tag :tag => 'textarea', :attributes => {:id => 'content_text'}, :content => 'edited'
155 assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'}
155 assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'}
156 end
156 end
157
157
158 def test_update_stale_page_should_not_raise_an_error
158 def test_update_stale_page_should_not_raise_an_error
159 @request.session[:user_id] = 2
159 @request.session[:user_id] = 2
160 c = Wiki.find(1).find_page('Another_page').content
160 c = Wiki.find(1).find_page('Another_page').content
161 c.text = 'Previous text'
161 c.text = 'Previous text'
162 c.save!
162 c.save!
163 assert_equal 2, c.version
163 assert_equal 2, c.version
164
164
165 assert_no_difference 'WikiPage.count' do
165 assert_no_difference 'WikiPage.count' do
166 assert_no_difference 'WikiContent.count' do
166 assert_no_difference 'WikiContent.count' do
167 assert_no_difference 'WikiContent::Version.count' do
167 assert_no_difference 'WikiContent::Version.count' do
168 put :update, :project_id => 1,
168 put :update, :project_id => 1,
169 :id => 'Another_page',
169 :id => 'Another_page',
170 :content => {
170 :content => {
171 :comments => 'My comments',
171 :comments => 'My comments',
172 :text => 'Text should not be lost',
172 :text => 'Text should not be lost',
173 :version => 1
173 :version => 1
174 }
174 }
175 end
175 end
176 end
176 end
177 end
177 end
178 assert_response :success
178 assert_response :success
179 assert_template 'edit'
179 assert_template 'edit'
180 assert_tag :div,
180 assert_tag :div,
181 :attributes => { :class => /error/ },
181 :attributes => { :class => /error/ },
182 :content => /Data has been updated by another user/
182 :content => /Data has been updated by another user/
183 assert_tag 'textarea',
183 assert_tag 'textarea',
184 :attributes => { :name => 'content[text]' },
184 :attributes => { :name => 'content[text]' },
185 :content => /Text should not be lost/
185 :content => /Text should not be lost/
186 assert_tag 'input',
186 assert_tag 'input',
187 :attributes => { :name => 'content[comments]', :value => 'My comments' }
187 :attributes => { :name => 'content[comments]', :value => 'My comments' }
188
188
189 c.reload
189 c.reload
190 assert_equal 'Previous text', c.text
190 assert_equal 'Previous text', c.text
191 assert_equal 2, c.version
191 assert_equal 2, c.version
192 end
192 end
193
193
194 def test_preview
194 def test_preview
195 @request.session[:user_id] = 2
195 @request.session[:user_id] = 2
196 xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation',
196 xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation',
197 :content => { :comments => '',
197 :content => { :comments => '',
198 :text => 'this is a *previewed text*',
198 :text => 'this is a *previewed text*',
199 :version => 3 }
199 :version => 3 }
200 assert_response :success
200 assert_response :success
201 assert_template 'common/_preview'
201 assert_template 'common/_preview'
202 assert_tag :tag => 'strong', :content => /previewed text/
202 assert_tag :tag => 'strong', :content => /previewed text/
203 end
203 end
204
204
205 def test_preview_new_page
205 def test_preview_new_page
206 @request.session[:user_id] = 2
206 @request.session[:user_id] = 2
207 xhr :post, :preview, :project_id => 1, :id => 'New page',
207 xhr :post, :preview, :project_id => 1, :id => 'New page',
208 :content => { :text => 'h1. New page',
208 :content => { :text => 'h1. New page',
209 :comments => '',
209 :comments => '',
210 :version => 0 }
210 :version => 0 }
211 assert_response :success
211 assert_response :success
212 assert_template 'common/_preview'
212 assert_template 'common/_preview'
213 assert_tag :tag => 'h1', :content => /New page/
213 assert_tag :tag => 'h1', :content => /New page/
214 end
214 end
215
215
216 def test_history
216 def test_history
217 get :history, :project_id => 1, :id => 'CookBook_documentation'
217 get :history, :project_id => 1, :id => 'CookBook_documentation'
218 assert_response :success
218 assert_response :success
219 assert_template 'history'
219 assert_template 'history'
220 assert_not_nil assigns(:versions)
220 assert_not_nil assigns(:versions)
221 assert_equal 3, assigns(:versions).size
221 assert_equal 3, assigns(:versions).size
222 assert_select "input[type=submit][name=commit]"
222 assert_select "input[type=submit][name=commit]"
223 end
223 end
224
224
225 def test_history_with_one_version
225 def test_history_with_one_version
226 get :history, :project_id => 1, :id => 'Another_page'
226 get :history, :project_id => 1, :id => 'Another_page'
227 assert_response :success
227 assert_response :success
228 assert_template 'history'
228 assert_template 'history'
229 assert_not_nil assigns(:versions)
229 assert_not_nil assigns(:versions)
230 assert_equal 1, assigns(:versions).size
230 assert_equal 1, assigns(:versions).size
231 assert_select "input[type=submit][name=commit]", false
231 assert_select "input[type=submit][name=commit]", false
232 end
232 end
233
233
234 def test_diff
234 def test_diff
235 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => 2, :version_from => 1
235 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => 2, :version_from => 1
236 assert_response :success
236 assert_response :success
237 assert_template 'diff'
237 assert_template 'diff'
238 assert_tag :tag => 'span', :attributes => { :class => 'diff_in'},
238 assert_tag :tag => 'span', :attributes => { :class => 'diff_in'},
239 :content => /updated/
239 :content => /updated/
240 end
240 end
241
241
242 def test_annotate
242 def test_annotate
243 get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2
243 get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2
244 assert_response :success
244 assert_response :success
245 assert_template 'annotate'
245 assert_template 'annotate'
246 # Line 1
246 # Line 1
247 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1' },
247 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1' },
248 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/ },
248 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/ },
249 :child => { :tag => 'td', :content => /h1\. CookBook documentation/ }
249 :child => { :tag => 'td', :content => /h1\. CookBook documentation/ }
250 # Line 2
250 # Line 2
251 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '2' },
251 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '2' },
252 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/ },
252 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/ },
253 :child => { :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ }
253 :child => { :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ }
254 end
254 end
255
255
256 def test_get_rename
256 def test_get_rename
257 @request.session[:user_id] = 2
257 @request.session[:user_id] = 2
258 get :rename, :project_id => 1, :id => 'Another_page'
258 get :rename, :project_id => 1, :id => 'Another_page'
259 assert_response :success
259 assert_response :success
260 assert_template 'rename'
260 assert_template 'rename'
261 assert_tag 'option',
261 assert_tag 'option',
262 :attributes => {:value => ''},
262 :attributes => {:value => ''},
263 :content => '',
263 :content => '',
264 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
264 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
265 assert_no_tag 'option',
265 assert_no_tag 'option',
266 :attributes => {:selected => 'selected'},
266 :attributes => {:selected => 'selected'},
267 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
267 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
268 end
268 end
269
269
270 def test_get_rename_child_page
270 def test_get_rename_child_page
271 @request.session[:user_id] = 2
271 @request.session[:user_id] = 2
272 get :rename, :project_id => 1, :id => 'Child_1'
272 get :rename, :project_id => 1, :id => 'Child_1'
273 assert_response :success
273 assert_response :success
274 assert_template 'rename'
274 assert_template 'rename'
275 assert_tag 'option',
275 assert_tag 'option',
276 :attributes => {:value => ''},
276 :attributes => {:value => ''},
277 :content => '',
277 :content => '',
278 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
278 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
279 assert_tag 'option',
279 assert_tag 'option',
280 :attributes => {:value => '2', :selected => 'selected'},
280 :attributes => {:value => '2', :selected => 'selected'},
281 :content => /Another page/,
281 :content => /Another page/,
282 :parent => {
282 :parent => {
283 :tag => 'select',
283 :tag => 'select',
284 :attributes => {:name => 'wiki_page[parent_id]'}
284 :attributes => {:name => 'wiki_page[parent_id]'}
285 }
285 }
286 end
286 end
287
287
288 def test_rename_with_redirect
288 def test_rename_with_redirect
289 @request.session[:user_id] = 2
289 @request.session[:user_id] = 2
290 post :rename, :project_id => 1, :id => 'Another_page',
290 post :rename, :project_id => 1, :id => 'Another_page',
291 :wiki_page => { :title => 'Another renamed page',
291 :wiki_page => { :title => 'Another renamed page',
292 :redirect_existing_links => 1 }
292 :redirect_existing_links => 1 }
293 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
293 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
294 wiki = Project.find(1).wiki
294 wiki = Project.find(1).wiki
295 # Check redirects
295 # Check redirects
296 assert_not_nil wiki.find_page('Another page')
296 assert_not_nil wiki.find_page('Another page')
297 assert_nil wiki.find_page('Another page', :with_redirect => false)
297 assert_nil wiki.find_page('Another page', :with_redirect => false)
298 end
298 end
299
299
300 def test_rename_without_redirect
300 def test_rename_without_redirect
301 @request.session[:user_id] = 2
301 @request.session[:user_id] = 2
302 post :rename, :project_id => 1, :id => 'Another_page',
302 post :rename, :project_id => 1, :id => 'Another_page',
303 :wiki_page => { :title => 'Another renamed page',
303 :wiki_page => { :title => 'Another renamed page',
304 :redirect_existing_links => "0" }
304 :redirect_existing_links => "0" }
305 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
305 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
306 wiki = Project.find(1).wiki
306 wiki = Project.find(1).wiki
307 # Check that there's no redirects
307 # Check that there's no redirects
308 assert_nil wiki.find_page('Another page')
308 assert_nil wiki.find_page('Another page')
309 end
309 end
310
310
311 def test_rename_with_parent_assignment
311 def test_rename_with_parent_assignment
312 @request.session[:user_id] = 2
312 @request.session[:user_id] = 2
313 post :rename, :project_id => 1, :id => 'Another_page',
313 post :rename, :project_id => 1, :id => 'Another_page',
314 :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' }
314 :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' }
315 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
315 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
316 assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent
316 assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent
317 end
317 end
318
318
319 def test_rename_with_parent_unassignment
319 def test_rename_with_parent_unassignment
320 @request.session[:user_id] = 2
320 @request.session[:user_id] = 2
321 post :rename, :project_id => 1, :id => 'Child_1',
321 post :rename, :project_id => 1, :id => 'Child_1',
322 :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' }
322 :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' }
323 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1'
323 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1'
324 assert_nil WikiPage.find_by_title('Child_1').parent
324 assert_nil WikiPage.find_by_title('Child_1').parent
325 end
325 end
326
326
327 def test_destroy_child
327 def test_destroy_child
328 @request.session[:user_id] = 2
328 @request.session[:user_id] = 2
329 delete :destroy, :project_id => 1, :id => 'Child_1'
329 delete :destroy, :project_id => 1, :id => 'Child_1'
330 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
330 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
331 end
331 end
332
332
333 def test_destroy_parent
333 def test_destroy_parent
334 @request.session[:user_id] = 2
334 @request.session[:user_id] = 2
335 assert_no_difference('WikiPage.count') do
335 assert_no_difference('WikiPage.count') do
336 delete :destroy, :project_id => 1, :id => 'Another_page'
336 delete :destroy, :project_id => 1, :id => 'Another_page'
337 end
337 end
338 assert_response :success
338 assert_response :success
339 assert_template 'destroy'
339 assert_template 'destroy'
340 end
340 end
341
341
342 def test_destroy_parent_with_nullify
342 def test_destroy_parent_with_nullify
343 @request.session[:user_id] = 2
343 @request.session[:user_id] = 2
344 assert_difference('WikiPage.count', -1) do
344 assert_difference('WikiPage.count', -1) do
345 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify'
345 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify'
346 end
346 end
347 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
347 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
348 assert_nil WikiPage.find_by_id(2)
348 assert_nil WikiPage.find_by_id(2)
349 end
349 end
350
350
351 def test_destroy_parent_with_cascade
351 def test_destroy_parent_with_cascade
352 @request.session[:user_id] = 2
352 @request.session[:user_id] = 2
353 assert_difference('WikiPage.count', -3) do
353 assert_difference('WikiPage.count', -3) do
354 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy'
354 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy'
355 end
355 end
356 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
356 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
357 assert_nil WikiPage.find_by_id(2)
357 assert_nil WikiPage.find_by_id(2)
358 assert_nil WikiPage.find_by_id(5)
358 assert_nil WikiPage.find_by_id(5)
359 end
359 end
360
360
361 def test_destroy_parent_with_reassign
361 def test_destroy_parent_with_reassign
362 @request.session[:user_id] = 2
362 @request.session[:user_id] = 2
363 assert_difference('WikiPage.count', -1) do
363 assert_difference('WikiPage.count', -1) do
364 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1
364 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1
365 end
365 end
366 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
366 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
367 assert_nil WikiPage.find_by_id(2)
367 assert_nil WikiPage.find_by_id(2)
368 assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent
368 assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent
369 end
369 end
370
370
371 def test_index
371 def test_index
372 get :index, :project_id => 'ecookbook'
372 get :index, :project_id => 'ecookbook'
373 assert_response :success
373 assert_response :success
374 assert_template 'index'
374 assert_template 'index'
375 pages = assigns(:pages)
375 pages = assigns(:pages)
376 assert_not_nil pages
376 assert_not_nil pages
377 assert_equal Project.find(1).wiki.pages.size, pages.size
377 assert_equal Project.find(1).wiki.pages.size, pages.size
378
378
379 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
379 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
380 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' },
380 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' },
381 :content => 'CookBook documentation' },
381 :content => 'CookBook documentation' },
382 :child => { :tag => 'ul',
382 :child => { :tag => 'ul',
383 :child => { :tag => 'li',
383 :child => { :tag => 'li',
384 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
384 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
385 :content => 'Page with an inline image' } } } },
385 :content => 'Page with an inline image' } } } },
386 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' },
386 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' },
387 :content => 'Another page' } }
387 :content => 'Another page' } }
388 end
388 end
389
390 def test_index_should_include_atom_link
391 get :index, :project_id => 'ecookbook'
392 assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'}
393 end
389
394
390 context "GET :export" do
395 context "GET :export" do
391 context "with an authorized user to export the wiki" do
396 context "with an authorized user to export the wiki" do
392 setup do
397 setup do
393 @request.session[:user_id] = 2
398 @request.session[:user_id] = 2
394 get :export, :project_id => 'ecookbook'
399 get :export, :project_id => 'ecookbook'
395 end
400 end
396
401
397 should_respond_with :success
402 should_respond_with :success
398 should_assign_to :pages
403 should_assign_to :pages
399 should_respond_with_content_type "text/html"
404 should_respond_with_content_type "text/html"
400 should "export all of the wiki pages to a single html file" do
405 should "export all of the wiki pages to a single html file" do
401 assert_select "a[name=?]", "CookBook_documentation"
406 assert_select "a[name=?]", "CookBook_documentation"
402 assert_select "a[name=?]", "Another_page"
407 assert_select "a[name=?]", "Another_page"
403 assert_select "a[name=?]", "Page_with_an_inline_image"
408 assert_select "a[name=?]", "Page_with_an_inline_image"
404 end
409 end
405
410
406 end
411 end
407
412
408 context "with an unauthorized user" do
413 context "with an unauthorized user" do
409 setup do
414 setup do
410 get :export, :project_id => 'ecookbook'
415 get :export, :project_id => 'ecookbook'
411
416
412 should_respond_with :redirect
417 should_respond_with :redirect
413 should_redirect_to('wiki index') { {:action => 'show', :project_id => @project, :id => nil} }
418 should_redirect_to('wiki index') { {:action => 'show', :project_id => @project, :id => nil} }
414 end
419 end
415 end
420 end
416 end
421 end
417
422
418 context "GET :date_index" do
423 context "GET :date_index" do
419 setup do
424 setup do
420 get :date_index, :project_id => 'ecookbook'
425 get :date_index, :project_id => 'ecookbook'
421 end
426 end
422
427
423 should_respond_with :success
428 should_respond_with :success
424 should_assign_to :pages
429 should_assign_to :pages
425 should_assign_to :pages_by_date
430 should_assign_to :pages_by_date
426 should_render_template 'wiki/date_index'
431 should_render_template 'wiki/date_index'
427
432
433 should "include atom link" do
434 assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'}
435 end
428 end
436 end
429
437
430 def test_not_found
438 def test_not_found
431 get :show, :project_id => 999
439 get :show, :project_id => 999
432 assert_response 404
440 assert_response 404
433 end
441 end
434
442
435 def test_protect_page
443 def test_protect_page
436 page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
444 page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
437 assert !page.protected?
445 assert !page.protected?
438 @request.session[:user_id] = 2
446 @request.session[:user_id] = 2
439 post :protect, :project_id => 1, :id => page.title, :protected => '1'
447 post :protect, :project_id => 1, :id => page.title, :protected => '1'
440 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
448 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
441 assert page.reload.protected?
449 assert page.reload.protected?
442 end
450 end
443
451
444 def test_unprotect_page
452 def test_unprotect_page
445 page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
453 page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
446 assert page.protected?
454 assert page.protected?
447 @request.session[:user_id] = 2
455 @request.session[:user_id] = 2
448 post :protect, :project_id => 1, :id => page.title, :protected => '0'
456 post :protect, :project_id => 1, :id => page.title, :protected => '0'
449 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation'
457 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation'
450 assert !page.reload.protected?
458 assert !page.reload.protected?
451 end
459 end
452
460
453 def test_show_page_with_edit_link
461 def test_show_page_with_edit_link
454 @request.session[:user_id] = 2
462 @request.session[:user_id] = 2
455 get :show, :project_id => 1
463 get :show, :project_id => 1
456 assert_response :success
464 assert_response :success
457 assert_template 'show'
465 assert_template 'show'
458 assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
466 assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
459 end
467 end
460
468
461 def test_show_page_without_edit_link
469 def test_show_page_without_edit_link
462 @request.session[:user_id] = 4
470 @request.session[:user_id] = 4
463 get :show, :project_id => 1
471 get :show, :project_id => 1
464 assert_response :success
472 assert_response :success
465 assert_template 'show'
473 assert_template 'show'
466 assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
474 assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
467 end
475 end
468
476
469 def test_edit_unprotected_page
477 def test_edit_unprotected_page
470 # Non members can edit unprotected wiki pages
478 # Non members can edit unprotected wiki pages
471 @request.session[:user_id] = 4
479 @request.session[:user_id] = 4
472 get :edit, :project_id => 1, :id => 'Another_page'
480 get :edit, :project_id => 1, :id => 'Another_page'
473 assert_response :success
481 assert_response :success
474 assert_template 'edit'
482 assert_template 'edit'
475 end
483 end
476
484
477 def test_edit_protected_page_by_nonmember
485 def test_edit_protected_page_by_nonmember
478 # Non members can't edit protected wiki pages
486 # Non members can't edit protected wiki pages
479 @request.session[:user_id] = 4
487 @request.session[:user_id] = 4
480 get :edit, :project_id => 1, :id => 'CookBook_documentation'
488 get :edit, :project_id => 1, :id => 'CookBook_documentation'
481 assert_response 403
489 assert_response 403
482 end
490 end
483
491
484 def test_edit_protected_page_by_member
492 def test_edit_protected_page_by_member
485 @request.session[:user_id] = 2
493 @request.session[:user_id] = 2
486 get :edit, :project_id => 1, :id => 'CookBook_documentation'
494 get :edit, :project_id => 1, :id => 'CookBook_documentation'
487 assert_response :success
495 assert_response :success
488 assert_template 'edit'
496 assert_template 'edit'
489 end
497 end
490
498
491 def test_history_of_non_existing_page_should_return_404
499 def test_history_of_non_existing_page_should_return_404
492 get :history, :project_id => 1, :id => 'Unknown_page'
500 get :history, :project_id => 1, :id => 'Unknown_page'
493 assert_response 404
501 assert_response 404
494 end
502 end
495 end
503 end
General Comments 0
You need to be logged in to leave comments. Login now