Refactor: change :id on WikiController to use :project_id

Using :id to track projects on non-project controllers is confusing and
makes routing with resources difficult.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4265 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Eric Davis 2010-10-20 21:26:30 +00:00
parent c058bc2245
commit d3381fb518
10 changed files with 82 additions and 81 deletions

View File

@ -79,7 +79,7 @@ class WikiController < ApplicationController
attachments = Attachment.attach_files(@page, params[:attachments]) attachments = Attachment.attach_files(@page, params[:attachments])
render_attachment_warning_if_needed(@page) render_attachment_warning_if_needed(@page)
# don't save if text wasn't changed # don't save if text wasn't changed
redirect_to :action => 'index', :id => @project, :page => @page.title redirect_to :action => 'index', :project_id => @project, :page => @page.title
return return
end end
#@content.text = params[:content][:text] #@content.text = params[:content][:text]
@ -91,7 +91,7 @@ class WikiController < ApplicationController
attachments = Attachment.attach_files(@page, params[:attachments]) attachments = Attachment.attach_files(@page, params[:attachments])
render_attachment_warning_if_needed(@page) render_attachment_warning_if_needed(@page)
call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page}) call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page})
redirect_to :action => 'index', :id => @project, :page => @page.title redirect_to :action => 'index', :project_id => @project, :page => @page.title
end end
end end
rescue ActiveRecord::StaleObjectError rescue ActiveRecord::StaleObjectError
@ -107,13 +107,13 @@ class WikiController < ApplicationController
@original_title = @page.pretty_title @original_title = @page.pretty_title
if request.post? && @page.update_attributes(params[:wiki_page]) if request.post? && @page.update_attributes(params[:wiki_page])
flash[:notice] = l(:notice_successful_update) flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'index', :id => @project, :page => @page.title redirect_to :action => 'index', :project_id => @project, :page => @page.title
end end
end end
def protect def protect
@page.update_attribute :protected, params[:protected] @page.update_attribute :protected, params[:protected]
redirect_to :action => 'index', :id => @project, :page => @page.title redirect_to :action => 'index', :project_id => @project, :page => @page.title
end end
# show page history # show page history
@ -166,7 +166,7 @@ class WikiController < ApplicationController
end end
end end
@page.destroy @page.destroy
redirect_to :action => 'page_index', :id => @project redirect_to :action => 'page_index', :project_id => @project
end end
# Export wiki to a single html file # Export wiki to a single html file
@ -176,7 +176,7 @@ class WikiController < ApplicationController
export = render_to_string :action => 'export_multiple', :layout => false export = render_to_string :action => 'export_multiple', :layout => false
send_data(export, :type => 'text/html', :filename => "wiki.html") send_data(export, :type => 'text/html', :filename => "wiki.html")
else else
redirect_to :action => 'index', :id => @project, :page => nil redirect_to :action => 'index', :project_id => @project, :page => nil
end end
end end
@ -210,7 +210,7 @@ class WikiController < ApplicationController
private private
def find_wiki def find_wiki
@project = Project.find(params[:id]) @project = Project.find(params[:project_id])
@wiki = @project.wiki @wiki = @project.wiki
render_404 unless @wiki render_404 unless @wiki
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound

View File

@ -182,7 +182,7 @@ module ApplicationHelper
content << "<ul class=\"pages-hierarchy\">\n" content << "<ul class=\"pages-hierarchy\">\n"
pages[node].each do |page| pages[node].each do |page|
content << "<li>" content << "<li>"
content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'index', :id => page.project, :page => page.title}, content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'index', :project_id => page.project, :page => page.title},
:title => (page.respond_to?(:updated_on) ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil)) :title => (page.respond_to?(:updated_on) ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
content << "\n" + render_page_hierarchy(pages, page.id) if pages[page.id] content << "\n" + render_page_hierarchy(pages, page.id) if pages[page.id]
content << "</li>\n" content << "</li>\n"
@ -551,7 +551,7 @@ module ApplicationHelper
when :local; "#{title}.html" when :local; "#{title}.html"
when :anchor; "##{title}" # used for single-file wiki export when :anchor; "##{title}" # used for single-file wiki export
else else
url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => link_project, :page => Wiki.titleize(page), :anchor => anchor) url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :project_id => link_project, :page => Wiki.titleize(page), :anchor => anchor)
end end
link_to((title || page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new'))) link_to((title || page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new')))
else else

