Feature #3108 » 3108_automatic_parent_with_tests.diff
test/functional/wiki_controller_test.rb (working copy) | ||
---|---|---|
57 | 57 |
:child => { :tag => 'li', |
58 | 58 |
:child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' }, |
59 | 59 |
:content => 'Page with an inline image' } } |
60 |
assert_tag :a, :attributes => { :href => '/projects/ecookbook/wiki/Documentation?parent=CookBook_documentation', |
|
61 |
:class => 'wiki-page new' }, |
|
62 |
:content => 'documentation' |
|
60 | 63 |
end |
61 | 64 |
|
62 | 65 |
def test_show_page_with_name |
... | ... | |
106 | 109 |
assert_not_nil page.content |
107 | 110 |
assert_equal 'Created the page', page.content.comments |
108 | 111 |
end |
109 |
|
|
112 | ||
113 |
def test_create_page_with_automatic_parent |
|
114 |
@request.session[:user_id] = 2 |
|
115 |
post :edit, :id => 1, |
|
116 |
:page => 'New page 2', |
|
117 |
:content => {:comments => 'Created the page 2', |
|
118 |
:text => "h1. New page 2\n\nThis is a new page with an auto parent !", |
|
119 |
:version => 0}, |
|
120 |
:set_parent => 'Save and set parent page', |
|
121 |
:parent => 'CookBook_documentation' |
|
122 |
assert_redirected_to :action => 'index', :id => 'ecookbook', :page => 'New_page_2' |
|
123 |
page = Project.find(1).wiki.find_page('New page 2') |
|
124 |
assert !page.new_record? |
|
125 |
assert_not_nil page.content |
|
126 |
assert_equal 'Created the page 2', page.content.comments |
|
127 |
assert_not_nil page.parent |
|
128 |
assert_equal 'CookBook_documentation', page.parent.title |
|
129 |
end |
|
130 |
|
|
131 |
def test_create_page_without_automatic_parent |
|
132 |
@request.session[:user_id] = 2 |
|
133 |
post :edit, :id => 1, |
|
134 |
:page => 'New page 3', |
|
135 |
:content => {:comments => 'Created the page 3', |
|
136 |
:text => "h1. New page 3\n\nThis is a new page without an auto parent :-(", |
|
137 |
:version => 0}, |
|
138 |
:parent => 'CookBook_documentation' |
|
139 |
assert_redirected_to :action => 'index', :id => 'ecookbook', :page => 'New_page_3' |
|
140 |
page = Project.find(1).wiki.find_page('New page 3') |
|
141 |
assert !page.new_record? |
|
142 |
assert_not_nil page.content |
|
143 |
assert_equal 'Created the page 3', page.content.comments |
|
144 |
assert_nil page.parent |
|
145 |
end |
|
146 |
|
|
110 | 147 |
def test_preview_routing |
111 | 148 |
assert_routing( |
112 | 149 |
{:method => :post, :path => '/projects/567/wiki/CookBook_documentation/preview'}, |
app/helpers/application_helper.rb (working copy) | ||
---|---|---|
361 | 361 |
case options[:wiki_links] |
362 | 362 |
when :local |
363 | 363 |
# used for local links to html files |
364 |
format_wiki_link = Proc.new {|project, title, anchor| "#{title}.html" } |
|
364 |
format_wiki_link = Proc.new {|project, title, anchor, parent| "#{title}.html" }
|
|
365 | 365 |
when :anchor |
366 | 366 |
# used for single-file wiki export |
367 |
format_wiki_link = Proc.new {|project, title, anchor| "##{title}" } |
|
367 |
format_wiki_link = Proc.new {|project, title, anchor, parent| "##{title}" }
|
|
368 | 368 |
else |
369 |
format_wiki_link = Proc.new {|project, title, anchor| url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => project, :page => title, :anchor => anchor) }
|
|
369 |
format_wiki_link = Proc.new {|project, title, anchor, parent| url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => project, :page => title, :anchor => anchor, :parent => parent) }
|
|
370 | 370 |
end |
371 | 371 | |
372 | 372 |
project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil) |
... | ... | |
399 | 399 |
end |
400 | 400 |
# check if page exists |
401 | 401 |
wiki_page = link_project.wiki.find_page(page) |
402 |
link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page), anchor), |
|
403 |
:class => ('wiki-page' + (wiki_page ? '' : ' new'))) |
|
402 |
link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page), anchor, (wiki_page || @page.nil? ? nil : @page.title)), :class => ('wiki-page' + (wiki_page ? '' : ' new'))) |
|
404 | 403 |
else |
405 | 404 |
# project or wiki doesn't exist |
406 | 405 |
all |
app/controllers/wiki_controller.rb (working copy) | ||
---|---|---|
80 | 80 |
#@content.comments = params[:content][:comments] |
81 | 81 |
@content.attributes = params[:content] |
82 | 82 |
@content.author = User.current |
83 |
if params[:set_parent] && !params[:parent].blank? |
|
84 |
@page.parent_title = params[:parent] |
|
85 |
@page.parent_title = nil unless @page.valid? |
|
86 |
end |
|
83 | 87 |
# if page is new @page.save will also save content, but not if page isn't a new record |
84 | 88 |
if (@page.new_record? ? @page.save : @content.save) |
85 | 89 |
redirect_to :action => 'index', :id => @project, :page => @page.title |
app/views/wiki/edit.rhtml (working copy) | ||
---|---|---|
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 |
<% if params[:parent] %> |
|
10 |
<%= hidden_field_tag :parent, params[:parent] -%> |
|
11 |
<% end %> |
|
9 | 12 |
<p><%= submit_tag l(:button_save) %> |
13 |
<%= submit_tag l(:button_save_and_set_parent), :name => 'set_parent' if params[:parent] %> |
|
10 | 14 |
<%= link_to_remote l(:label_preview), |
11 | 15 |
{ :url => { :controller => 'wiki', :action => 'preview', :id => @project, :page => @page.title }, |
12 | 16 |
:method => 'post', |
config/locales/en.yml (working copy) | ||
---|---|---|
682 | 682 |
button_login: Login |
683 | 683 |
button_submit: Submit |
684 | 684 |
button_save: Save |
685 |
button_save_and_set_parent: Save and set parent page |
|
685 | 686 |
button_check_all: Check all |
686 | 687 |
button_uncheck_all: Uncheck all |
687 | 688 |
button_delete: Delete |
config/locales/fr.yml (working copy) | ||
---|---|---|
712 | 712 |
button_login: Connexion |
713 | 713 |
button_submit: Soumettre |
714 | 714 |
button_save: Sauvegarder |
715 |
button_save_and_set_parent: Sauvegarder et définir la page parent |
|
715 | 716 |
button_check_all: Tout cocher |
716 | 717 |
button_uncheck_all: Tout décocher |
717 | 718 |
button_delete: Supprimer |