I'm writing integration tests for my app, and am trying to sign in the user using Capybara. When I create a User
object in the test itself and enter that user's details, it passes and the user is logged in.
But when I try signing in using a fixture's details, the user never gets logged in. As can be seen in test.log, a 401 error is being returned:
Started POST "/users/sign_in" for 127.0.0.1 at 2015-10-14 18:54:21 +0000
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "user"=>{"email"=>"user@company.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Log in"}
Completed 401 Unauthorized in 1ms (ActiveRecord: 0.0ms)
Processing by Devise::SessionsController#new as HTML
Below are some other relevant files. The first two are the same test; the first version being the test that successfully logs the user in, and the second being the one that doesn't.
(Successfully logs in) project_flows_test.rb
require 'test_helper'
class ProjectFlowsTest < ActionDispatch::IntegrationTest
test "fixtures debugging" do
@user = User.create(email: "user@company.com", password: "useruser123")
visit new_user_session_path
fill_in "Email", with: @user.email
fill_in "Password", with: @user.password
click_button "Log in"
end
end
(Doesn't log in and returns 401) project_flows_test.rb
require 'test_helper'
class ProjectFlowsTest < ActionDispatch::IntegrationTest
test "fixtures debugging" do
visit new_user_session_path
fill_in "Email", with: users(:standard_user).email
fill_in "Password", with: users(:standard_user).password
click_button "Log in"
end
end