View File

@ -18,7 +18,7 @@
<% @annotate.lines.each do |line| -%> <% @annotate.lines.each do |line| -%>
<tr class="bloc-<%= colors[line[0]] %>"> <tr class="bloc-<%= colors[line[0]] %>">
<th class="line-num"><%= line_num %></th> <th class="line-num"><%= line_num %></th>
<td class="revision"><%= link_to line[0], :controller => 'wiki', :action => 'index', :id => @project, :page => @page.title, :version => line[0] %></td> <td class="revision"><%= link_to line[0], :controller => 'wiki', :action => 'index', :project_id => @project, :page => @page.title, :version => line[0] %></td>
<td class="author"><%= h(line[1]) %></td> <td class="author"><%= h(line[1]) %></td>
<td class="line-code"><pre><%=h line[2] %></pre></td> <td class="line-code"><pre><%=h line[2] %></pre></td>
</tr> </tr>

View File

@ -15,5 +15,5 @@
</div> </div>
<%= submit_tag l(:button_apply) %> <%= submit_tag l(:button_apply) %>
<%= link_to l(:button_cancel), :controller => 'wiki', :action => 'index', :id => @project, :page => @page.title %> <%= link_to l(:button_cancel), :controller => 'wiki', :action => 'index', :project_id => @project, :page => @page.title %>
<% end %> <% end %>

View File

@ -10,7 +10,7 @@
<p><%= submit_tag l(:button_save) %> <p><%= submit_tag l(:button_save) %>
<%= link_to_remote l(:label_preview), <%= link_to_remote l(:label_preview),
{ :url => { :controller => 'wiki', :action => 'preview', :id => @project, :page => @page.title }, { :url => { :controller => 'wiki', :action => 'preview', :project_id => @project, :page => @page.title },
:method => 'post', :method => 'post',
:update => 'preview', :update => 'preview',
:with => "Form.serialize('wiki_form')", :with => "Form.serialize('wiki_form')",

View File

@ -3,6 +3,7 @@
<h3><%= l(:label_history) %></h3> <h3><%= l(:label_history) %></h3>
<% form_tag({:action => "diff"}, :method => :get) do %> <% form_tag({:action => "diff"}, :method => :get) do %>
<%= hidden_field_tag('project_id', h(@project.to_param)) %>
<table class="list"> <table class="list">
<thead><tr> <thead><tr>
<th>#</th> <th>#</th>

View File

@ -29,18 +29,18 @@ ActionController::Routing::Routes.draw do |map|
map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :post} map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :post}
map.with_options :controller => 'wiki' do |wiki_routes| map.with_options :controller => 'wiki' do |wiki_routes|
wiki_routes.with_options :conditions => {:method => :get} do |wiki_views| wiki_routes.with_options :conditions => {:method => :get} do |wiki_views|
wiki_views.connect 'projects/:id/wiki/export', :action => 'export' wiki_views.connect 'projects/:project_id/wiki/export', :action => 'export'
wiki_views.connect 'projects/:id/wiki/page_index', :action => 'page_index' wiki_views.connect 'projects/:project_id/wiki/page_index', :action => 'page_index'
wiki_views.connect 'projects/:id/wiki/date_index', :action => 'date_index' wiki_views.connect 'projects/:project_id/wiki/date_index', :action => 'date_index'
wiki_views.connect 'projects/:id/wiki/:page', :action => 'index', :page => nil wiki_views.connect 'projects/:project_id/wiki/:page', :action => 'index', :page => nil
wiki_views.connect 'projects/:id/wiki/:page/edit', :action => 'edit' wiki_views.connect 'projects/:project_id/wiki/:page/edit', :action => 'edit'
wiki_views.connect 'projects/:id/wiki/:page/rename', :action => 'rename' wiki_views.connect 'projects/:project_id/wiki/:page/rename', :action => 'rename'
wiki_views.connect 'projects/:id/wiki/:page/history', :action => 'history' wiki_views.connect 'projects/:project_id/wiki/:page/history', :action => 'history'
wiki_views.connect 'projects/:id/wiki/:page/diff/:version/vs/:version_from', :action => 'diff' wiki_views.connect 'projects/:project_id/wiki/:page/diff/:version/vs/:version_from', :action => 'diff'
wiki_views.connect 'projects/:id/wiki/:page/annotate/:version', :action => 'annotate' wiki_views.connect 'projects/:project_id/wiki/:page/annotate/:version', :action => 'annotate'
end end
wiki_routes.connect 'projects/:id/wiki/:page/:action', wiki_routes.connect 'projects/:project_id/wiki/:page/:action',
:action => /edit|rename|destroy|preview|protect/, :action => /edit|rename|destroy|preview|protect/,
:conditions => {:method => :post} :conditions => {:method => :post}
end end

