From bca84f9a577963d99c99e735690905c5afb744b3 Mon Sep 17 00:00:00 2001 From: Matthew Horan Date: Tue, 18 Dec 2012 22:46:24 -0500 Subject: [PATCH] Don't start queued commands more than once TimeoutCommand may receive pageFinished multiple times before PageLoadingCommand has finished. --- spec/integration/session_spec.rb | 46 ++++++++++++++++++++++++++++++++ src/TimeoutCommand.cpp | 3 +-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/spec/integration/session_spec.rb b/spec/integration/session_spec.rb index 37fa4da..05451dd 100644 --- a/spec/integration/session_spec.rb +++ b/spec/integration/session_spec.rb @@ -182,4 +182,50 @@ describe Capybara::Session do end end end + + context "session app" do + before do + @app = Class.new(ExampleApp) do + enable :sessions + get '/' do + <<-HTML + + +
+ + + +
+ + + HTML + end + + post '/sign_in' do + session[:username] = params[:username] + session[:password] = params[:password] + redirect '/' + end + + get '/other' do + <<-HTML + + +

Welcome, #{session[:username]}.

+ + + HTML + end + end + end + + it "should not start queued commands more than once" do + subject.visit('/') + subject.fill_in('username', with: 'admin') + subject.fill_in('password', with: 'temp4now') + subject.click_button('Submit') + subject.visit('/other') + subject.should have_content('admin') + end + end end diff --git a/src/TimeoutCommand.cpp b/src/TimeoutCommand.cpp index a7ba6f8..3d0fe81 100644 --- a/src/TimeoutCommand.cpp +++ b/src/TimeoutCommand.cpp @@ -39,12 +39,12 @@ void TimeoutCommand::startTimeout() { } void TimeoutCommand::pendingLoadFinished(bool success) { + disconnect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool))); if (success) { startCommand(); } else { disconnect(m_timer, SIGNAL(timeout()), this, SLOT(commandTimeout())); disconnect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand())); - disconnect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool))); emitFinished(false, m_manager->currentPage()->failureString()); } } @@ -64,7 +64,6 @@ void TimeoutCommand::commandTimeout() { void TimeoutCommand::commandFinished(Response *response) { disconnect(m_timer, SIGNAL(timeout()), this, SLOT(commandTimeout())); disconnect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand())); - disconnect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool))); emit finished(response); }