set_session_for does not update current user in a loop #1

Closed
swards opened this Issue Apr 19, 2009 · 5 comments

Projects

None yet

1 participant

swards commented Apr 19, 2009

This tests the response_code for each user to a page, the session[:user_credentials_id] will change when using the helper ‘set_session_for’ in a loop, but the ‘current user’ does not change. The response body, does not change.

This is the smallest test I could create.

```
test ‘All users hit home page’ do
for user in User.all
set_session_for(user)
get :home
assert_response :success
assert_tag :tag => ‘span’, :attributes => {:id => "name"}, :content => user.display_name
end
end
```

I have a span on the page that holds the users first name. This test will succeed the first time and fail on the second time through the loop. In the test output, the value in the tag is the name of the user that was set to the session the first time through the loop.

I would expect to be able to change the user in a functional test.

@ghost
ghost commented Apr 19, 2009

Right because the current user is returning the value if its set. Also, set_session_for is not available anymore. You should be doing setup :activate_authlogic then UserSession.create(user)

swards commented Apr 19, 2009

Will this allow me to change the user mid test? I’m currently using 1.4.1.

I appreciate the quick response!

@ghost
ghost commented Apr 19, 2009

I don’t see why not. YOu might try playing around with the current_user method and removing the first line in that method.

swards commented Apr 19, 2009

I upgraded to the latest gem. It doesn’t appear to change the result. I will look into modifying the current_user method.

swards commented Apr 19, 2009

I tried deleting the @current_user, @current_user_session. I tried to destroy the session object. I can’t set another user with UserSession.create. Do you have other suggestions?

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment