From 75f2afc2e173e43e2a9469789f989deba5814a94 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Fri, 27 Jan 2012 12:09:34 +0100 Subject: [PATCH] migrate logging_in --- features/logging_in.feature | 6 +++--- features/step_definitions/login_steps.rb | 16 +++++----------- .../step_definitions/page_navigation_steps.rb | 3 --- features/support/env.rb | 15 ++++++++------- 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/features/logging_in.feature b/features/logging_in.feature index 10874105..2f2e86e3 100644 --- a/features/logging_in.feature +++ b/features/logging_in.feature @@ -50,10 +50,10 @@ Feature: Existing user logging in | "top secret" project for user "testuser" | "top secret" project for user "testuser" | Logout (Test User) | | context page for "@secret location" for user "testuser" | context page for "@secret location" for user "testuser" | Logout (Test User) | - @selenium + @javascript Scenario: When session expires, you should be logged out When I go to the login page - And I submit the login form as user "testuser" with password "secret" - Then I should be on the login page + And I submit the login form as user "testuser" with password "secret" + Then I should be on the home page When my session expires Then I should be on the login page \ No newline at end of file diff --git a/features/step_definitions/login_steps.rb b/features/step_definitions/login_steps.rb index 1fc0d3ec..7766e181 100644 --- a/features/step_definitions/login_steps.rb +++ b/features/step_definitions/login_steps.rb @@ -3,10 +3,8 @@ Given /^I have logged in as "(.*)" with password "(.*)"$/ do |username, password fill_in "Login", :with => username fill_in "Password", :with => password uncheck "Stay logged in:" - click_button - if response.respond_to? :selenium - selenium.wait_for_page_to_load(5000) - end + click_button "Sign in »" + logout_regexp = @mobile_interface ? "Logout" : "Logout \(#{username}\)" response.should contain(logout_regexp) @current_user = User.find_by_login(username) @@ -16,21 +14,17 @@ When /^I submit the login form as user "([^\"]*)" with password "([^\"]*)"$/ do fill_in 'Login', :with => username fill_in 'Password', :with => password uncheck "Stay logged in:" - click_button + click_button "Sign in »" end When /^my session expires$/ do - selenium.wait_for_page_to_load(5000) - # use expire_session to force expiry of session js = '$.ajax({type: "GET", url: "/login/expire_session", dataType: "script", async: false});' - selenium.run_script(js); + page.execute_script(js); # force check of expiry bypassing timeout js = '$.ajax({type: "GET", url: "/login/check_expiry", dataType: "script", async: false});' - selenium.run_script(js); - - sleep(2) + page.execute_script(js); end When /^I log out of Tracks$/ do diff --git a/features/step_definitions/page_navigation_steps.rb b/features/step_definitions/page_navigation_steps.rb index c767c190..390c39fb 100644 --- a/features/step_definitions/page_navigation_steps.rb +++ b/features/step_definitions/page_navigation_steps.rb @@ -1,6 +1,3 @@ Then /^I should be redirected to (.+?)$/ do |page_name| - request.headers['HTTP_REFERER'].should_not be_nil - request.headers['HTTP_REFERER'].should_not == request.request_uri - Then "I should be on #{page_name}" end \ No newline at end of file diff --git a/features/support/env.rb b/features/support/env.rb index 2b87c0ad..d8d53ec8 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,6 +1,6 @@ # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. -# It is recommended to regenerate this file in the future when you upgrade to a -# newer version of cucumber-rails. Consider adding your own code to a new file +# It is recommended to regenerate this file in the future when you upgrade to a +# newer version of cucumber-rails. Consider adding your own code to a new file # instead of editing this one. Cucumber will automatically load all features/**/*.rb # files. @@ -16,14 +16,15 @@ require 'cucumber/web/tableish' require 'capybara/rails' require 'capybara/cucumber' require 'capybara/session' -require 'cucumber/rails/capybara_javascript_emulation' # Lets you click links with onclick javascript handlers without using @culerity or @javascript +# BUG in this version of cucumber/capybara: require 'cucumber/rails/capybara_javascript_emulation' # Lets you click links with onclick javascript handlers without using @culerity or @javascript + # Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In # order to ease the transition to Capybara we set the default here. If you'd # prefer to use XPath just remove this line and adjust any selectors in your # steps to use the XPath syntax. Capybara.default_selector = :css -# If you set this to false, any error raised from within your app will bubble +# If you set this to false, any error raised from within your app will bubble # up to your step definition and out to cucumber unless you catch it somewhere # on the way. You can make Rails rescue errors and render error pages on a # per-scenario basis by tagging a scenario or feature with the @allow-rescue tag. @@ -35,15 +36,15 @@ Capybara.default_selector = :css ActionController::Base.allow_rescue = false # If you set this to true, each scenario will run in a database transaction. -# You can still turn off transactions on a per-scenario basis, simply tagging +# You can still turn off transactions on a per-scenario basis, simply tagging # a feature or scenario with the @no-txn tag. If you are using Capybara, # tagging with @culerity or @javascript will also turn transactions off. # # If you set this to false, transactions will be off for all scenarios, # regardless of whether you use @no-txn or not. # -# Beware that turning transactions off will leave data in your database -# after each scenario, which can lead to hard-to-debug failures in +# Beware that turning transactions off will leave data in your database +# after each scenario, which can lead to hard-to-debug failures in # subsequent scenarios. If you do this, we recommend you create a Before # block that will explicitly put your database in a known state. Cucumber::Rails::World.use_transactional_fixtures = true