##// END OF EJS Templates
Merged r5185 from trunk....
Jean-Philippe Lang -
r5455:55fd2f55626f
parent child
Show More
@@ -1,279 +1,277
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require 'diff'
18 require 'diff'
19
19
20 # The WikiController follows the Rails REST controller pattern but with
20 # The WikiController follows the Rails REST controller pattern but with
21 # a few differences
21 # a few differences
22 #
22 #
23 # * index - shows a list of WikiPages grouped by page or date
23 # * index - shows a list of WikiPages grouped by page or date
24 # * new - not used
24 # * new - not used
25 # * create - not used
25 # * create - not used
26 # * show - will also show the form for creating a new wiki page
26 # * show - will also show the form for creating a new wiki page
27 # * edit - used to edit an existing or new page
27 # * edit - used to edit an existing or new page
28 # * update - used to save a wiki page update to the database, including new pages
28 # * update - used to save a wiki page update to the database, including new pages
29 # * destroy - normal
29 # * destroy - normal
30 #
30 #
31 # Other member and collection methods are also used
31 # Other member and collection methods are also used
32 #
32 #
33 # TODO: still being worked on
33 # TODO: still being worked on
34 class WikiController < ApplicationController
34 class WikiController < ApplicationController
35 default_search_scope :wiki_pages
35 default_search_scope :wiki_pages
36 before_filter :find_wiki, :authorize
36 before_filter :find_wiki, :authorize
37 before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy]
37 before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy]
38
38
39 verify :method => :post, :only => [:protect], :redirect_to => { :action => :show }
39 verify :method => :post, :only => [:protect], :redirect_to => { :action => :show }
40
40
41 helper :attachments
41 helper :attachments
42 include AttachmentsHelper
42 include AttachmentsHelper
43 helper :watchers
43 helper :watchers
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_grouped_by_date_without_content
47 load_pages_grouped_by_date_without_content
48 end
48 end
49
49
50 # display a page (in editing mode if it doesn't exist)
50 # display a page (in editing mode if it doesn't exist)
51 def show
51 def show
52 page_title = params[:id]
52 page_title = params[:id]
53 @page = @wiki.find_or_new_page(page_title)
53 @page = @wiki.find_or_new_page(page_title)
54 if @page.new_record?
54 if @page.new_record?
55 if User.current.allowed_to?(:edit_wiki_pages, @project) && editable?
55 if User.current.allowed_to?(:edit_wiki_pages, @project) && editable?
56 edit
56 edit
57 render :action => 'edit'
57 render :action => 'edit'
58 else
58 else
59 render_404
59 render_404
60 end
60 end
61 return
61 return
62 end
62 end
63 if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project)
63 if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project)
64 # Redirects user to the current version if he's not allowed to view previous versions
64 # Redirects user to the current version if he's not allowed to view previous versions
65 redirect_to :version => nil
65 redirect_to :version => nil
66 return
66 return
67 end
67 end
68 @content = @page.content_for_version(params[:version])
68 @content = @page.content_for_version(params[:version])
69 if User.current.allowed_to?(:export_wiki_pages, @project)
69 if User.current.allowed_to?(:export_wiki_pages, @project)
70 if params[:format] == 'html'
70 if params[:format] == 'html'
71 export = render_to_string :action => 'export', :layout => false
71 export = render_to_string :action => 'export', :layout => false
72 send_data(export, :type => 'text/html', :filename => "#{@page.title}.html")
72 send_data(export, :type => 'text/html', :filename => "#{@page.title}.html")
73 return
73 return
74 elsif params[:format] == 'txt'
74 elsif params[:format] == 'txt'
75 send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt")
75 send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt")
76 return
76 return
77 end
77 end
78 end
78 end
79 @editable = editable?
79 @editable = editable?
80 render :action => 'show'
80 render :action => 'show'
81 end
81 end
82
82
83 # edit an existing page or a new one
83 # edit an existing page or a new one
84 def edit
84 def edit
85 @page = @wiki.find_or_new_page(params[:id])
85 @page = @wiki.find_or_new_page(params[:id])
86 return render_403 unless editable?
86 return render_403 unless editable?
87 @page.content = WikiContent.new(:page => @page) if @page.new_record?
87 @page.content = WikiContent.new(:page => @page) if @page.new_record?
88
88
89 @content = @page.content_for_version(params[:version])
89 @content = @page.content_for_version(params[:version])
90 @content.text = initial_page_content(@page) if @content.text.blank?
90 @content.text = initial_page_content(@page) if @content.text.blank?
91 # don't keep previous comment
91 # don't keep previous comment
92 @content.comments = nil
92 @content.comments = nil
93
93
94 # To prevent StaleObjectError exception when reverting to a previous version
94 # To prevent StaleObjectError exception when reverting to a previous version
95 @content.version = @page.content.version
95 @content.version = @page.content.version
96 rescue ActiveRecord::StaleObjectError
97 # Optimistic locking exception
98 flash[:error] = l(:notice_locking_conflict)
99 end
96 end
100
97
101 verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
98 verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
102 # Creates a new page or updates an existing one
99 # Creates a new page or updates an existing one
103 def update
100 def update
104 @page = @wiki.find_or_new_page(params[:id])
101 @page = @wiki.find_or_new_page(params[:id])
105 return render_403 unless editable?
102 return render_403 unless editable?
106 @page.content = WikiContent.new(:page => @page) if @page.new_record?
103 @page.content = WikiContent.new(:page => @page) if @page.new_record?
107
104
108 @content = @page.content_for_version(params[:version])
105 @content = @page.content_for_version(params[:version])
109 @content.text = initial_page_content(@page) if @content.text.blank?
106 @content.text = initial_page_content(@page) if @content.text.blank?
110 # don't keep previous comment
107 # don't keep previous comment
111 @content.comments = nil
108 @content.comments = nil
112
109
113 if !@page.new_record? && params[:content].present? && @content.text == params[:content][:text]
110 if !@page.new_record? && params[:content].present? && @content.text == params[:content][:text]
114 attachments = Attachment.attach_files(@page, params[:attachments])
111 attachments = Attachment.attach_files(@page, params[:attachments])
115 render_attachment_warning_if_needed(@page)
112 render_attachment_warning_if_needed(@page)
116 # don't save if text wasn't changed
113 # don't save if text wasn't changed
117 redirect_to :action => 'show', :project_id => @project, :id => @page.title
114 redirect_to :action => 'show', :project_id => @project, :id => @page.title
118 return
115 return
119 end
116 end
120 @content.attributes = params[:content]
117 @content.attributes = params[:content]
121 @content.author = User.current
118 @content.author = User.current
122 # if page is new @page.save will also save content, but not if page isn't a new record
119 # if page is new @page.save will also save content, but not if page isn't a new record
123 if (@page.new_record? ? @page.save : @content.save)
120 if (@page.new_record? ? @page.save : @content.save)
124 attachments = Attachment.attach_files(@page, params[:attachments])
121 attachments = Attachment.attach_files(@page, params[:attachments])
125 render_attachment_warning_if_needed(@page)
122 render_attachment_warning_if_needed(@page)
126 call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page})
123 call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page})
127 redirect_to :action => 'show', :project_id => @project, :id => @page.title
124 redirect_to :action => 'show', :project_id => @project, :id => @page.title
128 else
125 else
129 render :action => 'edit'
126 render :action => 'edit'
130 end
127 end
131
128
132 rescue ActiveRecord::StaleObjectError
129 rescue ActiveRecord::StaleObjectError
133 # Optimistic locking exception
130 # Optimistic locking exception
134 flash[:error] = l(:notice_locking_conflict)
131 flash.now[:error] = l(:notice_locking_conflict)
132 render :action => 'edit'
135 end
133 end
136
134
137 # rename a page
135 # rename a page
138 def rename
136 def rename
139 return render_403 unless editable?
137 return render_403 unless editable?
140 @page.redirect_existing_links = true
138 @page.redirect_existing_links = true
141 # used to display the *original* title if some AR validation errors occur
139 # used to display the *original* title if some AR validation errors occur
142 @original_title = @page.pretty_title
140 @original_title = @page.pretty_title
143 if request.post? && @page.update_attributes(params[:wiki_page])
141 if request.post? && @page.update_attributes(params[:wiki_page])
144 flash[:notice] = l(:notice_successful_update)
142 flash[:notice] = l(:notice_successful_update)
145 redirect_to :action => 'show', :project_id => @project, :id => @page.title
143 redirect_to :action => 'show', :project_id => @project, :id => @page.title
146 end
144 end
147 end
145 end
148
146
149 def protect
147 def protect
150 @page.update_attribute :protected, params[:protected]
148 @page.update_attribute :protected, params[:protected]
151 redirect_to :action => 'show', :project_id => @project, :id => @page.title
149 redirect_to :action => 'show', :project_id => @project, :id => @page.title
152 end
150 end
153
151
154 # show page history
152 # show page history
155 def history
153 def history
156 @version_count = @page.content.versions.count
154 @version_count = @page.content.versions.count
157 @version_pages = Paginator.new self, @version_count, per_page_option, params['p']
155 @version_pages = Paginator.new self, @version_count, per_page_option, params['p']
158 # don't load text
156 # don't load text
159 @versions = @page.content.versions.find :all,
157 @versions = @page.content.versions.find :all,
160 :select => "id, author_id, comments, updated_on, version",
158 :select => "id, author_id, comments, updated_on, version",
161 :order => 'version DESC',
159 :order => 'version DESC',
162 :limit => @version_pages.items_per_page + 1,
160 :limit => @version_pages.items_per_page + 1,
163 :offset => @version_pages.current.offset
161 :offset => @version_pages.current.offset
164
162
165 render :layout => false if request.xhr?
163 render :layout => false if request.xhr?
166 end
164 end
167
165
168 def diff
166 def diff
169 @diff = @page.diff(params[:version], params[:version_from])
167 @diff = @page.diff(params[:version], params[:version_from])
170 render_404 unless @diff
168 render_404 unless @diff
171 end
169 end
172
170
173 def annotate
171 def annotate
174 @annotate = @page.annotate(params[:version])
172 @annotate = @page.annotate(params[:version])
175 render_404 unless @annotate
173 render_404 unless @annotate
176 end
174 end
177
175
178 verify :method => :delete, :only => [:destroy], :redirect_to => { :action => :show }
176 verify :method => :delete, :only => [:destroy], :redirect_to => { :action => :show }
179 # Removes a wiki page and its history
177 # Removes a wiki page and its history
180 # Children can be either set as root pages, removed or reassigned to another parent page
178 # Children can be either set as root pages, removed or reassigned to another parent page
181 def destroy
179 def destroy
182 return render_403 unless editable?
180 return render_403 unless editable?
183
181
184 @descendants_count = @page.descendants.size
182 @descendants_count = @page.descendants.size
185 if @descendants_count > 0
183 if @descendants_count > 0
186 case params[:todo]
184 case params[:todo]
187 when 'nullify'
185 when 'nullify'
188 # Nothing to do
186 # Nothing to do
189 when 'destroy'
187 when 'destroy'
190 # Removes all its descendants
188 # Removes all its descendants
191 @page.descendants.each(&:destroy)
189 @page.descendants.each(&:destroy)
192 when 'reassign'
190 when 'reassign'
193 # Reassign children to another parent page
191 # Reassign children to another parent page
194 reassign_to = @wiki.pages.find_by_id(params[:reassign_to_id].to_i)
192 reassign_to = @wiki.pages.find_by_id(params[:reassign_to_id].to_i)
195 return unless reassign_to
193 return unless reassign_to
196 @page.children.each do |child|
194 @page.children.each do |child|
197 child.update_attribute(:parent, reassign_to)
195 child.update_attribute(:parent, reassign_to)
198 end
196 end
199 else
197 else
200 @reassignable_to = @wiki.pages - @page.self_and_descendants
198 @reassignable_to = @wiki.pages - @page.self_and_descendants
201 return
199 return
202 end
200 end
203 end
201 end
204 @page.destroy
202 @page.destroy
205 redirect_to :action => 'index', :project_id => @project
203 redirect_to :action => 'index', :project_id => @project
206 end
204 end
207
205
208 # Export wiki to a single html file
206 # Export wiki to a single html file
209 def export
207 def export
210 if User.current.allowed_to?(:export_wiki_pages, @project)
208 if User.current.allowed_to?(:export_wiki_pages, @project)
211 @pages = @wiki.pages.find :all, :order => 'title'
209 @pages = @wiki.pages.find :all, :order => 'title'
212 export = render_to_string :action => 'export_multiple', :layout => false
210 export = render_to_string :action => 'export_multiple', :layout => false
213 send_data(export, :type => 'text/html', :filename => "wiki.html")
211 send_data(export, :type => 'text/html', :filename => "wiki.html")
214 else
212 else
215 redirect_to :action => 'show', :project_id => @project, :id => nil
213 redirect_to :action => 'show', :project_id => @project, :id => nil
216 end
214 end
217 end
215 end
218
216
219 def date_index
217 def date_index
220 load_pages_grouped_by_date_without_content
218 load_pages_grouped_by_date_without_content
221 end
219 end
222
220
223 def preview
221 def preview
224 page = @wiki.find_page(params[:id])
222 page = @wiki.find_page(params[:id])
225 # page is nil when previewing a new page
223 # page is nil when previewing a new page
226 return render_403 unless page.nil? || editable?(page)
224 return render_403 unless page.nil? || editable?(page)
227 if page
225 if page
228 @attachements = page.attachments
226 @attachements = page.attachments
229 @previewed = page.content
227 @previewed = page.content
230 end
228 end
231 @text = params[:content][:text]
229 @text = params[:content][:text]
232 render :partial => 'common/preview'
230 render :partial => 'common/preview'
233 end
231 end
234
232
235 def add_attachment
233 def add_attachment
236 return render_403 unless editable?
234 return render_403 unless editable?
237 attachments = Attachment.attach_files(@page, params[:attachments])
235 attachments = Attachment.attach_files(@page, params[:attachments])
238 render_attachment_warning_if_needed(@page)
236 render_attachment_warning_if_needed(@page)
239 redirect_to :action => 'show', :id => @page.title, :project_id => @project
237 redirect_to :action => 'show', :id => @page.title, :project_id => @project
240 end
238 end
241
239
242 private
240 private
243
241
244 def find_wiki
242 def find_wiki
245 @project = Project.find(params[:project_id])
243 @project = Project.find(params[:project_id])
246 @wiki = @project.wiki
244 @wiki = @project.wiki
247 render_404 unless @wiki
245 render_404 unless @wiki
248 rescue ActiveRecord::RecordNotFound
246 rescue ActiveRecord::RecordNotFound
249 render_404
247 render_404
250 end
248 end
251
249
252 # Finds the requested page and returns a 404 error if it doesn't exist
250 # Finds the requested page and returns a 404 error if it doesn't exist
253 def find_existing_page
251 def find_existing_page
254 @page = @wiki.find_page(params[:id])
252 @page = @wiki.find_page(params[:id])
255 render_404 if @page.nil?
253 render_404 if @page.nil?
256 end
254 end
257
255
258 # Returns true if the current user is allowed to edit the page, otherwise false
256 # Returns true if the current user is allowed to edit the page, otherwise false
259 def editable?(page = @page)
257 def editable?(page = @page)
260 page.editable_by?(User.current)
258 page.editable_by?(User.current)
261 end
259 end
262
260
263 # Returns the default content of a new wiki page
261 # Returns the default content of a new wiki page
264 def initial_page_content(page)
262 def initial_page_content(page)
265 helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting)
263 helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting)
266 extend helper unless self.instance_of?(helper)
264 extend helper unless self.instance_of?(helper)
267 helper.instance_method(:initial_page_content).bind(self).call(page)
265 helper.instance_method(:initial_page_content).bind(self).call(page)
268 end
266 end
269
267
270 # eager load information about last updates, without loading text
268 # eager load information about last updates, without loading text
271 def load_pages_grouped_by_date_without_content
269 def load_pages_grouped_by_date_without_content
272 @pages = @wiki.pages.find :all, :select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on",
270 @pages = @wiki.pages.find :all, :select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on",
273 :joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id",
271 :joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id",
274 :order => 'title'
272 :order => 'title'
275 @pages_by_date = @pages.group_by {|p| p.updated_on.to_date}
273 @pages_by_date = @pages.group_by {|p| p.updated_on.to_date}
276 @pages_by_parent_id = @pages.group_by(&:parent_id)
274 @pages_by_parent_id = @pages.group_by(&:parent_id)
277 end
275 end
278
276
279 end
277 end
@@ -1,459 +1,495
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19 require 'wiki_controller'
19 require 'wiki_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class WikiController; def rescue_action(e) raise e end; end
22 class WikiController; def rescue_action(e) raise e end; end
23
23
24 class WikiControllerTest < ActionController::TestCase
24 class WikiControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :attachments
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :attachments
26
26
27 def setup
27 def setup
28 @controller = WikiController.new
28 @controller = WikiController.new
29 @request = ActionController::TestRequest.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
30 @response = ActionController::TestResponse.new
31 User.current = nil
31 User.current = nil
32 end
32 end
33
33
34 def test_show_start_page
34 def test_show_start_page
35 get :show, :project_id => 'ecookbook'
35 get :show, :project_id => 'ecookbook'
36 assert_response :success
36 assert_response :success
37 assert_template 'show'
37 assert_template 'show'
38 assert_tag :tag => 'h1', :content => /CookBook documentation/
38 assert_tag :tag => 'h1', :content => /CookBook documentation/
39
39
40 # child_pages macro
40 # child_pages macro
41 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
41 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
42 :child => { :tag => 'li',
42 :child => { :tag => 'li',
43 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
43 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
44 :content => 'Page with an inline image' } }
44 :content => 'Page with an inline image' } }
45 end
45 end
46
46
47 def test_show_page_with_name
47 def test_show_page_with_name
48 get :show, :project_id => 1, :id => 'Another_page'
48 get :show, :project_id => 1, :id => 'Another_page'
49 assert_response :success
49 assert_response :success
50 assert_template 'show'
50 assert_template 'show'
51 assert_tag :tag => 'h1', :content => /Another page/
51 assert_tag :tag => 'h1', :content => /Another page/
52 # Included page with an inline image
52 # Included page with an inline image
53 assert_tag :tag => 'p', :content => /This is an inline image/
53 assert_tag :tag => 'p', :content => /This is an inline image/
54 assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3',
54 assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3',
55 :alt => 'This is a logo' }
55 :alt => 'This is a logo' }
56 end
56 end
57
57
58 def test_show_with_sidebar
58 def test_show_with_sidebar
59 page = Project.find(1).wiki.pages.new(:title => 'Sidebar')
59 page = Project.find(1).wiki.pages.new(:title => 'Sidebar')
60 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
60 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
61 page.save!
61 page.save!
62
62
63 get :show, :project_id => 1, :id => 'Another_page'
63 get :show, :project_id => 1, :id => 'Another_page'
64 assert_response :success
64 assert_response :success
65 assert_tag :tag => 'div', :attributes => {:id => 'sidebar'},
65 assert_tag :tag => 'div', :attributes => {:id => 'sidebar'},
66 :content => /Side bar content for test_show_with_sidebar/
66 :content => /Side bar content for test_show_with_sidebar/
67 end
67 end
68
68
69 def test_show_unexistent_page_without_edit_right
69 def test_show_unexistent_page_without_edit_right
70 get :show, :project_id => 1, :id => 'Unexistent page'
70 get :show, :project_id => 1, :id => 'Unexistent page'
71 assert_response 404
71 assert_response 404
72 end
72 end
73
73
74 def test_show_unexistent_page_with_edit_right
74 def test_show_unexistent_page_with_edit_right
75 @request.session[:user_id] = 2
75 @request.session[:user_id] = 2
76 get :show, :project_id => 1, :id => 'Unexistent page'
76 get :show, :project_id => 1, :id => 'Unexistent page'
77 assert_response :success
77 assert_response :success
78 assert_template 'edit'
78 assert_template 'edit'
79 end
79 end
80
80
81 def test_create_page
81 def test_create_page
82 @request.session[:user_id] = 2
82 @request.session[:user_id] = 2
83 put :update, :project_id => 1,
83 put :update, :project_id => 1,
84 :id => 'New page',
84 :id => 'New page',
85 :content => {:comments => 'Created the page',
85 :content => {:comments => 'Created the page',
86 :text => "h1. New page\n\nThis is a new page",
86 :text => "h1. New page\n\nThis is a new page",
87 :version => 0}
87 :version => 0}
88 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page'
88 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page'
89 page = Project.find(1).wiki.find_page('New page')
89 page = Project.find(1).wiki.find_page('New page')
90 assert !page.new_record?
90 assert !page.new_record?
91 assert_not_nil page.content
91 assert_not_nil page.content
92 assert_equal 'Created the page', page.content.comments
92 assert_equal 'Created the page', page.content.comments
93 end
93 end
94
94
95 def test_create_page_with_attachments
95 def test_create_page_with_attachments
96 @request.session[:user_id] = 2
96 @request.session[:user_id] = 2
97 assert_difference 'WikiPage.count' do
97 assert_difference 'WikiPage.count' do
98 assert_difference 'Attachment.count' do
98 assert_difference 'Attachment.count' do
99 put :update, :project_id => 1,
99 put :update, :project_id => 1,
100 :id => 'New page',
100 :id => 'New page',
101 :content => {:comments => 'Created the page',
101 :content => {:comments => 'Created the page',
102 :text => "h1. New page\n\nThis is a new page",
102 :text => "h1. New page\n\nThis is a new page",
103 :version => 0},
103 :version => 0},
104 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
104 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
105 end
105 end
106 end
106 end
107 page = Project.find(1).wiki.find_page('New page')
107 page = Project.find(1).wiki.find_page('New page')
108 assert_equal 1, page.attachments.count
108 assert_equal 1, page.attachments.count
109 assert_equal 'testfile.txt', page.attachments.first.filename
109 assert_equal 'testfile.txt', page.attachments.first.filename
110 end
110 end
111
111
112 def test_update_page
112 def test_update_page
113 @request.session[:user_id] = 2
113 @request.session[:user_id] = 2
114 assert_no_difference 'WikiPage.count' do
114 assert_no_difference 'WikiPage.count' do
115 assert_no_difference 'WikiContent.count' do
115 assert_no_difference 'WikiContent.count' do
116 assert_difference 'WikiContent::Version.count' do
116 assert_difference 'WikiContent::Version.count' do
117 put :update, :project_id => 1,
117 put :update, :project_id => 1,
118 :id => 'Another_page',
118 :id => 'Another_page',
119 :content => {
119 :content => {
120 :comments => "my comments",
120 :comments => "my comments",
121 :text => "edited",
121 :text => "edited",
122 :version => 1
122 :version => 1
123 }
123 }
124 end
124 end
125 end
125 end
126 end
126 end
127 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
127 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
128
128
129 page = Wiki.find(1).pages.find_by_title('Another_page')
129 page = Wiki.find(1).pages.find_by_title('Another_page')
130 assert_equal "edited", page.content.text
130 assert_equal "edited", page.content.text
131 assert_equal 2, page.content.version
131 assert_equal 2, page.content.version
132 assert_equal "my comments", page.content.comments
132 assert_equal "my comments", page.content.comments
133 end
133 end
134
134
135 def test_update_page_with_failure
135 def test_update_page_with_failure
136 @request.session[:user_id] = 2
136 @request.session[:user_id] = 2
137 assert_no_difference 'WikiPage.count' do
137 assert_no_difference 'WikiPage.count' do
138 assert_no_difference 'WikiContent.count' do
138 assert_no_difference 'WikiContent.count' do
139 assert_no_difference 'WikiContent::Version.count' do
139 assert_no_difference 'WikiContent::Version.count' do
140 put :update, :project_id => 1,
140 put :update, :project_id => 1,
141 :id => 'Another_page',
141 :id => 'Another_page',
142 :content => {
142 :content => {
143 :comments => 'a' * 300, # failure here, comment is too long
143 :comments => 'a' * 300, # failure here, comment is too long
144 :text => 'edited',
144 :text => 'edited',
145 :version => 1
145 :version => 1
146 }
146 }
147 end
147 end
148 end
148 end
149 end
149 end
150 assert_response :success
150 assert_response :success
151 assert_template 'edit'
151 assert_template 'edit'
152
152
153 assert_error_tag :descendant => {:content => /Comment is too long/}
153 assert_error_tag :descendant => {:content => /Comment is too long/}
154 assert_tag :tag => 'textarea', :attributes => {:id => 'content_text'}, :content => 'edited'
154 assert_tag :tag => 'textarea', :attributes => {:id => 'content_text'}, :content => 'edited'
155 assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'}
155 assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'}
156 end
156 end
157
157
158 def test_update_stale_page_should_not_raise_an_error
159 @request.session[:user_id] = 2
160 c = Wiki.find(1).find_page('Another_page').content
161 c.text = 'Previous text'
162 c.save!
163 assert_equal 2, c.version
164
165 assert_no_difference 'WikiPage.count' do
166 assert_no_difference 'WikiContent.count' do
167 assert_no_difference 'WikiContent::Version.count' do
168 put :update, :project_id => 1,
169 :id => 'Another_page',
170 :content => {
171 :comments => 'My comments',
172 :text => 'Text should not be lost',
173 :version => 1
174 }
175 end
176 end
177 end
178 assert_response :success
179 assert_template 'edit'
180 assert_tag :div,
181 :attributes => { :class => /error/ },
182 :content => /Data has been updated by another user/
183 assert_tag 'textarea',
184 :attributes => { :name => 'content[text]' },
185 :content => /Text should not be lost/
186 assert_tag 'input',
187 :attributes => { :name => 'content[comments]', :value => 'My comments' }
188
189 c.reload
190 assert_equal 'Previous text', c.text
191 assert_equal 2, c.version
192 end
193
158 def test_preview
194 def test_preview
159 @request.session[:user_id] = 2
195 @request.session[:user_id] = 2
160 xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation',
196 xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation',
161 :content => { :comments => '',
197 :content => { :comments => '',
162 :text => 'this is a *previewed text*',
198 :text => 'this is a *previewed text*',
163 :version => 3 }
199 :version => 3 }
164 assert_response :success
200 assert_response :success
165 assert_template 'common/_preview'
201 assert_template 'common/_preview'
166 assert_tag :tag => 'strong', :content => /previewed text/
202 assert_tag :tag => 'strong', :content => /previewed text/
167 end
203 end
168
204
169 def test_preview_new_page
205 def test_preview_new_page
170 @request.session[:user_id] = 2
206 @request.session[:user_id] = 2
171 xhr :post, :preview, :project_id => 1, :id => 'New page',
207 xhr :post, :preview, :project_id => 1, :id => 'New page',
172 :content => { :text => 'h1. New page',
208 :content => { :text => 'h1. New page',
173 :comments => '',
209 :comments => '',
174 :version => 0 }
210 :version => 0 }
175 assert_response :success
211 assert_response :success
176 assert_template 'common/_preview'
212 assert_template 'common/_preview'
177 assert_tag :tag => 'h1', :content => /New page/
213 assert_tag :tag => 'h1', :content => /New page/
178 end
214 end
179
215
180 def test_history
216 def test_history
181 get :history, :project_id => 1, :id => 'CookBook_documentation'
217 get :history, :project_id => 1, :id => 'CookBook_documentation'
182 assert_response :success
218 assert_response :success
183 assert_template 'history'
219 assert_template 'history'
184 assert_not_nil assigns(:versions)
220 assert_not_nil assigns(:versions)
185 assert_equal 3, assigns(:versions).size
221 assert_equal 3, assigns(:versions).size
186 assert_select "input[type=submit][name=commit]"
222 assert_select "input[type=submit][name=commit]"
187 end
223 end
188
224
189 def test_history_with_one_version
225 def test_history_with_one_version
190 get :history, :project_id => 1, :id => 'Another_page'
226 get :history, :project_id => 1, :id => 'Another_page'
191 assert_response :success
227 assert_response :success
192 assert_template 'history'
228 assert_template 'history'
193 assert_not_nil assigns(:versions)
229 assert_not_nil assigns(:versions)
194 assert_equal 1, assigns(:versions).size
230 assert_equal 1, assigns(:versions).size
195 assert_select "input[type=submit][name=commit]", false
231 assert_select "input[type=submit][name=commit]", false
196 end
232 end
197
233
198 def test_diff
234 def test_diff
199 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => 2, :version_from => 1
235 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => 2, :version_from => 1
200 assert_response :success
236 assert_response :success
201 assert_template 'diff'
237 assert_template 'diff'
202 assert_tag :tag => 'span', :attributes => { :class => 'diff_in'},
238 assert_tag :tag => 'span', :attributes => { :class => 'diff_in'},
203 :content => /updated/
239 :content => /updated/
204 end
240 end
205
241
206 def test_annotate
242 def test_annotate
207 get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2
243 get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2
208 assert_response :success
244 assert_response :success
209 assert_template 'annotate'
245 assert_template 'annotate'
210 # Line 1
246 # Line 1
211 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1' },
247 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1' },
212 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/ },
248 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/ },
213 :child => { :tag => 'td', :content => /h1\. CookBook documentation/ }
249 :child => { :tag => 'td', :content => /h1\. CookBook documentation/ }
214 # Line 2
250 # Line 2
215 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '2' },
251 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '2' },
216 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/ },
252 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/ },
217 :child => { :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ }
253 :child => { :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ }
218 end
254 end
219
255
220 def test_get_rename
256 def test_get_rename
221 @request.session[:user_id] = 2
257 @request.session[:user_id] = 2
222 get :rename, :project_id => 1, :id => 'Another_page'
258 get :rename, :project_id => 1, :id => 'Another_page'
223 assert_response :success
259 assert_response :success
224 assert_template 'rename'
260 assert_template 'rename'
225 assert_tag 'option',
261 assert_tag 'option',
226 :attributes => {:value => ''},
262 :attributes => {:value => ''},
227 :content => '',
263 :content => '',
228 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
264 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
229 assert_no_tag 'option',
265 assert_no_tag 'option',
230 :attributes => {:selected => 'selected'},
266 :attributes => {:selected => 'selected'},
231 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
267 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
232 end
268 end
233
269
234 def test_get_rename_child_page
270 def test_get_rename_child_page
235 @request.session[:user_id] = 2
271 @request.session[:user_id] = 2
236 get :rename, :project_id => 1, :id => 'Child_1'
272 get :rename, :project_id => 1, :id => 'Child_1'
237 assert_response :success
273 assert_response :success
238 assert_template 'rename'
274 assert_template 'rename'
239 assert_tag 'option',
275 assert_tag 'option',
240 :attributes => {:value => ''},
276 :attributes => {:value => ''},
241 :content => '',
277 :content => '',
242 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
278 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
243 assert_tag 'option',
279 assert_tag 'option',
244 :attributes => {:value => '2', :selected => 'selected'},
280 :attributes => {:value => '2', :selected => 'selected'},
245 :content => /Another page/,
281 :content => /Another page/,
246 :parent => {
282 :parent => {
247 :tag => 'select',
283 :tag => 'select',
248 :attributes => {:name => 'wiki_page[parent_id]'}
284 :attributes => {:name => 'wiki_page[parent_id]'}
249 }
285 }
250 end
286 end
251
287
252 def test_rename_with_redirect
288 def test_rename_with_redirect
253 @request.session[:user_id] = 2
289 @request.session[:user_id] = 2
254 post :rename, :project_id => 1, :id => 'Another_page',
290 post :rename, :project_id => 1, :id => 'Another_page',
255 :wiki_page => { :title => 'Another renamed page',
291 :wiki_page => { :title => 'Another renamed page',
256 :redirect_existing_links => 1 }
292 :redirect_existing_links => 1 }
257 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
293 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
258 wiki = Project.find(1).wiki
294 wiki = Project.find(1).wiki
259 # Check redirects
295 # Check redirects
260 assert_not_nil wiki.find_page('Another page')
296 assert_not_nil wiki.find_page('Another page')
261 assert_nil wiki.find_page('Another page', :with_redirect => false)
297 assert_nil wiki.find_page('Another page', :with_redirect => false)
262 end
298 end
263
299
264 def test_rename_without_redirect
300 def test_rename_without_redirect
265 @request.session[:user_id] = 2
301 @request.session[:user_id] = 2
266 post :rename, :project_id => 1, :id => 'Another_page',
302 post :rename, :project_id => 1, :id => 'Another_page',
267 :wiki_page => { :title => 'Another renamed page',
303 :wiki_page => { :title => 'Another renamed page',
268 :redirect_existing_links => "0" }
304 :redirect_existing_links => "0" }
269 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
305 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
270 wiki = Project.find(1).wiki
306 wiki = Project.find(1).wiki
271 # Check that there's no redirects
307 # Check that there's no redirects
272 assert_nil wiki.find_page('Another page')
308 assert_nil wiki.find_page('Another page')
273 end
309 end
274
310
275 def test_rename_with_parent_assignment
311 def test_rename_with_parent_assignment
276 @request.session[:user_id] = 2
312 @request.session[:user_id] = 2
277 post :rename, :project_id => 1, :id => 'Another_page',
313 post :rename, :project_id => 1, :id => 'Another_page',
278 :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' }
314 :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' }
279 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
315 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
280 assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent
316 assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent
281 end
317 end
282
318
283 def test_rename_with_parent_unassignment
319 def test_rename_with_parent_unassignment
284 @request.session[:user_id] = 2
320 @request.session[:user_id] = 2
285 post :rename, :project_id => 1, :id => 'Child_1',
321 post :rename, :project_id => 1, :id => 'Child_1',
286 :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' }
322 :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' }
287 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1'
323 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1'
288 assert_nil WikiPage.find_by_title('Child_1').parent
324 assert_nil WikiPage.find_by_title('Child_1').parent
289 end
325 end
290
326
291 def test_destroy_child
327 def test_destroy_child
292 @request.session[:user_id] = 2
328 @request.session[:user_id] = 2
293 delete :destroy, :project_id => 1, :id => 'Child_1'
329 delete :destroy, :project_id => 1, :id => 'Child_1'
294 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
330 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
295 end
331 end
296
332
297 def test_destroy_parent
333 def test_destroy_parent
298 @request.session[:user_id] = 2
334 @request.session[:user_id] = 2
299 assert_no_difference('WikiPage.count') do
335 assert_no_difference('WikiPage.count') do
300 delete :destroy, :project_id => 1, :id => 'Another_page'
336 delete :destroy, :project_id => 1, :id => 'Another_page'
301 end
337 end
302 assert_response :success
338 assert_response :success
303 assert_template 'destroy'
339 assert_template 'destroy'
304 end
340 end
305
341
306 def test_destroy_parent_with_nullify
342 def test_destroy_parent_with_nullify
307 @request.session[:user_id] = 2
343 @request.session[:user_id] = 2
308 assert_difference('WikiPage.count', -1) do
344 assert_difference('WikiPage.count', -1) do
309 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify'
345 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify'
310 end
346 end
311 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
347 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
312 assert_nil WikiPage.find_by_id(2)
348 assert_nil WikiPage.find_by_id(2)
313 end
349 end
314
350
315 def test_destroy_parent_with_cascade
351 def test_destroy_parent_with_cascade
316 @request.session[:user_id] = 2
352 @request.session[:user_id] = 2
317 assert_difference('WikiPage.count', -3) do
353 assert_difference('WikiPage.count', -3) do
318 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy'
354 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy'
319 end
355 end
320 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
356 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
321 assert_nil WikiPage.find_by_id(2)
357 assert_nil WikiPage.find_by_id(2)
322 assert_nil WikiPage.find_by_id(5)
358 assert_nil WikiPage.find_by_id(5)
323 end
359 end
324
360
325 def test_destroy_parent_with_reassign
361 def test_destroy_parent_with_reassign
326 @request.session[:user_id] = 2
362 @request.session[:user_id] = 2
327 assert_difference('WikiPage.count', -1) do
363 assert_difference('WikiPage.count', -1) do
328 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1
364 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1
329 end
365 end
330 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
366 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
331 assert_nil WikiPage.find_by_id(2)
367 assert_nil WikiPage.find_by_id(2)
332 assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent
368 assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent
333 end
369 end
334
370
335 def test_index
371 def test_index
336 get :index, :project_id => 'ecookbook'
372 get :index, :project_id => 'ecookbook'
337 assert_response :success
373 assert_response :success
338 assert_template 'index'
374 assert_template 'index'
339 pages = assigns(:pages)
375 pages = assigns(:pages)
340 assert_not_nil pages
376 assert_not_nil pages
341 assert_equal Project.find(1).wiki.pages.size, pages.size
377 assert_equal Project.find(1).wiki.pages.size, pages.size
342
378
343 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
379 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
344 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' },
380 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' },
345 :content => 'CookBook documentation' },
381 :content => 'CookBook documentation' },
346 :child => { :tag => 'ul',
382 :child => { :tag => 'ul',
347 :child => { :tag => 'li',
383 :child => { :tag => 'li',
348 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
384 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
349 :content => 'Page with an inline image' } } } },
385 :content => 'Page with an inline image' } } } },
350 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' },
386 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' },
351 :content => 'Another page' } }
387 :content => 'Another page' } }
352 end
388 end
353
389
354 context "GET :export" do
390 context "GET :export" do
355 context "with an authorized user to export the wiki" do
391 context "with an authorized user to export the wiki" do
356 setup do
392 setup do
357 @request.session[:user_id] = 2
393 @request.session[:user_id] = 2
358 get :export, :project_id => 'ecookbook'
394 get :export, :project_id => 'ecookbook'
359 end
395 end
360
396
361 should_respond_with :success
397 should_respond_with :success
362 should_assign_to :pages
398 should_assign_to :pages
363 should_respond_with_content_type "text/html"
399 should_respond_with_content_type "text/html"
364 should "export all of the wiki pages to a single html file" do
400 should "export all of the wiki pages to a single html file" do
365 assert_select "a[name=?]", "CookBook_documentation"
401 assert_select "a[name=?]", "CookBook_documentation"
366 assert_select "a[name=?]", "Another_page"
402 assert_select "a[name=?]", "Another_page"
367 assert_select "a[name=?]", "Page_with_an_inline_image"
403 assert_select "a[name=?]", "Page_with_an_inline_image"
368 end
404 end
369
405
370 end
406 end
371
407
372 context "with an unauthorized user" do
408 context "with an unauthorized user" do
373 setup do
409 setup do
374 get :export, :project_id => 'ecookbook'
410 get :export, :project_id => 'ecookbook'
375
411
376 should_respond_with :redirect
412 should_respond_with :redirect
377 should_redirect_to('wiki index') { {:action => 'show', :project_id => @project, :id => nil} }
413 should_redirect_to('wiki index') { {:action => 'show', :project_id => @project, :id => nil} }
378 end
414 end
379 end
415 end
380 end
416 end
381
417
382 context "GET :date_index" do
418 context "GET :date_index" do
383 setup do
419 setup do
384 get :date_index, :project_id => 'ecookbook'
420 get :date_index, :project_id => 'ecookbook'
385 end
421 end
386
422
387 should_respond_with :success
423 should_respond_with :success
388 should_assign_to :pages
424 should_assign_to :pages
389 should_assign_to :pages_by_date
425 should_assign_to :pages_by_date
390 should_render_template 'wiki/date_index'
426 should_render_template 'wiki/date_index'
391
427
392 end
428 end
393
429
394 def test_not_found
430 def test_not_found
395 get :show, :project_id => 999
431 get :show, :project_id => 999
396 assert_response 404
432 assert_response 404
397 end
433 end
398
434
399 def test_protect_page
435 def test_protect_page
400 page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
436 page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
401 assert !page.protected?
437 assert !page.protected?
402 @request.session[:user_id] = 2
438 @request.session[:user_id] = 2
403 post :protect, :project_id => 1, :id => page.title, :protected => '1'
439 post :protect, :project_id => 1, :id => page.title, :protected => '1'
404 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
440 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
405 assert page.reload.protected?
441 assert page.reload.protected?
406 end
442 end
407
443
408 def test_unprotect_page
444 def test_unprotect_page
409 page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
445 page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
410 assert page.protected?
446 assert page.protected?
411 @request.session[:user_id] = 2
447 @request.session[:user_id] = 2
412 post :protect, :project_id => 1, :id => page.title, :protected => '0'
448 post :protect, :project_id => 1, :id => page.title, :protected => '0'
413 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation'
449 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation'
414 assert !page.reload.protected?
450 assert !page.reload.protected?
415 end
451 end
416
452
417 def test_show_page_with_edit_link
453 def test_show_page_with_edit_link
418 @request.session[:user_id] = 2
454 @request.session[:user_id] = 2
419 get :show, :project_id => 1
455 get :show, :project_id => 1
420 assert_response :success
456 assert_response :success
421 assert_template 'show'
457 assert_template 'show'
422 assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
458 assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
423 end
459 end
424
460
425 def test_show_page_without_edit_link
461 def test_show_page_without_edit_link
426 @request.session[:user_id] = 4
462 @request.session[:user_id] = 4
427 get :show, :project_id => 1
463 get :show, :project_id => 1
428 assert_response :success
464 assert_response :success
429 assert_template 'show'
465 assert_template 'show'
430 assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
466 assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
431 end
467 end
432
468
433 def test_edit_unprotected_page
469 def test_edit_unprotected_page
434 # Non members can edit unprotected wiki pages
470 # Non members can edit unprotected wiki pages
435 @request.session[:user_id] = 4
471 @request.session[:user_id] = 4
436 get :edit, :project_id => 1, :id => 'Another_page'
472 get :edit, :project_id => 1, :id => 'Another_page'
437 assert_response :success
473 assert_response :success
438 assert_template 'edit'
474 assert_template 'edit'
439 end
475 end
440
476
441 def test_edit_protected_page_by_nonmember
477 def test_edit_protected_page_by_nonmember
442 # Non members can't edit protected wiki pages
478 # Non members can't edit protected wiki pages
443 @request.session[:user_id] = 4
479 @request.session[:user_id] = 4
444 get :edit, :project_id => 1, :id => 'CookBook_documentation'
480 get :edit, :project_id => 1, :id => 'CookBook_documentation'
445 assert_response 403
481 assert_response 403
446 end
482 end
447
483
448 def test_edit_protected_page_by_member
484 def test_edit_protected_page_by_member
449 @request.session[:user_id] = 2
485 @request.session[:user_id] = 2
450 get :edit, :project_id => 1, :id => 'CookBook_documentation'
486 get :edit, :project_id => 1, :id => 'CookBook_documentation'
451 assert_response :success
487 assert_response :success
452 assert_template 'edit'
488 assert_template 'edit'
453 end
489 end
454
490
455 def test_history_of_non_existing_page_should_return_404
491 def test_history_of_non_existing_page_should_return_404
456 get :history, :project_id => 1, :id => 'Unknown_page'
492 get :history, :project_id => 1, :id => 'Unknown_page'
457 assert_response 404
493 assert_response 404
458 end
494 end
459 end
495 end
General Comments 0
You need to be logged in to leave comments. Login now