##// END OF EJS Templates
Refactor: split WikiController#edit into #update...
Eric Davis -
r4158:cac3b1e5381d
parent child
Show More
@@ -1,247 +1,261
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 default_search_scope :wiki_pages
22 22 before_filter :find_wiki, :authorize
23 23 before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy]
24 24
25 25 verify :method => :post, :only => [:destroy, :protect], :redirect_to => { :action => :show }
26 26
27 27 helper :attachments
28 28 include AttachmentsHelper
29 29 helper :watchers
30 30
31 31 # display a page (in editing mode if it doesn't exist)
32 32 def show
33 33 page_title = params[:page]
34 34 @page = @wiki.find_or_new_page(page_title)
35 35 if @page.new_record?
36 36 if User.current.allowed_to?(:edit_wiki_pages, @project) && editable?
37 37 edit
38 38 render :action => 'edit'
39 39 else
40 40 render_404
41 41 end
42 42 return
43 43 end
44 44 if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project)
45 45 # Redirects user to the current version if he's not allowed to view previous versions
46 46 redirect_to :version => nil
47 47 return
48 48 end
49 49 @content = @page.content_for_version(params[:version])
50 50 if User.current.allowed_to?(:export_wiki_pages, @project)
51 51 if params[:format] == 'html'
52 52 export = render_to_string :action => 'export', :layout => false
53 53 send_data(export, :type => 'text/html', :filename => "#{@page.title}.html")
54 54 return
55 55 elsif params[:format] == 'txt'
56 56 send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt")
57 57 return
58 58 end
59 59 end
60 60 @editable = editable?
61 61 render :action => 'show'
62 62 end
63 63
64 64 # edit an existing page or a new one
65 65 def edit
66 66 @page = @wiki.find_or_new_page(params[:page])
67 67 return render_403 unless editable?
68 68 @page.content = WikiContent.new(:page => @page) if @page.new_record?
69 69
70 70 @content = @page.content_for_version(params[:version])
71 71 @content.text = initial_page_content(@page) if @content.text.blank?
72 72 # don't keep previous comment
73 73 @content.comments = nil
74 if request.get?
75 # To prevent StaleObjectError exception when reverting to a previous version
76 @content.version = @page.content.version
77 else
78 if !@page.new_record? && @content.text == params[:content][:text]
79 attachments = Attachment.attach_files(@page, params[:attachments])
80 render_attachment_warning_if_needed(@page)
81 # don't save if text wasn't changed
82 redirect_to :action => 'show', :project_id => @project, :page => @page.title
83 return
84 end
85 #@content.text = params[:content][:text]
86 #@content.comments = params[:content][:comments]
87 @content.attributes = params[:content]
88 @content.author = User.current
89 # if page is new @page.save will also save content, but not if page isn't a new record
90 if (@page.new_record? ? @page.save : @content.save)
91 attachments = Attachment.attach_files(@page, params[:attachments])
92 render_attachment_warning_if_needed(@page)
93 call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page})
94 redirect_to :action => 'show', :project_id => @project, :page => @page.title
95 end
74
75 # To prevent StaleObjectError exception when reverting to a previous version
76 @content.version = @page.content.version
77 rescue ActiveRecord::StaleObjectError
78 # Optimistic locking exception
79 flash[:error] = l(:notice_locking_conflict)
80 end
81
82 verify :method => :post, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
83 # Creates a new page or updates an existing one
84 def update
85 @page = @wiki.find_or_new_page(params[:page])
86 return render_403 unless editable?
87 @page.content = WikiContent.new(:page => @page) if @page.new_record?
88
89 @content = @page.content_for_version(params[:version])
90 @content.text = initial_page_content(@page) if @content.text.blank?
91 # don't keep previous comment
92 @content.comments = nil
93
94 if !@page.new_record? && params[:content].present? && @content.text == params[:content][:text]
95 attachments = Attachment.attach_files(@page, params[:attachments])
96 render_attachment_warning_if_needed(@page)
97 # don't save if text wasn't changed
98 redirect_to :action => 'show', :project_id => @project, :page => @page.title
99 return
100 end
101 @content.attributes = params[:content]
102 @content.author = User.current
103 # if page is new @page.save will also save content, but not if page isn't a new record
104 if (@page.new_record? ? @page.save : @content.save)
105 attachments = Attachment.attach_files(@page, params[:attachments])
106 render_attachment_warning_if_needed(@page)
107 call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page})
108 redirect_to :action => 'show', :project_id => @project, :page => @page.title
96 109 end
110
97 111 rescue ActiveRecord::StaleObjectError
98 112 # Optimistic locking exception
99 113 flash[:error] = l(:notice_locking_conflict)
100 114 end
101
115
102 116 # rename a page
103 117 def rename
104 118 return render_403 unless editable?
105 119 @page.redirect_existing_links = true
106 120 # used to display the *original* title if some AR validation errors occur
107 121 @original_title = @page.pretty_title
108 122 if request.post? && @page.update_attributes(params[:wiki_page])
109 123 flash[:notice] = l(:notice_successful_update)
110 124 redirect_to :action => 'show', :project_id => @project, :page => @page.title
111 125 end
112 126 end
113 127
114 128 def protect
115 129 @page.update_attribute :protected, params[:protected]
116 130 redirect_to :action => 'show', :project_id => @project, :page => @page.title
117 131 end
118 132
119 133 # show page history
120 134 def history
121 135 @version_count = @page.content.versions.count
122 136 @version_pages = Paginator.new self, @version_count, per_page_option, params['p']
123 137 # don't load text
124 138 @versions = @page.content.versions.find :all,
125 139 :select => "id, author_id, comments, updated_on, version",
126 140 :order => 'version DESC',
127 141 :limit => @version_pages.items_per_page + 1,
128 142 :offset => @version_pages.current.offset
129 143
130 144 render :layout => false if request.xhr?
131 145 end
132 146
133 147 def diff
134 148 @diff = @page.diff(params[:version], params[:version_from])
135 149 render_404 unless @diff
136 150 end
137 151
138 152 def annotate
139 153 @annotate = @page.annotate(params[:version])
140 154 render_404 unless @annotate
141 155 end
142 156
143 157 # Removes a wiki page and its history
144 158 # Children can be either set as root pages, removed or reassigned to another parent page
145 159 def destroy
146 160 return render_403 unless editable?
147 161
148 162 @descendants_count = @page.descendants.size
149 163 if @descendants_count > 0
150 164 case params[:todo]
151 165 when 'nullify'
152 166 # Nothing to do
153 167 when 'destroy'
154 168 # Removes all its descendants
155 169 @page.descendants.each(&:destroy)
156 170 when 'reassign'
157 171 # Reassign children to another parent page
158 172 reassign_to = @wiki.pages.find_by_id(params[:reassign_to_id].to_i)
159 173 return unless reassign_to
160 174 @page.children.each do |child|
161 175 child.update_attribute(:parent, reassign_to)
162 176 end
163 177 else
164 178 @reassignable_to = @wiki.pages - @page.self_and_descendants
165 179 return
166 180 end
167 181 end
168 182 @page.destroy
169 183 redirect_to :action => 'page_index', :project_id => @project
170 184 end
171 185
172 186 # Export wiki to a single html file
173 187 def export
174 188 if User.current.allowed_to?(:export_wiki_pages, @project)
175 189 @pages = @wiki.pages.find :all, :order => 'title'
176 190 export = render_to_string :action => 'export_multiple', :layout => false
177 191 send_data(export, :type => 'text/html', :filename => "wiki.html")
178 192 else
179 193 redirect_to :action => 'show', :project_id => @project, :page => nil
180 194 end
181 195 end
182 196
183 197 def page_index
184 198 load_pages_grouped_by_date_without_content
185 199 end
186 200
187 201 def date_index
188 202 load_pages_grouped_by_date_without_content
189 203 end
190 204
191 205 def preview
192 206 page = @wiki.find_page(params[:page])
193 207 # page is nil when previewing a new page
194 208 return render_403 unless page.nil? || editable?(page)
195 209 if page
196 210 @attachements = page.attachments
197 211 @previewed = page.content
198 212 end
199 213 @text = params[:content][:text]
200 214 render :partial => 'common/preview'
201 215 end
202 216
203 217 def add_attachment
204 218 return render_403 unless editable?
205 219 attachments = Attachment.attach_files(@page, params[:attachments])
206 220 render_attachment_warning_if_needed(@page)
207 221 redirect_to :action => 'show', :page => @page.title
208 222 end
209 223
210 224 private
211 225
212 226 def find_wiki
213 227 @project = Project.find(params[:project_id])
214 228 @wiki = @project.wiki
215 229 render_404 unless @wiki
216 230 rescue ActiveRecord::RecordNotFound
217 231 render_404
218 232 end
219 233
220 234 # Finds the requested page and returns a 404 error if it doesn't exist
221 235 def find_existing_page
222 236 @page = @wiki.find_page(params[:page])
223 237 render_404 if @page.nil?
224 238 end
225 239
226 240 # Returns true if the current user is allowed to edit the page, otherwise false
227 241 def editable?(page = @page)
228 242 page.editable_by?(User.current)
229 243 end
230 244
231 245 # Returns the default content of a new wiki page
232 246 def initial_page_content(page)
233 247 helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting)
234 248 extend helper unless self.instance_of?(helper)
235 249 helper.instance_method(:initial_page_content).bind(self).call(page)
236 250 end
237 251
238 252 # eager load information about last updates, without loading text
239 253 def load_pages_grouped_by_date_without_content
240 254 @pages = @wiki.pages.find :all, :select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on",
241 255 :joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id",
242 256 :order => 'title'
243 257 @pages_by_date = @pages.group_by {|p| p.updated_on.to_date}
244 258 @pages_by_parent_id = @pages.group_by(&:parent_id)
245 259 end
246 260
247 261 end
@@ -1,28 +1,28
1 1 <h2><%=h @page.pretty_title %></h2>
2 2
3 <% form_for :content, @content, :url => {:action => 'edit', :page => @page.title}, :html => {:multipart => true, :id => 'wiki_form'} do |f| %>
3 <% form_for :content, @content, :url => {:action => 'update', :page => @page.title}, :html => {:multipart => true, :id => 'wiki_form'} do |f| %>
4 4 <%= f.hidden_field :version %>
5 5 <%= error_messages_for 'content' %>
6 6
7 7 <p><%= f.text_area :text, :cols => 100, :rows => 25, :class => 'wiki-edit', :accesskey => accesskey(:edit) %></p>
8 8 <p><label><%= l(:field_comments) %></label><br /><%= f.text_field :comments, :size => 120 %></p>
9 9 <p><label><%=l(:label_attachment_plural)%></label><br /><%= render :partial => 'attachments/form' %></p>
10 10
11 11 <p><%= submit_tag l(:button_save) %>
12 12 <%= link_to_remote l(:label_preview),
13 13 { :url => { :controller => 'wiki', :action => 'preview', :project_id => @project, :page => @page.title },
14 14 :method => 'post',
15 15 :update => 'preview',
16 16 :with => "Form.serialize('wiki_form')",
17 17 :complete => "Element.scrollTo('preview')"
18 18 }, :accesskey => accesskey(:preview) %></p>
19 19 <%= wikitoolbar_for 'content_text' %>
20 20 <% end %>
21 21
22 22 <div id="preview" class="wiki"></div>
23 23
24 24 <% content_for :header_tags do %>
25 25 <%= stylesheet_link_tag 'scm' %>
26 26 <% end %>
27 27
28 28 <% html_title @page.pretty_title %>
@@ -1,248 +1,250
1 1 ActionController::Routing::Routes.draw do |map|
2 2 # Add your own custom routes here.
3 3 # The priority is based upon order of creation: first created -> highest priority.
4 4
5 5 # Here's a sample route:
6 6 # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
7 7 # Keep in mind you can assign values other than :controller and :action
8 8
9 9 map.home '', :controller => 'welcome'
10 10
11 11 map.signin 'login', :controller => 'account', :action => 'login'
12 12 map.signout 'logout', :controller => 'account', :action => 'logout'
13 13
14 14 map.connect 'roles/workflow/:id/:role_id/:tracker_id', :controller => 'roles', :action => 'workflow'
15 15 map.connect 'help/:ctrl/:page', :controller => 'help'
16 16
17 17 map.connect 'projects/:project_id/time_entries/report', :controller => 'time_entry_reports', :action => 'report'
18 18 map.with_options :controller => 'time_entry_reports', :action => 'report',:conditions => {:method => :get} do |time_report|
19 19 time_report.connect 'time_entries/report'
20 20 time_report.connect 'time_entries/report.:format'
21 21 time_report.connect 'projects/:project_id/time_entries/report.:format'
22 22 end
23 23
24 24 # TODO: wasteful since this is also nested under issues, projects, and projects/issues
25 25 map.resources :time_entries, :controller => 'timelog'
26 26
27 27 map.connect 'projects/:id/wiki', :controller => 'wikis', :action => 'edit', :conditions => {:method => :post}
28 28 map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :get}
29 29 map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :post}
30 30 map.with_options :controller => 'wiki' do |wiki_routes|
31 31 wiki_routes.with_options :conditions => {:method => :get} do |wiki_views|
32 32 wiki_views.connect 'projects/:project_id/wiki/export', :action => 'export'
33 33 wiki_views.connect 'projects/:project_id/wiki/page_index', :action => 'page_index'
34 34 wiki_views.connect 'projects/:project_id/wiki/date_index', :action => 'date_index'
35 35 wiki_views.connect 'projects/:project_id/wiki/:page', :action => 'show', :page => nil
36 36 wiki_views.connect 'projects/:project_id/wiki/:page/edit', :action => 'edit'
37 37 wiki_views.connect 'projects/:project_id/wiki/:page/rename', :action => 'rename'
38 38 wiki_views.connect 'projects/:project_id/wiki/:page/history', :action => 'history'
39 39 wiki_views.connect 'projects/:project_id/wiki/:page/diff/:version/vs/:version_from', :action => 'diff'
40 40 wiki_views.connect 'projects/:project_id/wiki/:page/annotate/:version', :action => 'annotate'
41 41 end
42 42
43 43 wiki_routes.connect 'projects/:project_id/wiki/:page/:action',
44 :action => /edit|rename|destroy|preview|protect/,
44 :action => /rename|destroy|preview|protect/,
45 45 :conditions => {:method => :post}
46
47 wiki_routes.connect 'projects/:project_id/wiki/:page/edit', :action => 'update', :conditions => {:method => :post}
46 48 end
47 49
48 50 map.with_options :controller => 'messages' do |messages_routes|
49 51 messages_routes.with_options :conditions => {:method => :get} do |messages_views|
50 52 messages_views.connect 'boards/:board_id/topics/new', :action => 'new'
51 53 messages_views.connect 'boards/:board_id/topics/:id', :action => 'show'
52 54 messages_views.connect 'boards/:board_id/topics/:id/edit', :action => 'edit'
53 55 end
54 56 messages_routes.with_options :conditions => {:method => :post} do |messages_actions|
55 57 messages_actions.connect 'boards/:board_id/topics/new', :action => 'new'
56 58 messages_actions.connect 'boards/:board_id/topics/:id/replies', :action => 'reply'
57 59 messages_actions.connect 'boards/:board_id/topics/:id/:action', :action => /edit|destroy/
58 60 end
59 61 end
60 62
61 63 map.with_options :controller => 'boards' do |board_routes|
62 64 board_routes.with_options :conditions => {:method => :get} do |board_views|
63 65 board_views.connect 'projects/:project_id/boards', :action => 'index'
64 66 board_views.connect 'projects/:project_id/boards/new', :action => 'new'
65 67 board_views.connect 'projects/:project_id/boards/:id', :action => 'show'
66 68 board_views.connect 'projects/:project_id/boards/:id.:format', :action => 'show'
67 69 board_views.connect 'projects/:project_id/boards/:id/edit', :action => 'edit'
68 70 end
69 71 board_routes.with_options :conditions => {:method => :post} do |board_actions|
70 72 board_actions.connect 'projects/:project_id/boards', :action => 'new'
71 73 board_actions.connect 'projects/:project_id/boards/:id/:action', :action => /edit|destroy/
72 74 end
73 75 end
74 76
75 77 map.with_options :controller => 'documents' do |document_routes|
76 78 document_routes.with_options :conditions => {:method => :get} do |document_views|
77 79 document_views.connect 'projects/:project_id/documents', :action => 'index'
78 80 document_views.connect 'projects/:project_id/documents/new', :action => 'new'
79 81 document_views.connect 'documents/:id', :action => 'show'
80 82 document_views.connect 'documents/:id/edit', :action => 'edit'
81 83 end
82 84 document_routes.with_options :conditions => {:method => :post} do |document_actions|
83 85 document_actions.connect 'projects/:project_id/documents', :action => 'new'
84 86 document_actions.connect 'documents/:id/:action', :action => /destroy|edit/
85 87 end
86 88 end
87 89
88 90 map.resources :issue_moves, :only => [:new, :create], :path_prefix => '/issues', :as => 'move'
89 91
90 92 # Misc issue routes. TODO: move into resources
91 93 map.auto_complete_issues '/issues/auto_complete', :controller => 'auto_completes', :action => 'issues'
92 94 map.preview_issue '/issues/preview/:id', :controller => 'previews', :action => 'issue' # TODO: would look nicer as /issues/:id/preview
93 95 map.issues_context_menu '/issues/context_menu', :controller => 'context_menus', :action => 'issues'
94 96 map.issue_changes '/issues/changes', :controller => 'journals', :action => 'index'
95 97 map.bulk_edit_issue 'issues/bulk_edit', :controller => 'issues', :action => 'bulk_edit', :conditions => { :method => :get }
96 98 map.bulk_update_issue 'issues/bulk_edit', :controller => 'issues', :action => 'bulk_update', :conditions => { :method => :post }
97 99 map.quoted_issue '/issues/:id/quoted', :controller => 'journals', :action => 'new', :id => /\d+/, :conditions => { :method => :post }
98 100 map.connect '/issues/:id/destroy', :controller => 'issues', :action => 'destroy', :conditions => { :method => :post } # legacy
99 101
100 102 map.resource :gantt, :path_prefix => '/issues', :controller => 'gantts', :only => [:show, :update]
101 103 map.resource :gantt, :path_prefix => '/projects/:project_id/issues', :controller => 'gantts', :only => [:show, :update]
102 104 map.resource :calendar, :path_prefix => '/issues', :controller => 'calendars', :only => [:show, :update]
103 105 map.resource :calendar, :path_prefix => '/projects/:project_id/issues', :controller => 'calendars', :only => [:show, :update]
104 106
105 107 map.with_options :controller => 'reports', :conditions => {:method => :get} do |reports|
106 108 reports.connect 'projects/:id/issues/report', :action => 'issue_report'
107 109 reports.connect 'projects/:id/issues/report/:detail', :action => 'issue_report_details'
108 110 end
109 111
110 112 # Following two routes conflict with the resources because #index allows POST
111 113 map.connect '/issues', :controller => 'issues', :action => 'index', :conditions => { :method => :post }
112 114 map.connect '/issues/create', :controller => 'issues', :action => 'index', :conditions => { :method => :post }
113 115
114 116 map.resources :issues, :member => { :edit => :post }, :collection => {} do |issues|
115 117 issues.resources :time_entries, :controller => 'timelog'
116 118 end
117 119
118 120 map.resources :issues, :path_prefix => '/projects/:project_id', :collection => { :create => :post } do |issues|
119 121 issues.resources :time_entries, :controller => 'timelog'
120 122 end
121 123
122 124 map.with_options :controller => 'issue_relations', :conditions => {:method => :post} do |relations|
123 125 relations.connect 'issues/:issue_id/relations/:id', :action => 'new'
124 126 relations.connect 'issues/:issue_id/relations/:id/destroy', :action => 'destroy'
125 127 end
126 128
127 129 map.connect 'projects/:id/members/new', :controller => 'members', :action => 'new'
128 130
129 131 map.with_options :controller => 'users' do |users|
130 132 users.connect 'users/:id/edit/:tab', :action => 'edit', :tab => nil, :conditions => {:method => :get}
131 133
132 134 users.with_options :conditions => {:method => :post} do |user_actions|
133 135 user_actions.connect 'users/:id/memberships', :action => 'edit_membership'
134 136 user_actions.connect 'users/:id/memberships/:membership_id', :action => 'edit_membership'
135 137 user_actions.connect 'users/:id/memberships/:membership_id/destroy', :action => 'destroy_membership'
136 138 end
137 139 end
138 140
139 141 map.resources :users, :member => {
140 142 :edit_membership => :post,
141 143 :destroy_membership => :post
142 144 },
143 145 :except => [:destroy]
144 146
145 147 # For nice "roadmap" in the url for the index action
146 148 map.connect 'projects/:project_id/roadmap', :controller => 'versions', :action => 'index'
147 149
148 150 map.all_news 'news', :controller => 'news', :action => 'index'
149 151 map.formatted_all_news 'news.:format', :controller => 'news', :action => 'index'
150 152 map.preview_news '/news/preview', :controller => 'previews', :action => 'news'
151 153 map.connect 'news/:id/comments', :controller => 'comments', :action => 'create', :conditions => {:method => :post}
152 154 map.connect 'news/:id/comments/:comment_id', :controller => 'comments', :action => 'destroy', :conditions => {:method => :delete}
153 155
154 156 map.resources :projects, :member => {
155 157 :copy => [:get, :post],
156 158 :settings => :get,
157 159 :modules => :post,
158 160 :archive => :post,
159 161 :unarchive => :post
160 162 } do |project|
161 163 project.resource :project_enumerations, :as => 'enumerations', :only => [:update, :destroy]
162 164 project.resources :files, :only => [:index, :new, :create]
163 165 project.resources :versions, :collection => {:close_completed => :put}, :member => {:status_by => :post}
164 166 project.resources :news, :shallow => true
165 167 project.resources :time_entries, :controller => 'timelog', :path_prefix => 'projects/:project_id'
166 168
167 169
168 170 end
169 171
170 172 # Destroy uses a get request to prompt the user before the actual DELETE request
171 173 map.project_destroy_confirm 'projects/:id/destroy', :controller => 'projects', :action => 'destroy', :conditions => {:method => :get}
172 174
173 175 # TODO: port to be part of the resources route(s)
174 176 map.with_options :controller => 'projects' do |project_mapper|
175 177 project_mapper.with_options :conditions => {:method => :get} do |project_views|
176 178 project_views.connect 'projects/:id/settings/:tab', :controller => 'projects', :action => 'settings'
177 179 project_views.connect 'projects/:project_id/issues/:copy_from/copy', :controller => 'issues', :action => 'new'
178 180 end
179 181 end
180 182
181 183 map.with_options :controller => 'activities', :action => 'index', :conditions => {:method => :get} do |activity|
182 184 activity.connect 'projects/:id/activity'
183 185 activity.connect 'projects/:id/activity.:format'
184 186 activity.connect 'activity', :id => nil
185 187 activity.connect 'activity.:format', :id => nil
186 188 end
187 189
188 190
189 191 map.with_options :controller => 'issue_categories' do |categories|
190 192 categories.connect 'projects/:project_id/issue_categories/new', :action => 'new'
191 193 end
192 194
193 195 map.with_options :controller => 'repositories' do |repositories|
194 196 repositories.with_options :conditions => {:method => :get} do |repository_views|
195 197 repository_views.connect 'projects/:id/repository', :action => 'show'
196 198 repository_views.connect 'projects/:id/repository/edit', :action => 'edit'
197 199 repository_views.connect 'projects/:id/repository/statistics', :action => 'stats'
198 200 repository_views.connect 'projects/:id/repository/revisions', :action => 'revisions'
199 201 repository_views.connect 'projects/:id/repository/revisions.:format', :action => 'revisions'
200 202 repository_views.connect 'projects/:id/repository/revisions/:rev', :action => 'revision'
201 203 repository_views.connect 'projects/:id/repository/revisions/:rev/diff', :action => 'diff'
202 204 repository_views.connect 'projects/:id/repository/revisions/:rev/diff.:format', :action => 'diff'
203 205 repository_views.connect 'projects/:id/repository/revisions/:rev/raw/*path', :action => 'entry', :format => 'raw', :requirements => { :rev => /[a-z0-9\.\-_]+/ }
204 206 repository_views.connect 'projects/:id/repository/revisions/:rev/:action/*path', :requirements => { :rev => /[a-z0-9\.\-_]+/ }
205 207 repository_views.connect 'projects/:id/repository/raw/*path', :action => 'entry', :format => 'raw'
206 208 # TODO: why the following route is required?
207 209 repository_views.connect 'projects/:id/repository/entry/*path', :action => 'entry'
208 210 repository_views.connect 'projects/:id/repository/:action/*path'
209 211 end
210 212
211 213 repositories.connect 'projects/:id/repository/:action', :conditions => {:method => :post}
212 214 end
213 215
214 216 map.connect 'attachments/:id', :controller => 'attachments', :action => 'show', :id => /\d+/
215 217 map.connect 'attachments/:id/:filename', :controller => 'attachments', :action => 'show', :id => /\d+/, :filename => /.*/
216 218 map.connect 'attachments/download/:id/:filename', :controller => 'attachments', :action => 'download', :id => /\d+/, :filename => /.*/
217 219
218 220 map.resources :groups
219 221
220 222 #left old routes at the bottom for backwards compat
221 223 map.connect 'projects/:project_id/issues/:action', :controller => 'issues'
222 224 map.connect 'projects/:project_id/documents/:action', :controller => 'documents'
223 225 map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards'
224 226 map.connect 'boards/:board_id/topics/:action/:id', :controller => 'messages'
225 227 map.connect 'wiki/:id/:page/:action', :page => nil, :controller => 'wiki'
226 228 map.connect 'issues/:issue_id/relations/:action/:id', :controller => 'issue_relations'
227 229 map.connect 'projects/:project_id/news/:action', :controller => 'news'
228 230 map.connect 'projects/:project_id/timelog/:action/:id', :controller => 'timelog', :project_id => /.+/
229 231 map.with_options :controller => 'repositories' do |omap|
230 232 omap.repositories_show 'repositories/browse/:id/*path', :action => 'browse'
231 233 omap.repositories_changes 'repositories/changes/:id/*path', :action => 'changes'
232 234 omap.repositories_diff 'repositories/diff/:id/*path', :action => 'diff'
233 235 omap.repositories_entry 'repositories/entry/:id/*path', :action => 'entry'
234 236 omap.repositories_entry 'repositories/annotate/:id/*path', :action => 'annotate'
235 237 omap.connect 'repositories/revision/:id/:rev', :action => 'revision'
236 238 end
237 239
238 240 map.with_options :controller => 'sys' do |sys|
239 241 sys.connect 'sys/projects.:format', :action => 'projects', :conditions => {:method => :get}
240 242 sys.connect 'sys/projects/:id/repository.:format', :action => 'create_project_repository', :conditions => {:method => :post}
241 243 end
242 244
243 245 # Install the default route as the lowest priority.
244 246 map.connect ':controller/:action/:id'
245 247 map.connect 'robots.txt', :controller => 'welcome', :action => 'robots'
246 248 # Used for OpenID
247 249 map.root :controller => 'account', :action => 'login'
248 250 end
@@ -1,231 +1,231
1 1 require 'redmine/access_control'
2 2 require 'redmine/menu_manager'
3 3 require 'redmine/activity'
4 4 require 'redmine/search'
5 5 require 'redmine/custom_field_format'
6 6 require 'redmine/mime_type'
7 7 require 'redmine/core_ext'
8 8 require 'redmine/themes'
9 9 require 'redmine/hook'
10 10 require 'redmine/plugin'
11 11 require 'redmine/notifiable'
12 12 require 'redmine/wiki_formatting'
13 13 require 'redmine/scm/base'
14 14
15 15 begin
16 16 require_library_or_gem 'RMagick' unless Object.const_defined?(:Magick)
17 17 rescue LoadError
18 18 # RMagick is not available
19 19 end
20 20
21 21 if RUBY_VERSION < '1.9'
22 22 require 'faster_csv'
23 23 else
24 24 require 'csv'
25 25 FCSV = CSV
26 26 end
27 27
28 28 Redmine::Scm::Base.add "Subversion"
29 29 Redmine::Scm::Base.add "Darcs"
30 30 Redmine::Scm::Base.add "Mercurial"
31 31 Redmine::Scm::Base.add "Cvs"
32 32 Redmine::Scm::Base.add "Bazaar"
33 33 Redmine::Scm::Base.add "Git"
34 34 Redmine::Scm::Base.add "Filesystem"
35 35
36 36 Redmine::CustomFieldFormat.map do |fields|
37 37 fields.register Redmine::CustomFieldFormat.new('string', :label => :label_string, :order => 1)
38 38 fields.register Redmine::CustomFieldFormat.new('text', :label => :label_text, :order => 2)
39 39 fields.register Redmine::CustomFieldFormat.new('int', :label => :label_integer, :order => 3)
40 40 fields.register Redmine::CustomFieldFormat.new('float', :label => :label_float, :order => 4)
41 41 fields.register Redmine::CustomFieldFormat.new('list', :label => :label_list, :order => 5)
42 42 fields.register Redmine::CustomFieldFormat.new('date', :label => :label_date, :order => 6)
43 43 fields.register Redmine::CustomFieldFormat.new('bool', :label => :label_boolean, :order => 7)
44 44 end
45 45
46 46 # Permissions
47 47 Redmine::AccessControl.map do |map|
48 48 map.permission :view_project, {:projects => [:show], :activities => [:index]}, :public => true
49 49 map.permission :search_project, {:search => :index}, :public => true
50 50 map.permission :add_project, {:projects => [:new, :create]}, :require => :loggedin
51 51 map.permission :edit_project, {:projects => [:settings, :edit, :update]}, :require => :member
52 52 map.permission :select_project_modules, {:projects => :modules}, :require => :member
53 53 map.permission :manage_members, {:projects => :settings, :members => [:new, :edit, :destroy, :autocomplete_for_member]}, :require => :member
54 54 map.permission :manage_versions, {:projects => :settings, :versions => [:new, :create, :edit, :update, :close_completed, :destroy]}, :require => :member
55 55 map.permission :add_subprojects, {:projects => [:new, :create]}, :require => :member
56 56
57 57 map.project_module :issue_tracking do |map|
58 58 # Issue categories
59 59 map.permission :manage_categories, {:projects => :settings, :issue_categories => [:new, :edit, :destroy]}, :require => :member
60 60 # Issues
61 61 map.permission :view_issues, {:issues => [:index, :show],
62 62 :auto_complete => [:issues],
63 63 :context_menus => [:issues],
64 64 :versions => [:index, :show, :status_by],
65 65 :journals => :index,
66 66 :queries => :index,
67 67 :reports => [:issue_report, :issue_report_details]}
68 68 map.permission :add_issues, {:issues => [:new, :create, :update_form]}
69 69 map.permission :edit_issues, {:issues => [:edit, :update, :bulk_edit, :bulk_update, :update_form], :journals => [:new]}
70 70 map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]}
71 71 map.permission :manage_subtasks, {}
72 72 map.permission :add_issue_notes, {:issues => [:edit, :update], :journals => [:new]}
73 73 map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin
74 74 map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin
75 75 map.permission :move_issues, {:issue_moves => [:new, :create]}, :require => :loggedin
76 76 map.permission :delete_issues, {:issues => :destroy}, :require => :member
77 77 # Queries
78 78 map.permission :manage_public_queries, {:queries => [:new, :edit, :destroy]}, :require => :member
79 79 map.permission :save_queries, {:queries => [:new, :edit, :destroy]}, :require => :loggedin
80 80 # Watchers
81 81 map.permission :view_issue_watchers, {}
82 82 map.permission :add_issue_watchers, {:watchers => :new}
83 83 map.permission :delete_issue_watchers, {:watchers => :destroy}
84 84 end
85 85
86 86 map.project_module :time_tracking do |map|
87 87 map.permission :log_time, {:timelog => [:new, :create, :edit, :update]}, :require => :loggedin
88 88 map.permission :view_time_entries, :timelog => [:index], :time_entry_reports => [:report]
89 89 map.permission :edit_time_entries, {:timelog => [:new, :create, :edit, :update, :destroy]}, :require => :member
90 90 map.permission :edit_own_time_entries, {:timelog => [:new, :create, :edit, :update, :destroy]}, :require => :loggedin
91 91 map.permission :manage_project_activities, {:project_enumerations => [:update, :destroy]}, :require => :member
92 92 end
93 93
94 94 map.project_module :news do |map|
95 95 map.permission :manage_news, {:news => [:new, :create, :edit, :update, :destroy], :comments => [:destroy]}, :require => :member
96 96 map.permission :view_news, {:news => [:index, :show]}, :public => true
97 97 map.permission :comment_news, {:comments => :create}
98 98 end
99 99
100 100 map.project_module :documents do |map|
101 101 map.permission :manage_documents, {:documents => [:new, :edit, :destroy, :add_attachment]}, :require => :loggedin
102 102 map.permission :view_documents, :documents => [:index, :show, :download]
103 103 end
104 104
105 105 map.project_module :files do |map|
106 106 map.permission :manage_files, {:files => [:new, :create]}, :require => :loggedin
107 107 map.permission :view_files, :files => :index, :versions => :download
108 108 end
109 109
110 110 map.project_module :wiki do |map|
111 111 map.permission :manage_wiki, {:wikis => [:edit, :destroy]}, :require => :member
112 112 map.permission :rename_wiki_pages, {:wiki => :rename}, :require => :member
113 113 map.permission :delete_wiki_pages, {:wiki => :destroy}, :require => :member
114 114 map.permission :view_wiki_pages, :wiki => [:show, :special, :page_index, :date_index]
115 115 map.permission :export_wiki_pages, :wiki => [:export]
116 116 map.permission :view_wiki_edits, :wiki => [:history, :diff, :annotate]
117 map.permission :edit_wiki_pages, :wiki => [:edit, :preview, :add_attachment]
117 map.permission :edit_wiki_pages, :wiki => [:edit, :update, :preview, :add_attachment]
118 118 map.permission :delete_wiki_pages_attachments, {}
119 119 map.permission :protect_wiki_pages, {:wiki => :protect}, :require => :member
120 120 end
121 121
122 122 map.project_module :repository do |map|
123 123 map.permission :manage_repository, {:repositories => [:edit, :committers, :destroy]}, :require => :member
124 124 map.permission :browse_repository, :repositories => [:show, :browse, :entry, :annotate, :changes, :diff, :stats, :graph]
125 125 map.permission :view_changesets, :repositories => [:show, :revisions, :revision]
126 126 map.permission :commit_access, {}
127 127 end
128 128
129 129 map.project_module :boards do |map|
130 130 map.permission :manage_boards, {:boards => [:new, :edit, :destroy]}, :require => :member
131 131 map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true
132 132 map.permission :add_messages, {:messages => [:new, :reply, :quote]}
133 133 map.permission :edit_messages, {:messages => :edit}, :require => :member
134 134 map.permission :edit_own_messages, {:messages => :edit}, :require => :loggedin
135 135 map.permission :delete_messages, {:messages => :destroy}, :require => :member
136 136 map.permission :delete_own_messages, {:messages => :destroy}, :require => :loggedin
137 137 end
138 138
139 139 map.project_module :calendar do |map|
140 140 map.permission :view_calendar, :calendars => [:show, :update]
141 141 end
142 142
143 143 map.project_module :gantt do |map|
144 144 map.permission :view_gantt, :gantts => [:show, :update]
145 145 end
146 146 end
147 147
148 148 Redmine::MenuManager.map :top_menu do |menu|
149 149 menu.push :home, :home_path
150 150 menu.push :my_page, { :controller => 'my', :action => 'page' }, :if => Proc.new { User.current.logged? }
151 151 menu.push :projects, { :controller => 'projects', :action => 'index' }, :caption => :label_project_plural
152 152 menu.push :administration, { :controller => 'admin', :action => 'index' }, :if => Proc.new { User.current.admin? }, :last => true
153 153 menu.push :help, Redmine::Info.help_url, :last => true
154 154 end
155 155
156 156 Redmine::MenuManager.map :account_menu do |menu|
157 157 menu.push :login, :signin_path, :if => Proc.new { !User.current.logged? }
158 158 menu.push :register, { :controller => 'account', :action => 'register' }, :if => Proc.new { !User.current.logged? && Setting.self_registration? }
159 159 menu.push :my_account, { :controller => 'my', :action => 'account' }, :if => Proc.new { User.current.logged? }
160 160 menu.push :logout, :signout_path, :if => Proc.new { User.current.logged? }
161 161 end
162 162
163 163 Redmine::MenuManager.map :application_menu do |menu|
164 164 # Empty
165 165 end
166 166
167 167 Redmine::MenuManager.map :admin_menu do |menu|
168 168 menu.push :projects, {:controller => 'admin', :action => 'projects'}, :caption => :label_project_plural
169 169 menu.push :users, {:controller => 'users'}, :caption => :label_user_plural
170 170 menu.push :groups, {:controller => 'groups'}, :caption => :label_group_plural
171 171 menu.push :roles, {:controller => 'roles'}, :caption => :label_role_and_permissions
172 172 menu.push :trackers, {:controller => 'trackers'}, :caption => :label_tracker_plural
173 173 menu.push :issue_statuses, {:controller => 'issue_statuses'}, :caption => :label_issue_status_plural,
174 174 :html => {:class => 'issue_statuses'}
175 175 menu.push :workflows, {:controller => 'workflows', :action => 'edit'}, :caption => :label_workflow
176 176 menu.push :custom_fields, {:controller => 'custom_fields'}, :caption => :label_custom_field_plural,
177 177 :html => {:class => 'custom_fields'}
178 178 menu.push :enumerations, {:controller => 'enumerations'}
179 179 menu.push :settings, {:controller => 'settings'}
180 180 menu.push :ldap_authentication, {:controller => 'ldap_auth_sources', :action => 'index'},
181 181 :html => {:class => 'server_authentication'}
182 182 menu.push :plugins, {:controller => 'admin', :action => 'plugins'}, :last => true
183 183 menu.push :info, {:controller => 'admin', :action => 'info'}, :caption => :label_information_plural, :last => true
184 184 end
185 185
186 186 Redmine::MenuManager.map :project_menu do |menu|
187 187 menu.push :overview, { :controller => 'projects', :action => 'show' }
188 188 menu.push :activity, { :controller => 'activities', :action => 'index' }
189 189 menu.push :roadmap, { :controller => 'versions', :action => 'index' }, :param => :project_id,
190 190 :if => Proc.new { |p| p.shared_versions.any? }
191 191 menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural
192 192 menu.push :new_issue, { :controller => 'issues', :action => 'new' }, :param => :project_id, :caption => :label_issue_new,
193 193 :html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) }
194 194 menu.push :gantt, { :controller => 'gantts', :action => 'show' }, :param => :project_id, :caption => :label_gantt
195 195 menu.push :calendar, { :controller => 'calendars', :action => 'show' }, :param => :project_id, :caption => :label_calendar
196 196 menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural
197 197 menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural
198 198 menu.push :wiki, { :controller => 'wiki', :action => 'show', :page => nil }, :param => :project_id,
199 199 :if => Proc.new { |p| p.wiki && !p.wiki.new_record? }
200 200 menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id,
201 201 :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural
202 202 menu.push :files, { :controller => 'files', :action => 'index' }, :caption => :label_file_plural, :param => :project_id
203 203 menu.push :repository, { :controller => 'repositories', :action => 'show' },
204 204 :if => Proc.new { |p| p.repository && !p.repository.new_record? }
205 205 menu.push :settings, { :controller => 'projects', :action => 'settings' }, :last => true
206 206 end
207 207
208 208 Redmine::Activity.map do |activity|
209 209 activity.register :issues, :class_name => %w(Issue Journal)
210 210 activity.register :changesets
211 211 activity.register :news
212 212 activity.register :documents, :class_name => %w(Document Attachment)
213 213 activity.register :files, :class_name => 'Attachment'
214 214 activity.register :wiki_edits, :class_name => 'WikiContent::Version', :default => false
215 215 activity.register :messages, :default => false
216 216 activity.register :time_entries, :default => false
217 217 end
218 218
219 219 Redmine::Search.map do |search|
220 220 search.register :issues
221 221 search.register :news
222 222 search.register :documents
223 223 search.register :changesets
224 224 search.register :wiki_pages
225 225 search.register :messages
226 226 search.register :projects
227 227 end
228 228
229 229 Redmine::WikiFormatting.map do |format|
230 230 format.register :textile, Redmine::WikiFormatting::Textile::Formatter, Redmine::WikiFormatting::Textile::Helper
231 231 end
@@ -1,365 +1,365
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 < ActionController::TestCase
25 25 fixtures :projects, :users, :roles, :members, :member_roles, :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 :show, :project_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 => '/projects/ecookbook/wiki/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 :show, :project_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_with_sidebar
59 59 page = Project.find(1).wiki.pages.new(:title => 'Sidebar')
60 60 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
61 61 page.save!
62 62
63 63 get :show, :project_id => 1, :page => 'Another_page'
64 64 assert_response :success
65 65 assert_tag :tag => 'div', :attributes => {:id => 'sidebar'},
66 66 :content => /Side bar content for test_show_with_sidebar/
67 67 end
68 68
69 69 def test_show_unexistent_page_without_edit_right
70 70 get :show, :project_id => 1, :page => 'Unexistent page'
71 71 assert_response 404
72 72 end
73 73
74 74 def test_show_unexistent_page_with_edit_right
75 75 @request.session[:user_id] = 2
76 76 get :show, :project_id => 1, :page => 'Unexistent page'
77 77 assert_response :success
78 78 assert_template 'edit'
79 79 end
80 80
81 81 def test_create_page
82 82 @request.session[:user_id] = 2
83 post :edit, :project_id => 1,
83 post :update, :project_id => 1,
84 84 :page => 'New page',
85 85 :content => {:comments => 'Created the page',
86 86 :text => "h1. New page\n\nThis is a new page",
87 87 :version => 0}
88 88 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :page => 'New_page'
89 89 page = Project.find(1).wiki.find_page('New page')
90 90 assert !page.new_record?
91 91 assert_not_nil page.content
92 92 assert_equal 'Created the page', page.content.comments
93 93 end
94 94
95 95 def test_create_page_with_attachments
96 96 @request.session[:user_id] = 2
97 97 assert_difference 'WikiPage.count' do
98 98 assert_difference 'Attachment.count' do
99 post :edit, :project_id => 1,
99 post :update, :project_id => 1,
100 100 :page => 'New page',
101 101 :content => {:comments => 'Created the page',
102 102 :text => "h1. New page\n\nThis is a new page",
103 103 :version => 0},
104 104 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
105 105 end
106 106 end
107 107 page = Project.find(1).wiki.find_page('New page')
108 108 assert_equal 1, page.attachments.count
109 109 assert_equal 'testfile.txt', page.attachments.first.filename
110 110 end
111 111
112 112 def test_preview
113 113 @request.session[:user_id] = 2
114 114 xhr :post, :preview, :project_id => 1, :page => 'CookBook_documentation',
115 115 :content => { :comments => '',
116 116 :text => 'this is a *previewed text*',
117 117 :version => 3 }
118 118 assert_response :success
119 119 assert_template 'common/_preview'
120 120 assert_tag :tag => 'strong', :content => /previewed text/
121 121 end
122 122
123 123 def test_preview_new_page
124 124 @request.session[:user_id] = 2
125 125 xhr :post, :preview, :project_id => 1, :page => 'New page',
126 126 :content => { :text => 'h1. New page',
127 127 :comments => '',
128 128 :version => 0 }
129 129 assert_response :success
130 130 assert_template 'common/_preview'
131 131 assert_tag :tag => 'h1', :content => /New page/
132 132 end
133 133
134 134 def test_history
135 135 get :history, :project_id => 1, :page => 'CookBook_documentation'
136 136 assert_response :success
137 137 assert_template 'history'
138 138 assert_not_nil assigns(:versions)
139 139 assert_equal 3, assigns(:versions).size
140 140 assert_select "input[type=submit][name=commit]"
141 141 end
142 142
143 143 def test_history_with_one_version
144 144 get :history, :project_id => 1, :page => 'Another_page'
145 145 assert_response :success
146 146 assert_template 'history'
147 147 assert_not_nil assigns(:versions)
148 148 assert_equal 1, assigns(:versions).size
149 149 assert_select "input[type=submit][name=commit]", false
150 150 end
151 151
152 152 def test_diff
153 153 get :diff, :project_id => 1, :page => 'CookBook_documentation', :version => 2, :version_from => 1
154 154 assert_response :success
155 155 assert_template 'diff'
156 156 assert_tag :tag => 'span', :attributes => { :class => 'diff_in'},
157 157 :content => /updated/
158 158 end
159 159
160 160 def test_annotate
161 161 get :annotate, :project_id => 1, :page => 'CookBook_documentation', :version => 2
162 162 assert_response :success
163 163 assert_template 'annotate'
164 164 # Line 1
165 165 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1' },
166 166 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/ },
167 167 :child => { :tag => 'td', :content => /h1\. CookBook documentation/ }
168 168 # Line 2
169 169 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '2' },
170 170 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/ },
171 171 :child => { :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ }
172 172 end
173 173
174 174 def test_rename_with_redirect
175 175 @request.session[:user_id] = 2
176 176 post :rename, :project_id => 1, :page => 'Another_page',
177 177 :wiki_page => { :title => 'Another renamed page',
178 178 :redirect_existing_links => 1 }
179 179 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :page => 'Another_renamed_page'
180 180 wiki = Project.find(1).wiki
181 181 # Check redirects
182 182 assert_not_nil wiki.find_page('Another page')
183 183 assert_nil wiki.find_page('Another page', :with_redirect => false)
184 184 end
185 185
186 186 def test_rename_without_redirect
187 187 @request.session[:user_id] = 2
188 188 post :rename, :project_id => 1, :page => 'Another_page',
189 189 :wiki_page => { :title => 'Another renamed page',
190 190 :redirect_existing_links => "0" }
191 191 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :page => 'Another_renamed_page'
192 192 wiki = Project.find(1).wiki
193 193 # Check that there's no redirects
194 194 assert_nil wiki.find_page('Another page')
195 195 end
196 196
197 197 def test_destroy_child
198 198 @request.session[:user_id] = 2
199 199 post :destroy, :project_id => 1, :page => 'Child_1'
200 200 assert_redirected_to :action => 'page_index', :project_id => 'ecookbook'
201 201 end
202 202
203 203 def test_destroy_parent
204 204 @request.session[:user_id] = 2
205 205 assert_no_difference('WikiPage.count') do
206 206 post :destroy, :project_id => 1, :page => 'Another_page'
207 207 end
208 208 assert_response :success
209 209 assert_template 'destroy'
210 210 end
211 211
212 212 def test_destroy_parent_with_nullify
213 213 @request.session[:user_id] = 2
214 214 assert_difference('WikiPage.count', -1) do
215 215 post :destroy, :project_id => 1, :page => 'Another_page', :todo => 'nullify'
216 216 end
217 217 assert_redirected_to :action => 'page_index', :project_id => 'ecookbook'
218 218 assert_nil WikiPage.find_by_id(2)
219 219 end
220 220
221 221 def test_destroy_parent_with_cascade
222 222 @request.session[:user_id] = 2
223 223 assert_difference('WikiPage.count', -3) do
224 224 post :destroy, :project_id => 1, :page => 'Another_page', :todo => 'destroy'
225 225 end
226 226 assert_redirected_to :action => 'page_index', :project_id => 'ecookbook'
227 227 assert_nil WikiPage.find_by_id(2)
228 228 assert_nil WikiPage.find_by_id(5)
229 229 end
230 230
231 231 def test_destroy_parent_with_reassign
232 232 @request.session[:user_id] = 2
233 233 assert_difference('WikiPage.count', -1) do
234 234 post :destroy, :project_id => 1, :page => 'Another_page', :todo => 'reassign', :reassign_to_id => 1
235 235 end
236 236 assert_redirected_to :action => 'page_index', :project_id => 'ecookbook'
237 237 assert_nil WikiPage.find_by_id(2)
238 238 assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent
239 239 end
240 240
241 241 def test_page_index
242 242 get :page_index, :project_id => 'ecookbook'
243 243 assert_response :success
244 244 assert_template 'page_index'
245 245 pages = assigns(:pages)
246 246 assert_not_nil pages
247 247 assert_equal Project.find(1).wiki.pages.size, pages.size
248 248
249 249 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
250 250 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' },
251 251 :content => 'CookBook documentation' },
252 252 :child => { :tag => 'ul',
253 253 :child => { :tag => 'li',
254 254 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
255 255 :content => 'Page with an inline image' } } } },
256 256 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' },
257 257 :content => 'Another page' } }
258 258 end
259 259
260 260 context "GET :export" do
261 261 context "with an authorized user to export the wiki" do
262 262 setup do
263 263 @request.session[:user_id] = 2
264 264 get :export, :project_id => 'ecookbook'
265 265 end
266 266
267 267 should_respond_with :success
268 268 should_assign_to :pages
269 269 should_respond_with_content_type "text/html"
270 270 should "export all of the wiki pages to a single html file" do
271 271 assert_select "a[name=?]", "CookBook_documentation"
272 272 assert_select "a[name=?]", "Another_page"
273 273 assert_select "a[name=?]", "Page_with_an_inline_image"
274 274 end
275 275
276 276 end
277 277
278 278 context "with an unauthorized user" do
279 279 setup do
280 280 get :export, :project_id => 'ecookbook'
281 281
282 282 should_respond_with :redirect
283 283 should_redirect_to('wiki index') { {:action => 'show', :project_id => @project, :page => nil} }
284 284 end
285 285 end
286 286 end
287 287
288 288 context "GET :date_index" do
289 289 setup do
290 290 get :date_index, :project_id => 'ecookbook'
291 291 end
292 292
293 293 should_respond_with :success
294 294 should_assign_to :pages
295 295 should_assign_to :pages_by_date
296 296 should_render_template 'wiki/date_index'
297 297
298 298 end
299 299
300 300 def test_not_found
301 301 get :show, :project_id => 999
302 302 assert_response 404
303 303 end
304 304
305 305 def test_protect_page
306 306 page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
307 307 assert !page.protected?
308 308 @request.session[:user_id] = 2
309 309 post :protect, :project_id => 1, :page => page.title, :protected => '1'
310 310 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :page => 'Another_page'
311 311 assert page.reload.protected?
312 312 end
313 313
314 314 def test_unprotect_page
315 315 page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
316 316 assert page.protected?
317 317 @request.session[:user_id] = 2
318 318 post :protect, :project_id => 1, :page => page.title, :protected => '0'
319 319 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :page => 'CookBook_documentation'
320 320 assert !page.reload.protected?
321 321 end
322 322
323 323 def test_show_page_with_edit_link
324 324 @request.session[:user_id] = 2
325 325 get :show, :project_id => 1
326 326 assert_response :success
327 327 assert_template 'show'
328 328 assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
329 329 end
330 330
331 331 def test_show_page_without_edit_link
332 332 @request.session[:user_id] = 4
333 333 get :show, :project_id => 1
334 334 assert_response :success
335 335 assert_template 'show'
336 336 assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
337 337 end
338 338
339 339 def test_edit_unprotected_page
340 340 # Non members can edit unprotected wiki pages
341 341 @request.session[:user_id] = 4
342 342 get :edit, :project_id => 1, :page => 'Another_page'
343 343 assert_response :success
344 344 assert_template 'edit'
345 345 end
346 346
347 347 def test_edit_protected_page_by_nonmember
348 348 # Non members can't edit protected wiki pages
349 349 @request.session[:user_id] = 4
350 350 get :edit, :project_id => 1, :page => 'CookBook_documentation'
351 351 assert_response 403
352 352 end
353 353
354 354 def test_edit_protected_page_by_member
355 355 @request.session[:user_id] = 2
356 356 get :edit, :project_id => 1, :page => 'CookBook_documentation'
357 357 assert_response :success
358 358 assert_template 'edit'
359 359 end
360 360
361 361 def test_history_of_non_existing_page_should_return_404
362 362 get :history, :project_id => 1, :page => 'Unknown_page'
363 363 assert_response 404
364 364 end
365 365 end
@@ -1,342 +1,342
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2010 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
20 20 class RoutingTest < ActionController::IntegrationTest
21 21 context "activities" do
22 22 should_route :get, "/activity", :controller => 'activities', :action => 'index', :id => nil
23 23 should_route :get, "/activity.atom", :controller => 'activities', :action => 'index', :id => nil, :format => 'atom'
24 24 end
25 25
26 26 context "attachments" do
27 27 should_route :get, "/attachments/1", :controller => 'attachments', :action => 'show', :id => '1'
28 28 should_route :get, "/attachments/1/filename.ext", :controller => 'attachments', :action => 'show', :id => '1', :filename => 'filename.ext'
29 29 should_route :get, "/attachments/download/1", :controller => 'attachments', :action => 'download', :id => '1'
30 30 should_route :get, "/attachments/download/1/filename.ext", :controller => 'attachments', :action => 'download', :id => '1', :filename => 'filename.ext'
31 31 end
32 32
33 33 context "boards" do
34 34 should_route :get, "/projects/world_domination/boards", :controller => 'boards', :action => 'index', :project_id => 'world_domination'
35 35 should_route :get, "/projects/world_domination/boards/new", :controller => 'boards', :action => 'new', :project_id => 'world_domination'
36 36 should_route :get, "/projects/world_domination/boards/44", :controller => 'boards', :action => 'show', :project_id => 'world_domination', :id => '44'
37 37 should_route :get, "/projects/world_domination/boards/44.atom", :controller => 'boards', :action => 'show', :project_id => 'world_domination', :id => '44', :format => 'atom'
38 38 should_route :get, "/projects/world_domination/boards/44/edit", :controller => 'boards', :action => 'edit', :project_id => 'world_domination', :id => '44'
39 39
40 40 should_route :post, "/projects/world_domination/boards/new", :controller => 'boards', :action => 'new', :project_id => 'world_domination'
41 41 should_route :post, "/projects/world_domination/boards/44/edit", :controller => 'boards', :action => 'edit', :project_id => 'world_domination', :id => '44'
42 42 should_route :post, "/projects/world_domination/boards/44/destroy", :controller => 'boards', :action => 'destroy', :project_id => 'world_domination', :id => '44'
43 43
44 44 end
45 45
46 46 context "documents" do
47 47 should_route :get, "/projects/567/documents", :controller => 'documents', :action => 'index', :project_id => '567'
48 48 should_route :get, "/projects/567/documents/new", :controller => 'documents', :action => 'new', :project_id => '567'
49 49 should_route :get, "/documents/22", :controller => 'documents', :action => 'show', :id => '22'
50 50 should_route :get, "/documents/22/edit", :controller => 'documents', :action => 'edit', :id => '22'
51 51
52 52 should_route :post, "/projects/567/documents/new", :controller => 'documents', :action => 'new', :project_id => '567'
53 53 should_route :post, "/documents/567/edit", :controller => 'documents', :action => 'edit', :id => '567'
54 54 should_route :post, "/documents/567/destroy", :controller => 'documents', :action => 'destroy', :id => '567'
55 55 end
56 56
57 57 context "issues" do
58 58 # REST actions
59 59 should_route :get, "/issues", :controller => 'issues', :action => 'index'
60 60 should_route :get, "/issues.pdf", :controller => 'issues', :action => 'index', :format => 'pdf'
61 61 should_route :get, "/issues.atom", :controller => 'issues', :action => 'index', :format => 'atom'
62 62 should_route :get, "/issues.xml", :controller => 'issues', :action => 'index', :format => 'xml'
63 63 should_route :get, "/projects/23/issues", :controller => 'issues', :action => 'index', :project_id => '23'
64 64 should_route :get, "/projects/23/issues.pdf", :controller => 'issues', :action => 'index', :project_id => '23', :format => 'pdf'
65 65 should_route :get, "/projects/23/issues.atom", :controller => 'issues', :action => 'index', :project_id => '23', :format => 'atom'
66 66 should_route :get, "/projects/23/issues.xml", :controller => 'issues', :action => 'index', :project_id => '23', :format => 'xml'
67 67 should_route :get, "/issues/64", :controller => 'issues', :action => 'show', :id => '64'
68 68 should_route :get, "/issues/64.pdf", :controller => 'issues', :action => 'show', :id => '64', :format => 'pdf'
69 69 should_route :get, "/issues/64.atom", :controller => 'issues', :action => 'show', :id => '64', :format => 'atom'
70 70 should_route :get, "/issues/64.xml", :controller => 'issues', :action => 'show', :id => '64', :format => 'xml'
71 71
72 72 should_route :get, "/projects/23/issues/new", :controller => 'issues', :action => 'new', :project_id => '23'
73 73 should_route :post, "/projects/23/issues", :controller => 'issues', :action => 'create', :project_id => '23'
74 74 should_route :post, "/issues.xml", :controller => 'issues', :action => 'create', :format => 'xml'
75 75
76 76 should_route :get, "/issues/64/edit", :controller => 'issues', :action => 'edit', :id => '64'
77 77 # TODO: Should use PUT
78 78 should_route :post, "/issues/64/edit", :controller => 'issues', :action => 'edit', :id => '64'
79 79 should_route :put, "/issues/1.xml", :controller => 'issues', :action => 'update', :id => '1', :format => 'xml'
80 80
81 81 # TODO: Should use DELETE
82 82 should_route :post, "/issues/64/destroy", :controller => 'issues', :action => 'destroy', :id => '64'
83 83 should_route :delete, "/issues/1.xml", :controller => 'issues', :action => 'destroy', :id => '1', :format => 'xml'
84 84
85 85 # Extra actions
86 86 should_route :get, "/projects/23/issues/64/copy", :controller => 'issues', :action => 'new', :project_id => '23', :copy_from => '64'
87 87
88 88 should_route :get, "/issues/move/new", :controller => 'issue_moves', :action => 'new'
89 89 should_route :post, "/issues/move", :controller => 'issue_moves', :action => 'create'
90 90
91 91 should_route :post, "/issues/1/quoted", :controller => 'journals', :action => 'new', :id => '1'
92 92
93 93 should_route :get, "/issues/calendar", :controller => 'calendars', :action => 'show'
94 94 should_route :put, "/issues/calendar", :controller => 'calendars', :action => 'update'
95 95 should_route :get, "/projects/project-name/issues/calendar", :controller => 'calendars', :action => 'show', :project_id => 'project-name'
96 96 should_route :put, "/projects/project-name/issues/calendar", :controller => 'calendars', :action => 'update', :project_id => 'project-name'
97 97
98 98 should_route :get, "/issues/gantt", :controller => 'gantts', :action => 'show'
99 99 should_route :put, "/issues/gantt", :controller => 'gantts', :action => 'update'
100 100 should_route :get, "/projects/project-name/issues/gantt", :controller => 'gantts', :action => 'show', :project_id => 'project-name'
101 101 should_route :put, "/projects/project-name/issues/gantt", :controller => 'gantts', :action => 'update', :project_id => 'project-name'
102 102
103 103 should_route :get, "/issues/auto_complete", :controller => 'auto_completes', :action => 'issues'
104 104
105 105 should_route :get, "/issues/preview/123", :controller => 'previews', :action => 'issue', :id => '123'
106 106 should_route :post, "/issues/preview/123", :controller => 'previews', :action => 'issue', :id => '123'
107 107 should_route :get, "/issues/context_menu", :controller => 'context_menus', :action => 'issues'
108 108 should_route :post, "/issues/context_menu", :controller => 'context_menus', :action => 'issues'
109 109
110 110 should_route :get, "/issues/changes", :controller => 'journals', :action => 'index'
111 111
112 112 should_route :get, "/issues/bulk_edit", :controller => 'issues', :action => 'bulk_edit'
113 113 should_route :post, "/issues/bulk_edit", :controller => 'issues', :action => 'bulk_update'
114 114 end
115 115
116 116 context "issue categories" do
117 117 should_route :get, "/projects/test/issue_categories/new", :controller => 'issue_categories', :action => 'new', :project_id => 'test'
118 118
119 119 should_route :post, "/projects/test/issue_categories/new", :controller => 'issue_categories', :action => 'new', :project_id => 'test'
120 120 end
121 121
122 122 context "issue relations" do
123 123 should_route :post, "/issues/1/relations", :controller => 'issue_relations', :action => 'new', :issue_id => '1'
124 124 should_route :post, "/issues/1/relations/23/destroy", :controller => 'issue_relations', :action => 'destroy', :issue_id => '1', :id => '23'
125 125 end
126 126
127 127 context "issue reports" do
128 128 should_route :get, "/projects/567/issues/report", :controller => 'reports', :action => 'issue_report', :id => '567'
129 129 should_route :get, "/projects/567/issues/report/assigned_to", :controller => 'reports', :action => 'issue_report_details', :id => '567', :detail => 'assigned_to'
130 130 end
131 131
132 132 context "members" do
133 133 should_route :post, "/projects/5234/members/new", :controller => 'members', :action => 'new', :id => '5234'
134 134 end
135 135
136 136 context "messages" do
137 137 should_route :get, "/boards/22/topics/2", :controller => 'messages', :action => 'show', :id => '2', :board_id => '22'
138 138 should_route :get, "/boards/lala/topics/new", :controller => 'messages', :action => 'new', :board_id => 'lala'
139 139 should_route :get, "/boards/lala/topics/22/edit", :controller => 'messages', :action => 'edit', :id => '22', :board_id => 'lala'
140 140
141 141 should_route :post, "/boards/lala/topics/new", :controller => 'messages', :action => 'new', :board_id => 'lala'
142 142 should_route :post, "/boards/lala/topics/22/edit", :controller => 'messages', :action => 'edit', :id => '22', :board_id => 'lala'
143 143 should_route :post, "/boards/22/topics/555/replies", :controller => 'messages', :action => 'reply', :id => '555', :board_id => '22'
144 144 should_route :post, "/boards/22/topics/555/destroy", :controller => 'messages', :action => 'destroy', :id => '555', :board_id => '22'
145 145 end
146 146
147 147 context "news" do
148 148 should_route :get, "/news", :controller => 'news', :action => 'index'
149 149 should_route :get, "/news.atom", :controller => 'news', :action => 'index', :format => 'atom'
150 150 should_route :get, "/news.xml", :controller => 'news', :action => 'index', :format => 'xml'
151 151 should_route :get, "/news.json", :controller => 'news', :action => 'index', :format => 'json'
152 152 should_route :get, "/projects/567/news", :controller => 'news', :action => 'index', :project_id => '567'
153 153 should_route :get, "/projects/567/news.atom", :controller => 'news', :action => 'index', :format => 'atom', :project_id => '567'
154 154 should_route :get, "/projects/567/news.xml", :controller => 'news', :action => 'index', :format => 'xml', :project_id => '567'
155 155 should_route :get, "/projects/567/news.json", :controller => 'news', :action => 'index', :format => 'json', :project_id => '567'
156 156 should_route :get, "/news/2", :controller => 'news', :action => 'show', :id => '2'
157 157 should_route :get, "/projects/567/news/new", :controller => 'news', :action => 'new', :project_id => '567'
158 158 should_route :get, "/news/234", :controller => 'news', :action => 'show', :id => '234'
159 159 should_route :get, "/news/567/edit", :controller => 'news', :action => 'edit', :id => '567'
160 160 should_route :get, "/news/preview", :controller => 'previews', :action => 'news'
161 161
162 162 should_route :post, "/projects/567/news", :controller => 'news', :action => 'create', :project_id => '567'
163 163 should_route :post, "/news/567/comments", :controller => 'comments', :action => 'create', :id => '567'
164 164
165 165 should_route :put, "/news/567", :controller => 'news', :action => 'update', :id => '567'
166 166
167 167 should_route :delete, "/news/567", :controller => 'news', :action => 'destroy', :id => '567'
168 168 should_route :delete, "/news/567/comments/15", :controller => 'comments', :action => 'destroy', :id => '567', :comment_id => '15'
169 169 end
170 170
171 171 context "projects" do
172 172 should_route :get, "/projects", :controller => 'projects', :action => 'index'
173 173 should_route :get, "/projects.atom", :controller => 'projects', :action => 'index', :format => 'atom'
174 174 should_route :get, "/projects.xml", :controller => 'projects', :action => 'index', :format => 'xml'
175 175 should_route :get, "/projects/new", :controller => 'projects', :action => 'new'
176 176 should_route :get, "/projects/test", :controller => 'projects', :action => 'show', :id => 'test'
177 177 should_route :get, "/projects/1.xml", :controller => 'projects', :action => 'show', :id => '1', :format => 'xml'
178 178 should_route :get, "/projects/4223/settings", :controller => 'projects', :action => 'settings', :id => '4223'
179 179 should_route :get, "/projects/4223/settings/members", :controller => 'projects', :action => 'settings', :id => '4223', :tab => 'members'
180 180 should_route :get, "/projects/33/files", :controller => 'files', :action => 'index', :project_id => '33'
181 181 should_route :get, "/projects/33/files/new", :controller => 'files', :action => 'new', :project_id => '33'
182 182 should_route :get, "/projects/33/roadmap", :controller => 'versions', :action => 'index', :project_id => '33'
183 183 should_route :get, "/projects/33/activity", :controller => 'activities', :action => 'index', :id => '33'
184 184 should_route :get, "/projects/33/activity.atom", :controller => 'activities', :action => 'index', :id => '33', :format => 'atom'
185 185
186 186 should_route :post, "/projects", :controller => 'projects', :action => 'create'
187 187 should_route :post, "/projects.xml", :controller => 'projects', :action => 'create', :format => 'xml'
188 188 should_route :post, "/projects/33/files", :controller => 'files', :action => 'create', :project_id => '33'
189 189 should_route :post, "/projects/64/archive", :controller => 'projects', :action => 'archive', :id => '64'
190 190 should_route :post, "/projects/64/unarchive", :controller => 'projects', :action => 'unarchive', :id => '64'
191 191
192 192 should_route :put, "/projects/64/enumerations", :controller => 'project_enumerations', :action => 'update', :project_id => '64'
193 193 should_route :put, "/projects/4223", :controller => 'projects', :action => 'update', :id => '4223'
194 194 should_route :put, "/projects/1.xml", :controller => 'projects', :action => 'update', :id => '1', :format => 'xml'
195 195
196 196 should_route :delete, "/projects/64", :controller => 'projects', :action => 'destroy', :id => '64'
197 197 should_route :delete, "/projects/1.xml", :controller => 'projects', :action => 'destroy', :id => '1', :format => 'xml'
198 198 should_route :delete, "/projects/64/enumerations", :controller => 'project_enumerations', :action => 'destroy', :project_id => '64'
199 199 end
200 200
201 201 context "repositories" do
202 202 should_route :get, "/projects/redmine/repository", :controller => 'repositories', :action => 'show', :id => 'redmine'
203 203 should_route :get, "/projects/redmine/repository/edit", :controller => 'repositories', :action => 'edit', :id => 'redmine'
204 204 should_route :get, "/projects/redmine/repository/revisions", :controller => 'repositories', :action => 'revisions', :id => 'redmine'
205 205 should_route :get, "/projects/redmine/repository/revisions.atom", :controller => 'repositories', :action => 'revisions', :id => 'redmine', :format => 'atom'
206 206 should_route :get, "/projects/redmine/repository/revisions/2457", :controller => 'repositories', :action => 'revision', :id => 'redmine', :rev => '2457'
207 207 should_route :get, "/projects/redmine/repository/revisions/2457/diff", :controller => 'repositories', :action => 'diff', :id => 'redmine', :rev => '2457'
208 208 should_route :get, "/projects/redmine/repository/revisions/2457/diff.diff", :controller => 'repositories', :action => 'diff', :id => 'redmine', :rev => '2457', :format => 'diff'
209 209 should_route :get, "/projects/redmine/repository/diff/path/to/file.c", :controller => 'repositories', :action => 'diff', :id => 'redmine', :path => %w[path to file.c]
210 210 should_route :get, "/projects/redmine/repository/revisions/2/diff/path/to/file.c", :controller => 'repositories', :action => 'diff', :id => 'redmine', :path => %w[path to file.c], :rev => '2'
211 211 should_route :get, "/projects/redmine/repository/browse/path/to/file.c", :controller => 'repositories', :action => 'browse', :id => 'redmine', :path => %w[path to file.c]
212 212 should_route :get, "/projects/redmine/repository/entry/path/to/file.c", :controller => 'repositories', :action => 'entry', :id => 'redmine', :path => %w[path to file.c]
213 213 should_route :get, "/projects/redmine/repository/revisions/2/entry/path/to/file.c", :controller => 'repositories', :action => 'entry', :id => 'redmine', :path => %w[path to file.c], :rev => '2'
214 214 should_route :get, "/projects/redmine/repository/raw/path/to/file.c", :controller => 'repositories', :action => 'entry', :id => 'redmine', :path => %w[path to file.c], :format => 'raw'
215 215 should_route :get, "/projects/redmine/repository/revisions/2/raw/path/to/file.c", :controller => 'repositories', :action => 'entry', :id => 'redmine', :path => %w[path to file.c], :rev => '2', :format => 'raw'
216 216 should_route :get, "/projects/redmine/repository/annotate/path/to/file.c", :controller => 'repositories', :action => 'annotate', :id => 'redmine', :path => %w[path to file.c]
217 217 should_route :get, "/projects/redmine/repository/changes/path/to/file.c", :controller => 'repositories', :action => 'changes', :id => 'redmine', :path => %w[path to file.c]
218 218 should_route :get, "/projects/redmine/repository/statistics", :controller => 'repositories', :action => 'stats', :id => 'redmine'
219 219
220 220
221 221 should_route :post, "/projects/redmine/repository/edit", :controller => 'repositories', :action => 'edit', :id => 'redmine'
222 222 end
223 223
224 224 context "timelogs (global)" do
225 225 should_route :get, "/time_entries", :controller => 'timelog', :action => 'index'
226 226 should_route :get, "/time_entries.csv", :controller => 'timelog', :action => 'index', :format => 'csv'
227 227 should_route :get, "/time_entries.atom", :controller => 'timelog', :action => 'index', :format => 'atom'
228 228 should_route :get, "/time_entries/new", :controller => 'timelog', :action => 'new'
229 229 should_route :get, "/time_entries/22/edit", :controller => 'timelog', :action => 'edit', :id => '22'
230 230
231 231 should_route :post, "/time_entries", :controller => 'timelog', :action => 'create'
232 232
233 233 should_route :put, "/time_entries/22", :controller => 'timelog', :action => 'update', :id => '22'
234 234
235 235 should_route :delete, "/time_entries/55", :controller => 'timelog', :action => 'destroy', :id => '55'
236 236 end
237 237
238 238 context "timelogs (scoped under project)" do
239 239 should_route :get, "/projects/567/time_entries", :controller => 'timelog', :action => 'index', :project_id => '567'
240 240 should_route :get, "/projects/567/time_entries.csv", :controller => 'timelog', :action => 'index', :project_id => '567', :format => 'csv'
241 241 should_route :get, "/projects/567/time_entries.atom", :controller => 'timelog', :action => 'index', :project_id => '567', :format => 'atom'
242 242 should_route :get, "/projects/567/time_entries/new", :controller => 'timelog', :action => 'new', :project_id => '567'
243 243 should_route :get, "/projects/567/time_entries/22/edit", :controller => 'timelog', :action => 'edit', :id => '22', :project_id => '567'
244 244
245 245 should_route :post, "/projects/567/time_entries", :controller => 'timelog', :action => 'create', :project_id => '567'
246 246
247 247 should_route :put, "/projects/567/time_entries/22", :controller => 'timelog', :action => 'update', :id => '22', :project_id => '567'
248 248
249 249 should_route :delete, "/projects/567/time_entries/55", :controller => 'timelog', :action => 'destroy', :id => '55', :project_id => '567'
250 250 end
251 251
252 252 context "timelogs (scoped under issues)" do
253 253 should_route :get, "/issues/234/time_entries", :controller => 'timelog', :action => 'index', :issue_id => '234'
254 254 should_route :get, "/issues/234/time_entries.csv", :controller => 'timelog', :action => 'index', :issue_id => '234', :format => 'csv'
255 255 should_route :get, "/issues/234/time_entries.atom", :controller => 'timelog', :action => 'index', :issue_id => '234', :format => 'atom'
256 256 should_route :get, "/issues/234/time_entries/new", :controller => 'timelog', :action => 'new', :issue_id => '234'
257 257 should_route :get, "/issues/234/time_entries/22/edit", :controller => 'timelog', :action => 'edit', :id => '22', :issue_id => '234'
258 258
259 259 should_route :post, "/issues/234/time_entries", :controller => 'timelog', :action => 'create', :issue_id => '234'
260 260
261 261 should_route :put, "/issues/234/time_entries/22", :controller => 'timelog', :action => 'update', :id => '22', :issue_id => '234'
262 262
263 263 should_route :delete, "/issues/234/time_entries/55", :controller => 'timelog', :action => 'destroy', :id => '55', :issue_id => '234'
264 264 end
265 265
266 266 context "timelogs (scoped under project and issues)" do
267 267 should_route :get, "/projects/ecookbook/issues/234/time_entries", :controller => 'timelog', :action => 'index', :issue_id => '234', :project_id => 'ecookbook'
268 268 should_route :get, "/projects/ecookbook/issues/234/time_entries.csv", :controller => 'timelog', :action => 'index', :issue_id => '234', :project_id => 'ecookbook', :format => 'csv'
269 269 should_route :get, "/projects/ecookbook/issues/234/time_entries.atom", :controller => 'timelog', :action => 'index', :issue_id => '234', :project_id => 'ecookbook', :format => 'atom'
270 270 should_route :get, "/projects/ecookbook/issues/234/time_entries/new", :controller => 'timelog', :action => 'new', :issue_id => '234', :project_id => 'ecookbook'
271 271 should_route :get, "/projects/ecookbook/issues/234/time_entries/22/edit", :controller => 'timelog', :action => 'edit', :id => '22', :issue_id => '234', :project_id => 'ecookbook'
272 272
273 273 should_route :post, "/projects/ecookbook/issues/234/time_entries", :controller => 'timelog', :action => 'create', :issue_id => '234', :project_id => 'ecookbook'
274 274
275 275 should_route :put, "/projects/ecookbook/issues/234/time_entries/22", :controller => 'timelog', :action => 'update', :id => '22', :issue_id => '234', :project_id => 'ecookbook'
276 276
277 277 should_route :delete, "/projects/ecookbook/issues/234/time_entries/55", :controller => 'timelog', :action => 'destroy', :id => '55', :issue_id => '234', :project_id => 'ecookbook'
278 278 end
279 279
280 280 context "time_entry_reports" do
281 281 should_route :get, "/time_entries/report", :controller => 'time_entry_reports', :action => 'report'
282 282 should_route :get, "/projects/567/time_entries/report", :controller => 'time_entry_reports', :action => 'report', :project_id => '567'
283 283 should_route :get, "/projects/567/time_entries/report.csv", :controller => 'time_entry_reports', :action => 'report', :project_id => '567', :format => 'csv'
284 284 end
285 285
286 286 context "users" do
287 287 should_route :get, "/users", :controller => 'users', :action => 'index'
288 288 should_route :get, "/users/44", :controller => 'users', :action => 'show', :id => '44'
289 289 should_route :get, "/users/new", :controller => 'users', :action => 'new'
290 290 should_route :get, "/users/444/edit", :controller => 'users', :action => 'edit', :id => '444'
291 291 should_route :get, "/users/222/edit/membership", :controller => 'users', :action => 'edit', :id => '222', :tab => 'membership'
292 292
293 293 should_route :post, "/users", :controller => 'users', :action => 'create'
294 294 should_route :post, "/users/123/memberships", :controller => 'users', :action => 'edit_membership', :id => '123'
295 295 should_route :post, "/users/123/memberships/55", :controller => 'users', :action => 'edit_membership', :id => '123', :membership_id => '55'
296 296 should_route :post, "/users/567/memberships/12/destroy", :controller => 'users', :action => 'destroy_membership', :id => '567', :membership_id => '12'
297 297
298 298 should_route :put, "/users/444", :controller => 'users', :action => 'update', :id => '444'
299 299 end
300 300
301 301 # TODO: should they all be scoped under /projects/:project_id ?
302 302 context "versions" do
303 303 should_route :get, "/projects/foo/versions/new", :controller => 'versions', :action => 'new', :project_id => 'foo'
304 304 should_route :get, "/versions/show/1", :controller => 'versions', :action => 'show', :id => '1'
305 305 should_route :get, "/versions/edit/1", :controller => 'versions', :action => 'edit', :id => '1'
306 306
307 307 should_route :post, "/projects/foo/versions", :controller => 'versions', :action => 'create', :project_id => 'foo'
308 308 should_route :post, "/versions/update/1", :controller => 'versions', :action => 'update', :id => '1'
309 309
310 310 should_route :delete, "/versions/destroy/1", :controller => 'versions', :action => 'destroy', :id => '1'
311 311 end
312 312
313 313 context "wiki (singular, project's pages)" do
314 314 should_route :get, "/projects/567/wiki", :controller => 'wiki', :action => 'show', :project_id => '567'
315 315 should_route :get, "/projects/567/wiki/lalala", :controller => 'wiki', :action => 'show', :project_id => '567', :page => 'lalala'
316 316 should_route :get, "/projects/567/wiki/my_page/edit", :controller => 'wiki', :action => 'edit', :project_id => '567', :page => 'my_page'
317 317 should_route :get, "/projects/1/wiki/CookBook_documentation/history", :controller => 'wiki', :action => 'history', :project_id => '1', :page => 'CookBook_documentation'
318 318 should_route :get, "/projects/1/wiki/CookBook_documentation/diff/2/vs/1", :controller => 'wiki', :action => 'diff', :project_id => '1', :page => 'CookBook_documentation', :version => '2', :version_from => '1'
319 319 should_route :get, "/projects/1/wiki/CookBook_documentation/annotate/2", :controller => 'wiki', :action => 'annotate', :project_id => '1', :page => 'CookBook_documentation', :version => '2'
320 320 should_route :get, "/projects/22/wiki/ladida/rename", :controller => 'wiki', :action => 'rename', :project_id => '22', :page => 'ladida'
321 321 should_route :get, "/projects/567/wiki/page_index", :controller => 'wiki', :action => 'page_index', :project_id => '567'
322 322 should_route :get, "/projects/567/wiki/date_index", :controller => 'wiki', :action => 'date_index', :project_id => '567'
323 323 should_route :get, "/projects/567/wiki/export", :controller => 'wiki', :action => 'export', :project_id => '567'
324 324
325 should_route :post, "/projects/567/wiki/my_page/edit", :controller => 'wiki', :action => 'edit', :project_id => '567', :page => 'my_page'
325 should_route :post, "/projects/567/wiki/my_page/edit", :controller => 'wiki', :action => 'update', :project_id => '567', :page => 'my_page'
326 326 should_route :post, "/projects/567/wiki/CookBook_documentation/preview", :controller => 'wiki', :action => 'preview', :project_id => '567', :page => 'CookBook_documentation'
327 327 should_route :post, "/projects/22/wiki/ladida/rename", :controller => 'wiki', :action => 'rename', :project_id => '22', :page => 'ladida'
328 328 should_route :post, "/projects/22/wiki/ladida/destroy", :controller => 'wiki', :action => 'destroy', :project_id => '22', :page => 'ladida'
329 329 should_route :post, "/projects/22/wiki/ladida/protect", :controller => 'wiki', :action => 'protect', :project_id => '22', :page => 'ladida'
330 330 end
331 331
332 332 context "wikis (plural, admin setup)" do
333 333 should_route :get, "/projects/ladida/wiki/destroy", :controller => 'wikis', :action => 'destroy', :id => 'ladida'
334 334
335 335 should_route :post, "/projects/ladida/wiki", :controller => 'wikis', :action => 'edit', :id => 'ladida'
336 336 should_route :post, "/projects/ladida/wiki/destroy", :controller => 'wikis', :action => 'destroy', :id => 'ladida'
337 337 end
338 338
339 339 context "administration panel" do
340 340 should_route :get, "/admin/projects", :controller => 'admin', :action => 'projects'
341 341 end
342 342 end
General Comments 0
You need to be logged in to leave comments. Login now