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