# display a page (in editing mode if it doesn't exist)
def show
- if @page.new_record?
+ if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project)
+ deny_access
+ return
+ end
+ @content = @page.content_for_version(params[:version])
+ if @content.nil?
if User.current.allowed_to?(:edit_wiki_pages, @project) && editable? && !api_request?
edit
render :action => 'edit'
end
return
end
- if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project)
- deny_access
- return
- end
- @content = @page.content_for_version(params[:version])
if User.current.allowed_to?(:export_wiki_pages, @project)
if params[:format] == 'pdf'
send_data(wiki_page_to_pdf(@page, @project), :type => 'application/pdf', :filename => "#{@page.title}.pdf")
def edit
return render_403 unless editable?
if @page.new_record?
- @page.content = WikiContent.new(:page => @page)
if params[:parent].present?
@page.parent = @page.wiki.find_page(params[:parent].to_s)
end
end
@content = @page.content_for_version(params[:version])
+ @content ||= WikiContent.new(:page => @page)
@content.text = initial_page_content(@page) if @content.text.blank?
# don't keep previous comment
@content.comments = nil
# To prevent StaleObjectError exception when reverting to a previous version
- @content.version = @page.content.version
+ @content.version = @page.content.version if @page.content
@text = @content.text
if params[:section].present? && Redmine::WikiFormatting.supports_section_edit?
def update
return render_403 unless editable?
was_new_page = @page.new_record?
- @page.content = WikiContent.new(:page => @page) if @page.new_record?
@page.safe_attributes = params[:wiki_page]
- @content = @page.content
+ @content = @page.content || WikiContent.new(:page => @page)
content_params = params[:content]
if content_params.nil? && params[:wiki_page].is_a?(Hash)
content_params = params[:wiki_page].slice(:text, :comments, :version)
end
@content.author = User.current
- if @page.save_with_content
+ if @page.save_with_content(@content)
attachments = Attachment.attach_files(@page, params[:attachments])
render_attachment_warning_if_needed(@page)
call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page})
assert_response 302
end
+ def test_show_page_without_content_should_display_the_edit_form
+ @request.session[:user_id] = 2
+ WikiPage.create!(:title => 'NoContent', :wiki => Project.find(1).wiki)
+
+ get :show, :project_id => 1, :id => 'NoContent'
+ assert_response :success
+ assert_template 'edit'
+ assert_select 'textarea[name=?]', 'content[text]'
+ end
+
def test_create_page
@request.session[:user_id] = 2
assert_difference 'WikiPage.count' do
assert_equal 2, c.version
end
+ def test_update_page_without_content_should_create_content
+ @request.session[:user_id] = 2
+ page = WikiPage.create!(:title => 'NoContent', :wiki => Project.find(1).wiki)
+
+ assert_no_difference 'WikiPage.count' do
+ assert_difference 'WikiContent.count' do
+ put :update, :project_id => 1, :id => 'NoContent', :content => {:text => 'Some content'}
+ assert_response 302
+ end
+ end
+ assert_equal 'Some content', page.reload.content.text
+ end
+
def test_update_section
@request.session[:user_id] = 2
page = WikiPage.find_by_title('Page_with_sections')