I had time to figure out how to log in and out using the response objects from Rails. Standard blogs were fine, but I finally diagnosed it and I wanted to write it here.
app.get '/' assert_response :success app.get '/auth_only_url' assert_response 302 user = User.find(:user_to_login) app.post '/signin_url', :user_email => user.email, :user_password => '<password in clear>' assert_response 302 app.follow_redirect! assert_response :success app.get '/auth_only_url' assert_response :success
Note. From the above it follows that you redirect after an unsuccessful auth request, and also redirect it after logging in.
To ensure that you load fixtures into the DB test environment (which usually occurs during the rake test), make sure that you do the following:
rake db:fixtures:load RAILS_ENV=test
(From Patrick Ritchie) The default URL will look like "www.example.com" since this host is set to ActionController :: Integration :: Session by default
ActionController::Integration::Session.new.host=> "www.example.com"
It is installed in actionpack / lib / action_controller / integration.rb # 75
To change it in the integration test, do the following:
session = open_session do |s| s.host = 'my-example-host.com' end
ruby ruby-on-rails
aronchick
source share