##// END OF EJS Templates
REST API for deleting wiki pages (#7082)....
Jean-Philippe Lang -
r10528:beb261065059
parent child
Show More
@@ -1,359 +1,363
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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 'diff'
18 require 'diff'
19
19
20 # The WikiController follows the Rails REST controller pattern but with
20 # The WikiController follows the Rails REST controller pattern but with
21 # a few differences
21 # a few differences
22 #
22 #
23 # * index - shows a list of WikiPages grouped by page or date
23 # * index - shows a list of WikiPages grouped by page or date
24 # * new - not used
24 # * new - not used
25 # * create - not used
25 # * create - not used
26 # * show - will also show the form for creating a new wiki page
26 # * show - will also show the form for creating a new wiki page
27 # * edit - used to edit an existing or new page
27 # * edit - used to edit an existing or new page
28 # * update - used to save a wiki page update to the database, including new pages
28 # * update - used to save a wiki page update to the database, including new pages
29 # * destroy - normal
29 # * destroy - normal
30 #
30 #
31 # Other member and collection methods are also used
31 # Other member and collection methods are also used
32 #
32 #
33 # TODO: still being worked on
33 # TODO: still being worked on
34 class WikiController < ApplicationController
34 class WikiController < ApplicationController
35 default_search_scope :wiki_pages
35 default_search_scope :wiki_pages
36 before_filter :find_wiki, :authorize
36 before_filter :find_wiki, :authorize
37 before_filter :find_existing_or_new_page, :only => [:show, :edit, :update]
37 before_filter :find_existing_or_new_page, :only => [:show, :edit, :update]
38 before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy, :destroy_version]
38 before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy, :destroy_version]
39 accept_api_auth :index, :show, :update
39 accept_api_auth :index, :show, :update, :destroy
40
40
41 helper :attachments
41 helper :attachments
42 include AttachmentsHelper
42 include AttachmentsHelper
43 helper :watchers
43 helper :watchers
44 include Redmine::Export::PDF
44 include Redmine::Export::PDF
45
45
46 # List of pages, sorted alphabetically and by parent (hierarchy)
46 # List of pages, sorted alphabetically and by parent (hierarchy)
47 def index
47 def index
48 load_pages_for_index
48 load_pages_for_index
49
49
50 respond_to do |format|
50 respond_to do |format|
51 format.html {
51 format.html {
52 @pages_by_parent_id = @pages.group_by(&:parent_id)
52 @pages_by_parent_id = @pages.group_by(&:parent_id)
53 }
53 }
54 format.api
54 format.api
55 end
55 end
56 end
56 end
57
57
58 # List of page, by last update
58 # List of page, by last update
59 def date_index
59 def date_index
60 load_pages_for_index
60 load_pages_for_index
61 @pages_by_date = @pages.group_by {|p| p.updated_on.to_date}
61 @pages_by_date = @pages.group_by {|p| p.updated_on.to_date}
62 end
62 end
63
63
64 # display a page (in editing mode if it doesn't exist)
64 # display a page (in editing mode if it doesn't exist)
65 def show
65 def show
66 if @page.new_record?
66 if @page.new_record?
67 if User.current.allowed_to?(:edit_wiki_pages, @project) && editable? && !api_request?
67 if User.current.allowed_to?(:edit_wiki_pages, @project) && editable? && !api_request?
68 edit
68 edit
69 render :action => 'edit'
69 render :action => 'edit'
70 else
70 else
71 render_404
71 render_404
72 end
72 end
73 return
73 return
74 end
74 end
75 if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project)
75 if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project)
76 deny_access
76 deny_access
77 return
77 return
78 end
78 end
79 @content = @page.content_for_version(params[:version])
79 @content = @page.content_for_version(params[:version])
80 if User.current.allowed_to?(:export_wiki_pages, @project)
80 if User.current.allowed_to?(:export_wiki_pages, @project)
81 if params[:format] == 'pdf'
81 if params[:format] == 'pdf'
82 send_data(wiki_page_to_pdf(@page, @project), :type => 'application/pdf', :filename => "#{@page.title}.pdf")
82 send_data(wiki_page_to_pdf(@page, @project), :type => 'application/pdf', :filename => "#{@page.title}.pdf")
83 return
83 return
84 elsif params[:format] == 'html'
84 elsif params[:format] == 'html'
85 export = render_to_string :action => 'export', :layout => false
85 export = render_to_string :action => 'export', :layout => false
86 send_data(export, :type => 'text/html', :filename => "#{@page.title}.html")
86 send_data(export, :type => 'text/html', :filename => "#{@page.title}.html")
87 return
87 return
88 elsif params[:format] == 'txt'
88 elsif params[:format] == 'txt'
89 send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt")
89 send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt")
90 return
90 return
91 end
91 end
92 end
92 end
93 @editable = editable?
93 @editable = editable?
94 @sections_editable = @editable && User.current.allowed_to?(:edit_wiki_pages, @page.project) &&
94 @sections_editable = @editable && User.current.allowed_to?(:edit_wiki_pages, @page.project) &&
95 @content.current_version? &&
95 @content.current_version? &&
96 Redmine::WikiFormatting.supports_section_edit?
96 Redmine::WikiFormatting.supports_section_edit?
97
97
98 respond_to do |format|
98 respond_to do |format|
99 format.html
99 format.html
100 format.api
100 format.api
101 end
101 end
102 end
102 end
103
103
104 # edit an existing page or a new one
104 # edit an existing page or a new one
105 def edit
105 def edit
106 return render_403 unless editable?
106 return render_403 unless editable?
107 if @page.new_record?
107 if @page.new_record?
108 @page.content = WikiContent.new(:page => @page)
108 @page.content = WikiContent.new(:page => @page)
109 if params[:parent].present?
109 if params[:parent].present?
110 @page.parent = @page.wiki.find_page(params[:parent].to_s)
110 @page.parent = @page.wiki.find_page(params[:parent].to_s)
111 end
111 end
112 end
112 end
113
113
114 @content = @page.content_for_version(params[:version])
114 @content = @page.content_for_version(params[:version])
115 @content.text = initial_page_content(@page) if @content.text.blank?
115 @content.text = initial_page_content(@page) if @content.text.blank?
116 # don't keep previous comment
116 # don't keep previous comment
117 @content.comments = nil
117 @content.comments = nil
118
118
119 # To prevent StaleObjectError exception when reverting to a previous version
119 # To prevent StaleObjectError exception when reverting to a previous version
120 @content.version = @page.content.version
120 @content.version = @page.content.version
121
121
122 @text = @content.text
122 @text = @content.text
123 if params[:section].present? && Redmine::WikiFormatting.supports_section_edit?
123 if params[:section].present? && Redmine::WikiFormatting.supports_section_edit?
124 @section = params[:section].to_i
124 @section = params[:section].to_i
125 @text, @section_hash = Redmine::WikiFormatting.formatter.new(@text).get_section(@section)
125 @text, @section_hash = Redmine::WikiFormatting.formatter.new(@text).get_section(@section)
126 render_404 if @text.blank?
126 render_404 if @text.blank?
127 end
127 end
128 end
128 end
129
129
130 # Creates a new page or updates an existing one
130 # Creates a new page or updates an existing one
131 def update
131 def update
132 return render_403 unless editable?
132 return render_403 unless editable?
133 was_new_page = @page.new_record?
133 was_new_page = @page.new_record?
134 @page.content = WikiContent.new(:page => @page) if @page.new_record?
134 @page.content = WikiContent.new(:page => @page) if @page.new_record?
135 @page.safe_attributes = params[:wiki_page]
135 @page.safe_attributes = params[:wiki_page]
136
136
137 @content = @page.content
137 @content = @page.content
138 content_params = params[:content]
138 content_params = params[:content]
139 if content_params.nil? && params[:wiki_page].is_a?(Hash)
139 if content_params.nil? && params[:wiki_page].is_a?(Hash)
140 content_params = params[:wiki_page].slice(:text, :comments, :version)
140 content_params = params[:wiki_page].slice(:text, :comments, :version)
141 end
141 end
142 content_params ||= {}
142 content_params ||= {}
143
143
144 if !@page.new_record? && content_params.present? && @content.text == content_params[:text]
144 if !@page.new_record? && content_params.present? && @content.text == content_params[:text]
145 attachments = Attachment.attach_files(@page, params[:attachments])
145 attachments = Attachment.attach_files(@page, params[:attachments])
146 render_attachment_warning_if_needed(@page)
146 render_attachment_warning_if_needed(@page)
147 # don't save content if text wasn't changed
147 # don't save content if text wasn't changed
148 @page.save
148 @page.save
149 redirect_to :action => 'show', :project_id => @project, :id => @page.title
149 redirect_to :action => 'show', :project_id => @project, :id => @page.title
150 return
150 return
151 end
151 end
152
152
153 @content.comments = content_params[:comments]
153 @content.comments = content_params[:comments]
154 @text = content_params[:text]
154 @text = content_params[:text]
155 if params[:section].present? && Redmine::WikiFormatting.supports_section_edit?
155 if params[:section].present? && Redmine::WikiFormatting.supports_section_edit?
156 @section = params[:section].to_i
156 @section = params[:section].to_i
157 @section_hash = params[:section_hash]
157 @section_hash = params[:section_hash]
158 @content.text = Redmine::WikiFormatting.formatter.new(@content.text).update_section(params[:section].to_i, @text, @section_hash)
158 @content.text = Redmine::WikiFormatting.formatter.new(@content.text).update_section(params[:section].to_i, @text, @section_hash)
159 else
159 else
160 @content.version = content_params[:version] if content_params[:version]
160 @content.version = content_params[:version] if content_params[:version]
161 @content.text = @text
161 @content.text = @text
162 end
162 end
163 @content.author = User.current
163 @content.author = User.current
164 @page.content = @content
164 @page.content = @content
165 if @page.save
165 if @page.save
166 attachments = Attachment.attach_files(@page, params[:attachments])
166 attachments = Attachment.attach_files(@page, params[:attachments])
167 render_attachment_warning_if_needed(@page)
167 render_attachment_warning_if_needed(@page)
168 call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page})
168 call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page})
169
169
170 respond_to do |format|
170 respond_to do |format|
171 format.html { redirect_to :action => 'show', :project_id => @project, :id => @page.title }
171 format.html { redirect_to :action => 'show', :project_id => @project, :id => @page.title }
172 format.api {
172 format.api {
173 if was_new_page
173 if was_new_page
174 render :action => 'show', :status => :created, :location => url_for(:controller => 'wiki', :action => 'show', :project_id => @project, :id => @page.title)
174 render :action => 'show', :status => :created, :location => url_for(:controller => 'wiki', :action => 'show', :project_id => @project, :id => @page.title)
175 else
175 else
176 render_api_ok
176 render_api_ok
177 end
177 end
178 }
178 }
179 end
179 end
180 else
180 else
181 respond_to do |format|
181 respond_to do |format|
182 format.html { render :action => 'edit' }
182 format.html { render :action => 'edit' }
183 format.api { render_validation_errors(@content) }
183 format.api { render_validation_errors(@content) }
184 end
184 end
185 end
185 end
186
186
187 rescue ActiveRecord::StaleObjectError, Redmine::WikiFormatting::StaleSectionError
187 rescue ActiveRecord::StaleObjectError, Redmine::WikiFormatting::StaleSectionError
188 # Optimistic locking exception
188 # Optimistic locking exception
189 respond_to do |format|
189 respond_to do |format|
190 format.html {
190 format.html {
191 flash.now[:error] = l(:notice_locking_conflict)
191 flash.now[:error] = l(:notice_locking_conflict)
192 render :action => 'edit'
192 render :action => 'edit'
193 }
193 }
194 format.api { render_api_head :conflict }
194 format.api { render_api_head :conflict }
195 end
195 end
196 rescue ActiveRecord::RecordNotSaved
196 rescue ActiveRecord::RecordNotSaved
197 respond_to do |format|
197 respond_to do |format|
198 format.html { render :action => 'edit' }
198 format.html { render :action => 'edit' }
199 format.api { render_validation_errors(@content) }
199 format.api { render_validation_errors(@content) }
200 end
200 end
201 end
201 end
202
202
203 # rename a page
203 # rename a page
204 def rename
204 def rename
205 return render_403 unless editable?
205 return render_403 unless editable?
206 @page.redirect_existing_links = true
206 @page.redirect_existing_links = true
207 # used to display the *original* title if some AR validation errors occur
207 # used to display the *original* title if some AR validation errors occur
208 @original_title = @page.pretty_title
208 @original_title = @page.pretty_title
209 if request.post? && @page.update_attributes(params[:wiki_page])
209 if request.post? && @page.update_attributes(params[:wiki_page])
210 flash[:notice] = l(:notice_successful_update)
210 flash[:notice] = l(:notice_successful_update)
211 redirect_to :action => 'show', :project_id => @project, :id => @page.title
211 redirect_to :action => 'show', :project_id => @project, :id => @page.title
212 end
212 end
213 end
213 end
214
214
215 def protect
215 def protect
216 @page.update_attribute :protected, params[:protected]
216 @page.update_attribute :protected, params[:protected]
217 redirect_to :action => 'show', :project_id => @project, :id => @page.title
217 redirect_to :action => 'show', :project_id => @project, :id => @page.title
218 end
218 end
219
219
220 # show page history
220 # show page history
221 def history
221 def history
222 @version_count = @page.content.versions.count
222 @version_count = @page.content.versions.count
223 @version_pages = Paginator.new self, @version_count, per_page_option, params['p']
223 @version_pages = Paginator.new self, @version_count, per_page_option, params['p']
224 # don't load text
224 # don't load text
225 @versions = @page.content.versions.find :all,
225 @versions = @page.content.versions.find :all,
226 :select => "id, author_id, comments, updated_on, version",
226 :select => "id, author_id, comments, updated_on, version",
227 :order => 'version DESC',
227 :order => 'version DESC',
228 :limit => @version_pages.items_per_page + 1,
228 :limit => @version_pages.items_per_page + 1,
229 :offset => @version_pages.current.offset
229 :offset => @version_pages.current.offset
230
230
231 render :layout => false if request.xhr?
231 render :layout => false if request.xhr?
232 end
232 end
233
233
234 def diff
234 def diff
235 @diff = @page.diff(params[:version], params[:version_from])
235 @diff = @page.diff(params[:version], params[:version_from])
236 render_404 unless @diff
236 render_404 unless @diff
237 end
237 end
238
238
239 def annotate
239 def annotate
240 @annotate = @page.annotate(params[:version])
240 @annotate = @page.annotate(params[:version])
241 render_404 unless @annotate
241 render_404 unless @annotate
242 end
242 end
243
243
244 # Removes a wiki page and its history
244 # Removes a wiki page and its history
245 # Children can be either set as root pages, removed or reassigned to another parent page
245 # Children can be either set as root pages, removed or reassigned to another parent page
246 def destroy
246 def destroy
247 return render_403 unless editable?
247 return render_403 unless editable?
248
248
249 @descendants_count = @page.descendants.size
249 @descendants_count = @page.descendants.size
250 if @descendants_count > 0
250 if @descendants_count > 0
251 case params[:todo]
251 case params[:todo]
252 when 'nullify'
252 when 'nullify'
253 # Nothing to do
253 # Nothing to do
254 when 'destroy'
254 when 'destroy'
255 # Removes all its descendants
255 # Removes all its descendants
256 @page.descendants.each(&:destroy)
256 @page.descendants.each(&:destroy)
257 when 'reassign'
257 when 'reassign'
258 # Reassign children to another parent page
258 # Reassign children to another parent page
259 reassign_to = @wiki.pages.find_by_id(params[:reassign_to_id].to_i)
259 reassign_to = @wiki.pages.find_by_id(params[:reassign_to_id].to_i)
260 return unless reassign_to
260 return unless reassign_to
261 @page.children.each do |child|
261 @page.children.each do |child|
262 child.update_attribute(:parent, reassign_to)
262 child.update_attribute(:parent, reassign_to)
263 end
263 end
264 else
264 else
265 @reassignable_to = @wiki.pages - @page.self_and_descendants
265 @reassignable_to = @wiki.pages - @page.self_and_descendants
266 return
266 # display the destroy form if it's a user request
267 return unless api_request?
267 end
268 end
268 end
269 end
269 @page.destroy
270 @page.destroy
270 redirect_to :action => 'index', :project_id => @project
271 respond_to do |format|
272 format.html { redirect_to :action => 'index', :project_id => @project }
273 format.api { render_api_ok }
274 end
271 end
275 end
272
276
273 def destroy_version
277 def destroy_version
274 return render_403 unless editable?
278 return render_403 unless editable?
275
279
276 @content = @page.content_for_version(params[:version])
280 @content = @page.content_for_version(params[:version])
277 @content.destroy
281 @content.destroy
278 redirect_to_referer_or :action => 'history', :id => @page.title, :project_id => @project
282 redirect_to_referer_or :action => 'history', :id => @page.title, :project_id => @project
279 end
283 end
280
284
281 # Export wiki to a single pdf or html file
285 # Export wiki to a single pdf or html file
282 def export
286 def export
283 @pages = @wiki.pages.all(:order => 'title', :include => [:content, :attachments], :limit => 75)
287 @pages = @wiki.pages.all(:order => 'title', :include => [:content, :attachments], :limit => 75)
284 respond_to do |format|
288 respond_to do |format|
285 format.html {
289 format.html {
286 export = render_to_string :action => 'export_multiple', :layout => false
290 export = render_to_string :action => 'export_multiple', :layout => false
287 send_data(export, :type => 'text/html', :filename => "wiki.html")
291 send_data(export, :type => 'text/html', :filename => "wiki.html")
288 }
292 }
289 format.pdf {
293 format.pdf {
290 send_data(wiki_pages_to_pdf(@pages, @project), :type => 'application/pdf', :filename => "#{@project.identifier}.pdf")
294 send_data(wiki_pages_to_pdf(@pages, @project), :type => 'application/pdf', :filename => "#{@project.identifier}.pdf")
291 }
295 }
292 end
296 end
293 end
297 end
294
298
295 def preview
299 def preview
296 page = @wiki.find_page(params[:id])
300 page = @wiki.find_page(params[:id])
297 # page is nil when previewing a new page
301 # page is nil when previewing a new page
298 return render_403 unless page.nil? || editable?(page)
302 return render_403 unless page.nil? || editable?(page)
299 if page
303 if page
300 @attachements = page.attachments
304 @attachements = page.attachments
301 @previewed = page.content
305 @previewed = page.content
302 end
306 end
303 @text = params[:content][:text]
307 @text = params[:content][:text]
304 render :partial => 'common/preview'
308 render :partial => 'common/preview'
305 end
309 end
306
310
307 def add_attachment
311 def add_attachment
308 return render_403 unless editable?
312 return render_403 unless editable?
309 attachments = Attachment.attach_files(@page, params[:attachments])
313 attachments = Attachment.attach_files(@page, params[:attachments])
310 render_attachment_warning_if_needed(@page)
314 render_attachment_warning_if_needed(@page)
311 redirect_to :action => 'show', :id => @page.title, :project_id => @project
315 redirect_to :action => 'show', :id => @page.title, :project_id => @project
312 end
316 end
313
317
314 private
318 private
315
319
316 def find_wiki
320 def find_wiki
317 @project = Project.find(params[:project_id])
321 @project = Project.find(params[:project_id])
318 @wiki = @project.wiki
322 @wiki = @project.wiki
319 render_404 unless @wiki
323 render_404 unless @wiki
320 rescue ActiveRecord::RecordNotFound
324 rescue ActiveRecord::RecordNotFound
321 render_404
325 render_404
322 end
326 end
323
327
324 # Finds the requested page or a new page if it doesn't exist
328 # Finds the requested page or a new page if it doesn't exist
325 def find_existing_or_new_page
329 def find_existing_or_new_page
326 @page = @wiki.find_or_new_page(params[:id])
330 @page = @wiki.find_or_new_page(params[:id])
327 if @wiki.page_found_with_redirect?
331 if @wiki.page_found_with_redirect?
328 redirect_to params.update(:id => @page.title)
332 redirect_to params.update(:id => @page.title)
329 end
333 end
330 end
334 end
331
335
332 # Finds the requested page and returns a 404 error if it doesn't exist
336 # Finds the requested page and returns a 404 error if it doesn't exist
333 def find_existing_page
337 def find_existing_page
334 @page = @wiki.find_page(params[:id])
338 @page = @wiki.find_page(params[:id])
335 if @page.nil?
339 if @page.nil?
336 render_404
340 render_404
337 return
341 return
338 end
342 end
339 if @wiki.page_found_with_redirect?
343 if @wiki.page_found_with_redirect?
340 redirect_to params.update(:id => @page.title)
344 redirect_to params.update(:id => @page.title)
341 end
345 end
342 end
346 end
343
347
344 # Returns true if the current user is allowed to edit the page, otherwise false
348 # Returns true if the current user is allowed to edit the page, otherwise false
345 def editable?(page = @page)
349 def editable?(page = @page)
346 page.editable_by?(User.current)
350 page.editable_by?(User.current)
347 end
351 end
348
352
349 # Returns the default content of a new wiki page
353 # Returns the default content of a new wiki page
350 def initial_page_content(page)
354 def initial_page_content(page)
351 helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting)
355 helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting)
352 extend helper unless self.instance_of?(helper)
356 extend helper unless self.instance_of?(helper)
353 helper.instance_method(:initial_page_content).bind(self).call(page)
357 helper.instance_method(:initial_page_content).bind(self).call(page)
354 end
358 end
355
359
356 def load_pages_for_index
360 def load_pages_for_index
357 @pages = @wiki.pages.with_updated_on.order("#{WikiPage.table_name}.title").includes(:wiki => :project).includes(:parent).all
361 @pages = @wiki.pages.with_updated_on.order("#{WikiPage.table_name}.title").includes(:wiki => :project).includes(:parent).all
358 end
362 end
359 end
363 end
@@ -1,184 +1,193
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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
19
20 class ApiTest::WikiPagesTest < ActionController::IntegrationTest
20 class ApiTest::WikiPagesTest < ActionController::IntegrationTest
21 fixtures :projects, :users, :roles, :members, :member_roles,
21 fixtures :projects, :users, :roles, :members, :member_roles,
22 :enabled_modules, :wikis, :wiki_pages, :wiki_contents,
22 :enabled_modules, :wikis, :wiki_pages, :wiki_contents,
23 :wiki_content_versions, :attachments
23 :wiki_content_versions, :attachments
24
24
25 def setup
25 def setup
26 Setting.rest_api_enabled = '1'
26 Setting.rest_api_enabled = '1'
27 end
27 end
28
28
29 test "GET /projects/:project_id/wiki/index.xml should return wiki pages" do
29 test "GET /projects/:project_id/wiki/index.xml should return wiki pages" do
30 get '/projects/ecookbook/wiki/index.xml'
30 get '/projects/ecookbook/wiki/index.xml'
31 assert_response 200
31 assert_response 200
32 assert_equal 'application/xml', response.content_type
32 assert_equal 'application/xml', response.content_type
33 assert_select 'wiki_pages[type=array]' do
33 assert_select 'wiki_pages[type=array]' do
34 assert_select 'wiki_page', :count => Wiki.find(1).pages.count
34 assert_select 'wiki_page', :count => Wiki.find(1).pages.count
35 assert_select 'wiki_page' do
35 assert_select 'wiki_page' do
36 assert_select 'title', :text => 'CookBook_documentation'
36 assert_select 'title', :text => 'CookBook_documentation'
37 assert_select 'version', :text => '3'
37 assert_select 'version', :text => '3'
38 assert_select 'created_on'
38 assert_select 'created_on'
39 assert_select 'updated_on'
39 assert_select 'updated_on'
40 end
40 end
41 assert_select 'wiki_page' do
41 assert_select 'wiki_page' do
42 assert_select 'title', :text => 'Page_with_an_inline_image'
42 assert_select 'title', :text => 'Page_with_an_inline_image'
43 assert_select 'parent[title=?]', 'CookBook_documentation'
43 assert_select 'parent[title=?]', 'CookBook_documentation'
44 end
44 end
45 end
45 end
46 end
46 end
47
47
48 test "GET /projects/:project_id/wiki/:title.xml should return wiki page" do
48 test "GET /projects/:project_id/wiki/:title.xml should return wiki page" do
49 get '/projects/ecookbook/wiki/CookBook_documentation.xml'
49 get '/projects/ecookbook/wiki/CookBook_documentation.xml'
50 assert_response 200
50 assert_response 200
51 assert_equal 'application/xml', response.content_type
51 assert_equal 'application/xml', response.content_type
52 assert_select 'wiki_page' do
52 assert_select 'wiki_page' do
53 assert_select 'title', :text => 'CookBook_documentation'
53 assert_select 'title', :text => 'CookBook_documentation'
54 assert_select 'version', :text => '3'
54 assert_select 'version', :text => '3'
55 assert_select 'text'
55 assert_select 'text'
56 assert_select 'author'
56 assert_select 'author'
57 assert_select 'comments'
57 assert_select 'comments'
58 assert_select 'created_on'
58 assert_select 'created_on'
59 assert_select 'updated_on'
59 assert_select 'updated_on'
60 end
60 end
61 end
61 end
62
62
63 test "GET /projects/:project_id/wiki/:title.xml?include=attachments should include attachments" do
63 test "GET /projects/:project_id/wiki/:title.xml?include=attachments should include attachments" do
64 get '/projects/ecookbook/wiki/Page_with_an_inline_image.xml?include=attachments'
64 get '/projects/ecookbook/wiki/Page_with_an_inline_image.xml?include=attachments'
65 assert_response 200
65 assert_response 200
66 assert_equal 'application/xml', response.content_type
66 assert_equal 'application/xml', response.content_type
67 assert_select 'wiki_page' do
67 assert_select 'wiki_page' do
68 assert_select 'title', :text => 'Page_with_an_inline_image'
68 assert_select 'title', :text => 'Page_with_an_inline_image'
69 assert_select 'attachments[type=array]' do
69 assert_select 'attachments[type=array]' do
70 assert_select 'attachment' do
70 assert_select 'attachment' do
71 assert_select 'id', :text => '3'
71 assert_select 'id', :text => '3'
72 assert_select 'filename', :text => 'logo.gif'
72 assert_select 'filename', :text => 'logo.gif'
73 end
73 end
74 end
74 end
75 end
75 end
76 end
76 end
77
77
78 test "GET /projects/:project_id/wiki/:title.xml with unknown title and edit permission should respond with 404" do
78 test "GET /projects/:project_id/wiki/:title.xml with unknown title and edit permission should respond with 404" do
79 get '/projects/ecookbook/wiki/Invalid_Page.xml', {}, credentials('jsmith')
79 get '/projects/ecookbook/wiki/Invalid_Page.xml', {}, credentials('jsmith')
80 assert_response 404
80 assert_response 404
81 assert_equal 'application/xml', response.content_type
81 assert_equal 'application/xml', response.content_type
82 end
82 end
83
83
84 test "GET /projects/:project_id/wiki/:title/:version.xml should return wiki page version" do
84 test "GET /projects/:project_id/wiki/:title/:version.xml should return wiki page version" do
85 get '/projects/ecookbook/wiki/CookBook_documentation/2.xml'
85 get '/projects/ecookbook/wiki/CookBook_documentation/2.xml'
86 assert_response 200
86 assert_response 200
87 assert_equal 'application/xml', response.content_type
87 assert_equal 'application/xml', response.content_type
88 assert_select 'wiki_page' do
88 assert_select 'wiki_page' do
89 assert_select 'title', :text => 'CookBook_documentation'
89 assert_select 'title', :text => 'CookBook_documentation'
90 assert_select 'version', :text => '2'
90 assert_select 'version', :text => '2'
91 assert_select 'text'
91 assert_select 'text'
92 assert_select 'author'
92 assert_select 'author'
93 assert_select 'created_on'
93 assert_select 'created_on'
94 assert_select 'updated_on'
94 assert_select 'updated_on'
95 end
95 end
96 end
96 end
97
97
98 test "GET /projects/:project_id/wiki/:title/:version.xml without permission should be denied" do
98 test "GET /projects/:project_id/wiki/:title/:version.xml without permission should be denied" do
99 Role.anonymous.remove_permission! :view_wiki_edits
99 Role.anonymous.remove_permission! :view_wiki_edits
100
100
101 get '/projects/ecookbook/wiki/CookBook_documentation/2.xml'
101 get '/projects/ecookbook/wiki/CookBook_documentation/2.xml'
102 assert_response 401
102 assert_response 401
103 assert_equal 'application/xml', response.content_type
103 assert_equal 'application/xml', response.content_type
104 end
104 end
105
105
106 test "PUT /projects/:project_id/wiki/:title.xml should update wiki page" do
106 test "PUT /projects/:project_id/wiki/:title.xml should update wiki page" do
107 assert_no_difference 'WikiPage.count' do
107 assert_no_difference 'WikiPage.count' do
108 assert_difference 'WikiContent::Version.count' do
108 assert_difference 'WikiContent::Version.count' do
109 put '/projects/ecookbook/wiki/CookBook_documentation.xml',
109 put '/projects/ecookbook/wiki/CookBook_documentation.xml',
110 {:wiki_page => {:text => 'New content from API', :comments => 'API update'}},
110 {:wiki_page => {:text => 'New content from API', :comments => 'API update'}},
111 credentials('jsmith')
111 credentials('jsmith')
112 assert_response 200
112 assert_response 200
113 end
113 end
114 end
114 end
115
115
116 page = WikiPage.find(1)
116 page = WikiPage.find(1)
117 assert_equal 'New content from API', page.content.text
117 assert_equal 'New content from API', page.content.text
118 assert_equal 4, page.content.version
118 assert_equal 4, page.content.version
119 assert_equal 'API update', page.content.comments
119 assert_equal 'API update', page.content.comments
120 assert_equal 'jsmith', page.content.author.login
120 assert_equal 'jsmith', page.content.author.login
121 end
121 end
122
122
123 test "PUT /projects/:project_id/wiki/:title.xml with current versino should update wiki page" do
123 test "PUT /projects/:project_id/wiki/:title.xml with current versino should update wiki page" do
124 assert_no_difference 'WikiPage.count' do
124 assert_no_difference 'WikiPage.count' do
125 assert_difference 'WikiContent::Version.count' do
125 assert_difference 'WikiContent::Version.count' do
126 put '/projects/ecookbook/wiki/CookBook_documentation.xml',
126 put '/projects/ecookbook/wiki/CookBook_documentation.xml',
127 {:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '3'}},
127 {:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '3'}},
128 credentials('jsmith')
128 credentials('jsmith')
129 assert_response 200
129 assert_response 200
130 end
130 end
131 end
131 end
132
132
133 page = WikiPage.find(1)
133 page = WikiPage.find(1)
134 assert_equal 'New content from API', page.content.text
134 assert_equal 'New content from API', page.content.text
135 assert_equal 4, page.content.version
135 assert_equal 4, page.content.version
136 assert_equal 'API update', page.content.comments
136 assert_equal 'API update', page.content.comments
137 assert_equal 'jsmith', page.content.author.login
137 assert_equal 'jsmith', page.content.author.login
138 end
138 end
139
139
140 test "PUT /projects/:project_id/wiki/:title.xml with stale version should respond with 409" do
140 test "PUT /projects/:project_id/wiki/:title.xml with stale version should respond with 409" do
141 assert_no_difference 'WikiPage.count' do
141 assert_no_difference 'WikiPage.count' do
142 assert_no_difference 'WikiContent::Version.count' do
142 assert_no_difference 'WikiContent::Version.count' do
143 put '/projects/ecookbook/wiki/CookBook_documentation.xml',
143 put '/projects/ecookbook/wiki/CookBook_documentation.xml',
144 {:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '2'}},
144 {:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '2'}},
145 credentials('jsmith')
145 credentials('jsmith')
146 assert_response 409
146 assert_response 409
147 end
147 end
148 end
148 end
149 end
149 end
150
150
151 test "PUT /projects/:project_id/wiki/:title.xml should create the page if it does not exist" do
151 test "PUT /projects/:project_id/wiki/:title.xml should create the page if it does not exist" do
152 assert_difference 'WikiPage.count' do
152 assert_difference 'WikiPage.count' do
153 assert_difference 'WikiContent::Version.count' do
153 assert_difference 'WikiContent::Version.count' do
154 put '/projects/ecookbook/wiki/New_page_from_API.xml',
154 put '/projects/ecookbook/wiki/New_page_from_API.xml',
155 {:wiki_page => {:text => 'New content from API', :comments => 'API create'}},
155 {:wiki_page => {:text => 'New content from API', :comments => 'API create'}},
156 credentials('jsmith')
156 credentials('jsmith')
157 assert_response 201
157 assert_response 201
158 end
158 end
159 end
159 end
160
160
161 page = WikiPage.order('id DESC').first
161 page = WikiPage.order('id DESC').first
162 assert_equal 'New_page_from_API', page.title
162 assert_equal 'New_page_from_API', page.title
163 assert_equal 'New content from API', page.content.text
163 assert_equal 'New content from API', page.content.text
164 assert_equal 1, page.content.version
164 assert_equal 1, page.content.version
165 assert_equal 'API create', page.content.comments
165 assert_equal 'API create', page.content.comments
166 assert_equal 'jsmith', page.content.author.login
166 assert_equal 'jsmith', page.content.author.login
167 assert_nil page.parent
167 assert_nil page.parent
168 end
168 end
169
169
170 test "PUT /projects/:project_id/wiki/:title.xml with parent" do
170 test "PUT /projects/:project_id/wiki/:title.xml with parent" do
171 assert_difference 'WikiPage.count' do
171 assert_difference 'WikiPage.count' do
172 assert_difference 'WikiContent::Version.count' do
172 assert_difference 'WikiContent::Version.count' do
173 put '/projects/ecookbook/wiki/New_subpage_from_API.xml',
173 put '/projects/ecookbook/wiki/New_subpage_from_API.xml',
174 {:wiki_page => {:parent_title => 'CookBook_documentation', :text => 'New content from API', :comments => 'API create'}},
174 {:wiki_page => {:parent_title => 'CookBook_documentation', :text => 'New content from API', :comments => 'API create'}},
175 credentials('jsmith')
175 credentials('jsmith')
176 assert_response 201
176 assert_response 201
177 end
177 end
178 end
178 end
179
179
180 page = WikiPage.order('id DESC').first
180 page = WikiPage.order('id DESC').first
181 assert_equal 'New_subpage_from_API', page.title
181 assert_equal 'New_subpage_from_API', page.title
182 assert_equal WikiPage.find(1), page.parent
182 assert_equal WikiPage.find(1), page.parent
183 end
183 end
184
185 test "DELETE /projects/:project_id/wiki/:title.xml should destroy the page" do
186 assert_difference 'WikiPage.count', -1 do
187 delete '/projects/ecookbook/wiki/CookBook_documentation.xml', {}, credentials('jsmith')
188 assert_response 200
189 end
190
191 assert_nil WikiPage.find_by_id(1)
192 end
184 end
193 end
@@ -1,172 +1,182
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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
19
20 class RoutingWikiTest < ActionController::IntegrationTest
20 class RoutingWikiTest < ActionController::IntegrationTest
21 def test_wiki_matching
21 def test_wiki_matching
22 assert_routing(
22 assert_routing(
23 { :method => 'get', :path => "/projects/567/wiki" },
23 { :method => 'get', :path => "/projects/567/wiki" },
24 { :controller => 'wiki', :action => 'show', :project_id => '567' }
24 { :controller => 'wiki', :action => 'show', :project_id => '567' }
25 )
25 )
26 assert_routing(
26 assert_routing(
27 { :method => 'get', :path => "/projects/567/wiki/lalala" },
27 { :method => 'get', :path => "/projects/567/wiki/lalala" },
28 { :controller => 'wiki', :action => 'show', :project_id => '567',
28 { :controller => 'wiki', :action => 'show', :project_id => '567',
29 :id => 'lalala' }
29 :id => 'lalala' }
30 )
30 )
31 assert_routing(
31 assert_routing(
32 { :method => 'get', :path => "/projects/567/wiki/lalala.pdf" },
32 { :method => 'get', :path => "/projects/567/wiki/lalala.pdf" },
33 { :controller => 'wiki', :action => 'show', :project_id => '567',
33 { :controller => 'wiki', :action => 'show', :project_id => '567',
34 :id => 'lalala', :format => 'pdf' }
34 :id => 'lalala', :format => 'pdf' }
35 )
35 )
36 assert_routing(
36 assert_routing(
37 { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/diff" },
37 { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/diff" },
38 { :controller => 'wiki', :action => 'diff', :project_id => '1',
38 { :controller => 'wiki', :action => 'diff', :project_id => '1',
39 :id => 'CookBook_documentation' }
39 :id => 'CookBook_documentation' }
40 )
40 )
41 assert_routing(
41 assert_routing(
42 { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/2" },
42 { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/2" },
43 { :controller => 'wiki', :action => 'show', :project_id => '1',
43 { :controller => 'wiki', :action => 'show', :project_id => '1',
44 :id => 'CookBook_documentation', :version => '2' }
44 :id => 'CookBook_documentation', :version => '2' }
45 )
45 )
46 assert_routing(
46 assert_routing(
47 { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/2/diff" },
47 { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/2/diff" },
48 { :controller => 'wiki', :action => 'diff', :project_id => '1',
48 { :controller => 'wiki', :action => 'diff', :project_id => '1',
49 :id => 'CookBook_documentation', :version => '2' }
49 :id => 'CookBook_documentation', :version => '2' }
50 )
50 )
51 assert_routing(
51 assert_routing(
52 { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/2/annotate" },
52 { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/2/annotate" },
53 { :controller => 'wiki', :action => 'annotate', :project_id => '1',
53 { :controller => 'wiki', :action => 'annotate', :project_id => '1',
54 :id => 'CookBook_documentation', :version => '2' }
54 :id => 'CookBook_documentation', :version => '2' }
55 )
55 )
56 end
56 end
57
57
58 def test_wiki_misc
58 def test_wiki_misc
59 assert_routing(
59 assert_routing(
60 { :method => 'get', :path => "/projects/567/wiki/date_index" },
60 { :method => 'get', :path => "/projects/567/wiki/date_index" },
61 { :controller => 'wiki', :action => 'date_index', :project_id => '567' }
61 { :controller => 'wiki', :action => 'date_index', :project_id => '567' }
62 )
62 )
63 assert_routing(
63 assert_routing(
64 { :method => 'get', :path => "/projects/567/wiki/export" },
64 { :method => 'get', :path => "/projects/567/wiki/export" },
65 { :controller => 'wiki', :action => 'export', :project_id => '567' }
65 { :controller => 'wiki', :action => 'export', :project_id => '567' }
66 )
66 )
67 assert_routing(
67 assert_routing(
68 { :method => 'get', :path => "/projects/567/wiki/export.pdf" },
68 { :method => 'get', :path => "/projects/567/wiki/export.pdf" },
69 { :controller => 'wiki', :action => 'export', :project_id => '567', :format => 'pdf' }
69 { :controller => 'wiki', :action => 'export', :project_id => '567', :format => 'pdf' }
70 )
70 )
71 assert_routing(
71 assert_routing(
72 { :method => 'get', :path => "/projects/567/wiki/index" },
72 { :method => 'get', :path => "/projects/567/wiki/index" },
73 { :controller => 'wiki', :action => 'index', :project_id => '567' }
73 { :controller => 'wiki', :action => 'index', :project_id => '567' }
74 )
74 )
75 end
75 end
76
76
77 def test_wiki_resources
77 def test_wiki_resources
78 assert_routing(
78 assert_routing(
79 { :method => 'get', :path => "/projects/567/wiki/my_page/edit" },
79 { :method => 'get', :path => "/projects/567/wiki/my_page/edit" },
80 { :controller => 'wiki', :action => 'edit', :project_id => '567',
80 { :controller => 'wiki', :action => 'edit', :project_id => '567',
81 :id => 'my_page' }
81 :id => 'my_page' }
82 )
82 )
83 assert_routing(
83 assert_routing(
84 { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/history" },
84 { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/history" },
85 { :controller => 'wiki', :action => 'history', :project_id => '1',
85 { :controller => 'wiki', :action => 'history', :project_id => '1',
86 :id => 'CookBook_documentation' }
86 :id => 'CookBook_documentation' }
87 )
87 )
88 assert_routing(
88 assert_routing(
89 { :method => 'get', :path => "/projects/22/wiki/ladida/rename" },
89 { :method => 'get', :path => "/projects/22/wiki/ladida/rename" },
90 { :controller => 'wiki', :action => 'rename', :project_id => '22',
90 { :controller => 'wiki', :action => 'rename', :project_id => '22',
91 :id => 'ladida' }
91 :id => 'ladida' }
92 )
92 )
93 ["post", "put"].each do |method|
93 ["post", "put"].each do |method|
94 assert_routing(
94 assert_routing(
95 { :method => method, :path => "/projects/567/wiki/CookBook_documentation/preview" },
95 { :method => method, :path => "/projects/567/wiki/CookBook_documentation/preview" },
96 { :controller => 'wiki', :action => 'preview', :project_id => '567',
96 { :controller => 'wiki', :action => 'preview', :project_id => '567',
97 :id => 'CookBook_documentation' }
97 :id => 'CookBook_documentation' }
98 )
98 )
99 end
99 end
100 assert_routing(
100 assert_routing(
101 { :method => 'post', :path => "/projects/22/wiki/ladida/rename" },
101 { :method => 'post', :path => "/projects/22/wiki/ladida/rename" },
102 { :controller => 'wiki', :action => 'rename', :project_id => '22',
102 { :controller => 'wiki', :action => 'rename', :project_id => '22',
103 :id => 'ladida' }
103 :id => 'ladida' }
104 )
104 )
105 assert_routing(
105 assert_routing(
106 { :method => 'post', :path => "/projects/22/wiki/ladida/protect" },
106 { :method => 'post', :path => "/projects/22/wiki/ladida/protect" },
107 { :controller => 'wiki', :action => 'protect', :project_id => '22',
107 { :controller => 'wiki', :action => 'protect', :project_id => '22',
108 :id => 'ladida' }
108 :id => 'ladida' }
109 )
109 )
110 assert_routing(
110 assert_routing(
111 { :method => 'post', :path => "/projects/22/wiki/ladida/add_attachment" },
111 { :method => 'post', :path => "/projects/22/wiki/ladida/add_attachment" },
112 { :controller => 'wiki', :action => 'add_attachment', :project_id => '22',
112 { :controller => 'wiki', :action => 'add_attachment', :project_id => '22',
113 :id => 'ladida' }
113 :id => 'ladida' }
114 )
114 )
115 assert_routing(
115 assert_routing(
116 { :method => 'put', :path => "/projects/567/wiki/my_page" },
116 { :method => 'put', :path => "/projects/567/wiki/my_page" },
117 { :controller => 'wiki', :action => 'update', :project_id => '567',
117 { :controller => 'wiki', :action => 'update', :project_id => '567',
118 :id => 'my_page' }
118 :id => 'my_page' }
119 )
119 )
120 assert_routing(
120 assert_routing(
121 { :method => 'delete', :path => "/projects/22/wiki/ladida" },
121 { :method => 'delete', :path => "/projects/22/wiki/ladida" },
122 { :controller => 'wiki', :action => 'destroy', :project_id => '22',
122 { :controller => 'wiki', :action => 'destroy', :project_id => '22',
123 :id => 'ladida' }
123 :id => 'ladida' }
124 )
124 )
125 assert_routing(
125 assert_routing(
126 { :method => 'delete', :path => "/projects/22/wiki/ladida/3" },
126 { :method => 'delete', :path => "/projects/22/wiki/ladida/3" },
127 { :controller => 'wiki', :action => 'destroy_version', :project_id => '22',
127 { :controller => 'wiki', :action => 'destroy_version', :project_id => '22',
128 :id => 'ladida', :version => '3' }
128 :id => 'ladida', :version => '3' }
129 )
129 )
130 end
130 end
131
131
132 def test_api
132 def test_api
133 assert_routing(
133 assert_routing(
134 { :method => 'get', :path => "/projects/567/wiki/my_page.xml" },
134 { :method => 'get', :path => "/projects/567/wiki/my_page.xml" },
135 { :controller => 'wiki', :action => 'show', :project_id => '567',
135 { :controller => 'wiki', :action => 'show', :project_id => '567',
136 :id => 'my_page', :format => 'xml' }
136 :id => 'my_page', :format => 'xml' }
137 )
137 )
138 assert_routing(
138 assert_routing(
139 { :method => 'get', :path => "/projects/567/wiki/my_page.json" },
139 { :method => 'get', :path => "/projects/567/wiki/my_page.json" },
140 { :controller => 'wiki', :action => 'show', :project_id => '567',
140 { :controller => 'wiki', :action => 'show', :project_id => '567',
141 :id => 'my_page', :format => 'json' }
141 :id => 'my_page', :format => 'json' }
142 )
142 )
143 assert_routing(
143 assert_routing(
144 { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/2.xml" },
144 { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/2.xml" },
145 { :controller => 'wiki', :action => 'show', :project_id => '1',
145 { :controller => 'wiki', :action => 'show', :project_id => '1',
146 :id => 'CookBook_documentation', :version => '2', :format => 'xml' }
146 :id => 'CookBook_documentation', :version => '2', :format => 'xml' }
147 )
147 )
148 assert_routing(
148 assert_routing(
149 { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/2.json" },
149 { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/2.json" },
150 { :controller => 'wiki', :action => 'show', :project_id => '1',
150 { :controller => 'wiki', :action => 'show', :project_id => '1',
151 :id => 'CookBook_documentation', :version => '2', :format => 'json' }
151 :id => 'CookBook_documentation', :version => '2', :format => 'json' }
152 )
152 )
153 assert_routing(
153 assert_routing(
154 { :method => 'get', :path => "/projects/567/wiki/index.xml" },
154 { :method => 'get', :path => "/projects/567/wiki/index.xml" },
155 { :controller => 'wiki', :action => 'index', :project_id => '567', :format => 'xml' }
155 { :controller => 'wiki', :action => 'index', :project_id => '567', :format => 'xml' }
156 )
156 )
157 assert_routing(
157 assert_routing(
158 { :method => 'get', :path => "/projects/567/wiki/index.json" },
158 { :method => 'get', :path => "/projects/567/wiki/index.json" },
159 { :controller => 'wiki', :action => 'index', :project_id => '567', :format => 'json' }
159 { :controller => 'wiki', :action => 'index', :project_id => '567', :format => 'json' }
160 )
160 )
161 assert_routing(
161 assert_routing(
162 { :method => 'put', :path => "/projects/567/wiki/my_page.xml" },
162 { :method => 'put', :path => "/projects/567/wiki/my_page.xml" },
163 { :controller => 'wiki', :action => 'update', :project_id => '567',
163 { :controller => 'wiki', :action => 'update', :project_id => '567',
164 :id => 'my_page', :format => 'xml' }
164 :id => 'my_page', :format => 'xml' }
165 )
165 )
166 assert_routing(
166 assert_routing(
167 { :method => 'put', :path => "/projects/567/wiki/my_page.json" },
167 { :method => 'put', :path => "/projects/567/wiki/my_page.json" },
168 { :controller => 'wiki', :action => 'update', :project_id => '567',
168 { :controller => 'wiki', :action => 'update', :project_id => '567',
169 :id => 'my_page', :format => 'json' }
169 :id => 'my_page', :format => 'json' }
170 )
170 )
171 assert_routing(
172 { :method => 'delete', :path => "/projects/567/wiki/my_page.xml" },
173 { :controller => 'wiki', :action => 'destroy', :project_id => '567',
174 :id => 'my_page', :format => 'xml' }
175 )
176 assert_routing(
177 { :method => 'delete', :path => "/projects/567/wiki/my_page.json" },
178 { :controller => 'wiki', :action => 'destroy', :project_id => '567',
179 :id => 'my_page', :format => 'json' }
180 )
171 end
181 end
172 end
182 end
General Comments 0
You need to be logged in to leave comments. Login now