@@ -95,7 +95,12 class WikiController < ApplicationController | |||||
95 | # edit an existing page or a new one |
|
95 | # edit an existing page or a new one | |
96 | def edit |
|
96 | def edit | |
97 | return render_403 unless editable? |
|
97 | return render_403 unless editable? | |
98 | @page.content = WikiContent.new(:page => @page) if @page.new_record? |
|
98 | if @page.new_record? | |
|
99 | @page.content = WikiContent.new(:page => @page) | |||
|
100 | if params[:parent].present? | |||
|
101 | @page.parent = @page.wiki.find_page(params[:parent].to_s) | |||
|
102 | end | |||
|
103 | end | |||
99 |
|
104 | |||
100 | @content = @page.content_for_version(params[:version]) |
|
105 | @content = @page.content_for_version(params[:version]) | |
101 | @content.text = initial_page_content(@page) if @content.text.blank? |
|
106 | @content.text = initial_page_content(@page) if @content.text.blank? | |
@@ -143,6 +148,9 class WikiController < ApplicationController | |||||
143 | @content.text = @text |
|
148 | @content.text = @text | |
144 | end |
|
149 | end | |
145 | @content.author = User.current |
|
150 | @content.author = User.current | |
|
151 | if @page.new_record? && params[:page] | |||
|
152 | @page.parent_id = params[:page][:parent_id] | |||
|
153 | end | |||
146 | # if page is new @page.save will also save content, but not if page isn't a new record |
|
154 | # if page is new @page.save will also save content, but not if page isn't a new record | |
147 | if (@page.new_record? ? @page.save : @content.save) |
|
155 | if (@page.new_record? ? @page.save : @content.save) | |
148 | attachments = Attachment.attach_files(@page, params[:attachments]) |
|
156 | attachments = Attachment.attach_files(@page, params[:attachments]) |
@@ -596,7 +596,9 module ApplicationHelper | |||||
596 | when :anchor; "##{page.present? ? Wiki.titleize(page) : title}" + (anchor.present? ? "_#{anchor}" : '') # used for single-file wiki export |
|
596 | when :anchor; "##{page.present? ? Wiki.titleize(page) : title}" + (anchor.present? ? "_#{anchor}" : '') # used for single-file wiki export | |
597 | else |
|
597 | else | |
598 | wiki_page_id = page.present? ? Wiki.titleize(page) : nil |
|
598 | wiki_page_id = page.present? ? Wiki.titleize(page) : nil | |
599 | url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project, :id => wiki_page_id, :anchor => anchor) |
|
599 | parent = wiki_page.nil? && obj.is_a?(WikiContent) && obj.page && project == link_project ? obj.page.title : nil | |
|
600 | url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project, | |||
|
601 | :id => wiki_page_id, :anchor => anchor, :parent => parent) | |||
600 | end |
|
602 | end | |
601 | end |
|
603 | end | |
602 | link_to(title.present? ? title.html_safe : h(page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new'))) |
|
604 | link_to(title.present? ? title.html_safe : h(page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new'))) |
@@ -13,6 +13,10 | |||||
13 | <div class="box tabular"> |
|
13 | <div class="box tabular"> | |
14 | <%= text_area_tag 'content[text]', @text, :cols => 100, :rows => 25, :class => 'wiki-edit', :accesskey => accesskey(:edit) %> |
|
14 | <%= text_area_tag 'content[text]', @text, :cols => 100, :rows => 25, :class => 'wiki-edit', :accesskey => accesskey(:edit) %> | |
15 |
|
15 | |||
|
16 | <% if @page.new_record? && @page.parent %> | |||
|
17 | <p><label><%= check_box_tag 'page[parent_id]', @page.parent.id %> <%= l(:field_parent_title) %></label> <%=h @page.parent.pretty_title %></p> | |||
|
18 | <% end %> | |||
|
19 | ||||
16 | <p><label><%= l(:field_comments) %></label><%= f.text_field :comments, :size => 120 %></p> |
|
20 | <p><label><%= l(:field_comments) %></label><%= f.text_field :comments, :size => 120 %></p> | |
17 | <p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p> |
|
21 | <p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p> | |
18 | </div> |
|
22 | </div> |
@@ -81,11 +81,6 class WikiControllerTest < ActionController::TestCase | |||||
81 | assert_tag :tag => 'div', :attributes => {:id => 'sidebar'}, |
|
81 | assert_tag :tag => 'div', :attributes => {:id => 'sidebar'}, | |
82 | :content => /Side bar content for test_show_with_sidebar/ |
|
82 | :content => /Side bar content for test_show_with_sidebar/ | |
83 | end |
|
83 | end | |
84 |
|
||||
85 | def test_show_unexistent_page_without_edit_right |
|
|||
86 | get :show, :project_id => 1, :id => 'Unexistent page' |
|
|||
87 | assert_response 404 |
|
|||
88 | end |
|
|||
89 |
|
84 | |||
90 | def test_show_should_display_section_edit_links |
|
85 | def test_show_should_display_section_edit_links | |
91 | @request.session[:user_id] = 2 |
|
86 | @request.session[:user_id] = 2 | |
@@ -119,11 +114,25 class WikiControllerTest < ActionController::TestCase | |||||
119 | } |
|
114 | } | |
120 | end |
|
115 | end | |
121 |
|
116 | |||
|
117 | def test_show_unexistent_page_without_edit_right | |||
|
118 | get :show, :project_id => 1, :id => 'Unexistent page' | |||
|
119 | assert_response 404 | |||
|
120 | end | |||
|
121 | ||||
122 | def test_show_unexistent_page_with_edit_right |
|
122 | def test_show_unexistent_page_with_edit_right | |
123 | @request.session[:user_id] = 2 |
|
123 | @request.session[:user_id] = 2 | |
124 | get :show, :project_id => 1, :id => 'Unexistent page' |
|
124 | get :show, :project_id => 1, :id => 'Unexistent page' | |
125 | assert_response :success |
|
125 | assert_response :success | |
126 | assert_template 'edit' |
|
126 | assert_template 'edit' | |
|
127 | assert_no_tag 'input', :attributes => {:name => 'page[parent_id]'} | |||
|
128 | end | |||
|
129 | ||||
|
130 | def test_show_unexistent_page_with_parent | |||
|
131 | @request.session[:user_id] = 2 | |||
|
132 | get :show, :project_id => 1, :id => 'Unexistent page', :parent => 'Another_page' | |||
|
133 | assert_response :success | |||
|
134 | assert_template 'edit' | |||
|
135 | assert_tag 'input', :attributes => {:name => 'page[parent_id]', :value => '2'} | |||
127 | end |
|
136 | end | |
128 |
|
137 | |||
129 | def test_show_should_not_show_history_without_permission |
|
138 | def test_show_should_not_show_history_without_permission | |
@@ -135,15 +144,20 class WikiControllerTest < ActionController::TestCase | |||||
135 |
|
144 | |||
136 | def test_create_page |
|
145 | def test_create_page | |
137 | @request.session[:user_id] = 2 |
|
146 | @request.session[:user_id] = 2 | |
138 | put :update, :project_id => 1, |
|
147 | assert_difference 'WikiPage.count' do | |
139 | :id => 'New page', |
|
148 | assert_difference 'WikiContent.count' do | |
140 | :content => {:comments => 'Created the page', |
|
149 | put :update, :project_id => 1, | |
141 |
|
|
150 | :id => 'New page', | |
142 | :version => 0} |
|
151 | :content => {:comments => 'Created the page', | |
|
152 | :text => "h1. New page\n\nThis is a new page", | |||
|
153 | :version => 0} | |||
|
154 | end | |||
|
155 | end | |||
143 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page' |
|
156 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page' | |
144 | page = Project.find(1).wiki.find_page('New page') |
|
157 | page = Project.find(1).wiki.find_page('New page') | |
145 | assert !page.new_record? |
|
158 | assert !page.new_record? | |
146 | assert_not_nil page.content |
|
159 | assert_not_nil page.content | |
|
160 | assert_nil page.parent | |||
147 | assert_equal 'Created the page', page.content.comments |
|
161 | assert_equal 'Created the page', page.content.comments | |
148 | end |
|
162 | end | |
149 |
|
163 | |||
@@ -164,6 +178,17 class WikiControllerTest < ActionController::TestCase | |||||
164 | assert_equal 'testfile.txt', page.attachments.first.filename |
|
178 | assert_equal 'testfile.txt', page.attachments.first.filename | |
165 | end |
|
179 | end | |
166 |
|
180 | |||
|
181 | def test_create_page_with_parent | |||
|
182 | @request.session[:user_id] = 2 | |||
|
183 | assert_difference 'WikiPage.count' do | |||
|
184 | put :update, :project_id => 1, :id => 'New page', | |||
|
185 | :content => {:text => "h1. New page\n\nThis is a new page", :version => 0}, | |||
|
186 | :page => {:parent_id => 2} | |||
|
187 | end | |||
|
188 | page = Project.find(1).wiki.find_page('New page') | |||
|
189 | assert_equal WikiPage.find(2), page.parent | |||
|
190 | end | |||
|
191 | ||||
167 | def test_edit_page |
|
192 | def test_edit_page | |
168 | @request.session[:user_id] = 2 |
|
193 | @request.session[:user_id] = 2 | |
169 | get :edit, :project_id => 'ecookbook', :id => 'Another_page' |
|
194 | get :edit, :project_id => 'ecookbook', :id => 'Another_page' |
@@ -502,10 +502,10 RAW | |||||
502 | '[[Another page#anchor]]' => '<a href="#anchor" class="wiki-page">Another page</a>', |
|
502 | '[[Another page#anchor]]' => '<a href="#anchor" class="wiki-page">Another page</a>', | |
503 | '[[Another page#anchor|Page]]' => '<a href="#anchor" class="wiki-page">Page</a>', |
|
503 | '[[Another page#anchor|Page]]' => '<a href="#anchor" class="wiki-page">Page</a>', | |
504 | # page that doesn't exist |
|
504 | # page that doesn't exist | |
505 | '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>', |
|
505 | '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page" class="wiki-page new">Unknown page</a>', | |
506 | '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>', |
|
506 | '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page" class="wiki-page new">404</a>', | |
507 | '[[Unknown page#anchor]]' => '<a href="/projects/ecookbook/wiki/Unknown_page#anchor" class="wiki-page new">Unknown page</a>', |
|
507 | '[[Unknown page#anchor]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor" class="wiki-page new">Unknown page</a>', | |
508 | '[[Unknown page#anchor|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page#anchor" class="wiki-page new">404</a>', |
|
508 | '[[Unknown page#anchor|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor" class="wiki-page new">404</a>', | |
509 | } |
|
509 | } | |
510 |
|
510 | |||
511 | @project = Project.find(1) |
|
511 | @project = Project.find(1) |
General Comments 0
You need to be logged in to leave comments.
Login now