Unsuccessful save unlocks the page; some tweaks and debug-level logging in in return_to_last_remembered

This commit is contained in:
Alexey Verkhovsky 2005-01-18 00:36:43 +00:00
parent 94292199b2
commit 7c02805102
3 changed files with 15 additions and 8 deletions

View file

@ -28,12 +28,15 @@ class ApplicationController < ActionController::Base
$instiki_wiki_service
end
@@REMEMBER_NOT = []
@@REMEMBER_NOT = ['locked', 'save']
def remember_location
logger.debug @request.method
if @response.headers['Status'] == '200 OK'
@session[:return_to] = url_for unless @@REMEMBER_NOT.include? action_name
@session[:already_tried_index_as_fallback] = false
unless @@REMEMBER_NOT.include? action_name or @request.method != :get
@session[:return_to] = url_for
logger.debug("Session ##{session.object_id}: remembered URL '#{@session[:return_to]}'")
end
end
end
@ -42,10 +45,11 @@ class ApplicationController < ActionController::Base
redirect_target, @session[:return_to] = @session[:return_to], nil
# then try to redirect to it
if redirect_target.nil?
raise 'Cannot redirect to index' if @session[:already_tried_index_as_fallback]
@session[:already_tried_index_as_fallback] = true
logger.debug("Session ##{session.object_id}: no remembered redirect location, trying /")
redirect_to_url '/'
else
logger.debug("Session ##{session.object_id}: " +
"redirect to the last remembered URL #{redirect_target}")
redirect_to_url(redirect_target)
end
end

View file

@ -216,20 +216,22 @@ class WikiController < ApplicationController
cookies['author'] = @params['author']
begin
page = @web.pages[@page_name]
if @web.pages[@page_name]
page = wiki.revise_page(
wiki.revise_page(
@web_name, @page_name, @params['content'], Time.now,
Author.new(@params['author'], remote_ip)
)
page.unlock
else
page = wiki.write_page(
wiki.write_page(
@web_name, @page_name, @params['content'], Time.now,
Author.new(@params['author'], remote_ip)
)
end
redirect_show(@page_name)
rescue Instiki::ValidationError => e
page.unlock if defined? page
flash[:error] = e
return_to_last_remembered
end

View file

@ -542,6 +542,7 @@ class WikiControllerTest < Test::Unit::TestCase
def test_save_new_revision_identical_to_last
revisions_before = @home.revisions.size
@home.lock(Time.now, 'AnAuthor')
r = process 'save', {'web' => 'wiki1', 'id' => 'HomePage',
'content' => @home.revisions.last.content.dup,
@ -553,7 +554,7 @@ class WikiControllerTest < Test::Unit::TestCase
revisions_after = @home.revisions.size
assert_equal revisions_before, revisions_after
assert !@home.locked?(Time.now), 'HomePage should be unlocked if an edit was unsuccessful'
end