Closed janko closed 2 years ago
@janko I tested this out and I no longer get the error. It seems to be working, however, I can't seem to get a 200 success response. Only a 302 redirect. This is the only way I can get the test to pass:
before(:each) do
login(user)
end
it "should GET index" do
get :index
expect(response).to redirect_to("http://www.example.com/stores")
end
If I update the test to do a second request to:
get :index
It fails saying the response was a 302 to "http://www.example.com/stores"
So, after signing in, it doesn't seem to be holding on to the session, but I may be wrong. A few other notes, which is we are using RSpec and also we have:
login_return_to_requested_location? true
set.
That's strange. I'm not able to reproduce this in the test/controllers/test_controller_test.rb
in this PR, nor in the rodauth-demo-rails app. What Rails version are you using, and is there something more in your Rodauth configuration? What you posted shouldn't affect this, as it's not used in #login_session
.
@janko I talked to one of my colleagues and we think the issue is somewhere in our application. So, I think this is a good update. Thank you for working on this. I really appreciate it.
OK, thanks for the feedback, I will merge it shortly, and make a release tomorrow.
BTW, I ended up removing the #rodauth
method, as to me it increases coupling of controller tests to Rodauth, and I didn't find that using Rodauth simplifies anything. This is the documented way to log in now:
account = Account.create!(email: "user@example.com", password: "secret", status: "verified")
session[:account_id] = account.id
session[:authenticated_by] = ["password"]
This allows controllers calling Rodauth to be controller-tested, via
ActionController::TestCase
that's internally used by RSpec's controller specs. It ensures Rodauth instance(s) are set in request env, converts Rodauth responses into controller responses, and provides the#rodauth
method.Afterwards I would consider the possibility of adding some login/logout test helper methods, similar to what Devise has.