View File

@ -195,7 +195,7 @@ Redmine::MenuManager.map :project_menu do |menu|
menu.push :calendar, { :controller => 'calendars', :action => 'show' }, :param => :project_id, :caption => :label_calendar menu.push :calendar, { :controller => 'calendars', :action => 'show' }, :param => :project_id, :caption => :label_calendar
menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural
menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural
menu.push :wiki, { :controller => 'wiki', :action => 'index', :page => nil }, menu.push :wiki, { :controller => 'wiki', :action => 'index', :page => nil }, :param => :project_id,
:if => Proc.new { |p| p.wiki && !p.wiki.new_record? } :if => Proc.new { |p| p.wiki && !p.wiki.new_record? }
menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id, menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id,
:if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural

View File

@ -32,7 +32,7 @@ class WikiControllerTest < ActionController::TestCase
end end
def test_show_start_page def test_show_start_page
get :index, :id => 'ecookbook' get :index, :project_id => 'ecookbook'
assert_response :success assert_response :success
assert_template 'show' assert_template 'show'
assert_tag :tag => 'h1', :content => /CookBook documentation/ assert_tag :tag => 'h1', :content => /CookBook documentation/
@ -45,7 +45,7 @@ class WikiControllerTest < ActionController::TestCase
end end
def test_show_page_with_name def test_show_page_with_name
get :index, :id => 1, :page => 'Another_page' get :index, :project_id => 1, :page => 'Another_page'
assert_response :success assert_response :success
assert_template 'show' assert_template 'show'
assert_tag :tag => 'h1', :content => /Another page/ assert_tag :tag => 'h1', :content => /Another page/
@ -60,32 +60,32 @@ class WikiControllerTest < ActionController::TestCase
page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar') page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
page.save! page.save!
get :index, :id => 1, :page => 'Another_page' get :index, :project_id => 1, :page => 'Another_page'
assert_response :success assert_response :success
assert_tag :tag => 'div', :attributes => {:id => 'sidebar'}, assert_tag :tag => 'div', :attributes => {:id => 'sidebar'},
:content => /Side bar content for test_show_with_sidebar/ :content => /Side bar content for test_show_with_sidebar/
end end
def test_show_unexistent_page_without_edit_right def test_show_unexistent_page_without_edit_right
get :index, :id => 1, :page => 'Unexistent page' get :index, :project_id => 1, :page => 'Unexistent page'
assert_response 404 assert_response 404
end end
def test_show_unexistent_page_with_edit_right def test_show_unexistent_page_with_edit_right
@request.session[:user_id] = 2 @request.session[:user_id] = 2
get :index, :id => 1, :page => 'Unexistent page' get :index, :project_id => 1, :page => 'Unexistent page'
assert_response :success assert_response :success
assert_template 'edit' assert_template 'edit'
end end
def test_create_page def test_create_page
@request.session[:user_id] = 2 @request.session[:user_id] = 2
post :edit, :id => 1, post :edit, :project_id => 1,
:page => 'New page', :page => 'New page',
:content => {:comments => 'Created the page', :content => {:comments => 'Created the page',
:text => "h1. New page\n\nThis is a new page", :text => "h1. New page\n\nThis is a new page",
:version => 0} :version => 0}
assert_redirected_to :action => 'index', :id => 'ecookbook', :page => 'New_page' assert_redirected_to :action => 'index', :project_id => 'ecookbook', :page => 'New_page'
page = Project.find(1).wiki.find_page('New page') page = Project.find(1).wiki.find_page('New page')
assert !page.new_record? assert !page.new_record?
assert_not_nil page.content assert_not_nil page.content
@ -96,7 +96,7 @@ class WikiControllerTest < ActionController::TestCase
@request.session[:user_id] = 2 @request.session[:user_id] = 2
assert_difference 'WikiPage.count' do assert_difference 'WikiPage.count' do
assert_difference 'Attachment.count' do assert_difference 'Attachment.count' do
post :edit, :id => 1, post :edit, :project_id => 1,
:page => 'New page', :page => 'New page',
:content => {:comments => 'Created the page', :content => {:comments => 'Created the page',
:text => "h1. New page\n\nThis is a new page", :text => "h1. New page\n\nThis is a new page",
@ -111,7 +111,7 @@ class WikiControllerTest < ActionController::TestCase
def test_preview def test_preview
@request.session[:user_id] = 2 @request.session[:user_id] = 2
xhr :post, :preview, :id => 1, :page => 'CookBook_documentation', xhr :post, :preview, :project_id => 1, :page => 'CookBook_documentation',
:content => { :comments => '', :content => { :comments => '',
:text => 'this is a *previewed text*', :text => 'this is a *previewed text*',
:version => 3 } :version => 3 }
@ -122,7 +122,7 @@ class WikiControllerTest < ActionController::TestCase
def test_preview_new_page def test_preview_new_page
@request.session[:user_id] = 2 @request.session[:user_id] = 2
xhr :post, :preview, :id => 1, :page => 'New page', xhr :post, :preview, :project_id => 1, :page => 'New page',
:content => { :text => 'h1. New page', :content => { :text => 'h1. New page',
:comments => '', :comments => '',
:version => 0 } :version => 0 }
@ -132,7 +132,7 @@ class WikiControllerTest < ActionController::TestCase
end end
def test_history def test_history
get :history, :id => 1, :page => 'CookBook_documentation' get :history, :project_id => 1, :page => 'CookBook_documentation'
assert_response :success assert_response :success
assert_template 'history' assert_template 'history'
assert_not_nil assigns(:versions) assert_not_nil assigns(:versions)
@ -141,7 +141,7 @@ class WikiControllerTest < ActionController::TestCase
end end
def test_history_with_one_version def test_history_with_one_version
get :history, :id => 1, :page => 'Another_page' get :history, :project_id => 1, :page => 'Another_page'
assert_response :success assert_response :success
assert_template 'history' assert_template 'history'
assert_not_nil assigns(:versions) assert_not_nil assigns(:versions)
@ -150,7 +150,7 @@ class WikiControllerTest < ActionController::TestCase
end end
def test_diff def test_diff
get :diff, :id => 1, :page => 'CookBook_documentation', :version => 2, :version_from => 1 get :diff, :project_id => 1, :page => 'CookBook_documentation', :version => 2, :version_from => 1
assert_response :success assert_response :success
assert_template 'diff' assert_template 'diff'
assert_tag :tag => 'span', :attributes => { :class => 'diff_in'}, assert_tag :tag => 'span', :attributes => { :class => 'diff_in'},
@ -158,7 +158,7 @@ class WikiControllerTest < ActionController::TestCase
end end
def test_annotate def test_annotate
get :annotate, :id => 1, :page => 'CookBook_documentation', :version => 2 get :annotate, :project_id => 1, :page => 'CookBook_documentation', :version => 2
assert_response :success assert_response :success
assert_template 'annotate' assert_template 'annotate'
# Line 1 # Line 1
@ -173,10 +173,10 @@ class WikiControllerTest < ActionController::TestCase
def test_rename_with_redirect def test_rename_with_redirect
@request.session[:user_id] = 2 @request.session[:user_id] = 2
post :rename, :id => 1, :page => 'Another_page', post :rename, :project_id => 1, :page => 'Another_page',
:wiki_page => { :title => 'Another renamed page', :wiki_page => { :title => 'Another renamed page',
:redirect_existing_links => 1 } :redirect_existing_links => 1 }
assert_redirected_to :action => 'index', :id => 'ecookbook', :page => 'Another_renamed_page' assert_redirected_to :action => 'index', :project_id => 'ecookbook', :page => 'Another_renamed_page'
wiki = Project.find(1).wiki wiki = Project.find(1).wiki
# Check redirects # Check redirects
assert_not_nil wiki.find_page('Another page') assert_not_nil wiki.find_page('Another page')
@ -185,10 +185,10 @@ class WikiControllerTest < ActionController::TestCase
def test_rename_without_redirect def test_rename_without_redirect
@request.session[:user_id] = 2 @request.session[:user_id] = 2
post :rename, :id => 1, :page => 'Another_page', post :rename, :project_id => 1, :page => 'Another_page',
:wiki_page => { :title => 'Another renamed page', :wiki_page => { :title => 'Another renamed page',
:redirect_existing_links => "0" } :redirect_existing_links => "0" }
assert_redirected_to :action => 'index', :id => 'ecookbook', :page => 'Another_renamed_page' assert_redirected_to :action => 'index', :project_id => 'ecookbook', :page => 'Another_renamed_page'
wiki = Project.find(1).wiki wiki = Project.find(1).wiki
# Check that there's no redirects # Check that there's no redirects
assert_nil wiki.find_page('Another page') assert_nil wiki.find_page('Another page')
@ -196,14 +196,14 @@ class WikiControllerTest < ActionController::TestCase
def test_destroy_child def test_destroy_child
@request.session[:user_id] = 2 @request.session[:user_id] = 2
post :destroy, :id => 1, :page => 'Child_1' post :destroy, :project_id => 1, :page => 'Child_1'
assert_redirected_to :action => 'page_index', :id => 'ecookbook' assert_redirected_to :action => 'page_index', :project_id => 'ecookbook'
end end
def test_destroy_parent def test_destroy_parent
@request.session[:user_id] = 2 @request.session[:user_id] = 2
assert_no_difference('WikiPage.count') do assert_no_difference('WikiPage.count') do
post :destroy, :id => 1, :page => 'Another_page' post :destroy, :project_id => 1, :page => 'Another_page'
end end
assert_response :success assert_response :success
assert_template 'destroy' assert_template 'destroy'
@ -212,18 +212,18 @@ class WikiControllerTest < ActionController::TestCase
def test_destroy_parent_with_nullify def test_destroy_parent_with_nullify
@request.session[:user_id] = 2 @request.session[:user_id] = 2
assert_difference('WikiPage.count', -1) do assert_difference('WikiPage.count', -1) do
post :destroy, :id => 1, :page => 'Another_page', :todo => 'nullify' post :destroy, :project_id => 1, :page => 'Another_page', :todo => 'nullify'
end end
assert_redirected_to :action => 'page_index', :id => 'ecookbook' assert_redirected_to :action => 'page_index', :project_id => 'ecookbook'
assert_nil WikiPage.find_by_id(2) assert_nil WikiPage.find_by_id(2)
end end
def test_destroy_parent_with_cascade def test_destroy_parent_with_cascade
@request.session[:user_id] = 2 @request.session[:user_id] = 2
assert_difference('WikiPage.count', -3) do assert_difference('WikiPage.count', -3) do
post :destroy, :id => 1, :page => 'Another_page', :todo => 'destroy' post :destroy, :project_id => 1, :page => 'Another_page', :todo => 'destroy'
end end
assert_redirected_to :action => 'page_index', :id => 'ecookbook' assert_redirected_to :action => 'page_index', :project_id => 'ecookbook'
assert_nil WikiPage.find_by_id(2) assert_nil WikiPage.find_by_id(2)
assert_nil WikiPage.find_by_id(5) assert_nil WikiPage.find_by_id(5)
end end
@ -231,15 +231,15 @@ class WikiControllerTest < ActionController::TestCase
def test_destroy_parent_with_reassign def test_destroy_parent_with_reassign
@request.session[:user_id] = 2 @request.session[:user_id] = 2
assert_difference('WikiPage.count', -1) do assert_difference('WikiPage.count', -1) do
post :destroy, :id => 1, :page => 'Another_page', :todo => 'reassign', :reassign_to_id => 1 post :destroy, :project_id => 1, :page => 'Another_page', :todo => 'reassign', :reassign_to_id => 1
end end
assert_redirected_to :action => 'page_index', :id => 'ecookbook' assert_redirected_to :action => 'page_index', :project_id => 'ecookbook'
assert_nil WikiPage.find_by_id(2) assert_nil WikiPage.find_by_id(2)
assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent
end end
def test_page_index def test_page_index
get :page_index, :id => 'ecookbook' get :page_index, :project_id => 'ecookbook'
assert_response :success assert_response :success
assert_template 'page_index' assert_template 'page_index'
pages = assigns(:pages) pages = assigns(:pages)
@ -261,7 +261,7 @@ class WikiControllerTest < ActionController::TestCase
context "with an authorized user to export the wiki" do context "with an authorized user to export the wiki" do
setup do setup do
@request.session[:user_id] = 2 @request.session[:user_id] = 2
get :export, :id => 'ecookbook' get :export, :project_id => 'ecookbook'
end end
should_respond_with :success should_respond_with :success
@ -277,17 +277,17 @@ class WikiControllerTest < ActionController::TestCase
context "with an unauthorized user" do context "with an unauthorized user" do
setup do setup do
get :export, :id => 'ecookbook' get :export, :project_id => 'ecookbook'
should_respond_with :redirect should_respond_with :redirect
should_redirect_to('wiki index') { {:action => 'index', :id => @project, :page => nil} } should_redirect_to('wiki index') { {:action => 'index', :project_id => @project, :page => nil} }
end end
end end
end end
context "GET :date_index" do context "GET :date_index" do
setup do setup do
get :date_index, :id => 'ecookbook' get :date_index, :project_id => 'ecookbook'
end end
should_respond_with :success should_respond_with :success
@ -298,7 +298,7 @@ class WikiControllerTest < ActionController::TestCase
end end
def test_not_found def test_not_found
get :index, :id => 999 get :index, :project_id => 999
assert_response 404 assert_response 404
end end
@ -306,8 +306,8 @@ class WikiControllerTest < ActionController::TestCase
page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page') page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
assert !page.protected? assert !page.protected?
@request.session[:user_id] = 2 @request.session[:user_id] = 2
post :protect, :id => 1, :page => page.title, :protected => '1' post :protect, :project_id => 1, :page => page.title, :protected => '1'
assert_redirected_to :action => 'index', :id => 'ecookbook', :page => 'Another_page' assert_redirected_to :action => 'index', :project_id => 'ecookbook', :page => 'Another_page'
assert page.reload.protected? assert page.reload.protected?
end end
@ -315,14 +315,14 @@ class WikiControllerTest < ActionController::TestCase
page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation') page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
assert page.protected? assert page.protected?
@request.session[:user_id] = 2 @request.session[:user_id] = 2
post :protect, :id => 1, :page => page.title, :protected => '0' post :protect, :project_id => 1, :page => page.title, :protected => '0'
assert_redirected_to :action => 'index', :id => 'ecookbook', :page => 'CookBook_documentation' assert_redirected_to :action => 'index', :project_id => 'ecookbook', :page => 'CookBook_documentation'
assert !page.reload.protected? assert !page.reload.protected?
end end
def test_show_page_with_edit_link def test_show_page_with_edit_link
@request.session[:user_id] = 2 @request.session[:user_id] = 2
get :index, :id => 1 get :index, :project_id => 1
assert_response :success assert_response :success
assert_template 'show' assert_template 'show'
assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' } assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
@ -330,7 +330,7 @@ class WikiControllerTest < ActionController::TestCase
def test_show_page_without_edit_link def test_show_page_without_edit_link
@request.session[:user_id] = 4 @request.session[:user_id] = 4
get :index, :id => 1 get :index, :project_id => 1
assert_response :success assert_response :success
assert_template 'show' assert_template 'show'
assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' } assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
@ -339,7 +339,7 @@ class WikiControllerTest < ActionController::TestCase
def test_edit_unprotected_page def test_edit_unprotected_page
# Non members can edit unprotected wiki pages # Non members can edit unprotected wiki pages
@request.session[:user_id] = 4 @request.session[:user_id] = 4
get :edit, :id => 1, :page => 'Another_page' get :edit, :project_id => 1, :page => 'Another_page'
assert_response :success assert_response :success
assert_template 'edit' assert_template 'edit'
end end
@ -347,19 +347,19 @@ class WikiControllerTest < ActionController::TestCase
def test_edit_protected_page_by_nonmember def test_edit_protected_page_by_nonmember
# Non members can't edit protected wiki pages # Non members can't edit protected wiki pages
@request.session[:user_id] = 4 @request.session[:user_id] = 4
get :edit, :id => 1, :page => 'CookBook_documentation' get :edit, :project_id => 1, :page => 'CookBook_documentation'
assert_response 403 assert_response 403
end end
def test_edit_protected_page_by_member def test_edit_protected_page_by_member
@request.session[:user_id] = 2 @request.session[:user_id] = 2
get :edit, :id => 1, :page => 'CookBook_documentation' get :edit, :project_id => 1, :page => 'CookBook_documentation'
assert_response :success assert_response :success
assert_template 'edit' assert_template 'edit'
end end
def test_history_of_non_existing_page_should_return_404 def test_history_of_non_existing_page_should_return_404
get :history, :id => 1, :page => 'Unknown_page' get :history, :project_id => 1, :page => 'Unknown_page'
assert_response 404 assert_response 404
end end
end end

View File

@ -311,22 +311,22 @@ class RoutingTest < ActionController::IntegrationTest
end end
context "wiki (singular, project's pages)" do context "wiki (singular, project's pages)" do
should_route :get, "/projects/567/wiki", :controller => 'wiki', :action => 'index', :id => '567' should_route :get, "/projects/567/wiki", :controller => 'wiki', :action => 'index', :project_id => '567'
should_route :get, "/projects/567/wiki/lalala", :controller => 'wiki', :action => 'index', :id => '567', :page => 'lalala' should_route :get, "/projects/567/wiki/lalala", :controller => 'wiki', :action => 'index', :project_id => '567', :page => 'lalala'
should_route :get, "/projects/567/wiki/my_page/edit", :controller => 'wiki', :action => 'edit', :id => '567', :page => 'my_page' should_route :get, "/projects/567/wiki/my_page/edit", :controller => 'wiki', :action => 'edit', :project_id => '567', :page => 'my_page'
should_route :get, "/projects/1/wiki/CookBook_documentation/history", :controller => 'wiki', :action => 'history', :id => '1', :page => 'CookBook_documentation' should_route :get, "/projects/1/wiki/CookBook_documentation/history", :controller => 'wiki', :action => 'history', :project_id => '1', :page => 'CookBook_documentation'
should_route :get, "/projects/1/wiki/CookBook_documentation/diff/2/vs/1", :controller => 'wiki', :action => 'diff', :id => '1', :page => 'CookBook_documentation', :version => '2', :version_from => '1' 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'
should_route :get, "/projects/1/wiki/CookBook_documentation/annotate/2", :controller => 'wiki', :action => 'annotate', :id => '1', :page => 'CookBook_documentation', :version => '2' should_route :get, "/projects/1/wiki/CookBook_documentation/annotate/2", :controller => 'wiki', :action => 'annotate', :project_id => '1', :page => 'CookBook_documentation', :version => '2'
should_route :get, "/projects/22/wiki/ladida/rename", :controller => 'wiki', :action => 'rename', :id => '22', :page => 'ladida' should_route :get, "/projects/22/wiki/ladida/rename", :controller => 'wiki', :action => 'rename', :project_id => '22', :page => 'ladida'
should_route :get, "/projects/567/wiki/page_index", :controller => 'wiki', :action => 'page_index', :id => '567' should_route :get, "/projects/567/wiki/page_index", :controller => 'wiki', :action => 'page_index', :project_id => '567'
should_route :get, "/projects/567/wiki/date_index", :controller => 'wiki', :action => 'date_index', :id => '567' should_route :get, "/projects/567/wiki/date_index", :controller => 'wiki', :action => 'date_index', :project_id => '567'
should_route :get, "/projects/567/wiki/export", :controller => 'wiki', :action => 'export', :id => '567' should_route :get, "/projects/567/wiki/export", :controller => 'wiki', :action => 'export', :project_id => '567'
should_route :post, "/projects/567/wiki/my_page/edit", :controller => 'wiki', :action => 'edit', :id => '567', :page => 'my_page' should_route :post, "/projects/567/wiki/my_page/edit", :controller => 'wiki', :action => 'edit', :project_id => '567', :page => 'my_page'
should_route :post, "/projects/567/wiki/CookBook_documentation/preview", :controller => 'wiki', :action => 'preview', :id => '567', :page => 'CookBook_documentation' should_route :post, "/projects/567/wiki/CookBook_documentation/preview", :controller => 'wiki', :action => 'preview', :project_id => '567', :page => 'CookBook_documentation'
should_route :post, "/projects/22/wiki/ladida/rename", :controller => 'wiki', :action => 'rename', :id => '22', :page => 'ladida' should_route :post, "/projects/22/wiki/ladida/rename", :controller => 'wiki', :action => 'rename', :project_id => '22', :page => 'ladida'
should_route :post, "/projects/22/wiki/ladida/destroy", :controller => 'wiki', :action => 'destroy', :id => '22', :page => 'ladida' should_route :post, "/projects/22/wiki/ladida/destroy", :controller => 'wiki', :action => 'destroy', :project_id => '22', :page => 'ladida'
should_route :post, "/projects/22/wiki/ladida/protect", :controller => 'wiki', :action => 'protect', :id => '22', :page => 'ladida' should_route :post, "/projects/22/wiki/ladida/protect", :controller => 'wiki', :action => 'protect', :project_id => '22', :page => 'ladida'
end end
context "wikis (plural, admin setup)" do context "wikis (plural, admin setup)" do