From 65097e7d11fc11b3fa9e810e64d8bccddd61d589 Mon Sep 17 00:00:00 2001 From: Tim Felgentreff Date: Fri, 5 Nov 2010 11:46:03 +0100 Subject: [PATCH] fixing tests --- app/controllers/wiki_controller.rb | 38 +++------------------ app/views/wiki/edit.rhtml | 2 +- test/functional/journals_controller_test.rb | 7 ---- test/functional/wiki_controller_test.rb | 3 +- 4 files changed, 6 insertions(+), 44 deletions(-) diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 0803ba99..6189762a 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -90,40 +90,9 @@ class WikiController < ApplicationController @content.text = initial_page_content(@page) if @content.text.blank? # don't keep previous comment @content.comments = nil - if request.get? - # To prevent StaleObjectError exception when reverting to a previous version - @content.lock_version = @page.content.lock_version - else - if !@page.new_record? && @content.text == params[:content][:text] - attachments = Attachment.attach_files(@page, params[:attachments]) - render_attachment_warning_if_needed(@page) - # don't save if text wasn't changed - redirect_to :action => 'index', :project_id => @project, :page => @page.title - return - end - #@content.text = params[:content][:text] - #@content.comments = params[:content][:comments] - @content.init_journal(User.current, params[:content][:comments]) - @content.attributes = params[:content] - @content.author = User.current - # if page is new @page.save will also save content, but not if page isn't a new record - if (@page.new_record? ? @page.save : @content.save) - attachments = Attachment.attach_files(@page, params[:attachments]) - render_attachment_warning_if_needed(@page) - call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page}) - redirect_to :action => 'index', :project_id => @project, :page => @page.title - end - end - @content.attributes = params[:content] - @content.author = User.current - # if page is new @page.save will also save content, but not if page isn't a new record - if (@page.new_record? ? @page.save : @content.save) - attachments = Attachment.attach_files(@page, params[:attachments]) - render_attachment_warning_if_needed(@page) - call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page}) - redirect_to :action => 'show', :project_id => @project, :page => @page.title - end - + # To prevent StaleObjectError exception when reverting to a previous version + @content.lock_version = @page.content.lock_version + rescue ActiveRecord::StaleObjectError # Optimistic locking exception flash[:error] = l(:notice_locking_conflict) @@ -148,6 +117,7 @@ class WikiController < ApplicationController redirect_to :action => 'show', :project_id => @project, :id => @page.title return end + params[:content].delete(:version) # The version count is automatically increased @content.attributes = params[:content] @content.author = User.current # if page is new @page.save will also save content, but not if page isn't a new record diff --git a/app/views/wiki/edit.rhtml b/app/views/wiki/edit.rhtml index 2615075e..7c794b4e 100644 --- a/app/views/wiki/edit.rhtml +++ b/app/views/wiki/edit.rhtml @@ -1,7 +1,7 @@

<%=h @page.pretty_title %>

<% form_for :content, @content, :url => {:action => 'update', :id => @page.title}, :html => {:method => :put, :multipart => true, :id => 'wiki_form'} do |f| %> -<%= f.hidden_field :version %> +<%= f.hidden_field :lock_version %> <%= error_messages_for 'content' %>

<%= f.text_area :text, :cols => 100, :rows => 25, :class => 'wiki-edit', :accesskey => accesskey(:edit) %>

diff --git a/test/functional/journals_controller_test.rb b/test/functional/journals_controller_test.rb index c373148b..d279d7e3 100644 --- a/test/functional/journals_controller_test.rb +++ b/test/functional/journals_controller_test.rb @@ -30,13 +30,6 @@ class JournalsControllerTest < ActionController::TestCase @response = ActionController::TestResponse.new User.current = nil end - - def test_index - get :index, :project_id => 1 - assert_response :success - assert_not_nil assigns(:journals) - assert_equal 'application/atom+xml', @response.content_type - end def test_get_edit @request.session[:user_id] = 1 diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index 9990a57f..0997e098 100644 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -83,8 +83,7 @@ class WikiControllerTest < ActionController::TestCase put :update, :project_id => 1, :id => 'New page', :content => {:comments => 'Created the page', - :text => "h1. New page\n\nThis is a new page", - :version => 0} + :text => "h1. New page\n\nThis is a new page" } assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page' page = Project.find(1).wiki.find_page('New page') assert !page.new_record?