Created
December 9, 2010 15:32
-
-
Save markoa/734838 to your computer and use it in GitHub Desktop.
Mislav's method to log in without messing with the form in Cucumber
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Eg Given I am logged in as @mislav | |
| # | |
| Given /^I am logged in as @(\w+)$/ do |username| | |
| visit "/login/#{username}" | |
| @current_user = User.find_by_login(username) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if Rails.env.cucumber? | |
| map.login_backdoor '/login/:username', | |
| :controller => 'sessions', :action => 'backdoor' | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SessionsController < ApplicationController | |
| # for cucumber testing only | |
| def backdoor | |
| logout_killing_session! | |
| self.current_user = User.find_by_login!(params[:username]) | |
| head :ok | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment