@@ -1,211 +1,211 | |||||
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 | class WikiController < ApplicationController |
|
20 | class WikiController < ApplicationController | |
21 | before_filter :find_wiki, :authorize |
|
21 | before_filter :find_wiki, :authorize | |
|
22 | before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy] | |||
22 |
|
23 | |||
23 | verify :method => :post, :only => [:destroy, :protect], :redirect_to => { :action => :index } |
|
24 | verify :method => :post, :only => [:destroy, :protect], :redirect_to => { :action => :index } | |
24 |
|
25 | |||
25 | helper :attachments |
|
26 | helper :attachments | |
26 | include AttachmentsHelper |
|
27 | include AttachmentsHelper | |
27 |
|
28 | |||
28 | # display a page (in editing mode if it doesn't exist) |
|
29 | # display a page (in editing mode if it doesn't exist) | |
29 | def index |
|
30 | def index | |
30 | page_title = params[:page] |
|
31 | page_title = params[:page] | |
31 | @page = @wiki.find_or_new_page(page_title) |
|
32 | @page = @wiki.find_or_new_page(page_title) | |
32 | if @page.new_record? |
|
33 | if @page.new_record? | |
33 | if User.current.allowed_to?(:edit_wiki_pages, @project) |
|
34 | if User.current.allowed_to?(:edit_wiki_pages, @project) | |
34 | edit |
|
35 | edit | |
35 | render :action => 'edit' |
|
36 | render :action => 'edit' | |
36 | else |
|
37 | else | |
37 | render_404 |
|
38 | render_404 | |
38 | end |
|
39 | end | |
39 | return |
|
40 | return | |
40 | end |
|
41 | end | |
41 | if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project) |
|
42 | if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project) | |
42 | # Redirects user to the current version if he's not allowed to view previous versions |
|
43 | # Redirects user to the current version if he's not allowed to view previous versions | |
43 | redirect_to :version => nil |
|
44 | redirect_to :version => nil | |
44 | return |
|
45 | return | |
45 | end |
|
46 | end | |
46 | @content = @page.content_for_version(params[:version]) |
|
47 | @content = @page.content_for_version(params[:version]) | |
47 | if params[:export] == 'html' |
|
48 | if params[:export] == 'html' | |
48 | export = render_to_string :action => 'export', :layout => false |
|
49 | export = render_to_string :action => 'export', :layout => false | |
49 | send_data(export, :type => 'text/html', :filename => "#{@page.title}.html") |
|
50 | send_data(export, :type => 'text/html', :filename => "#{@page.title}.html") | |
50 | return |
|
51 | return | |
51 | elsif params[:export] == 'txt' |
|
52 | elsif params[:export] == 'txt' | |
52 | send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt") |
|
53 | send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt") | |
53 | return |
|
54 | return | |
54 | end |
|
55 | end | |
55 | @editable = editable? |
|
56 | @editable = editable? | |
56 | render :action => 'show' |
|
57 | render :action => 'show' | |
57 | end |
|
58 | end | |
58 |
|
59 | |||
59 | # edit an existing page or a new one |
|
60 | # edit an existing page or a new one | |
60 | def edit |
|
61 | def edit | |
61 | @page = @wiki.find_or_new_page(params[:page]) |
|
62 | @page = @wiki.find_or_new_page(params[:page]) | |
62 | return render_403 unless editable? |
|
63 | return render_403 unless editable? | |
63 | @page.content = WikiContent.new(:page => @page) if @page.new_record? |
|
64 | @page.content = WikiContent.new(:page => @page) if @page.new_record? | |
64 |
|
65 | |||
65 | @content = @page.content_for_version(params[:version]) |
|
66 | @content = @page.content_for_version(params[:version]) | |
66 | @content.text = initial_page_content(@page) if @content.text.blank? |
|
67 | @content.text = initial_page_content(@page) if @content.text.blank? | |
67 | # don't keep previous comment |
|
68 | # don't keep previous comment | |
68 | @content.comments = nil |
|
69 | @content.comments = nil | |
69 | if request.get? |
|
70 | if request.get? | |
70 | # To prevent StaleObjectError exception when reverting to a previous version |
|
71 | # To prevent StaleObjectError exception when reverting to a previous version | |
71 | @content.version = @page.content.version |
|
72 | @content.version = @page.content.version | |
72 | else |
|
73 | else | |
73 | if !@page.new_record? && @content.text == params[:content][:text] |
|
74 | if !@page.new_record? && @content.text == params[:content][:text] | |
74 | # don't save if text wasn't changed |
|
75 | # don't save if text wasn't changed | |
75 | redirect_to :action => 'index', :id => @project, :page => @page.title |
|
76 | redirect_to :action => 'index', :id => @project, :page => @page.title | |
76 | return |
|
77 | return | |
77 | end |
|
78 | end | |
78 | #@content.text = params[:content][:text] |
|
79 | #@content.text = params[:content][:text] | |
79 | #@content.comments = params[:content][:comments] |
|
80 | #@content.comments = params[:content][:comments] | |
80 | @content.attributes = params[:content] |
|
81 | @content.attributes = params[:content] | |
81 | @content.author = User.current |
|
82 | @content.author = User.current | |
82 | # if page is new @page.save will also save content, but not if page isn't a new record |
|
83 | # if page is new @page.save will also save content, but not if page isn't a new record | |
83 | if (@page.new_record? ? @page.save : @content.save) |
|
84 | if (@page.new_record? ? @page.save : @content.save) | |
84 | redirect_to :action => 'index', :id => @project, :page => @page.title |
|
85 | redirect_to :action => 'index', :id => @project, :page => @page.title | |
85 | end |
|
86 | end | |
86 | end |
|
87 | end | |
87 | rescue ActiveRecord::StaleObjectError |
|
88 | rescue ActiveRecord::StaleObjectError | |
88 | # Optimistic locking exception |
|
89 | # Optimistic locking exception | |
89 | flash[:error] = l(:notice_locking_conflict) |
|
90 | flash[:error] = l(:notice_locking_conflict) | |
90 | end |
|
91 | end | |
91 |
|
92 | |||
92 | # rename a page |
|
93 | # rename a page | |
93 | def rename |
|
94 | def rename | |
94 | @page = @wiki.find_page(params[:page]) |
|
95 | return render_403 unless editable? | |
95 | return render_403 unless editable? |
|
|||
96 | @page.redirect_existing_links = true |
|
96 | @page.redirect_existing_links = true | |
97 | # used to display the *original* title if some AR validation errors occur |
|
97 | # used to display the *original* title if some AR validation errors occur | |
98 | @original_title = @page.pretty_title |
|
98 | @original_title = @page.pretty_title | |
99 | if request.post? && @page.update_attributes(params[:wiki_page]) |
|
99 | if request.post? && @page.update_attributes(params[:wiki_page]) | |
100 | flash[:notice] = l(:notice_successful_update) |
|
100 | flash[:notice] = l(:notice_successful_update) | |
101 | redirect_to :action => 'index', :id => @project, :page => @page.title |
|
101 | redirect_to :action => 'index', :id => @project, :page => @page.title | |
102 | end |
|
102 | end | |
103 | end |
|
103 | end | |
104 |
|
104 | |||
105 | def protect |
|
105 | def protect | |
106 | page = @wiki.find_page(params[:page]) |
|
106 | @page.update_attribute :protected, params[:protected] | |
107 | page.update_attribute :protected, params[:protected] |
|
107 | redirect_to :action => 'index', :id => @project, :page => @page.title | |
108 | redirect_to :action => 'index', :id => @project, :page => page.title |
|
|||
109 | end |
|
108 | end | |
110 |
|
109 | |||
111 | # show page history |
|
110 | # show page history | |
112 | def history |
|
111 | def history | |
113 | @page = @wiki.find_page(params[:page]) |
|
|||
114 |
|
||||
115 | @version_count = @page.content.versions.count |
|
112 | @version_count = @page.content.versions.count | |
116 | @version_pages = Paginator.new self, @version_count, per_page_option, params['p'] |
|
113 | @version_pages = Paginator.new self, @version_count, per_page_option, params['p'] | |
117 | # don't load text |
|
114 | # don't load text | |
118 | @versions = @page.content.versions.find :all, |
|
115 | @versions = @page.content.versions.find :all, | |
119 | :select => "id, author_id, comments, updated_on, version", |
|
116 | :select => "id, author_id, comments, updated_on, version", | |
120 | :order => 'version DESC', |
|
117 | :order => 'version DESC', | |
121 | :limit => @version_pages.items_per_page + 1, |
|
118 | :limit => @version_pages.items_per_page + 1, | |
122 | :offset => @version_pages.current.offset |
|
119 | :offset => @version_pages.current.offset | |
123 |
|
120 | |||
124 | render :layout => false if request.xhr? |
|
121 | render :layout => false if request.xhr? | |
125 | end |
|
122 | end | |
126 |
|
123 | |||
127 | def diff |
|
124 | def diff | |
128 | @page = @wiki.find_page(params[:page]) |
|
|||
129 | @diff = @page.diff(params[:version], params[:version_from]) |
|
125 | @diff = @page.diff(params[:version], params[:version_from]) | |
130 | render_404 unless @diff |
|
126 | render_404 unless @diff | |
131 | end |
|
127 | end | |
132 |
|
128 | |||
133 | def annotate |
|
129 | def annotate | |
134 | @page = @wiki.find_page(params[:page]) |
|
|||
135 | @annotate = @page.annotate(params[:version]) |
|
130 | @annotate = @page.annotate(params[:version]) | |
|
131 | render_404 unless @annotate | |||
136 | end |
|
132 | end | |
137 |
|
133 | |||
138 | # remove a wiki page and its history |
|
134 | # remove a wiki page and its history | |
139 | def destroy |
|
135 | def destroy | |
140 | @page = @wiki.find_page(params[:page]) |
|
136 | return render_403 unless editable? | |
141 | return render_403 unless editable? |
|
137 | @page.destroy | |
142 | @page.destroy if @page |
|
|||
143 | redirect_to :action => 'special', :id => @project, :page => 'Page_index' |
|
138 | redirect_to :action => 'special', :id => @project, :page => 'Page_index' | |
144 | end |
|
139 | end | |
145 |
|
140 | |||
146 | # display special pages |
|
141 | # display special pages | |
147 | def special |
|
142 | def special | |
148 | page_title = params[:page].downcase |
|
143 | page_title = params[:page].downcase | |
149 | case page_title |
|
144 | case page_title | |
150 | # show pages index, sorted by title |
|
145 | # show pages index, sorted by title | |
151 | when 'page_index', 'date_index' |
|
146 | when 'page_index', 'date_index' | |
152 | # eager load information about last updates, without loading text |
|
147 | # eager load information about last updates, without loading text | |
153 | @pages = @wiki.pages.find :all, :select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on", |
|
148 | @pages = @wiki.pages.find :all, :select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on", | |
154 | :joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id", |
|
149 | :joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id", | |
155 | :order => 'title' |
|
150 | :order => 'title' | |
156 | @pages_by_date = @pages.group_by {|p| p.updated_on.to_date} |
|
151 | @pages_by_date = @pages.group_by {|p| p.updated_on.to_date} | |
157 | @pages_by_parent_id = @pages.group_by(&:parent_id) |
|
152 | @pages_by_parent_id = @pages.group_by(&:parent_id) | |
158 | # export wiki to a single html file |
|
153 | # export wiki to a single html file | |
159 | when 'export' |
|
154 | when 'export' | |
160 | @pages = @wiki.pages.find :all, :order => 'title' |
|
155 | @pages = @wiki.pages.find :all, :order => 'title' | |
161 | export = render_to_string :action => 'export_multiple', :layout => false |
|
156 | export = render_to_string :action => 'export_multiple', :layout => false | |
162 | send_data(export, :type => 'text/html', :filename => "wiki.html") |
|
157 | send_data(export, :type => 'text/html', :filename => "wiki.html") | |
163 | return |
|
158 | return | |
164 | else |
|
159 | else | |
165 | # requested special page doesn't exist, redirect to default page |
|
160 | # requested special page doesn't exist, redirect to default page | |
166 | redirect_to :action => 'index', :id => @project, :page => nil and return |
|
161 | redirect_to :action => 'index', :id => @project, :page => nil and return | |
167 | end |
|
162 | end | |
168 | render :action => "special_#{page_title}" |
|
163 | render :action => "special_#{page_title}" | |
169 | end |
|
164 | end | |
170 |
|
165 | |||
171 | def preview |
|
166 | def preview | |
172 | page = @wiki.find_page(params[:page]) |
|
167 | page = @wiki.find_page(params[:page]) | |
173 | # page is nil when previewing a new page |
|
168 | # page is nil when previewing a new page | |
174 | return render_403 unless page.nil? || editable?(page) |
|
169 | return render_403 unless page.nil? || editable?(page) | |
175 | if page |
|
170 | if page | |
176 | @attachements = page.attachments |
|
171 | @attachements = page.attachments | |
177 | @previewed = page.content |
|
172 | @previewed = page.content | |
178 | end |
|
173 | end | |
179 | @text = params[:content][:text] |
|
174 | @text = params[:content][:text] | |
180 | render :partial => 'common/preview' |
|
175 | render :partial => 'common/preview' | |
181 | end |
|
176 | end | |
182 |
|
177 | |||
183 | def add_attachment |
|
178 | def add_attachment | |
184 | @page = @wiki.find_page(params[:page]) |
|
|||
185 | return render_403 unless editable? |
|
179 | return render_403 unless editable? | |
186 | attach_files(@page, params[:attachments]) |
|
180 | attach_files(@page, params[:attachments]) | |
187 | redirect_to :action => 'index', :page => @page.title |
|
181 | redirect_to :action => 'index', :page => @page.title | |
188 | end |
|
182 | end | |
189 |
|
183 | |||
190 | private |
|
184 | private | |
191 |
|
185 | |||
192 | def find_wiki |
|
186 | def find_wiki | |
193 | @project = Project.find(params[:id]) |
|
187 | @project = Project.find(params[:id]) | |
194 | @wiki = @project.wiki |
|
188 | @wiki = @project.wiki | |
195 | render_404 unless @wiki |
|
189 | render_404 unless @wiki | |
196 | rescue ActiveRecord::RecordNotFound |
|
190 | rescue ActiveRecord::RecordNotFound | |
197 | render_404 |
|
191 | render_404 | |
198 | end |
|
192 | end | |
199 |
|
193 | |||
|
194 | # Finds the requested page and returns a 404 error if it doesn't exist | |||
|
195 | def find_existing_page | |||
|
196 | @page = @wiki.find_page(params[:page]) | |||
|
197 | render_404 if @page.nil? | |||
|
198 | end | |||
|
199 | ||||
200 | # Returns true if the current user is allowed to edit the page, otherwise false |
|
200 | # Returns true if the current user is allowed to edit the page, otherwise false | |
201 | def editable?(page = @page) |
|
201 | def editable?(page = @page) | |
202 | page.editable_by?(User.current) |
|
202 | page.editable_by?(User.current) | |
203 | end |
|
203 | end | |
204 |
|
204 | |||
205 | # Returns the default content of a new wiki page |
|
205 | # Returns the default content of a new wiki page | |
206 | def initial_page_content(page) |
|
206 | def initial_page_content(page) | |
207 | helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting) |
|
207 | helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting) | |
208 | extend helper unless self.instance_of?(helper) |
|
208 | extend helper unless self.instance_of?(helper) | |
209 | helper.instance_method(:initial_page_content).bind(self).call(page) |
|
209 | helper.instance_method(:initial_page_content).bind(self).call(page) | |
210 | end |
|
210 | end | |
211 | end |
|
211 | end |
@@ -1,254 +1,259 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.dirname(__FILE__) + '/../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |
19 | require 'wiki_controller' |
|
19 | require 'wiki_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class WikiController; def rescue_action(e) raise e end; end |
|
22 | class WikiController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class WikiControllerTest < Test::Unit::TestCase |
|
24 | class WikiControllerTest < Test::Unit::TestCase | |
25 | fixtures :projects, :users, :roles, :members, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :attachments |
|
25 | fixtures :projects, :users, :roles, :members, :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 :index, :id => 'ecookbook' |
|
35 | get :index, :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 => '/wiki/ecookbook/Page_with_an_inline_image' }, |
|
43 | :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/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 :index, :id => 1, :page => 'Another_page' |
|
48 | get :index, :id => 1, :page => '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_unexistent_page_without_edit_right |
|
58 | def test_show_unexistent_page_without_edit_right | |
59 | get :index, :id => 1, :page => 'Unexistent page' |
|
59 | get :index, :id => 1, :page => 'Unexistent page' | |
60 | assert_response 404 |
|
60 | assert_response 404 | |
61 | end |
|
61 | end | |
62 |
|
62 | |||
63 | def test_show_unexistent_page_with_edit_right |
|
63 | def test_show_unexistent_page_with_edit_right | |
64 | @request.session[:user_id] = 2 |
|
64 | @request.session[:user_id] = 2 | |
65 | get :index, :id => 1, :page => 'Unexistent page' |
|
65 | get :index, :id => 1, :page => 'Unexistent page' | |
66 | assert_response :success |
|
66 | assert_response :success | |
67 | assert_template 'edit' |
|
67 | assert_template 'edit' | |
68 | end |
|
68 | end | |
69 |
|
69 | |||
70 | def test_create_page |
|
70 | def test_create_page | |
71 | @request.session[:user_id] = 2 |
|
71 | @request.session[:user_id] = 2 | |
72 | post :edit, :id => 1, |
|
72 | post :edit, :id => 1, | |
73 | :page => 'New page', |
|
73 | :page => 'New page', | |
74 | :content => {:comments => 'Created the page', |
|
74 | :content => {:comments => 'Created the page', | |
75 | :text => "h1. New page\n\nThis is a new page", |
|
75 | :text => "h1. New page\n\nThis is a new page", | |
76 | :version => 0} |
|
76 | :version => 0} | |
77 | assert_redirected_to 'wiki/ecookbook/New_page' |
|
77 | assert_redirected_to 'wiki/ecookbook/New_page' | |
78 | page = Project.find(1).wiki.find_page('New page') |
|
78 | page = Project.find(1).wiki.find_page('New page') | |
79 | assert !page.new_record? |
|
79 | assert !page.new_record? | |
80 | assert_not_nil page.content |
|
80 | assert_not_nil page.content | |
81 | assert_equal 'Created the page', page.content.comments |
|
81 | assert_equal 'Created the page', page.content.comments | |
82 | end |
|
82 | end | |
83 |
|
83 | |||
84 | def test_preview |
|
84 | def test_preview | |
85 | @request.session[:user_id] = 2 |
|
85 | @request.session[:user_id] = 2 | |
86 | xhr :post, :preview, :id => 1, :page => 'CookBook_documentation', |
|
86 | xhr :post, :preview, :id => 1, :page => 'CookBook_documentation', | |
87 | :content => { :comments => '', |
|
87 | :content => { :comments => '', | |
88 | :text => 'this is a *previewed text*', |
|
88 | :text => 'this is a *previewed text*', | |
89 | :version => 3 } |
|
89 | :version => 3 } | |
90 | assert_response :success |
|
90 | assert_response :success | |
91 | assert_template 'common/_preview' |
|
91 | assert_template 'common/_preview' | |
92 | assert_tag :tag => 'strong', :content => /previewed text/ |
|
92 | assert_tag :tag => 'strong', :content => /previewed text/ | |
93 | end |
|
93 | end | |
94 |
|
94 | |||
95 | def test_preview_new_page |
|
95 | def test_preview_new_page | |
96 | @request.session[:user_id] = 2 |
|
96 | @request.session[:user_id] = 2 | |
97 | xhr :post, :preview, :id => 1, :page => 'New page', |
|
97 | xhr :post, :preview, :id => 1, :page => 'New page', | |
98 | :content => { :text => 'h1. New page', |
|
98 | :content => { :text => 'h1. New page', | |
99 | :comments => '', |
|
99 | :comments => '', | |
100 | :version => 0 } |
|
100 | :version => 0 } | |
101 | assert_response :success |
|
101 | assert_response :success | |
102 | assert_template 'common/_preview' |
|
102 | assert_template 'common/_preview' | |
103 | assert_tag :tag => 'h1', :content => /New page/ |
|
103 | assert_tag :tag => 'h1', :content => /New page/ | |
104 | end |
|
104 | end | |
105 |
|
105 | |||
106 | def test_history |
|
106 | def test_history | |
107 | get :history, :id => 1, :page => 'CookBook_documentation' |
|
107 | get :history, :id => 1, :page => 'CookBook_documentation' | |
108 | assert_response :success |
|
108 | assert_response :success | |
109 | assert_template 'history' |
|
109 | assert_template 'history' | |
110 | assert_not_nil assigns(:versions) |
|
110 | assert_not_nil assigns(:versions) | |
111 | assert_equal 3, assigns(:versions).size |
|
111 | assert_equal 3, assigns(:versions).size | |
112 | assert_select "input[type=submit][name=commit]" |
|
112 | assert_select "input[type=submit][name=commit]" | |
113 | end |
|
113 | end | |
114 |
|
114 | |||
115 | def test_history_with_one_version |
|
115 | def test_history_with_one_version | |
116 | get :history, :id => 1, :page => 'Another_page' |
|
116 | get :history, :id => 1, :page => 'Another_page' | |
117 | assert_response :success |
|
117 | assert_response :success | |
118 | assert_template 'history' |
|
118 | assert_template 'history' | |
119 | assert_not_nil assigns(:versions) |
|
119 | assert_not_nil assigns(:versions) | |
120 | assert_equal 1, assigns(:versions).size |
|
120 | assert_equal 1, assigns(:versions).size | |
121 | assert_select "input[type=submit][name=commit]", false |
|
121 | assert_select "input[type=submit][name=commit]", false | |
122 | end |
|
122 | end | |
123 |
|
123 | |||
124 | def test_diff |
|
124 | def test_diff | |
125 | get :diff, :id => 1, :page => 'CookBook_documentation', :version => 2, :version_from => 1 |
|
125 | get :diff, :id => 1, :page => 'CookBook_documentation', :version => 2, :version_from => 1 | |
126 | assert_response :success |
|
126 | assert_response :success | |
127 | assert_template 'diff' |
|
127 | assert_template 'diff' | |
128 | assert_tag :tag => 'span', :attributes => { :class => 'diff_in'}, |
|
128 | assert_tag :tag => 'span', :attributes => { :class => 'diff_in'}, | |
129 | :content => /updated/ |
|
129 | :content => /updated/ | |
130 | end |
|
130 | end | |
131 |
|
131 | |||
132 | def test_annotate |
|
132 | def test_annotate | |
133 | get :annotate, :id => 1, :page => 'CookBook_documentation', :version => 2 |
|
133 | get :annotate, :id => 1, :page => 'CookBook_documentation', :version => 2 | |
134 | assert_response :success |
|
134 | assert_response :success | |
135 | assert_template 'annotate' |
|
135 | assert_template 'annotate' | |
136 | # Line 1 |
|
136 | # Line 1 | |
137 | assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1' }, |
|
137 | assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1' }, | |
138 | :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/ }, |
|
138 | :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/ }, | |
139 | :child => { :tag => 'td', :content => /h1\. CookBook documentation/ } |
|
139 | :child => { :tag => 'td', :content => /h1\. CookBook documentation/ } | |
140 | # Line 2 |
|
140 | # Line 2 | |
141 | assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '2' }, |
|
141 | assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '2' }, | |
142 | :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/ }, |
|
142 | :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/ }, | |
143 | :child => { :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ } |
|
143 | :child => { :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ } | |
144 | end |
|
144 | end | |
145 |
|
145 | |||
146 | def test_rename_with_redirect |
|
146 | def test_rename_with_redirect | |
147 | @request.session[:user_id] = 2 |
|
147 | @request.session[:user_id] = 2 | |
148 | post :rename, :id => 1, :page => 'Another_page', |
|
148 | post :rename, :id => 1, :page => 'Another_page', | |
149 | :wiki_page => { :title => 'Another renamed page', |
|
149 | :wiki_page => { :title => 'Another renamed page', | |
150 | :redirect_existing_links => 1 } |
|
150 | :redirect_existing_links => 1 } | |
151 | assert_redirected_to 'wiki/ecookbook/Another_renamed_page' |
|
151 | assert_redirected_to 'wiki/ecookbook/Another_renamed_page' | |
152 | wiki = Project.find(1).wiki |
|
152 | wiki = Project.find(1).wiki | |
153 | # Check redirects |
|
153 | # Check redirects | |
154 | assert_not_nil wiki.find_page('Another page') |
|
154 | assert_not_nil wiki.find_page('Another page') | |
155 | assert_nil wiki.find_page('Another page', :with_redirect => false) |
|
155 | assert_nil wiki.find_page('Another page', :with_redirect => false) | |
156 | end |
|
156 | end | |
157 |
|
157 | |||
158 | def test_rename_without_redirect |
|
158 | def test_rename_without_redirect | |
159 | @request.session[:user_id] = 2 |
|
159 | @request.session[:user_id] = 2 | |
160 | post :rename, :id => 1, :page => 'Another_page', |
|
160 | post :rename, :id => 1, :page => 'Another_page', | |
161 | :wiki_page => { :title => 'Another renamed page', |
|
161 | :wiki_page => { :title => 'Another renamed page', | |
162 | :redirect_existing_links => "0" } |
|
162 | :redirect_existing_links => "0" } | |
163 | assert_redirected_to 'wiki/ecookbook/Another_renamed_page' |
|
163 | assert_redirected_to 'wiki/ecookbook/Another_renamed_page' | |
164 | wiki = Project.find(1).wiki |
|
164 | wiki = Project.find(1).wiki | |
165 | # Check that there's no redirects |
|
165 | # Check that there's no redirects | |
166 | assert_nil wiki.find_page('Another page') |
|
166 | assert_nil wiki.find_page('Another page') | |
167 | end |
|
167 | end | |
168 |
|
168 | |||
169 | def test_destroy |
|
169 | def test_destroy | |
170 | @request.session[:user_id] = 2 |
|
170 | @request.session[:user_id] = 2 | |
171 | post :destroy, :id => 1, :page => 'CookBook_documentation' |
|
171 | post :destroy, :id => 1, :page => 'CookBook_documentation' | |
172 | assert_redirected_to 'wiki/ecookbook/Page_index/special' |
|
172 | assert_redirected_to 'wiki/ecookbook/Page_index/special' | |
173 | end |
|
173 | end | |
174 |
|
174 | |||
175 | def test_page_index |
|
175 | def test_page_index | |
176 | get :special, :id => 'ecookbook', :page => 'Page_index' |
|
176 | get :special, :id => 'ecookbook', :page => 'Page_index' | |
177 | assert_response :success |
|
177 | assert_response :success | |
178 | assert_template 'special_page_index' |
|
178 | assert_template 'special_page_index' | |
179 | pages = assigns(:pages) |
|
179 | pages = assigns(:pages) | |
180 | assert_not_nil pages |
|
180 | assert_not_nil pages | |
181 | assert_equal Project.find(1).wiki.pages.size, pages.size |
|
181 | assert_equal Project.find(1).wiki.pages.size, pages.size | |
182 |
|
182 | |||
183 | assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, |
|
183 | assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, | |
184 | :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/CookBook_documentation' }, |
|
184 | :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/CookBook_documentation' }, | |
185 | :content => 'CookBook documentation' }, |
|
185 | :content => 'CookBook documentation' }, | |
186 | :child => { :tag => 'ul', |
|
186 | :child => { :tag => 'ul', | |
187 | :child => { :tag => 'li', |
|
187 | :child => { :tag => 'li', | |
188 | :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/Page_with_an_inline_image' }, |
|
188 | :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/Page_with_an_inline_image' }, | |
189 | :content => 'Page with an inline image' } } } }, |
|
189 | :content => 'Page with an inline image' } } } }, | |
190 | :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/Another_page' }, |
|
190 | :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/Another_page' }, | |
191 | :content => 'Another page' } } |
|
191 | :content => 'Another page' } } | |
192 | end |
|
192 | end | |
193 |
|
193 | |||
194 | def test_not_found |
|
194 | def test_not_found | |
195 | get :index, :id => 999 |
|
195 | get :index, :id => 999 | |
196 | assert_response 404 |
|
196 | assert_response 404 | |
197 | end |
|
197 | end | |
198 |
|
198 | |||
199 | def test_protect_page |
|
199 | def test_protect_page | |
200 | page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page') |
|
200 | page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page') | |
201 | assert !page.protected? |
|
201 | assert !page.protected? | |
202 | @request.session[:user_id] = 2 |
|
202 | @request.session[:user_id] = 2 | |
203 | post :protect, :id => 1, :page => page.title, :protected => '1' |
|
203 | post :protect, :id => 1, :page => page.title, :protected => '1' | |
204 | assert_redirected_to 'wiki/ecookbook/Another_page' |
|
204 | assert_redirected_to 'wiki/ecookbook/Another_page' | |
205 | assert page.reload.protected? |
|
205 | assert page.reload.protected? | |
206 | end |
|
206 | end | |
207 |
|
207 | |||
208 | def test_unprotect_page |
|
208 | def test_unprotect_page | |
209 | page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation') |
|
209 | page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation') | |
210 | assert page.protected? |
|
210 | assert page.protected? | |
211 | @request.session[:user_id] = 2 |
|
211 | @request.session[:user_id] = 2 | |
212 | post :protect, :id => 1, :page => page.title, :protected => '0' |
|
212 | post :protect, :id => 1, :page => page.title, :protected => '0' | |
213 | assert_redirected_to 'wiki/ecookbook' |
|
213 | assert_redirected_to 'wiki/ecookbook' | |
214 | assert !page.reload.protected? |
|
214 | assert !page.reload.protected? | |
215 | end |
|
215 | end | |
216 |
|
216 | |||
217 | def test_show_page_with_edit_link |
|
217 | def test_show_page_with_edit_link | |
218 | @request.session[:user_id] = 2 |
|
218 | @request.session[:user_id] = 2 | |
219 | get :index, :id => 1 |
|
219 | get :index, :id => 1 | |
220 | assert_response :success |
|
220 | assert_response :success | |
221 | assert_template 'show' |
|
221 | assert_template 'show' | |
222 | assert_tag :tag => 'a', :attributes => { :href => '/wiki/1/CookBook_documentation/edit' } |
|
222 | assert_tag :tag => 'a', :attributes => { :href => '/wiki/1/CookBook_documentation/edit' } | |
223 | end |
|
223 | end | |
224 |
|
224 | |||
225 | def test_show_page_without_edit_link |
|
225 | def test_show_page_without_edit_link | |
226 | @request.session[:user_id] = 4 |
|
226 | @request.session[:user_id] = 4 | |
227 | get :index, :id => 1 |
|
227 | get :index, :id => 1 | |
228 | assert_response :success |
|
228 | assert_response :success | |
229 | assert_template 'show' |
|
229 | assert_template 'show' | |
230 | assert_no_tag :tag => 'a', :attributes => { :href => '/wiki/1/CookBook_documentation/edit' } |
|
230 | assert_no_tag :tag => 'a', :attributes => { :href => '/wiki/1/CookBook_documentation/edit' } | |
231 | end |
|
231 | end | |
232 |
|
232 | |||
233 | def test_edit_unprotected_page |
|
233 | def test_edit_unprotected_page | |
234 | # Non members can edit unprotected wiki pages |
|
234 | # Non members can edit unprotected wiki pages | |
235 | @request.session[:user_id] = 4 |
|
235 | @request.session[:user_id] = 4 | |
236 | get :edit, :id => 1, :page => 'Another_page' |
|
236 | get :edit, :id => 1, :page => 'Another_page' | |
237 | assert_response :success |
|
237 | assert_response :success | |
238 | assert_template 'edit' |
|
238 | assert_template 'edit' | |
239 | end |
|
239 | end | |
240 |
|
240 | |||
241 | def test_edit_protected_page_by_nonmember |
|
241 | def test_edit_protected_page_by_nonmember | |
242 | # Non members can't edit protected wiki pages |
|
242 | # Non members can't edit protected wiki pages | |
243 | @request.session[:user_id] = 4 |
|
243 | @request.session[:user_id] = 4 | |
244 | get :edit, :id => 1, :page => 'CookBook_documentation' |
|
244 | get :edit, :id => 1, :page => 'CookBook_documentation' | |
245 | assert_response 403 |
|
245 | assert_response 403 | |
246 | end |
|
246 | end | |
247 |
|
247 | |||
248 | def test_edit_protected_page_by_member |
|
248 | def test_edit_protected_page_by_member | |
249 | @request.session[:user_id] = 2 |
|
249 | @request.session[:user_id] = 2 | |
250 | get :edit, :id => 1, :page => 'CookBook_documentation' |
|
250 | get :edit, :id => 1, :page => 'CookBook_documentation' | |
251 | assert_response :success |
|
251 | assert_response :success | |
252 | assert_template 'edit' |
|
252 | assert_template 'edit' | |
253 | end |
|
253 | end | |
|
254 | ||||
|
255 | def test_history_of_non_existing_page_should_return_404 | |||
|
256 | get :history, :id => 1, :page => 'Unknown_page' | |||
|
257 | assert_response 404 | |||
|
258 | end | |||
254 | end |
|
259 | end |
General Comments 0
You need to be logged in to leave comments.
Login now