@@ -1,387 +1,389 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2016 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 | # The WikiController follows the Rails REST controller pattern but with |
|
18 | # The WikiController follows the Rails REST controller pattern but with | |
19 | # a few differences |
|
19 | # a few differences | |
20 | # |
|
20 | # | |
21 | # * index - shows a list of WikiPages grouped by page or date |
|
21 | # * index - shows a list of WikiPages grouped by page or date | |
22 | # * new - not used |
|
22 | # * new - not used | |
23 | # * create - not used |
|
23 | # * create - not used | |
24 | # * show - will also show the form for creating a new wiki page |
|
24 | # * show - will also show the form for creating a new wiki page | |
25 | # * edit - used to edit an existing or new page |
|
25 | # * edit - used to edit an existing or new page | |
26 | # * update - used to save a wiki page update to the database, including new pages |
|
26 | # * update - used to save a wiki page update to the database, including new pages | |
27 | # * destroy - normal |
|
27 | # * destroy - normal | |
28 | # |
|
28 | # | |
29 | # Other member and collection methods are also used |
|
29 | # Other member and collection methods are also used | |
30 | # |
|
30 | # | |
31 | # TODO: still being worked on |
|
31 | # TODO: still being worked on | |
32 | class WikiController < ApplicationController |
|
32 | class WikiController < ApplicationController | |
33 | default_search_scope :wiki_pages |
|
33 | default_search_scope :wiki_pages | |
34 | before_action :find_wiki, :authorize |
|
34 | before_action :find_wiki, :authorize | |
35 | before_action :find_existing_or_new_page, :only => [:show, :edit, :update] |
|
35 | before_action :find_existing_or_new_page, :only => [:show, :edit, :update] | |
36 | before_action :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy, :destroy_version] |
|
36 | before_action :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy, :destroy_version] | |
37 | before_action :find_attachments, :only => [:preview] |
|
37 | before_action :find_attachments, :only => [:preview] | |
38 | accept_api_auth :index, :show, :update, :destroy |
|
38 | accept_api_auth :index, :show, :update, :destroy | |
39 |
|
39 | |||
40 | helper :attachments |
|
40 | helper :attachments | |
41 | include AttachmentsHelper |
|
41 | include AttachmentsHelper | |
42 | helper :watchers |
|
42 | helper :watchers | |
43 | include Redmine::Export::PDF |
|
43 | include Redmine::Export::PDF | |
44 |
|
44 | |||
45 | # List of pages, sorted alphabetically and by parent (hierarchy) |
|
45 | # List of pages, sorted alphabetically and by parent (hierarchy) | |
46 | def index |
|
46 | def index | |
47 | load_pages_for_index |
|
47 | load_pages_for_index | |
48 |
|
48 | |||
49 | respond_to do |format| |
|
49 | respond_to do |format| | |
50 | format.html { |
|
50 | format.html { | |
51 | @pages_by_parent_id = @pages.group_by(&:parent_id) |
|
51 | @pages_by_parent_id = @pages.group_by(&:parent_id) | |
52 | } |
|
52 | } | |
53 | format.api |
|
53 | format.api | |
54 | end |
|
54 | end | |
55 | end |
|
55 | end | |
56 |
|
56 | |||
57 | # List of page, by last update |
|
57 | # List of page, by last update | |
58 | def date_index |
|
58 | def date_index | |
59 | load_pages_for_index |
|
59 | load_pages_for_index | |
60 | @pages_by_date = @pages.group_by {|p| p.updated_on.to_date} |
|
60 | @pages_by_date = @pages.group_by {|p| p.updated_on.to_date} | |
61 | end |
|
61 | end | |
62 |
|
62 | |||
63 | def new |
|
63 | def new | |
64 | @page = WikiPage.new(:wiki => @wiki, :title => params[:title]) |
|
64 | @page = WikiPage.new(:wiki => @wiki, :title => params[:title]) | |
65 |
unless User.current.allowed_to?(:edit_wiki_pages, @project) |
|
65 | unless User.current.allowed_to?(:edit_wiki_pages, @project) | |
66 | render_403 |
|
66 | render_403 | |
|
67 | return | |||
67 | end |
|
68 | end | |
68 | if request.post? |
|
69 | if request.post? | |
|
70 | @page.title = '' unless editable? | |||
69 | @page.validate |
|
71 | @page.validate | |
70 | if @page.errors[:title].blank? |
|
72 | if @page.errors[:title].blank? | |
71 | path = project_wiki_page_path(@project, @page.title) |
|
73 | path = project_wiki_page_path(@project, @page.title) | |
72 | respond_to do |format| |
|
74 | respond_to do |format| | |
73 | format.html { redirect_to path } |
|
75 | format.html { redirect_to path } | |
74 | format.js { render :js => "window.location = #{path.to_json}" } |
|
76 | format.js { render :js => "window.location = #{path.to_json}" } | |
75 | end |
|
77 | end | |
76 | end |
|
78 | end | |
77 | end |
|
79 | end | |
78 | end |
|
80 | end | |
79 |
|
81 | |||
80 | # display a page (in editing mode if it doesn't exist) |
|
82 | # display a page (in editing mode if it doesn't exist) | |
81 | def show |
|
83 | def show | |
82 | if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project) |
|
84 | if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project) | |
83 | deny_access |
|
85 | deny_access | |
84 | return |
|
86 | return | |
85 | end |
|
87 | end | |
86 | @content = @page.content_for_version(params[:version]) |
|
88 | @content = @page.content_for_version(params[:version]) | |
87 | if @content.nil? |
|
89 | if @content.nil? | |
88 | if User.current.allowed_to?(:edit_wiki_pages, @project) && editable? && !api_request? |
|
90 | if User.current.allowed_to?(:edit_wiki_pages, @project) && editable? && !api_request? | |
89 | edit |
|
91 | edit | |
90 | render :action => 'edit' |
|
92 | render :action => 'edit' | |
91 | else |
|
93 | else | |
92 | render_404 |
|
94 | render_404 | |
93 | end |
|
95 | end | |
94 | return |
|
96 | return | |
95 | end |
|
97 | end | |
96 | if User.current.allowed_to?(:export_wiki_pages, @project) |
|
98 | if User.current.allowed_to?(:export_wiki_pages, @project) | |
97 | if params[:format] == 'pdf' |
|
99 | if params[:format] == 'pdf' | |
98 | send_file_headers! :type => 'application/pdf', :filename => "#{@page.title}.pdf" |
|
100 | send_file_headers! :type => 'application/pdf', :filename => "#{@page.title}.pdf" | |
99 | return |
|
101 | return | |
100 | elsif params[:format] == 'html' |
|
102 | elsif params[:format] == 'html' | |
101 | export = render_to_string :action => 'export', :layout => false |
|
103 | export = render_to_string :action => 'export', :layout => false | |
102 | send_data(export, :type => 'text/html', :filename => "#{@page.title}.html") |
|
104 | send_data(export, :type => 'text/html', :filename => "#{@page.title}.html") | |
103 | return |
|
105 | return | |
104 | elsif params[:format] == 'txt' |
|
106 | elsif params[:format] == 'txt' | |
105 | send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt") |
|
107 | send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt") | |
106 | return |
|
108 | return | |
107 | end |
|
109 | end | |
108 | end |
|
110 | end | |
109 | @editable = editable? |
|
111 | @editable = editable? | |
110 | @sections_editable = @editable && User.current.allowed_to?(:edit_wiki_pages, @page.project) && |
|
112 | @sections_editable = @editable && User.current.allowed_to?(:edit_wiki_pages, @page.project) && | |
111 | @content.current_version? && |
|
113 | @content.current_version? && | |
112 | Redmine::WikiFormatting.supports_section_edit? |
|
114 | Redmine::WikiFormatting.supports_section_edit? | |
113 |
|
115 | |||
114 | respond_to do |format| |
|
116 | respond_to do |format| | |
115 | format.html |
|
117 | format.html | |
116 | format.api |
|
118 | format.api | |
117 | end |
|
119 | end | |
118 | end |
|
120 | end | |
119 |
|
121 | |||
120 | # edit an existing page or a new one |
|
122 | # edit an existing page or a new one | |
121 | def edit |
|
123 | def edit | |
122 | return render_403 unless editable? |
|
124 | return render_403 unless editable? | |
123 | if @page.new_record? |
|
125 | if @page.new_record? | |
124 | if params[:parent].present? |
|
126 | if params[:parent].present? | |
125 | @page.parent = @page.wiki.find_page(params[:parent].to_s) |
|
127 | @page.parent = @page.wiki.find_page(params[:parent].to_s) | |
126 | end |
|
128 | end | |
127 | end |
|
129 | end | |
128 |
|
130 | |||
129 | @content = @page.content_for_version(params[:version]) |
|
131 | @content = @page.content_for_version(params[:version]) | |
130 | @content ||= WikiContent.new(:page => @page) |
|
132 | @content ||= WikiContent.new(:page => @page) | |
131 | @content.text = initial_page_content(@page) if @content.text.blank? |
|
133 | @content.text = initial_page_content(@page) if @content.text.blank? | |
132 | # don't keep previous comment |
|
134 | # don't keep previous comment | |
133 | @content.comments = nil |
|
135 | @content.comments = nil | |
134 |
|
136 | |||
135 | # To prevent StaleObjectError exception when reverting to a previous version |
|
137 | # To prevent StaleObjectError exception when reverting to a previous version | |
136 | @content.version = @page.content.version if @page.content |
|
138 | @content.version = @page.content.version if @page.content | |
137 |
|
139 | |||
138 | @text = @content.text |
|
140 | @text = @content.text | |
139 | if params[:section].present? && Redmine::WikiFormatting.supports_section_edit? |
|
141 | if params[:section].present? && Redmine::WikiFormatting.supports_section_edit? | |
140 | @section = params[:section].to_i |
|
142 | @section = params[:section].to_i | |
141 | @text, @section_hash = Redmine::WikiFormatting.formatter.new(@text).get_section(@section) |
|
143 | @text, @section_hash = Redmine::WikiFormatting.formatter.new(@text).get_section(@section) | |
142 | render_404 if @text.blank? |
|
144 | render_404 if @text.blank? | |
143 | end |
|
145 | end | |
144 | end |
|
146 | end | |
145 |
|
147 | |||
146 | # Creates a new page or updates an existing one |
|
148 | # Creates a new page or updates an existing one | |
147 | def update |
|
149 | def update | |
148 | return render_403 unless editable? |
|
150 | return render_403 unless editable? | |
149 | was_new_page = @page.new_record? |
|
151 | was_new_page = @page.new_record? | |
150 | @page.safe_attributes = params[:wiki_page] |
|
152 | @page.safe_attributes = params[:wiki_page] | |
151 |
|
153 | |||
152 | @content = @page.content || WikiContent.new(:page => @page) |
|
154 | @content = @page.content || WikiContent.new(:page => @page) | |
153 | content_params = params[:content] |
|
155 | content_params = params[:content] | |
154 | if content_params.nil? && params[:wiki_page].is_a?(Hash) |
|
156 | if content_params.nil? && params[:wiki_page].is_a?(Hash) | |
155 | content_params = params[:wiki_page].slice(:text, :comments, :version) |
|
157 | content_params = params[:wiki_page].slice(:text, :comments, :version) | |
156 | end |
|
158 | end | |
157 | content_params ||= {} |
|
159 | content_params ||= {} | |
158 |
|
160 | |||
159 | @content.comments = content_params[:comments] |
|
161 | @content.comments = content_params[:comments] | |
160 | @text = content_params[:text] |
|
162 | @text = content_params[:text] | |
161 | if params[:section].present? && Redmine::WikiFormatting.supports_section_edit? |
|
163 | if params[:section].present? && Redmine::WikiFormatting.supports_section_edit? | |
162 | @section = params[:section].to_i |
|
164 | @section = params[:section].to_i | |
163 | @section_hash = params[:section_hash] |
|
165 | @section_hash = params[:section_hash] | |
164 | @content.text = Redmine::WikiFormatting.formatter.new(@content.text).update_section(@section, @text, @section_hash) |
|
166 | @content.text = Redmine::WikiFormatting.formatter.new(@content.text).update_section(@section, @text, @section_hash) | |
165 | else |
|
167 | else | |
166 | @content.version = content_params[:version] if content_params[:version] |
|
168 | @content.version = content_params[:version] if content_params[:version] | |
167 | @content.text = @text |
|
169 | @content.text = @text | |
168 | end |
|
170 | end | |
169 | @content.author = User.current |
|
171 | @content.author = User.current | |
170 |
|
172 | |||
171 | if @page.save_with_content(@content) |
|
173 | if @page.save_with_content(@content) | |
172 | attachments = Attachment.attach_files(@page, params[:attachments] || (params[:wiki_page] && params[:wiki_page][:uploads])) |
|
174 | attachments = Attachment.attach_files(@page, params[:attachments] || (params[:wiki_page] && params[:wiki_page][:uploads])) | |
173 | render_attachment_warning_if_needed(@page) |
|
175 | render_attachment_warning_if_needed(@page) | |
174 | call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page}) |
|
176 | call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page}) | |
175 |
|
177 | |||
176 | respond_to do |format| |
|
178 | respond_to do |format| | |
177 | format.html { |
|
179 | format.html { | |
178 | anchor = @section ? "section-#{@section}" : nil |
|
180 | anchor = @section ? "section-#{@section}" : nil | |
179 | redirect_to project_wiki_page_path(@project, @page.title, :anchor => anchor) |
|
181 | redirect_to project_wiki_page_path(@project, @page.title, :anchor => anchor) | |
180 | } |
|
182 | } | |
181 | format.api { |
|
183 | format.api { | |
182 | if was_new_page |
|
184 | if was_new_page | |
183 | render :action => 'show', :status => :created, :location => project_wiki_page_path(@project, @page.title) |
|
185 | render :action => 'show', :status => :created, :location => project_wiki_page_path(@project, @page.title) | |
184 | else |
|
186 | else | |
185 | render_api_ok |
|
187 | render_api_ok | |
186 | end |
|
188 | end | |
187 | } |
|
189 | } | |
188 | end |
|
190 | end | |
189 | else |
|
191 | else | |
190 | respond_to do |format| |
|
192 | respond_to do |format| | |
191 | format.html { render :action => 'edit' } |
|
193 | format.html { render :action => 'edit' } | |
192 | format.api { render_validation_errors(@content) } |
|
194 | format.api { render_validation_errors(@content) } | |
193 | end |
|
195 | end | |
194 | end |
|
196 | end | |
195 |
|
197 | |||
196 | rescue ActiveRecord::StaleObjectError, Redmine::WikiFormatting::StaleSectionError |
|
198 | rescue ActiveRecord::StaleObjectError, Redmine::WikiFormatting::StaleSectionError | |
197 | # Optimistic locking exception |
|
199 | # Optimistic locking exception | |
198 | respond_to do |format| |
|
200 | respond_to do |format| | |
199 | format.html { |
|
201 | format.html { | |
200 | flash.now[:error] = l(:notice_locking_conflict) |
|
202 | flash.now[:error] = l(:notice_locking_conflict) | |
201 | render :action => 'edit' |
|
203 | render :action => 'edit' | |
202 | } |
|
204 | } | |
203 | format.api { render_api_head :conflict } |
|
205 | format.api { render_api_head :conflict } | |
204 | end |
|
206 | end | |
205 | end |
|
207 | end | |
206 |
|
208 | |||
207 | # rename a page |
|
209 | # rename a page | |
208 | def rename |
|
210 | def rename | |
209 | return render_403 unless editable? |
|
211 | return render_403 unless editable? | |
210 | @page.redirect_existing_links = true |
|
212 | @page.redirect_existing_links = true | |
211 | # used to display the *original* title if some AR validation errors occur |
|
213 | # used to display the *original* title if some AR validation errors occur | |
212 | @original_title = @page.pretty_title |
|
214 | @original_title = @page.pretty_title | |
213 | @page.safe_attributes = params[:wiki_page] |
|
215 | @page.safe_attributes = params[:wiki_page] | |
214 | if request.post? && @page.save |
|
216 | if request.post? && @page.save | |
215 | flash[:notice] = l(:notice_successful_update) |
|
217 | flash[:notice] = l(:notice_successful_update) | |
216 | redirect_to project_wiki_page_path(@page.project, @page.title) |
|
218 | redirect_to project_wiki_page_path(@page.project, @page.title) | |
217 | end |
|
219 | end | |
218 | end |
|
220 | end | |
219 |
|
221 | |||
220 | def protect |
|
222 | def protect | |
221 | @page.update_attribute :protected, params[:protected] |
|
223 | @page.update_attribute :protected, params[:protected] | |
222 | redirect_to project_wiki_page_path(@project, @page.title) |
|
224 | redirect_to project_wiki_page_path(@project, @page.title) | |
223 | end |
|
225 | end | |
224 |
|
226 | |||
225 | # show page history |
|
227 | # show page history | |
226 | def history |
|
228 | def history | |
227 | @version_count = @page.content.versions.count |
|
229 | @version_count = @page.content.versions.count | |
228 | @version_pages = Paginator.new @version_count, per_page_option, params['page'] |
|
230 | @version_pages = Paginator.new @version_count, per_page_option, params['page'] | |
229 | # don't load text |
|
231 | # don't load text | |
230 | @versions = @page.content.versions. |
|
232 | @versions = @page.content.versions. | |
231 | select("id, author_id, comments, updated_on, version"). |
|
233 | select("id, author_id, comments, updated_on, version"). | |
232 | reorder('version DESC'). |
|
234 | reorder('version DESC'). | |
233 | limit(@version_pages.per_page + 1). |
|
235 | limit(@version_pages.per_page + 1). | |
234 | offset(@version_pages.offset). |
|
236 | offset(@version_pages.offset). | |
235 | to_a |
|
237 | to_a | |
236 |
|
238 | |||
237 | render :layout => false if request.xhr? |
|
239 | render :layout => false if request.xhr? | |
238 | end |
|
240 | end | |
239 |
|
241 | |||
240 | def diff |
|
242 | def diff | |
241 | @diff = @page.diff(params[:version], params[:version_from]) |
|
243 | @diff = @page.diff(params[:version], params[:version_from]) | |
242 | render_404 unless @diff |
|
244 | render_404 unless @diff | |
243 | end |
|
245 | end | |
244 |
|
246 | |||
245 | def annotate |
|
247 | def annotate | |
246 | @annotate = @page.annotate(params[:version]) |
|
248 | @annotate = @page.annotate(params[:version]) | |
247 | render_404 unless @annotate |
|
249 | render_404 unless @annotate | |
248 | end |
|
250 | end | |
249 |
|
251 | |||
250 | # Removes a wiki page and its history |
|
252 | # Removes a wiki page and its history | |
251 | # Children can be either set as root pages, removed or reassigned to another parent page |
|
253 | # Children can be either set as root pages, removed or reassigned to another parent page | |
252 | def destroy |
|
254 | def destroy | |
253 | return render_403 unless editable? |
|
255 | return render_403 unless editable? | |
254 |
|
256 | |||
255 | @descendants_count = @page.descendants.size |
|
257 | @descendants_count = @page.descendants.size | |
256 | if @descendants_count > 0 |
|
258 | if @descendants_count > 0 | |
257 | case params[:todo] |
|
259 | case params[:todo] | |
258 | when 'nullify' |
|
260 | when 'nullify' | |
259 | # Nothing to do |
|
261 | # Nothing to do | |
260 | when 'destroy' |
|
262 | when 'destroy' | |
261 | # Removes all its descendants |
|
263 | # Removes all its descendants | |
262 | @page.descendants.each(&:destroy) |
|
264 | @page.descendants.each(&:destroy) | |
263 | when 'reassign' |
|
265 | when 'reassign' | |
264 | # Reassign children to another parent page |
|
266 | # Reassign children to another parent page | |
265 | reassign_to = @wiki.pages.find_by_id(params[:reassign_to_id].to_i) |
|
267 | reassign_to = @wiki.pages.find_by_id(params[:reassign_to_id].to_i) | |
266 | return unless reassign_to |
|
268 | return unless reassign_to | |
267 | @page.children.each do |child| |
|
269 | @page.children.each do |child| | |
268 | child.update_attribute(:parent, reassign_to) |
|
270 | child.update_attribute(:parent, reassign_to) | |
269 | end |
|
271 | end | |
270 | else |
|
272 | else | |
271 | @reassignable_to = @wiki.pages - @page.self_and_descendants |
|
273 | @reassignable_to = @wiki.pages - @page.self_and_descendants | |
272 | # display the destroy form if it's a user request |
|
274 | # display the destroy form if it's a user request | |
273 | return unless api_request? |
|
275 | return unless api_request? | |
274 | end |
|
276 | end | |
275 | end |
|
277 | end | |
276 | @page.destroy |
|
278 | @page.destroy | |
277 | respond_to do |format| |
|
279 | respond_to do |format| | |
278 | format.html { redirect_to project_wiki_index_path(@project) } |
|
280 | format.html { redirect_to project_wiki_index_path(@project) } | |
279 | format.api { render_api_ok } |
|
281 | format.api { render_api_ok } | |
280 | end |
|
282 | end | |
281 | end |
|
283 | end | |
282 |
|
284 | |||
283 | def destroy_version |
|
285 | def destroy_version | |
284 | return render_403 unless editable? |
|
286 | return render_403 unless editable? | |
285 |
|
287 | |||
286 | if content = @page.content.versions.find_by_version(params[:version]) |
|
288 | if content = @page.content.versions.find_by_version(params[:version]) | |
287 | content.destroy |
|
289 | content.destroy | |
288 | redirect_to_referer_or history_project_wiki_page_path(@project, @page.title) |
|
290 | redirect_to_referer_or history_project_wiki_page_path(@project, @page.title) | |
289 | else |
|
291 | else | |
290 | render_404 |
|
292 | render_404 | |
291 | end |
|
293 | end | |
292 | end |
|
294 | end | |
293 |
|
295 | |||
294 | # Export wiki to a single pdf or html file |
|
296 | # Export wiki to a single pdf or html file | |
295 | def export |
|
297 | def export | |
296 | @pages = @wiki.pages. |
|
298 | @pages = @wiki.pages. | |
297 | order('title'). |
|
299 | order('title'). | |
298 | includes([:content, {:attachments => :author}]). |
|
300 | includes([:content, {:attachments => :author}]). | |
299 | to_a |
|
301 | to_a | |
300 | respond_to do |format| |
|
302 | respond_to do |format| | |
301 | format.html { |
|
303 | format.html { | |
302 | export = render_to_string :action => 'export_multiple', :layout => false |
|
304 | export = render_to_string :action => 'export_multiple', :layout => false | |
303 | send_data(export, :type => 'text/html', :filename => "wiki.html") |
|
305 | send_data(export, :type => 'text/html', :filename => "wiki.html") | |
304 | } |
|
306 | } | |
305 | format.pdf { |
|
307 | format.pdf { | |
306 | send_file_headers! :type => 'application/pdf', :filename => "#{@project.identifier}.pdf" |
|
308 | send_file_headers! :type => 'application/pdf', :filename => "#{@project.identifier}.pdf" | |
307 | } |
|
309 | } | |
308 | end |
|
310 | end | |
309 | end |
|
311 | end | |
310 |
|
312 | |||
311 | def preview |
|
313 | def preview | |
312 | page = @wiki.find_page(params[:id]) |
|
314 | page = @wiki.find_page(params[:id]) | |
313 | # page is nil when previewing a new page |
|
315 | # page is nil when previewing a new page | |
314 | return render_403 unless page.nil? || editable?(page) |
|
316 | return render_403 unless page.nil? || editable?(page) | |
315 | if page |
|
317 | if page | |
316 | @attachments += page.attachments |
|
318 | @attachments += page.attachments | |
317 | @previewed = page.content |
|
319 | @previewed = page.content | |
318 | end |
|
320 | end | |
319 | @text = params[:content][:text] |
|
321 | @text = params[:content][:text] | |
320 | render :partial => 'common/preview' |
|
322 | render :partial => 'common/preview' | |
321 | end |
|
323 | end | |
322 |
|
324 | |||
323 | def add_attachment |
|
325 | def add_attachment | |
324 | return render_403 unless editable? |
|
326 | return render_403 unless editable? | |
325 | attachments = Attachment.attach_files(@page, params[:attachments]) |
|
327 | attachments = Attachment.attach_files(@page, params[:attachments]) | |
326 | render_attachment_warning_if_needed(@page) |
|
328 | render_attachment_warning_if_needed(@page) | |
327 | redirect_to :action => 'show', :id => @page.title, :project_id => @project |
|
329 | redirect_to :action => 'show', :id => @page.title, :project_id => @project | |
328 | end |
|
330 | end | |
329 |
|
331 | |||
330 | private |
|
332 | private | |
331 |
|
333 | |||
332 | def find_wiki |
|
334 | def find_wiki | |
333 | @project = Project.find(params[:project_id]) |
|
335 | @project = Project.find(params[:project_id]) | |
334 | @wiki = @project.wiki |
|
336 | @wiki = @project.wiki | |
335 | render_404 unless @wiki |
|
337 | render_404 unless @wiki | |
336 | rescue ActiveRecord::RecordNotFound |
|
338 | rescue ActiveRecord::RecordNotFound | |
337 | render_404 |
|
339 | render_404 | |
338 | end |
|
340 | end | |
339 |
|
341 | |||
340 | # Finds the requested page or a new page if it doesn't exist |
|
342 | # Finds the requested page or a new page if it doesn't exist | |
341 | def find_existing_or_new_page |
|
343 | def find_existing_or_new_page | |
342 | @page = @wiki.find_or_new_page(params[:id]) |
|
344 | @page = @wiki.find_or_new_page(params[:id]) | |
343 | if @wiki.page_found_with_redirect? |
|
345 | if @wiki.page_found_with_redirect? | |
344 | redirect_to_page @page |
|
346 | redirect_to_page @page | |
345 | end |
|
347 | end | |
346 | end |
|
348 | end | |
347 |
|
349 | |||
348 | # Finds the requested page and returns a 404 error if it doesn't exist |
|
350 | # Finds the requested page and returns a 404 error if it doesn't exist | |
349 | def find_existing_page |
|
351 | def find_existing_page | |
350 | @page = @wiki.find_page(params[:id]) |
|
352 | @page = @wiki.find_page(params[:id]) | |
351 | if @page.nil? |
|
353 | if @page.nil? | |
352 | render_404 |
|
354 | render_404 | |
353 | return |
|
355 | return | |
354 | end |
|
356 | end | |
355 | if @wiki.page_found_with_redirect? |
|
357 | if @wiki.page_found_with_redirect? | |
356 | redirect_to_page @page |
|
358 | redirect_to_page @page | |
357 | end |
|
359 | end | |
358 | end |
|
360 | end | |
359 |
|
361 | |||
360 | def redirect_to_page(page) |
|
362 | def redirect_to_page(page) | |
361 | if page.project && page.project.visible? |
|
363 | if page.project && page.project.visible? | |
362 | redirect_to :action => action_name, :project_id => page.project, :id => page.title |
|
364 | redirect_to :action => action_name, :project_id => page.project, :id => page.title | |
363 | else |
|
365 | else | |
364 | render_404 |
|
366 | render_404 | |
365 | end |
|
367 | end | |
366 | end |
|
368 | end | |
367 |
|
369 | |||
368 | # Returns true if the current user is allowed to edit the page, otherwise false |
|
370 | # Returns true if the current user is allowed to edit the page, otherwise false | |
369 | def editable?(page = @page) |
|
371 | def editable?(page = @page) | |
370 | page.editable_by?(User.current) |
|
372 | page.editable_by?(User.current) | |
371 | end |
|
373 | end | |
372 |
|
374 | |||
373 | # Returns the default content of a new wiki page |
|
375 | # Returns the default content of a new wiki page | |
374 | def initial_page_content(page) |
|
376 | def initial_page_content(page) | |
375 | helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting) |
|
377 | helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting) | |
376 | extend helper unless self.instance_of?(helper) |
|
378 | extend helper unless self.instance_of?(helper) | |
377 | helper.instance_method(:initial_page_content).bind(self).call(page) |
|
379 | helper.instance_method(:initial_page_content).bind(self).call(page) | |
378 | end |
|
380 | end | |
379 |
|
381 | |||
380 | def load_pages_for_index |
|
382 | def load_pages_for_index | |
381 | @pages = @wiki.pages.with_updated_on. |
|
383 | @pages = @wiki.pages.with_updated_on. | |
382 | reorder("#{WikiPage.table_name}.title"). |
|
384 | reorder("#{WikiPage.table_name}.title"). | |
383 | includes(:wiki => :project). |
|
385 | includes(:wiki => :project). | |
384 | includes(:parent). |
|
386 | includes(:parent). | |
385 | to_a |
|
387 | to_a | |
386 | end |
|
388 | end | |
387 | end |
|
389 | end |
@@ -1,1094 +1,1103 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2016 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 WikiControllerTest < Redmine::ControllerTest |
|
20 | class WikiControllerTest < Redmine::ControllerTest | |
21 | fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, |
|
21 | fixtures :projects, :users, :email_addresses, :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 | :issues, :issue_statuses, :trackers |
|
24 | :issues, :issue_statuses, :trackers | |
25 |
|
25 | |||
26 | def setup |
|
26 | def setup | |
27 | User.current = nil |
|
27 | User.current = nil | |
28 | end |
|
28 | end | |
29 |
|
29 | |||
30 | def test_show_start_page |
|
30 | def test_show_start_page | |
31 | get :show, :params => {:project_id => 'ecookbook'} |
|
31 | get :show, :params => {:project_id => 'ecookbook'} | |
32 | assert_response :success |
|
32 | assert_response :success | |
33 |
|
33 | |||
34 | assert_select 'h1', :text => /CookBook documentation/ |
|
34 | assert_select 'h1', :text => /CookBook documentation/ | |
35 | # child_pages macro |
|
35 | # child_pages macro | |
36 | assert_select 'ul.pages-hierarchy>li>a[href=?]', '/projects/ecookbook/wiki/Page_with_an_inline_image', |
|
36 | assert_select 'ul.pages-hierarchy>li>a[href=?]', '/projects/ecookbook/wiki/Page_with_an_inline_image', | |
37 | :text => 'Page with an inline image' |
|
37 | :text => 'Page with an inline image' | |
38 | end |
|
38 | end | |
39 |
|
39 | |||
40 | def test_export_link |
|
40 | def test_export_link | |
41 | Role.anonymous.add_permission! :export_wiki_pages |
|
41 | Role.anonymous.add_permission! :export_wiki_pages | |
42 | get :show, :params => {:project_id => 'ecookbook'} |
|
42 | get :show, :params => {:project_id => 'ecookbook'} | |
43 | assert_response :success |
|
43 | assert_response :success | |
44 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation.txt' |
|
44 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation.txt' | |
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | def test_show_page_with_name |
|
47 | def test_show_page_with_name | |
48 | get :show, :params => {:project_id => 1, :id => 'Another_page'} |
|
48 | get :show, :params => {:project_id => 1, :id => 'Another_page'} | |
49 | assert_response :success |
|
49 | assert_response :success | |
50 |
|
50 | |||
51 | assert_select 'h1', :text => /Another page/ |
|
51 | assert_select 'h1', :text => /Another page/ | |
52 | # Included page with an inline image |
|
52 | # Included page with an inline image | |
53 | assert_select 'p', :text => /This is an inline image/ |
|
53 | assert_select 'p', :text => /This is an inline image/ | |
54 | assert_select 'img[src=?][alt=?]', '/attachments/download/3/logo.gif', 'This is a logo' |
|
54 | assert_select 'img[src=?][alt=?]', '/attachments/download/3/logo.gif', 'This is a logo' | |
55 | end |
|
55 | end | |
56 |
|
56 | |||
57 | def test_show_old_version |
|
57 | def test_show_old_version | |
58 | with_settings :default_language => 'en' do |
|
58 | with_settings :default_language => 'en' do | |
59 | get :show, :params => {:project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '2'} |
|
59 | get :show, :params => {:project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '2'} | |
60 | end |
|
60 | end | |
61 | assert_response :success |
|
61 | assert_response :success | |
62 |
|
62 | |||
63 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/1', :text => /Previous/ |
|
63 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/1', :text => /Previous/ | |
64 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2/diff', :text => /diff/ |
|
64 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2/diff', :text => /diff/ | |
65 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/3', :text => /Next/ |
|
65 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/3', :text => /Next/ | |
66 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation', :text => /Current version/ |
|
66 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation', :text => /Current version/ | |
67 | end |
|
67 | end | |
68 |
|
68 | |||
69 | def test_show_old_version_with_attachments |
|
69 | def test_show_old_version_with_attachments | |
70 | page = WikiPage.find(4) |
|
70 | page = WikiPage.find(4) | |
71 | assert page.attachments.any? |
|
71 | assert page.attachments.any? | |
72 | content = page.content |
|
72 | content = page.content | |
73 | content.text = "update" |
|
73 | content.text = "update" | |
74 | content.save! |
|
74 | content.save! | |
75 |
|
75 | |||
76 | get :show, :params => {:project_id => 'ecookbook', :id => page.title, :version => '1'} |
|
76 | get :show, :params => {:project_id => 'ecookbook', :id => page.title, :version => '1'} | |
77 | assert_response :success |
|
77 | assert_response :success | |
78 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_an_inline_image', :text => /Current version/ |
|
78 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_an_inline_image', :text => /Current version/ | |
79 | end |
|
79 | end | |
80 |
|
80 | |||
81 | def test_show_old_version_without_permission_should_be_denied |
|
81 | def test_show_old_version_without_permission_should_be_denied | |
82 | Role.anonymous.remove_permission! :view_wiki_edits |
|
82 | Role.anonymous.remove_permission! :view_wiki_edits | |
83 |
|
83 | |||
84 | get :show, :params => {:project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '2'} |
|
84 | get :show, :params => {:project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '2'} | |
85 | assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fprojects%2Fecookbook%2Fwiki%2FCookBook_documentation%2F2' |
|
85 | assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fprojects%2Fecookbook%2Fwiki%2FCookBook_documentation%2F2' | |
86 | end |
|
86 | end | |
87 |
|
87 | |||
88 | def test_show_first_version |
|
88 | def test_show_first_version | |
89 | with_settings :default_language => 'en' do |
|
89 | with_settings :default_language => 'en' do | |
90 | get :show, :params => {:project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '1'} |
|
90 | get :show, :params => {:project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '1'} | |
91 | end |
|
91 | end | |
92 | assert_response :success |
|
92 | assert_response :success | |
93 |
|
93 | |||
94 | assert_select 'a', :text => /Previous/, :count => 0 |
|
94 | assert_select 'a', :text => /Previous/, :count => 0 | |
95 | assert_select 'a', :text => /diff/, :count => 0 |
|
95 | assert_select 'a', :text => /diff/, :count => 0 | |
96 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => /Next/ |
|
96 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => /Next/ | |
97 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation', :text => /Current version/ |
|
97 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation', :text => /Current version/ | |
98 | end |
|
98 | end | |
99 |
|
99 | |||
100 | def test_show_redirected_page |
|
100 | def test_show_redirected_page | |
101 | WikiRedirect.create!(:wiki_id => 1, :title => 'Old_title', :redirects_to => 'Another_page') |
|
101 | WikiRedirect.create!(:wiki_id => 1, :title => 'Old_title', :redirects_to => 'Another_page') | |
102 |
|
102 | |||
103 | get :show, :params => {:project_id => 'ecookbook', :id => 'Old_title'} |
|
103 | get :show, :params => {:project_id => 'ecookbook', :id => 'Old_title'} | |
104 | assert_redirected_to '/projects/ecookbook/wiki/Another_page' |
|
104 | assert_redirected_to '/projects/ecookbook/wiki/Another_page' | |
105 | end |
|
105 | end | |
106 |
|
106 | |||
107 | def test_show_with_sidebar |
|
107 | def test_show_with_sidebar | |
108 | page = Project.find(1).wiki.pages.new(:title => 'Sidebar') |
|
108 | page = Project.find(1).wiki.pages.new(:title => 'Sidebar') | |
109 | page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar') |
|
109 | page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar') | |
110 | page.save! |
|
110 | page.save! | |
111 |
|
111 | |||
112 | get :show, :params => {:project_id => 1, :id => 'Another_page'} |
|
112 | get :show, :params => {:project_id => 1, :id => 'Another_page'} | |
113 | assert_response :success |
|
113 | assert_response :success | |
114 | assert_select 'div#sidebar', :text => /Side bar content for test_show_with_sidebar/ |
|
114 | assert_select 'div#sidebar', :text => /Side bar content for test_show_with_sidebar/ | |
115 | end |
|
115 | end | |
116 |
|
116 | |||
117 | def test_show_should_display_section_edit_links |
|
117 | def test_show_should_display_section_edit_links | |
118 | @request.session[:user_id] = 2 |
|
118 | @request.session[:user_id] = 2 | |
119 | get :show, :params => {:project_id => 1, :id => 'Page with sections'} |
|
119 | get :show, :params => {:project_id => 1, :id => 'Page with sections'} | |
120 |
|
120 | |||
121 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=1', 0 |
|
121 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=1', 0 | |
122 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' |
|
122 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' | |
123 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=3' |
|
123 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=3' | |
124 | end |
|
124 | end | |
125 |
|
125 | |||
126 | def test_show_current_version_should_display_section_edit_links |
|
126 | def test_show_current_version_should_display_section_edit_links | |
127 | @request.session[:user_id] = 2 |
|
127 | @request.session[:user_id] = 2 | |
128 | get :show, :params => {:project_id => 1, :id => 'Page with sections', :version => 3} |
|
128 | get :show, :params => {:project_id => 1, :id => 'Page with sections', :version => 3} | |
129 |
|
129 | |||
130 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' |
|
130 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' | |
131 | end |
|
131 | end | |
132 |
|
132 | |||
133 | def test_show_old_version_should_not_display_section_edit_links |
|
133 | def test_show_old_version_should_not_display_section_edit_links | |
134 | @request.session[:user_id] = 2 |
|
134 | @request.session[:user_id] = 2 | |
135 | get :show, :params => {:project_id => 1, :id => 'Page with sections', :version => 2} |
|
135 | get :show, :params => {:project_id => 1, :id => 'Page with sections', :version => 2} | |
136 |
|
136 | |||
137 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2', 0 |
|
137 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2', 0 | |
138 | end |
|
138 | end | |
139 |
|
139 | |||
140 | def test_show_unexistent_page_without_edit_right |
|
140 | def test_show_unexistent_page_without_edit_right | |
141 | get :show, :params => {:project_id => 1, :id => 'Unexistent page'} |
|
141 | get :show, :params => {:project_id => 1, :id => 'Unexistent page'} | |
142 | assert_response 404 |
|
142 | assert_response 404 | |
143 | end |
|
143 | end | |
144 |
|
144 | |||
145 | def test_show_unexistent_page_with_edit_right |
|
145 | def test_show_unexistent_page_with_edit_right | |
146 | @request.session[:user_id] = 2 |
|
146 | @request.session[:user_id] = 2 | |
147 | get :show, :params => {:project_id => 1, :id => 'Unexistent page'} |
|
147 | get :show, :params => {:project_id => 1, :id => 'Unexistent page'} | |
148 | assert_response :success |
|
148 | assert_response :success | |
149 | assert_select 'textarea[name=?]', 'content[text]' |
|
149 | assert_select 'textarea[name=?]', 'content[text]' | |
150 | end |
|
150 | end | |
151 |
|
151 | |||
152 | def test_show_specific_version_of_an_unexistent_page_without_edit_right |
|
152 | def test_show_specific_version_of_an_unexistent_page_without_edit_right | |
153 | get :show, :params => {:project_id => 1, :id => 'Unexistent page', :version => 1} |
|
153 | get :show, :params => {:project_id => 1, :id => 'Unexistent page', :version => 1} | |
154 | assert_response 404 |
|
154 | assert_response 404 | |
155 | end |
|
155 | end | |
156 |
|
156 | |||
157 | def test_show_unexistent_page_with_parent_should_preselect_parent |
|
157 | def test_show_unexistent_page_with_parent_should_preselect_parent | |
158 | @request.session[:user_id] = 2 |
|
158 | @request.session[:user_id] = 2 | |
159 | get :show, :params => {:project_id => 1, :id => 'Unexistent page', :parent => 'Another_page'} |
|
159 | get :show, :params => {:project_id => 1, :id => 'Unexistent page', :parent => 'Another_page'} | |
160 | assert_response :success |
|
160 | assert_response :success | |
161 | assert_select 'select[name=?] option[value="2"][selected=selected]', 'wiki_page[parent_id]' |
|
161 | assert_select 'select[name=?] option[value="2"][selected=selected]', 'wiki_page[parent_id]' | |
162 | end |
|
162 | end | |
163 |
|
163 | |||
164 | def test_show_should_not_show_history_without_permission |
|
164 | def test_show_should_not_show_history_without_permission | |
165 | Role.anonymous.remove_permission! :view_wiki_edits |
|
165 | Role.anonymous.remove_permission! :view_wiki_edits | |
166 | get :show, :params => {:project_id => 1, :id => 'Page with sections', :version => 2} |
|
166 | get :show, :params => {:project_id => 1, :id => 'Page with sections', :version => 2} | |
167 |
|
167 | |||
168 | assert_response 302 |
|
168 | assert_response 302 | |
169 | end |
|
169 | end | |
170 |
|
170 | |||
171 | def test_show_page_without_content_should_display_the_edit_form |
|
171 | def test_show_page_without_content_should_display_the_edit_form | |
172 | @request.session[:user_id] = 2 |
|
172 | @request.session[:user_id] = 2 | |
173 | WikiPage.create!(:title => 'NoContent', :wiki => Project.find(1).wiki) |
|
173 | WikiPage.create!(:title => 'NoContent', :wiki => Project.find(1).wiki) | |
174 |
|
174 | |||
175 | get :show, :params => {:project_id => 1, :id => 'NoContent'} |
|
175 | get :show, :params => {:project_id => 1, :id => 'NoContent'} | |
176 | assert_response :success |
|
176 | assert_response :success | |
177 | assert_select 'textarea[name=?]', 'content[text]' |
|
177 | assert_select 'textarea[name=?]', 'content[text]' | |
178 | end |
|
178 | end | |
179 |
|
179 | |||
180 | def test_get_new |
|
180 | def test_get_new | |
181 | @request.session[:user_id] = 2 |
|
181 | @request.session[:user_id] = 2 | |
182 |
|
182 | |||
183 | get :new, :params => {:project_id => 'ecookbook'} |
|
183 | get :new, :params => {:project_id => 'ecookbook'} | |
184 | assert_response :success |
|
184 | assert_response :success | |
185 | assert_select 'input[name=?]', 'title' |
|
185 | assert_select 'input[name=?]', 'title' | |
186 | end |
|
186 | end | |
187 |
|
187 | |||
188 | def test_get_new_xhr |
|
188 | def test_get_new_xhr | |
189 | @request.session[:user_id] = 2 |
|
189 | @request.session[:user_id] = 2 | |
190 |
|
190 | |||
191 | xhr :get, :new, :params => {:project_id => 'ecookbook'} |
|
191 | xhr :get, :new, :params => {:project_id => 'ecookbook'} | |
192 | assert_response :success |
|
192 | assert_response :success | |
193 | assert_include 'Unallowed characters', response.body |
|
193 | assert_include 'Unallowed characters', response.body | |
194 | end |
|
194 | end | |
195 |
|
195 | |||
196 | def test_post_new_with_valid_title_should_redirect_to_edit |
|
196 | def test_post_new_with_valid_title_should_redirect_to_edit | |
197 | @request.session[:user_id] = 2 |
|
197 | @request.session[:user_id] = 2 | |
198 |
|
198 | |||
199 | post :new, :params => {:project_id => 'ecookbook', :title => 'New Page'} |
|
199 | post :new, :params => {:project_id => 'ecookbook', :title => 'New Page'} | |
200 | assert_redirected_to '/projects/ecookbook/wiki/New_Page' |
|
200 | assert_redirected_to '/projects/ecookbook/wiki/New_Page' | |
201 | end |
|
201 | end | |
202 |
|
202 | |||
203 | def test_post_new_xhr_with_valid_title_should_redirect_to_edit |
|
203 | def test_post_new_xhr_with_valid_title_should_redirect_to_edit | |
204 | @request.session[:user_id] = 2 |
|
204 | @request.session[:user_id] = 2 | |
205 |
|
205 | |||
206 | xhr :post, :new, :params => {:project_id => 'ecookbook', :title => 'New Page'} |
|
206 | xhr :post, :new, :params => {:project_id => 'ecookbook', :title => 'New Page'} | |
207 | assert_response :success |
|
207 | assert_response :success | |
208 | assert_equal 'window.location = "/projects/ecookbook/wiki/New_Page"', response.body |
|
208 | assert_equal 'window.location = "/projects/ecookbook/wiki/New_Page"', response.body | |
209 | end |
|
209 | end | |
210 |
|
210 | |||
211 | def test_post_new_with_invalid_title_should_display_errors |
|
211 | def test_post_new_with_invalid_title_should_display_errors | |
212 | @request.session[:user_id] = 2 |
|
212 | @request.session[:user_id] = 2 | |
213 |
|
213 | |||
214 | post :new, :params => {:project_id => 'ecookbook', :title => 'Another page'} |
|
214 | post :new, :params => {:project_id => 'ecookbook', :title => 'Another page'} | |
215 | assert_response :success |
|
215 | assert_response :success | |
216 | assert_select_error 'Title has already been taken' |
|
216 | assert_select_error 'Title has already been taken' | |
217 | end |
|
217 | end | |
218 |
|
218 | |||
|
219 | def test_post_new_with_protected_title_should_display_errors | |||
|
220 | Role.find(1).remove_permission!(:protect_wiki_pages) | |||
|
221 | @request.session[:user_id] = 2 | |||
|
222 | ||||
|
223 | post :new, :params => {:project_id => 'ecookbook', :title => 'Sidebar'} | |||
|
224 | assert_response :success | |||
|
225 | assert_select_error /Title/ | |||
|
226 | end | |||
|
227 | ||||
219 | def test_post_new_xhr_with_invalid_title_should_display_errors |
|
228 | def test_post_new_xhr_with_invalid_title_should_display_errors | |
220 | @request.session[:user_id] = 2 |
|
229 | @request.session[:user_id] = 2 | |
221 |
|
230 | |||
222 | xhr :post, :new, :params => {:project_id => 'ecookbook', :title => 'Another page'} |
|
231 | xhr :post, :new, :params => {:project_id => 'ecookbook', :title => 'Another page'} | |
223 | assert_response :success |
|
232 | assert_response :success | |
224 | assert_include 'Title has already been taken', response.body |
|
233 | assert_include 'Title has already been taken', response.body | |
225 | end |
|
234 | end | |
226 |
|
235 | |||
227 | def test_create_page |
|
236 | def test_create_page | |
228 | @request.session[:user_id] = 2 |
|
237 | @request.session[:user_id] = 2 | |
229 | assert_difference 'WikiPage.count' do |
|
238 | assert_difference 'WikiPage.count' do | |
230 | assert_difference 'WikiContent.count' do |
|
239 | assert_difference 'WikiContent.count' do | |
231 | put :update, :params => { |
|
240 | put :update, :params => { | |
232 | :project_id => 1, |
|
241 | :project_id => 1, | |
233 | :id => 'New page', |
|
242 | :id => 'New page', | |
234 | :content => { |
|
243 | :content => { | |
235 | :comments => 'Created the page', |
|
244 | :comments => 'Created the page', | |
236 | :text => "h1. New page\n\nThis is a new page", |
|
245 | :text => "h1. New page\n\nThis is a new page", | |
237 | :version => 0 |
|
246 | :version => 0 | |
238 | } |
|
247 | } | |
239 | } |
|
248 | } | |
240 | end |
|
249 | end | |
241 | end |
|
250 | end | |
242 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page' |
|
251 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page' | |
243 | page = Project.find(1).wiki.find_page('New page') |
|
252 | page = Project.find(1).wiki.find_page('New page') | |
244 | assert !page.new_record? |
|
253 | assert !page.new_record? | |
245 | assert_not_nil page.content |
|
254 | assert_not_nil page.content | |
246 | assert_nil page.parent |
|
255 | assert_nil page.parent | |
247 | assert_equal 'Created the page', page.content.comments |
|
256 | assert_equal 'Created the page', page.content.comments | |
248 | end |
|
257 | end | |
249 |
|
258 | |||
250 | def test_create_page_with_attachments |
|
259 | def test_create_page_with_attachments | |
251 | @request.session[:user_id] = 2 |
|
260 | @request.session[:user_id] = 2 | |
252 | assert_difference 'WikiPage.count' do |
|
261 | assert_difference 'WikiPage.count' do | |
253 | assert_difference 'Attachment.count' do |
|
262 | assert_difference 'Attachment.count' do | |
254 | put :update, :params => { |
|
263 | put :update, :params => { | |
255 | :project_id => 1, |
|
264 | :project_id => 1, | |
256 | :id => 'New page', |
|
265 | :id => 'New page', | |
257 | :content => { |
|
266 | :content => { | |
258 | :comments => 'Created the page', |
|
267 | :comments => 'Created the page', | |
259 | :text => "h1. New page\n\nThis is a new page", |
|
268 | :text => "h1. New page\n\nThis is a new page", | |
260 | :version => 0 |
|
269 | :version => 0 | |
261 | }, |
|
270 | }, | |
262 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
271 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
263 | } |
|
272 | } | |
264 | end |
|
273 | end | |
265 | end |
|
274 | end | |
266 | page = Project.find(1).wiki.find_page('New page') |
|
275 | page = Project.find(1).wiki.find_page('New page') | |
267 | assert_equal 1, page.attachments.count |
|
276 | assert_equal 1, page.attachments.count | |
268 | assert_equal 'testfile.txt', page.attachments.first.filename |
|
277 | assert_equal 'testfile.txt', page.attachments.first.filename | |
269 | end |
|
278 | end | |
270 |
|
279 | |||
271 | def test_create_page_with_parent |
|
280 | def test_create_page_with_parent | |
272 | @request.session[:user_id] = 2 |
|
281 | @request.session[:user_id] = 2 | |
273 | assert_difference 'WikiPage.count' do |
|
282 | assert_difference 'WikiPage.count' do | |
274 | put :update, :params => { |
|
283 | put :update, :params => { | |
275 | :project_id => 1, |
|
284 | :project_id => 1, | |
276 | :id => 'New page', |
|
285 | :id => 'New page', | |
277 | :content => { |
|
286 | :content => { | |
278 | :text => "h1. New page\n\nThis is a new page", |
|
287 | :text => "h1. New page\n\nThis is a new page", | |
279 | :version => 0 |
|
288 | :version => 0 | |
280 | }, |
|
289 | }, | |
281 | :wiki_page => {:parent_id => 2} |
|
290 | :wiki_page => {:parent_id => 2} | |
282 | } |
|
291 | } | |
283 | end |
|
292 | end | |
284 | page = Project.find(1).wiki.find_page('New page') |
|
293 | page = Project.find(1).wiki.find_page('New page') | |
285 | assert_equal WikiPage.find(2), page.parent |
|
294 | assert_equal WikiPage.find(2), page.parent | |
286 | end |
|
295 | end | |
287 |
|
296 | |||
288 | def test_edit_page |
|
297 | def test_edit_page | |
289 | @request.session[:user_id] = 2 |
|
298 | @request.session[:user_id] = 2 | |
290 | get :edit, :params => {:project_id => 'ecookbook', :id => 'Another_page'} |
|
299 | get :edit, :params => {:project_id => 'ecookbook', :id => 'Another_page'} | |
291 |
|
300 | |||
292 | assert_response :success |
|
301 | assert_response :success | |
293 |
|
302 | |||
294 | assert_select 'textarea[name=?]', 'content[text]', |
|
303 | assert_select 'textarea[name=?]', 'content[text]', | |
295 | :text => WikiPage.find_by_title('Another_page').content.text |
|
304 | :text => WikiPage.find_by_title('Another_page').content.text | |
296 | end |
|
305 | end | |
297 |
|
306 | |||
298 | def test_edit_section |
|
307 | def test_edit_section | |
299 | @request.session[:user_id] = 2 |
|
308 | @request.session[:user_id] = 2 | |
300 | get :edit, :params => {:project_id => 'ecookbook', :id => 'Page_with_sections', :section => 2} |
|
309 | get :edit, :params => {:project_id => 'ecookbook', :id => 'Page_with_sections', :section => 2} | |
301 |
|
310 | |||
302 | assert_response :success |
|
311 | assert_response :success | |
303 |
|
312 | |||
304 | page = WikiPage.find_by_title('Page_with_sections') |
|
313 | page = WikiPage.find_by_title('Page_with_sections') | |
305 | section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) |
|
314 | section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) | |
306 |
|
315 | |||
307 | assert_select 'textarea[name=?]', 'content[text]', :text => section |
|
316 | assert_select 'textarea[name=?]', 'content[text]', :text => section | |
308 | assert_select 'input[name=section][type=hidden][value="2"]' |
|
317 | assert_select 'input[name=section][type=hidden][value="2"]' | |
309 | assert_select 'input[name=section_hash][type=hidden][value=?]', hash |
|
318 | assert_select 'input[name=section_hash][type=hidden][value=?]', hash | |
310 | end |
|
319 | end | |
311 |
|
320 | |||
312 | def test_edit_invalid_section_should_respond_with_404 |
|
321 | def test_edit_invalid_section_should_respond_with_404 | |
313 | @request.session[:user_id] = 2 |
|
322 | @request.session[:user_id] = 2 | |
314 | get :edit, :params => {:project_id => 'ecookbook', :id => 'Page_with_sections', :section => 10} |
|
323 | get :edit, :params => {:project_id => 'ecookbook', :id => 'Page_with_sections', :section => 10} | |
315 |
|
324 | |||
316 | assert_response 404 |
|
325 | assert_response 404 | |
317 | end |
|
326 | end | |
318 |
|
327 | |||
319 | def test_update_page |
|
328 | def test_update_page | |
320 | @request.session[:user_id] = 2 |
|
329 | @request.session[:user_id] = 2 | |
321 | assert_no_difference 'WikiPage.count' do |
|
330 | assert_no_difference 'WikiPage.count' do | |
322 | assert_no_difference 'WikiContent.count' do |
|
331 | assert_no_difference 'WikiContent.count' do | |
323 | assert_difference 'WikiContent::Version.count' do |
|
332 | assert_difference 'WikiContent::Version.count' do | |
324 | put :update, :params => { |
|
333 | put :update, :params => { | |
325 | :project_id => 1, |
|
334 | :project_id => 1, | |
326 | :id => 'Another_page', |
|
335 | :id => 'Another_page', | |
327 | :content => { |
|
336 | :content => { | |
328 | :comments => "my comments", |
|
337 | :comments => "my comments", | |
329 | :text => "edited", |
|
338 | :text => "edited", | |
330 | :version => 1 |
|
339 | :version => 1 | |
331 | } |
|
340 | } | |
332 | } |
|
341 | } | |
333 | end |
|
342 | end | |
334 | end |
|
343 | end | |
335 | end |
|
344 | end | |
336 | assert_redirected_to '/projects/ecookbook/wiki/Another_page' |
|
345 | assert_redirected_to '/projects/ecookbook/wiki/Another_page' | |
337 |
|
346 | |||
338 | page = Wiki.find(1).pages.find_by_title('Another_page') |
|
347 | page = Wiki.find(1).pages.find_by_title('Another_page') | |
339 | assert_equal "edited", page.content.text |
|
348 | assert_equal "edited", page.content.text | |
340 | assert_equal 2, page.content.version |
|
349 | assert_equal 2, page.content.version | |
341 | assert_equal "my comments", page.content.comments |
|
350 | assert_equal "my comments", page.content.comments | |
342 | end |
|
351 | end | |
343 |
|
352 | |||
344 | def test_update_page_with_parent |
|
353 | def test_update_page_with_parent | |
345 | @request.session[:user_id] = 2 |
|
354 | @request.session[:user_id] = 2 | |
346 | assert_no_difference 'WikiPage.count' do |
|
355 | assert_no_difference 'WikiPage.count' do | |
347 | assert_no_difference 'WikiContent.count' do |
|
356 | assert_no_difference 'WikiContent.count' do | |
348 | assert_difference 'WikiContent::Version.count' do |
|
357 | assert_difference 'WikiContent::Version.count' do | |
349 | put :update, :params => { |
|
358 | put :update, :params => { | |
350 | :project_id => 1, |
|
359 | :project_id => 1, | |
351 | :id => 'Another_page', |
|
360 | :id => 'Another_page', | |
352 | :content => { |
|
361 | :content => { | |
353 | :comments => "my comments", |
|
362 | :comments => "my comments", | |
354 | :text => "edited", |
|
363 | :text => "edited", | |
355 | :version => 1 |
|
364 | :version => 1 | |
356 | }, |
|
365 | }, | |
357 | :wiki_page => {:parent_id => '1'} |
|
366 | :wiki_page => {:parent_id => '1'} | |
358 | } |
|
367 | } | |
359 | end |
|
368 | end | |
360 | end |
|
369 | end | |
361 | end |
|
370 | end | |
362 | assert_redirected_to '/projects/ecookbook/wiki/Another_page' |
|
371 | assert_redirected_to '/projects/ecookbook/wiki/Another_page' | |
363 |
|
372 | |||
364 | page = Wiki.find(1).pages.find_by_title('Another_page') |
|
373 | page = Wiki.find(1).pages.find_by_title('Another_page') | |
365 | assert_equal "edited", page.content.text |
|
374 | assert_equal "edited", page.content.text | |
366 | assert_equal 2, page.content.version |
|
375 | assert_equal 2, page.content.version | |
367 | assert_equal "my comments", page.content.comments |
|
376 | assert_equal "my comments", page.content.comments | |
368 | assert_equal WikiPage.find(1), page.parent |
|
377 | assert_equal WikiPage.find(1), page.parent | |
369 | end |
|
378 | end | |
370 |
|
379 | |||
371 | def test_update_page_with_failure |
|
380 | def test_update_page_with_failure | |
372 | @request.session[:user_id] = 2 |
|
381 | @request.session[:user_id] = 2 | |
373 | assert_no_difference 'WikiPage.count' do |
|
382 | assert_no_difference 'WikiPage.count' do | |
374 | assert_no_difference 'WikiContent.count' do |
|
383 | assert_no_difference 'WikiContent.count' do | |
375 | assert_no_difference 'WikiContent::Version.count' do |
|
384 | assert_no_difference 'WikiContent::Version.count' do | |
376 | put :update, :params => { |
|
385 | put :update, :params => { | |
377 | :project_id => 1, |
|
386 | :project_id => 1, | |
378 | :id => 'Another_page', |
|
387 | :id => 'Another_page', | |
379 | :content => { |
|
388 | :content => { | |
380 | :comments => 'a' * 1300, # failure here, comment is too long |
|
389 | :comments => 'a' * 1300, # failure here, comment is too long | |
381 | :text => 'edited' |
|
390 | :text => 'edited' | |
382 | }, |
|
391 | }, | |
383 | :wiki_page => { |
|
392 | :wiki_page => { | |
384 | :parent_id => "" |
|
393 | :parent_id => "" | |
385 | } |
|
394 | } | |
386 | } |
|
395 | } | |
387 | end |
|
396 | end | |
388 | end |
|
397 | end | |
389 | end |
|
398 | end | |
390 | assert_response :success |
|
399 | assert_response :success | |
391 |
|
400 | |||
392 | assert_select_error /Comment is too long/ |
|
401 | assert_select_error /Comment is too long/ | |
393 | assert_select 'textarea#content_text', :text => "edited" |
|
402 | assert_select 'textarea#content_text', :text => "edited" | |
394 | assert_select 'input#content_version[value="1"]' |
|
403 | assert_select 'input#content_version[value="1"]' | |
395 | end |
|
404 | end | |
396 |
|
405 | |||
397 | def test_update_page_with_parent_change_only_should_not_create_content_version |
|
406 | def test_update_page_with_parent_change_only_should_not_create_content_version | |
398 | @request.session[:user_id] = 2 |
|
407 | @request.session[:user_id] = 2 | |
399 | assert_no_difference 'WikiPage.count' do |
|
408 | assert_no_difference 'WikiPage.count' do | |
400 | assert_no_difference 'WikiContent.count' do |
|
409 | assert_no_difference 'WikiContent.count' do | |
401 | assert_no_difference 'WikiContent::Version.count' do |
|
410 | assert_no_difference 'WikiContent::Version.count' do | |
402 | put :update, :params => { |
|
411 | put :update, :params => { | |
403 | :project_id => 1, |
|
412 | :project_id => 1, | |
404 | :id => 'Another_page', |
|
413 | :id => 'Another_page', | |
405 | :content => { |
|
414 | :content => { | |
406 | :comments => '', |
|
415 | :comments => '', | |
407 | :text => Wiki.find(1).find_page('Another_page').content.text, |
|
416 | :text => Wiki.find(1).find_page('Another_page').content.text, | |
408 | :version => 1 |
|
417 | :version => 1 | |
409 | }, |
|
418 | }, | |
410 | :wiki_page => {:parent_id => '1'} |
|
419 | :wiki_page => {:parent_id => '1'} | |
411 | } |
|
420 | } | |
412 | end |
|
421 | end | |
413 | end |
|
422 | end | |
414 | end |
|
423 | end | |
415 | page = Wiki.find(1).pages.find_by_title('Another_page') |
|
424 | page = Wiki.find(1).pages.find_by_title('Another_page') | |
416 | assert_equal 1, page.content.version |
|
425 | assert_equal 1, page.content.version | |
417 | assert_equal WikiPage.find(1), page.parent |
|
426 | assert_equal WikiPage.find(1), page.parent | |
418 | end |
|
427 | end | |
419 |
|
428 | |||
420 | def test_update_page_with_attachments_only_should_not_create_content_version |
|
429 | def test_update_page_with_attachments_only_should_not_create_content_version | |
421 | @request.session[:user_id] = 2 |
|
430 | @request.session[:user_id] = 2 | |
422 | assert_no_difference 'WikiPage.count' do |
|
431 | assert_no_difference 'WikiPage.count' do | |
423 | assert_no_difference 'WikiContent.count' do |
|
432 | assert_no_difference 'WikiContent.count' do | |
424 | assert_no_difference 'WikiContent::Version.count' do |
|
433 | assert_no_difference 'WikiContent::Version.count' do | |
425 | assert_difference 'Attachment.count' do |
|
434 | assert_difference 'Attachment.count' do | |
426 | put :update, :params => { |
|
435 | put :update, :params => { | |
427 | :project_id => 1, |
|
436 | :project_id => 1, | |
428 | :id => 'Another_page', |
|
437 | :id => 'Another_page', | |
429 | :content => { |
|
438 | :content => { | |
430 | :comments => '', |
|
439 | :comments => '', | |
431 | :text => Wiki.find(1).find_page('Another_page').content.text, |
|
440 | :text => Wiki.find(1).find_page('Another_page').content.text, | |
432 | :version => 1 |
|
441 | :version => 1 | |
433 | }, |
|
442 | }, | |
434 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} |
|
443 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} | |
435 | } |
|
444 | } | |
436 | end |
|
445 | end | |
437 | end |
|
446 | end | |
438 | end |
|
447 | end | |
439 | end |
|
448 | end | |
440 | page = Wiki.find(1).pages.find_by_title('Another_page') |
|
449 | page = Wiki.find(1).pages.find_by_title('Another_page') | |
441 | assert_equal 1, page.content.version |
|
450 | assert_equal 1, page.content.version | |
442 | end |
|
451 | end | |
443 |
|
452 | |||
444 | def test_update_stale_page_should_not_raise_an_error |
|
453 | def test_update_stale_page_should_not_raise_an_error | |
445 | @request.session[:user_id] = 2 |
|
454 | @request.session[:user_id] = 2 | |
446 | c = Wiki.find(1).find_page('Another_page').content |
|
455 | c = Wiki.find(1).find_page('Another_page').content | |
447 | c.text = 'Previous text' |
|
456 | c.text = 'Previous text' | |
448 | c.save! |
|
457 | c.save! | |
449 | assert_equal 2, c.version |
|
458 | assert_equal 2, c.version | |
450 |
|
459 | |||
451 | assert_no_difference 'WikiPage.count' do |
|
460 | assert_no_difference 'WikiPage.count' do | |
452 | assert_no_difference 'WikiContent.count' do |
|
461 | assert_no_difference 'WikiContent.count' do | |
453 | assert_no_difference 'WikiContent::Version.count' do |
|
462 | assert_no_difference 'WikiContent::Version.count' do | |
454 | put :update, :params => { |
|
463 | put :update, :params => { | |
455 | :project_id => 1, |
|
464 | :project_id => 1, | |
456 | :id => 'Another_page', |
|
465 | :id => 'Another_page', | |
457 | :content => { |
|
466 | :content => { | |
458 | :comments => 'My comments', |
|
467 | :comments => 'My comments', | |
459 | :text => 'Text should not be lost', |
|
468 | :text => 'Text should not be lost', | |
460 | :version => 1 |
|
469 | :version => 1 | |
461 | } |
|
470 | } | |
462 | } |
|
471 | } | |
463 | end |
|
472 | end | |
464 | end |
|
473 | end | |
465 | end |
|
474 | end | |
466 | assert_response :success |
|
475 | assert_response :success | |
467 | assert_select 'div.error', :text => /Data has been updated by another user/ |
|
476 | assert_select 'div.error', :text => /Data has been updated by another user/ | |
468 | assert_select 'textarea[name=?]', 'content[text]', :text => /Text should not be lost/ |
|
477 | assert_select 'textarea[name=?]', 'content[text]', :text => /Text should not be lost/ | |
469 | assert_select 'input[name=?][value=?]', 'content[comments]', 'My comments' |
|
478 | assert_select 'input[name=?][value=?]', 'content[comments]', 'My comments' | |
470 |
|
479 | |||
471 | c.reload |
|
480 | c.reload | |
472 | assert_equal 'Previous text', c.text |
|
481 | assert_equal 'Previous text', c.text | |
473 | assert_equal 2, c.version |
|
482 | assert_equal 2, c.version | |
474 | end |
|
483 | end | |
475 |
|
484 | |||
476 | def test_update_page_without_content_should_create_content |
|
485 | def test_update_page_without_content_should_create_content | |
477 | @request.session[:user_id] = 2 |
|
486 | @request.session[:user_id] = 2 | |
478 | page = WikiPage.create!(:title => 'NoContent', :wiki => Project.find(1).wiki) |
|
487 | page = WikiPage.create!(:title => 'NoContent', :wiki => Project.find(1).wiki) | |
479 |
|
488 | |||
480 | assert_no_difference 'WikiPage.count' do |
|
489 | assert_no_difference 'WikiPage.count' do | |
481 | assert_difference 'WikiContent.count' do |
|
490 | assert_difference 'WikiContent.count' do | |
482 | put :update, :params => { |
|
491 | put :update, :params => { | |
483 | :project_id => 1, |
|
492 | :project_id => 1, | |
484 | :id => 'NoContent', |
|
493 | :id => 'NoContent', | |
485 | :content => {:text => 'Some content'} |
|
494 | :content => {:text => 'Some content'} | |
486 | } |
|
495 | } | |
487 | assert_response 302 |
|
496 | assert_response 302 | |
488 | end |
|
497 | end | |
489 | end |
|
498 | end | |
490 | assert_equal 'Some content', page.reload.content.text |
|
499 | assert_equal 'Some content', page.reload.content.text | |
491 | end |
|
500 | end | |
492 |
|
501 | |||
493 | def test_update_section |
|
502 | def test_update_section | |
494 | @request.session[:user_id] = 2 |
|
503 | @request.session[:user_id] = 2 | |
495 | page = WikiPage.find_by_title('Page_with_sections') |
|
504 | page = WikiPage.find_by_title('Page_with_sections') | |
496 | section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) |
|
505 | section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) | |
497 | text = page.content.text |
|
506 | text = page.content.text | |
498 |
|
507 | |||
499 | assert_no_difference 'WikiPage.count' do |
|
508 | assert_no_difference 'WikiPage.count' do | |
500 | assert_no_difference 'WikiContent.count' do |
|
509 | assert_no_difference 'WikiContent.count' do | |
501 | assert_difference 'WikiContent::Version.count' do |
|
510 | assert_difference 'WikiContent::Version.count' do | |
502 | put :update, :params => { |
|
511 | put :update, :params => { | |
503 | :project_id => 1, |
|
512 | :project_id => 1, | |
504 | :id => 'Page_with_sections', |
|
513 | :id => 'Page_with_sections', | |
505 | :content => { |
|
514 | :content => { | |
506 | :text => "New section content", |
|
515 | :text => "New section content", | |
507 | :version => 3 |
|
516 | :version => 3 | |
508 | }, |
|
517 | }, | |
509 | :section => 2, |
|
518 | :section => 2, | |
510 | :section_hash => hash |
|
519 | :section_hash => hash | |
511 | } |
|
520 | } | |
512 | end |
|
521 | end | |
513 | end |
|
522 | end | |
514 | end |
|
523 | end | |
515 | assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2' |
|
524 | assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2' | |
516 | assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.reload.content.text |
|
525 | assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.reload.content.text | |
517 | end |
|
526 | end | |
518 |
|
527 | |||
519 | def test_update_section_should_allow_stale_page_update |
|
528 | def test_update_section_should_allow_stale_page_update | |
520 | @request.session[:user_id] = 2 |
|
529 | @request.session[:user_id] = 2 | |
521 | page = WikiPage.find_by_title('Page_with_sections') |
|
530 | page = WikiPage.find_by_title('Page_with_sections') | |
522 | section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) |
|
531 | section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) | |
523 | text = page.content.text |
|
532 | text = page.content.text | |
524 |
|
533 | |||
525 | assert_no_difference 'WikiPage.count' do |
|
534 | assert_no_difference 'WikiPage.count' do | |
526 | assert_no_difference 'WikiContent.count' do |
|
535 | assert_no_difference 'WikiContent.count' do | |
527 | assert_difference 'WikiContent::Version.count' do |
|
536 | assert_difference 'WikiContent::Version.count' do | |
528 | put :update, :params => { |
|
537 | put :update, :params => { | |
529 | :project_id => 1, |
|
538 | :project_id => 1, | |
530 | :id => 'Page_with_sections', |
|
539 | :id => 'Page_with_sections', | |
531 | :content => { |
|
540 | :content => { | |
532 | :text => "New section content", |
|
541 | :text => "New section content", | |
533 | :version => 2 # Current version is 3 |
|
542 | :version => 2 # Current version is 3 | |
534 | }, |
|
543 | }, | |
535 | :section => 2, |
|
544 | :section => 2, | |
536 | :section_hash => hash |
|
545 | :section_hash => hash | |
537 | } |
|
546 | } | |
538 | end |
|
547 | end | |
539 | end |
|
548 | end | |
540 | end |
|
549 | end | |
541 | assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2' |
|
550 | assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2' | |
542 | page.reload |
|
551 | page.reload | |
543 | assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.content.text |
|
552 | assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.content.text | |
544 | assert_equal 4, page.content.version |
|
553 | assert_equal 4, page.content.version | |
545 | end |
|
554 | end | |
546 |
|
555 | |||
547 | def test_update_section_should_not_allow_stale_section_update |
|
556 | def test_update_section_should_not_allow_stale_section_update | |
548 | @request.session[:user_id] = 2 |
|
557 | @request.session[:user_id] = 2 | |
549 |
|
558 | |||
550 | assert_no_difference 'WikiPage.count' do |
|
559 | assert_no_difference 'WikiPage.count' do | |
551 | assert_no_difference 'WikiContent.count' do |
|
560 | assert_no_difference 'WikiContent.count' do | |
552 | assert_no_difference 'WikiContent::Version.count' do |
|
561 | assert_no_difference 'WikiContent::Version.count' do | |
553 | put :update, :params => { |
|
562 | put :update, :params => { | |
554 | :project_id => 1, |
|
563 | :project_id => 1, | |
555 | :id => 'Page_with_sections', |
|
564 | :id => 'Page_with_sections', | |
556 | :content => { |
|
565 | :content => { | |
557 | :comments => 'My comments', |
|
566 | :comments => 'My comments', | |
558 | :text => "Text should not be lost", |
|
567 | :text => "Text should not be lost", | |
559 | :version => 3 |
|
568 | :version => 3 | |
560 | }, |
|
569 | }, | |
561 | :section => 2, |
|
570 | :section => 2, | |
562 | :section_hash => Digest::MD5.hexdigest("wrong hash") |
|
571 | :section_hash => Digest::MD5.hexdigest("wrong hash") | |
563 | } |
|
572 | } | |
564 | end |
|
573 | end | |
565 | end |
|
574 | end | |
566 | end |
|
575 | end | |
567 | assert_response :success |
|
576 | assert_response :success | |
568 | assert_select 'div.error', :text => /Data has been updated by another user/ |
|
577 | assert_select 'div.error', :text => /Data has been updated by another user/ | |
569 | assert_select 'textarea[name=?]', 'content[text]', :text => /Text should not be lost/ |
|
578 | assert_select 'textarea[name=?]', 'content[text]', :text => /Text should not be lost/ | |
570 | assert_select 'input[name=?][value=?]', 'content[comments]', 'My comments' |
|
579 | assert_select 'input[name=?][value=?]', 'content[comments]', 'My comments' | |
571 | end |
|
580 | end | |
572 |
|
581 | |||
573 | def test_preview |
|
582 | def test_preview | |
574 | @request.session[:user_id] = 2 |
|
583 | @request.session[:user_id] = 2 | |
575 | xhr :post, :preview, :params => { |
|
584 | xhr :post, :preview, :params => { | |
576 | :project_id => 1, |
|
585 | :project_id => 1, | |
577 | :id => 'CookBook_documentation', |
|
586 | :id => 'CookBook_documentation', | |
578 | :content => { |
|
587 | :content => { | |
579 | :comments => '', |
|
588 | :comments => '', | |
580 | :text => 'this is a *previewed text*', |
|
589 | :text => 'this is a *previewed text*', | |
581 | :version => 3 |
|
590 | :version => 3 | |
582 | } |
|
591 | } | |
583 | } |
|
592 | } | |
584 | assert_response :success |
|
593 | assert_response :success | |
585 | assert_select 'strong', :text => /previewed text/ |
|
594 | assert_select 'strong', :text => /previewed text/ | |
586 | end |
|
595 | end | |
587 |
|
596 | |||
588 | def test_preview_new_page |
|
597 | def test_preview_new_page | |
589 | @request.session[:user_id] = 2 |
|
598 | @request.session[:user_id] = 2 | |
590 | xhr :post, :preview, :params => { |
|
599 | xhr :post, :preview, :params => { | |
591 | :project_id => 1, |
|
600 | :project_id => 1, | |
592 | :id => 'New page', |
|
601 | :id => 'New page', | |
593 | :content => { |
|
602 | :content => { | |
594 | :text => 'h1. New page', |
|
603 | :text => 'h1. New page', | |
595 | :comments => '', |
|
604 | :comments => '', | |
596 | :version => 0 |
|
605 | :version => 0 | |
597 | } |
|
606 | } | |
598 | } |
|
607 | } | |
599 | assert_response :success |
|
608 | assert_response :success | |
600 | assert_select 'h1', :text => /New page/ |
|
609 | assert_select 'h1', :text => /New page/ | |
601 | end |
|
610 | end | |
602 |
|
611 | |||
603 | def test_history |
|
612 | def test_history | |
604 | @request.session[:user_id] = 2 |
|
613 | @request.session[:user_id] = 2 | |
605 | get :history, :params => {:project_id => 'ecookbook', :id => 'CookBook_documentation'} |
|
614 | get :history, :params => {:project_id => 'ecookbook', :id => 'CookBook_documentation'} | |
606 | assert_response :success |
|
615 | assert_response :success | |
607 |
|
616 | |||
608 | assert_select 'table.wiki-page-versions tbody' do |
|
617 | assert_select 'table.wiki-page-versions tbody' do | |
609 | assert_select 'tr', 3 |
|
618 | assert_select 'tr', 3 | |
610 | end |
|
619 | end | |
611 |
|
620 | |||
612 | assert_select "input[type=submit][name=commit]" |
|
621 | assert_select "input[type=submit][name=commit]" | |
613 | assert_select 'td' do |
|
622 | assert_select 'td' do | |
614 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => '2' |
|
623 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => '2' | |
615 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2/annotate', :text => 'Annotate' |
|
624 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2/annotate', :text => 'Annotate' | |
616 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => 'Delete' |
|
625 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => 'Delete' | |
617 | end |
|
626 | end | |
618 | end |
|
627 | end | |
619 |
|
628 | |||
620 | def test_history_with_one_version |
|
629 | def test_history_with_one_version | |
621 | @request.session[:user_id] = 2 |
|
630 | @request.session[:user_id] = 2 | |
622 | get :history, :params => {:project_id => 'ecookbook', :id => 'Another_page'} |
|
631 | get :history, :params => {:project_id => 'ecookbook', :id => 'Another_page'} | |
623 | assert_response :success |
|
632 | assert_response :success | |
624 |
|
633 | |||
625 | assert_select 'table.wiki-page-versions tbody' do |
|
634 | assert_select 'table.wiki-page-versions tbody' do | |
626 | assert_select 'tr', 1 |
|
635 | assert_select 'tr', 1 | |
627 | end |
|
636 | end | |
628 |
|
637 | |||
629 | assert_select "input[type=submit][name=commit]", false |
|
638 | assert_select "input[type=submit][name=commit]", false | |
630 | assert_select 'td' do |
|
639 | assert_select 'td' do | |
631 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1', :text => '1' |
|
640 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1', :text => '1' | |
632 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1/annotate', :text => 'Annotate' |
|
641 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1/annotate', :text => 'Annotate' | |
633 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1', :text => 'Delete', :count => 0 |
|
642 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1', :text => 'Delete', :count => 0 | |
634 | end |
|
643 | end | |
635 | end |
|
644 | end | |
636 |
|
645 | |||
637 | def test_diff |
|
646 | def test_diff | |
638 | content = WikiPage.find(1).content |
|
647 | content = WikiPage.find(1).content | |
639 | assert_difference 'WikiContent::Version.count', 2 do |
|
648 | assert_difference 'WikiContent::Version.count', 2 do | |
640 | content.text = "Line removed\nThis is a sample text for testing diffs" |
|
649 | content.text = "Line removed\nThis is a sample text for testing diffs" | |
641 | content.save! |
|
650 | content.save! | |
642 | content.text = "This is a sample text for testing diffs\nLine added" |
|
651 | content.text = "This is a sample text for testing diffs\nLine added" | |
643 | content.save! |
|
652 | content.save! | |
644 | end |
|
653 | end | |
645 |
|
654 | |||
646 | get :diff, :params => { |
|
655 | get :diff, :params => { | |
647 | :project_id => 1, :id => 'CookBook_documentation', |
|
656 | :project_id => 1, :id => 'CookBook_documentation', | |
648 | :version => content.version, |
|
657 | :version => content.version, | |
649 | :version_from => (content.version - 1) |
|
658 | :version_from => (content.version - 1) | |
650 | } |
|
659 | } | |
651 | assert_response :success |
|
660 | assert_response :success | |
652 | assert_select 'span.diff_out', :text => 'Line removed' |
|
661 | assert_select 'span.diff_out', :text => 'Line removed' | |
653 | assert_select 'span.diff_in', :text => 'Line added' |
|
662 | assert_select 'span.diff_in', :text => 'Line added' | |
654 | end |
|
663 | end | |
655 |
|
664 | |||
656 | def test_diff_with_invalid_version_should_respond_with_404 |
|
665 | def test_diff_with_invalid_version_should_respond_with_404 | |
657 | get :diff, :params => { |
|
666 | get :diff, :params => { | |
658 | :project_id => 1, :id => 'CookBook_documentation', |
|
667 | :project_id => 1, :id => 'CookBook_documentation', | |
659 | :version => '99' |
|
668 | :version => '99' | |
660 | } |
|
669 | } | |
661 | assert_response 404 |
|
670 | assert_response 404 | |
662 | end |
|
671 | end | |
663 |
|
672 | |||
664 | def test_diff_with_invalid_version_from_should_respond_with_404 |
|
673 | def test_diff_with_invalid_version_from_should_respond_with_404 | |
665 | get :diff, :params => { |
|
674 | get :diff, :params => { | |
666 | :project_id => 1, :id => 'CookBook_documentation', |
|
675 | :project_id => 1, :id => 'CookBook_documentation', | |
667 | :version => '99', |
|
676 | :version => '99', | |
668 | :version_from => '98' |
|
677 | :version_from => '98' | |
669 | } |
|
678 | } | |
670 | assert_response 404 |
|
679 | assert_response 404 | |
671 | end |
|
680 | end | |
672 |
|
681 | |||
673 | def test_annotate |
|
682 | def test_annotate | |
674 | get :annotate, :params => { |
|
683 | get :annotate, :params => { | |
675 | :project_id => 1, :id => 'CookBook_documentation', |
|
684 | :project_id => 1, :id => 'CookBook_documentation', | |
676 | :version => 2 |
|
685 | :version => 2 | |
677 | } |
|
686 | } | |
678 | assert_response :success |
|
687 | assert_response :success | |
679 |
|
688 | |||
680 | # Line 1 |
|
689 | # Line 1 | |
681 | assert_select 'table.annotate tr:nth-child(1)' do |
|
690 | assert_select 'table.annotate tr:nth-child(1)' do | |
682 | assert_select 'th.line-num', :text => '1' |
|
691 | assert_select 'th.line-num', :text => '1' | |
683 | assert_select 'td.author', :text => /Redmine Admin/ |
|
692 | assert_select 'td.author', :text => /Redmine Admin/ | |
684 | assert_select 'td', :text => /h1\. CookBook documentation v2/ |
|
693 | assert_select 'td', :text => /h1\. CookBook documentation v2/ | |
685 | end |
|
694 | end | |
686 |
|
695 | |||
687 | # Line 4 |
|
696 | # Line 4 | |
688 | assert_select 'table.annotate tr:nth-child(4)' do |
|
697 | assert_select 'table.annotate tr:nth-child(4)' do | |
689 | assert_select 'th.line-num', :text => '4' |
|
698 | assert_select 'th.line-num', :text => '4' | |
690 | assert_select 'td.author', :text => /John Smith/ |
|
699 | assert_select 'td.author', :text => /John Smith/ | |
691 | assert_select 'td', :text => /Line from v1/ |
|
700 | assert_select 'td', :text => /Line from v1/ | |
692 | end |
|
701 | end | |
693 |
|
702 | |||
694 | # Line 5 |
|
703 | # Line 5 | |
695 | assert_select 'table.annotate tr:nth-child(5)' do |
|
704 | assert_select 'table.annotate tr:nth-child(5)' do | |
696 | assert_select 'th.line-num', :text => '5' |
|
705 | assert_select 'th.line-num', :text => '5' | |
697 | assert_select 'td.author', :text => /Redmine Admin/ |
|
706 | assert_select 'td.author', :text => /Redmine Admin/ | |
698 | assert_select 'td', :text => /Some updated \[\[documentation\]\] here/ |
|
707 | assert_select 'td', :text => /Some updated \[\[documentation\]\] here/ | |
699 | end |
|
708 | end | |
700 | end |
|
709 | end | |
701 |
|
710 | |||
702 | def test_annotate_with_invalid_version_should_respond_with_404 |
|
711 | def test_annotate_with_invalid_version_should_respond_with_404 | |
703 | get :annotate, :params => { |
|
712 | get :annotate, :params => { | |
704 | :project_id => 1, :id => 'CookBook_documentation', |
|
713 | :project_id => 1, :id => 'CookBook_documentation', | |
705 | :version => '99' |
|
714 | :version => '99' | |
706 | } |
|
715 | } | |
707 | assert_response 404 |
|
716 | assert_response 404 | |
708 | end |
|
717 | end | |
709 |
|
718 | |||
710 | def test_get_rename |
|
719 | def test_get_rename | |
711 | @request.session[:user_id] = 2 |
|
720 | @request.session[:user_id] = 2 | |
712 | get :rename, :params => {:project_id => 1, :id => 'Another_page'} |
|
721 | get :rename, :params => {:project_id => 1, :id => 'Another_page'} | |
713 | assert_response :success |
|
722 | assert_response :success | |
714 |
|
723 | |||
715 | assert_select 'select[name=?]', 'wiki_page[parent_id]' do |
|
724 | assert_select 'select[name=?]', 'wiki_page[parent_id]' do | |
716 | assert_select 'option[value=""]', :text => '' |
|
725 | assert_select 'option[value=""]', :text => '' | |
717 | assert_select 'option[selected=selected]', 0 |
|
726 | assert_select 'option[selected=selected]', 0 | |
718 | end |
|
727 | end | |
719 | end |
|
728 | end | |
720 |
|
729 | |||
721 | def test_get_rename_child_page |
|
730 | def test_get_rename_child_page | |
722 | @request.session[:user_id] = 2 |
|
731 | @request.session[:user_id] = 2 | |
723 | get :rename, :params => {:project_id => 1, :id => 'Child_1'} |
|
732 | get :rename, :params => {:project_id => 1, :id => 'Child_1'} | |
724 | assert_response :success |
|
733 | assert_response :success | |
725 |
|
734 | |||
726 | assert_select 'select[name=?]', 'wiki_page[parent_id]' do |
|
735 | assert_select 'select[name=?]', 'wiki_page[parent_id]' do | |
727 | assert_select 'option[value=""]', :text => '' |
|
736 | assert_select 'option[value=""]', :text => '' | |
728 | assert_select 'option[value="2"][selected=selected]', :text => /Another page/ |
|
737 | assert_select 'option[value="2"][selected=selected]', :text => /Another page/ | |
729 | end |
|
738 | end | |
730 | end |
|
739 | end | |
731 |
|
740 | |||
732 | def test_rename_with_redirect |
|
741 | def test_rename_with_redirect | |
733 | @request.session[:user_id] = 2 |
|
742 | @request.session[:user_id] = 2 | |
734 | post :rename, :params => { |
|
743 | post :rename, :params => { | |
735 | :project_id => 1, |
|
744 | :project_id => 1, | |
736 | :id => 'Another_page', |
|
745 | :id => 'Another_page', | |
737 | :wiki_page => { |
|
746 | :wiki_page => { | |
738 | :title => 'Another renamed page', |
|
747 | :title => 'Another renamed page', | |
739 | :redirect_existing_links => 1 |
|
748 | :redirect_existing_links => 1 | |
740 | } |
|
749 | } | |
741 | } |
|
750 | } | |
742 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page' |
|
751 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page' | |
743 | wiki = Project.find(1).wiki |
|
752 | wiki = Project.find(1).wiki | |
744 | # Check redirects |
|
753 | # Check redirects | |
745 | assert_not_nil wiki.find_page('Another page') |
|
754 | assert_not_nil wiki.find_page('Another page') | |
746 | assert_nil wiki.find_page('Another page', :with_redirect => false) |
|
755 | assert_nil wiki.find_page('Another page', :with_redirect => false) | |
747 | end |
|
756 | end | |
748 |
|
757 | |||
749 | def test_rename_without_redirect |
|
758 | def test_rename_without_redirect | |
750 | @request.session[:user_id] = 2 |
|
759 | @request.session[:user_id] = 2 | |
751 | post :rename, :params => { |
|
760 | post :rename, :params => { | |
752 | :project_id => 1, |
|
761 | :project_id => 1, | |
753 | :id => 'Another_page', |
|
762 | :id => 'Another_page', | |
754 | :wiki_page => { |
|
763 | :wiki_page => { | |
755 | :title => 'Another renamed page', |
|
764 | :title => 'Another renamed page', | |
756 | :redirect_existing_links => "0" |
|
765 | :redirect_existing_links => "0" | |
757 | } |
|
766 | } | |
758 | } |
|
767 | } | |
759 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page' |
|
768 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page' | |
760 | wiki = Project.find(1).wiki |
|
769 | wiki = Project.find(1).wiki | |
761 | # Check that there's no redirects |
|
770 | # Check that there's no redirects | |
762 | assert_nil wiki.find_page('Another page') |
|
771 | assert_nil wiki.find_page('Another page') | |
763 | end |
|
772 | end | |
764 |
|
773 | |||
765 | def test_rename_with_parent_assignment |
|
774 | def test_rename_with_parent_assignment | |
766 | @request.session[:user_id] = 2 |
|
775 | @request.session[:user_id] = 2 | |
767 | post :rename, :params => { |
|
776 | post :rename, :params => { | |
768 | :project_id => 1, |
|
777 | :project_id => 1, | |
769 | :id => 'Another_page', |
|
778 | :id => 'Another_page', | |
770 | :wiki_page => { |
|
779 | :wiki_page => { | |
771 | :title => 'Another page', |
|
780 | :title => 'Another page', | |
772 | :redirect_existing_links => "0", |
|
781 | :redirect_existing_links => "0", | |
773 | :parent_id => '4' |
|
782 | :parent_id => '4' | |
774 | } |
|
783 | } | |
775 | } |
|
784 | } | |
776 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' |
|
785 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' | |
777 | assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent |
|
786 | assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent | |
778 | end |
|
787 | end | |
779 |
|
788 | |||
780 | def test_rename_with_parent_unassignment |
|
789 | def test_rename_with_parent_unassignment | |
781 | @request.session[:user_id] = 2 |
|
790 | @request.session[:user_id] = 2 | |
782 | post :rename, :params => { |
|
791 | post :rename, :params => { | |
783 | :project_id => 1, |
|
792 | :project_id => 1, | |
784 | :id => 'Child_1', |
|
793 | :id => 'Child_1', | |
785 | :wiki_page => { |
|
794 | :wiki_page => { | |
786 | :title => 'Child 1', |
|
795 | :title => 'Child 1', | |
787 | :redirect_existing_links => "0", |
|
796 | :redirect_existing_links => "0", | |
788 | :parent_id => '' |
|
797 | :parent_id => '' | |
789 | } |
|
798 | } | |
790 | } |
|
799 | } | |
791 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1' |
|
800 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1' | |
792 | assert_nil WikiPage.find_by_title('Child_1').parent |
|
801 | assert_nil WikiPage.find_by_title('Child_1').parent | |
793 | end |
|
802 | end | |
794 |
|
803 | |||
795 | def test_get_rename_should_show_target_projects_list |
|
804 | def test_get_rename_should_show_target_projects_list | |
796 | @request.session[:user_id] = 2 |
|
805 | @request.session[:user_id] = 2 | |
797 | project = Project.find(5) |
|
806 | project = Project.find(5) | |
798 | project.enable_module! :wiki |
|
807 | project.enable_module! :wiki | |
799 |
|
808 | |||
800 | get :rename, :params => {:project_id => 1, :id => 'Another_page'} |
|
809 | get :rename, :params => {:project_id => 1, :id => 'Another_page'} | |
801 | assert_response :success |
|
810 | assert_response :success | |
802 |
|
811 | |||
803 | assert_select 'select[name=?]', 'wiki_page[wiki_id]' do |
|
812 | assert_select 'select[name=?]', 'wiki_page[wiki_id]' do | |
804 | assert_select 'option', 2 |
|
813 | assert_select 'option', 2 | |
805 | assert_select 'option[value=?][selected=selected]', '1', :text => /eCookbook/ |
|
814 | assert_select 'option[value=?][selected=selected]', '1', :text => /eCookbook/ | |
806 | assert_select 'option[value=?]', project.wiki.id.to_s, :text => /#{project.name}/ |
|
815 | assert_select 'option[value=?]', project.wiki.id.to_s, :text => /#{project.name}/ | |
807 | end |
|
816 | end | |
808 | end |
|
817 | end | |
809 |
|
818 | |||
810 | def test_rename_with_move |
|
819 | def test_rename_with_move | |
811 | @request.session[:user_id] = 2 |
|
820 | @request.session[:user_id] = 2 | |
812 | project = Project.find(5) |
|
821 | project = Project.find(5) | |
813 | project.enable_module! :wiki |
|
822 | project.enable_module! :wiki | |
814 |
|
823 | |||
815 | post :rename, :params => { |
|
824 | post :rename, :params => { | |
816 | :project_id => 1, |
|
825 | :project_id => 1, | |
817 | :id => 'Another_page', |
|
826 | :id => 'Another_page', | |
818 | :wiki_page => { |
|
827 | :wiki_page => { | |
819 | :wiki_id => project.wiki.id.to_s, |
|
828 | :wiki_id => project.wiki.id.to_s, | |
820 | :title => 'Another renamed page', |
|
829 | :title => 'Another renamed page', | |
821 | :redirect_existing_links => 1 |
|
830 | :redirect_existing_links => 1 | |
822 | } |
|
831 | } | |
823 | } |
|
832 | } | |
824 | assert_redirected_to '/projects/private-child/wiki/Another_renamed_page' |
|
833 | assert_redirected_to '/projects/private-child/wiki/Another_renamed_page' | |
825 |
|
834 | |||
826 | page = WikiPage.find(2) |
|
835 | page = WikiPage.find(2) | |
827 | assert_equal project.wiki.id, page.wiki_id |
|
836 | assert_equal project.wiki.id, page.wiki_id | |
828 | end |
|
837 | end | |
829 |
|
838 | |||
830 | def test_destroy_a_page_without_children_should_not_ask_confirmation |
|
839 | def test_destroy_a_page_without_children_should_not_ask_confirmation | |
831 | @request.session[:user_id] = 2 |
|
840 | @request.session[:user_id] = 2 | |
832 | delete :destroy, :params => {:project_id => 1, :id => 'Child_2'} |
|
841 | delete :destroy, :params => {:project_id => 1, :id => 'Child_2'} | |
833 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
842 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
834 | end |
|
843 | end | |
835 |
|
844 | |||
836 | def test_destroy_parent_should_ask_confirmation |
|
845 | def test_destroy_parent_should_ask_confirmation | |
837 | @request.session[:user_id] = 2 |
|
846 | @request.session[:user_id] = 2 | |
838 | assert_no_difference('WikiPage.count') do |
|
847 | assert_no_difference('WikiPage.count') do | |
839 | delete :destroy, :params => {:project_id => 1, :id => 'Another_page'} |
|
848 | delete :destroy, :params => {:project_id => 1, :id => 'Another_page'} | |
840 | end |
|
849 | end | |
841 | assert_response :success |
|
850 | assert_response :success | |
842 | assert_select 'form' do |
|
851 | assert_select 'form' do | |
843 | assert_select 'input[name=todo][value=nullify]' |
|
852 | assert_select 'input[name=todo][value=nullify]' | |
844 | assert_select 'input[name=todo][value=destroy]' |
|
853 | assert_select 'input[name=todo][value=destroy]' | |
845 | assert_select 'input[name=todo][value=reassign]' |
|
854 | assert_select 'input[name=todo][value=reassign]' | |
846 | end |
|
855 | end | |
847 | end |
|
856 | end | |
848 |
|
857 | |||
849 | def test_destroy_parent_with_nullify_should_delete_parent_only |
|
858 | def test_destroy_parent_with_nullify_should_delete_parent_only | |
850 | @request.session[:user_id] = 2 |
|
859 | @request.session[:user_id] = 2 | |
851 | assert_difference('WikiPage.count', -1) do |
|
860 | assert_difference('WikiPage.count', -1) do | |
852 | delete :destroy, :params => {:project_id => 1, :id => 'Another_page', :todo => 'nullify'} |
|
861 | delete :destroy, :params => {:project_id => 1, :id => 'Another_page', :todo => 'nullify'} | |
853 | end |
|
862 | end | |
854 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
863 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
855 | assert_nil WikiPage.find_by_id(2) |
|
864 | assert_nil WikiPage.find_by_id(2) | |
856 | end |
|
865 | end | |
857 |
|
866 | |||
858 | def test_destroy_parent_with_cascade_should_delete_descendants |
|
867 | def test_destroy_parent_with_cascade_should_delete_descendants | |
859 | @request.session[:user_id] = 2 |
|
868 | @request.session[:user_id] = 2 | |
860 | assert_difference('WikiPage.count', -4) do |
|
869 | assert_difference('WikiPage.count', -4) do | |
861 | delete :destroy, :params => {:project_id => 1, :id => 'Another_page', :todo => 'destroy'} |
|
870 | delete :destroy, :params => {:project_id => 1, :id => 'Another_page', :todo => 'destroy'} | |
862 | end |
|
871 | end | |
863 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
872 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
864 | assert_nil WikiPage.find_by_id(2) |
|
873 | assert_nil WikiPage.find_by_id(2) | |
865 | assert_nil WikiPage.find_by_id(5) |
|
874 | assert_nil WikiPage.find_by_id(5) | |
866 | end |
|
875 | end | |
867 |
|
876 | |||
868 | def test_destroy_parent_with_reassign |
|
877 | def test_destroy_parent_with_reassign | |
869 | @request.session[:user_id] = 2 |
|
878 | @request.session[:user_id] = 2 | |
870 | assert_difference('WikiPage.count', -1) do |
|
879 | assert_difference('WikiPage.count', -1) do | |
871 | delete :destroy, :params => {:project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1} |
|
880 | delete :destroy, :params => {:project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1} | |
872 | end |
|
881 | end | |
873 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
882 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
874 | assert_nil WikiPage.find_by_id(2) |
|
883 | assert_nil WikiPage.find_by_id(2) | |
875 | assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent |
|
884 | assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent | |
876 | end |
|
885 | end | |
877 |
|
886 | |||
878 | def test_destroy_version |
|
887 | def test_destroy_version | |
879 | @request.session[:user_id] = 2 |
|
888 | @request.session[:user_id] = 2 | |
880 | assert_difference 'WikiContent::Version.count', -1 do |
|
889 | assert_difference 'WikiContent::Version.count', -1 do | |
881 | assert_no_difference 'WikiContent.count' do |
|
890 | assert_no_difference 'WikiContent.count' do | |
882 | assert_no_difference 'WikiPage.count' do |
|
891 | assert_no_difference 'WikiPage.count' do | |
883 | delete :destroy_version, :params => {:project_id => 'ecookbook', :id => 'CookBook_documentation', :version => 2} |
|
892 | delete :destroy_version, :params => {:project_id => 'ecookbook', :id => 'CookBook_documentation', :version => 2} | |
884 | assert_redirected_to '/projects/ecookbook/wiki/CookBook_documentation/history' |
|
893 | assert_redirected_to '/projects/ecookbook/wiki/CookBook_documentation/history' | |
885 | end |
|
894 | end | |
886 | end |
|
895 | end | |
887 | end |
|
896 | end | |
888 | end |
|
897 | end | |
889 |
|
898 | |||
890 | def test_destroy_invalid_version_should_respond_with_404 |
|
899 | def test_destroy_invalid_version_should_respond_with_404 | |
891 | @request.session[:user_id] = 2 |
|
900 | @request.session[:user_id] = 2 | |
892 | assert_no_difference 'WikiContent::Version.count' do |
|
901 | assert_no_difference 'WikiContent::Version.count' do | |
893 | assert_no_difference 'WikiContent.count' do |
|
902 | assert_no_difference 'WikiContent.count' do | |
894 | assert_no_difference 'WikiPage.count' do |
|
903 | assert_no_difference 'WikiPage.count' do | |
895 | delete :destroy_version, :params => {:project_id => 'ecookbook', :id => 'CookBook_documentation', :version => 99} |
|
904 | delete :destroy_version, :params => {:project_id => 'ecookbook', :id => 'CookBook_documentation', :version => 99} | |
896 | end |
|
905 | end | |
897 | end |
|
906 | end | |
898 | end |
|
907 | end | |
899 | assert_response 404 |
|
908 | assert_response 404 | |
900 | end |
|
909 | end | |
901 |
|
910 | |||
902 | def test_index |
|
911 | def test_index | |
903 | get :index, :params => {:project_id => 'ecookbook'} |
|
912 | get :index, :params => {:project_id => 'ecookbook'} | |
904 | assert_response :success |
|
913 | assert_response :success | |
905 |
|
914 | |||
906 | assert_select 'ul.pages-hierarchy' do |
|
915 | assert_select 'ul.pages-hierarchy' do | |
907 | assert_select 'li', Project.find(1).wiki.pages.count |
|
916 | assert_select 'li', Project.find(1).wiki.pages.count | |
908 | end |
|
917 | end | |
909 |
|
918 | |||
910 | assert_select 'ul.pages-hierarchy' do |
|
919 | assert_select 'ul.pages-hierarchy' do | |
911 | assert_select 'li' do |
|
920 | assert_select 'li' do | |
912 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation', :text => 'CookBook documentation' |
|
921 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation', :text => 'CookBook documentation' | |
913 | assert_select 'ul li a[href=?]', '/projects/ecookbook/wiki/Page_with_an_inline_image', :text => 'Page with an inline image' |
|
922 | assert_select 'ul li a[href=?]', '/projects/ecookbook/wiki/Page_with_an_inline_image', :text => 'Page with an inline image' | |
914 | end |
|
923 | end | |
915 | assert_select 'li a[href=?]', '/projects/ecookbook/wiki/Another_page', :text => 'Another page' |
|
924 | assert_select 'li a[href=?]', '/projects/ecookbook/wiki/Another_page', :text => 'Another page' | |
916 | end |
|
925 | end | |
917 | end |
|
926 | end | |
918 |
|
927 | |||
919 | def test_index_should_include_atom_link |
|
928 | def test_index_should_include_atom_link | |
920 | get :index, :params => {:project_id => 'ecookbook'} |
|
929 | get :index, :params => {:project_id => 'ecookbook'} | |
921 | assert_select 'a[href=?]', '/projects/ecookbook/activity.atom?show_wiki_edits=1' |
|
930 | assert_select 'a[href=?]', '/projects/ecookbook/activity.atom?show_wiki_edits=1' | |
922 | end |
|
931 | end | |
923 |
|
932 | |||
924 | def test_export_to_html |
|
933 | def test_export_to_html | |
925 | @request.session[:user_id] = 2 |
|
934 | @request.session[:user_id] = 2 | |
926 | get :export, :params => {:project_id => 'ecookbook'} |
|
935 | get :export, :params => {:project_id => 'ecookbook'} | |
927 |
|
936 | |||
928 | assert_response :success |
|
937 | assert_response :success | |
929 | assert_equal "text/html", @response.content_type |
|
938 | assert_equal "text/html", @response.content_type | |
930 |
|
939 | |||
931 | assert_select "a[name=?]", "CookBook_documentation" |
|
940 | assert_select "a[name=?]", "CookBook_documentation" | |
932 | assert_select "a[name=?]", "Another_page" |
|
941 | assert_select "a[name=?]", "Another_page" | |
933 | assert_select "a[name=?]", "Page_with_an_inline_image" |
|
942 | assert_select "a[name=?]", "Page_with_an_inline_image" | |
934 | end |
|
943 | end | |
935 |
|
944 | |||
936 | def test_export_to_pdf |
|
945 | def test_export_to_pdf | |
937 | @request.session[:user_id] = 2 |
|
946 | @request.session[:user_id] = 2 | |
938 | get :export, :params => {:project_id => 'ecookbook', :format => 'pdf'} |
|
947 | get :export, :params => {:project_id => 'ecookbook', :format => 'pdf'} | |
939 |
|
948 | |||
940 | assert_response :success |
|
949 | assert_response :success | |
941 | assert_equal 'application/pdf', @response.content_type |
|
950 | assert_equal 'application/pdf', @response.content_type | |
942 | assert_equal 'attachment; filename="ecookbook.pdf"', @response.headers['Content-Disposition'] |
|
951 | assert_equal 'attachment; filename="ecookbook.pdf"', @response.headers['Content-Disposition'] | |
943 | assert @response.body.starts_with?('%PDF') |
|
952 | assert @response.body.starts_with?('%PDF') | |
944 | end |
|
953 | end | |
945 |
|
954 | |||
946 | def test_export_without_permission_should_be_denied |
|
955 | def test_export_without_permission_should_be_denied | |
947 | @request.session[:user_id] = 2 |
|
956 | @request.session[:user_id] = 2 | |
948 | Role.find_by_name('Manager').remove_permission! :export_wiki_pages |
|
957 | Role.find_by_name('Manager').remove_permission! :export_wiki_pages | |
949 | get :export, :params => {:project_id => 'ecookbook'} |
|
958 | get :export, :params => {:project_id => 'ecookbook'} | |
950 |
|
959 | |||
951 | assert_response 403 |
|
960 | assert_response 403 | |
952 | end |
|
961 | end | |
953 |
|
962 | |||
954 | def test_date_index |
|
963 | def test_date_index | |
955 | get :date_index, :params => {:project_id => 'ecookbook'} |
|
964 | get :date_index, :params => {:project_id => 'ecookbook'} | |
956 |
|
965 | |||
957 | assert_response :success |
|
966 | assert_response :success | |
958 |
|
967 | |||
959 | assert_select 'a[href=?]', '/projects/ecookbook/activity.atom?show_wiki_edits=1' |
|
968 | assert_select 'a[href=?]', '/projects/ecookbook/activity.atom?show_wiki_edits=1' | |
960 | end |
|
969 | end | |
961 |
|
970 | |||
962 | def test_not_found |
|
971 | def test_not_found | |
963 | get :show, :params => {:project_id => 999} |
|
972 | get :show, :params => {:project_id => 999} | |
964 | assert_response 404 |
|
973 | assert_response 404 | |
965 | end |
|
974 | end | |
966 |
|
975 | |||
967 | def test_protect_page |
|
976 | def test_protect_page | |
968 | page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page') |
|
977 | page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page') | |
969 | assert !page.protected? |
|
978 | assert !page.protected? | |
970 | @request.session[:user_id] = 2 |
|
979 | @request.session[:user_id] = 2 | |
971 | post :protect, :params => {:project_id => 1, :id => page.title, :protected => '1'} |
|
980 | post :protect, :params => {:project_id => 1, :id => page.title, :protected => '1'} | |
972 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' |
|
981 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' | |
973 | assert page.reload.protected? |
|
982 | assert page.reload.protected? | |
974 | end |
|
983 | end | |
975 |
|
984 | |||
976 | def test_unprotect_page |
|
985 | def test_unprotect_page | |
977 | page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation') |
|
986 | page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation') | |
978 | assert page.protected? |
|
987 | assert page.protected? | |
979 | @request.session[:user_id] = 2 |
|
988 | @request.session[:user_id] = 2 | |
980 | post :protect, :params => {:project_id => 1, :id => page.title, :protected => '0'} |
|
989 | post :protect, :params => {:project_id => 1, :id => page.title, :protected => '0'} | |
981 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation' |
|
990 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation' | |
982 | assert !page.reload.protected? |
|
991 | assert !page.reload.protected? | |
983 | end |
|
992 | end | |
984 |
|
993 | |||
985 | def test_show_page_with_edit_link |
|
994 | def test_show_page_with_edit_link | |
986 | @request.session[:user_id] = 2 |
|
995 | @request.session[:user_id] = 2 | |
987 | get :show, :params => {:project_id => 1} |
|
996 | get :show, :params => {:project_id => 1} | |
988 | assert_response :success |
|
997 | assert_response :success | |
989 |
|
998 | |||
990 | assert_select 'a[href=?]', '/projects/1/wiki/CookBook_documentation/edit' |
|
999 | assert_select 'a[href=?]', '/projects/1/wiki/CookBook_documentation/edit' | |
991 | end |
|
1000 | end | |
992 |
|
1001 | |||
993 | def test_show_page_without_edit_link |
|
1002 | def test_show_page_without_edit_link | |
994 | @request.session[:user_id] = 4 |
|
1003 | @request.session[:user_id] = 4 | |
995 | get :show, :params => {:project_id => 1} |
|
1004 | get :show, :params => {:project_id => 1} | |
996 | assert_response :success |
|
1005 | assert_response :success | |
997 |
|
1006 | |||
998 | assert_select 'a[href=?]', '/projects/1/wiki/CookBook_documentation/edit', 0 |
|
1007 | assert_select 'a[href=?]', '/projects/1/wiki/CookBook_documentation/edit', 0 | |
999 | end |
|
1008 | end | |
1000 |
|
1009 | |||
1001 | def test_show_pdf |
|
1010 | def test_show_pdf | |
1002 | @request.session[:user_id] = 2 |
|
1011 | @request.session[:user_id] = 2 | |
1003 | get :show, :params => {:project_id => 1, :format => 'pdf'} |
|
1012 | get :show, :params => {:project_id => 1, :format => 'pdf'} | |
1004 | assert_response :success |
|
1013 | assert_response :success | |
1005 |
|
1014 | |||
1006 | assert_equal 'application/pdf', @response.content_type |
|
1015 | assert_equal 'application/pdf', @response.content_type | |
1007 | assert_equal 'attachment; filename="CookBook_documentation.pdf"', |
|
1016 | assert_equal 'attachment; filename="CookBook_documentation.pdf"', | |
1008 | @response.headers['Content-Disposition'] |
|
1017 | @response.headers['Content-Disposition'] | |
1009 | end |
|
1018 | end | |
1010 |
|
1019 | |||
1011 | def test_show_html |
|
1020 | def test_show_html | |
1012 | @request.session[:user_id] = 2 |
|
1021 | @request.session[:user_id] = 2 | |
1013 | get :show, :params => {:project_id => 1, :format => 'html'} |
|
1022 | get :show, :params => {:project_id => 1, :format => 'html'} | |
1014 | assert_response :success |
|
1023 | assert_response :success | |
1015 |
|
1024 | |||
1016 | assert_equal 'text/html', @response.content_type |
|
1025 | assert_equal 'text/html', @response.content_type | |
1017 | assert_equal 'attachment; filename="CookBook_documentation.html"', |
|
1026 | assert_equal 'attachment; filename="CookBook_documentation.html"', | |
1018 | @response.headers['Content-Disposition'] |
|
1027 | @response.headers['Content-Disposition'] | |
1019 | assert_select 'h1', :text => /CookBook documentation/ |
|
1028 | assert_select 'h1', :text => /CookBook documentation/ | |
1020 | end |
|
1029 | end | |
1021 |
|
1030 | |||
1022 | def test_show_versioned_html |
|
1031 | def test_show_versioned_html | |
1023 | @request.session[:user_id] = 2 |
|
1032 | @request.session[:user_id] = 2 | |
1024 | get :show, :params => {:project_id => 1, :format => 'html', :version => 2} |
|
1033 | get :show, :params => {:project_id => 1, :format => 'html', :version => 2} | |
1025 | assert_response :success |
|
1034 | assert_response :success | |
1026 |
|
1035 | |||
1027 | assert_equal 'text/html', @response.content_type |
|
1036 | assert_equal 'text/html', @response.content_type | |
1028 | assert_equal 'attachment; filename="CookBook_documentation.html"', |
|
1037 | assert_equal 'attachment; filename="CookBook_documentation.html"', | |
1029 | @response.headers['Content-Disposition'] |
|
1038 | @response.headers['Content-Disposition'] | |
1030 | assert_select 'h1', :text => /CookBook documentation v2/ |
|
1039 | assert_select 'h1', :text => /CookBook documentation v2/ | |
1031 | end |
|
1040 | end | |
1032 |
|
1041 | |||
1033 | def test_show_txt |
|
1042 | def test_show_txt | |
1034 | @request.session[:user_id] = 2 |
|
1043 | @request.session[:user_id] = 2 | |
1035 | get :show, :params => {:project_id => 1, :format => 'txt'} |
|
1044 | get :show, :params => {:project_id => 1, :format => 'txt'} | |
1036 | assert_response :success |
|
1045 | assert_response :success | |
1037 |
|
1046 | |||
1038 | assert_equal 'text/plain', @response.content_type |
|
1047 | assert_equal 'text/plain', @response.content_type | |
1039 | assert_equal 'attachment; filename="CookBook_documentation.txt"', |
|
1048 | assert_equal 'attachment; filename="CookBook_documentation.txt"', | |
1040 | @response.headers['Content-Disposition'] |
|
1049 | @response.headers['Content-Disposition'] | |
1041 | assert_include 'h1. CookBook documentation', @response.body |
|
1050 | assert_include 'h1. CookBook documentation', @response.body | |
1042 | end |
|
1051 | end | |
1043 |
|
1052 | |||
1044 | def test_show_versioned_txt |
|
1053 | def test_show_versioned_txt | |
1045 | @request.session[:user_id] = 2 |
|
1054 | @request.session[:user_id] = 2 | |
1046 | get :show, :params => {:project_id => 1, :format => 'txt', :version => 2} |
|
1055 | get :show, :params => {:project_id => 1, :format => 'txt', :version => 2} | |
1047 | assert_response :success |
|
1056 | assert_response :success | |
1048 |
|
1057 | |||
1049 | assert_equal 'text/plain', @response.content_type |
|
1058 | assert_equal 'text/plain', @response.content_type | |
1050 | assert_equal 'attachment; filename="CookBook_documentation.txt"', |
|
1059 | assert_equal 'attachment; filename="CookBook_documentation.txt"', | |
1051 | @response.headers['Content-Disposition'] |
|
1060 | @response.headers['Content-Disposition'] | |
1052 | assert_include 'h1. CookBook documentation v2', @response.body |
|
1061 | assert_include 'h1. CookBook documentation v2', @response.body | |
1053 | end |
|
1062 | end | |
1054 |
|
1063 | |||
1055 | def test_edit_unprotected_page |
|
1064 | def test_edit_unprotected_page | |
1056 | # Non members can edit unprotected wiki pages |
|
1065 | # Non members can edit unprotected wiki pages | |
1057 | @request.session[:user_id] = 4 |
|
1066 | @request.session[:user_id] = 4 | |
1058 | get :edit, :params => {:project_id => 1, :id => 'Another_page'} |
|
1067 | get :edit, :params => {:project_id => 1, :id => 'Another_page'} | |
1059 | assert_response :success |
|
1068 | assert_response :success | |
1060 | end |
|
1069 | end | |
1061 |
|
1070 | |||
1062 | def test_edit_protected_page_by_nonmember |
|
1071 | def test_edit_protected_page_by_nonmember | |
1063 | # Non members cannot edit protected wiki pages |
|
1072 | # Non members cannot edit protected wiki pages | |
1064 | @request.session[:user_id] = 4 |
|
1073 | @request.session[:user_id] = 4 | |
1065 | get :edit, :params => {:project_id => 1, :id => 'CookBook_documentation'} |
|
1074 | get :edit, :params => {:project_id => 1, :id => 'CookBook_documentation'} | |
1066 | assert_response 403 |
|
1075 | assert_response 403 | |
1067 | end |
|
1076 | end | |
1068 |
|
1077 | |||
1069 | def test_edit_protected_page_by_member |
|
1078 | def test_edit_protected_page_by_member | |
1070 | @request.session[:user_id] = 2 |
|
1079 | @request.session[:user_id] = 2 | |
1071 | get :edit, :params => {:project_id => 1, :id => 'CookBook_documentation'} |
|
1080 | get :edit, :params => {:project_id => 1, :id => 'CookBook_documentation'} | |
1072 | assert_response :success |
|
1081 | assert_response :success | |
1073 | end |
|
1082 | end | |
1074 |
|
1083 | |||
1075 | def test_history_of_non_existing_page_should_return_404 |
|
1084 | def test_history_of_non_existing_page_should_return_404 | |
1076 | get :history, :params => {:project_id => 1, :id => 'Unknown_page'} |
|
1085 | get :history, :params => {:project_id => 1, :id => 'Unknown_page'} | |
1077 | assert_response 404 |
|
1086 | assert_response 404 | |
1078 | end |
|
1087 | end | |
1079 |
|
1088 | |||
1080 | def test_add_attachment |
|
1089 | def test_add_attachment | |
1081 | @request.session[:user_id] = 2 |
|
1090 | @request.session[:user_id] = 2 | |
1082 | assert_difference 'Attachment.count' do |
|
1091 | assert_difference 'Attachment.count' do | |
1083 | post :add_attachment, :params => { |
|
1092 | post :add_attachment, :params => { | |
1084 | :project_id => 1, |
|
1093 | :project_id => 1, | |
1085 | :id => 'CookBook_documentation', |
|
1094 | :id => 'CookBook_documentation', | |
1086 | :attachments => { |
|
1095 | :attachments => { | |
1087 | '1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'} |
|
1096 | '1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'} | |
1088 | } |
|
1097 | } | |
1089 | } |
|
1098 | } | |
1090 | end |
|
1099 | end | |
1091 | attachment = Attachment.order('id DESC').first |
|
1100 | attachment = Attachment.order('id DESC').first | |
1092 | assert_equal Wiki.find(1).find_page('CookBook_documentation'), attachment.container |
|
1101 | assert_equal Wiki.find(1).find_page('CookBook_documentation'), attachment.container | |
1093 | end |
|
1102 | end | |
1094 | end |
|
1103 | end |
General Comments 0
You need to be logged in to leave comments.
Login now