railsware / rack_session_access

Rack middleware that provides access to rack.session environment
MIT License
257 stars 29 forks source link

Missing callback function with devise integration #18

Closed ckornaros closed 9 years ago

ckornaros commented 9 years ago

Hi, I use your helper with devise for my test :

module FeatureHelpers def logged_as(user) page.set_rack_session('warden.user.user.key' => User.serialize_into_session(user).unshift("User")) end end

It works good but I notice that set_rack_session dosen't call the device callback function => "after_sign_in_path_for" More information here : https://github.com/plataformatec/devise/wiki/How-To%3A-Redirect-to-a-specific-page-on-successful-sign-in-and-sign-out

Do you think you can fix this ?

By the way thank you for your good work :)

ayanko commented 9 years ago

Hello.

And It shouldn't.

logged_as helper (as it name says) gives you ability to start your scenarios omitting boring authentication steps and thus speed up your scenarios a bit.

Write usual scenario if you want to test what happens with user on sign in . E.g

feature 'Login' do
  scenario 'User logs in to' do
    visit '/users/sign_in'
    fill_in :email, with: 'a@b.com'
    fill_in :password, with: 'secret'
    click_button 'Log in'
    expect(page).to have_content('After login...')
  end
end

Another tip: use rspec-example_steps for writing read-able acceptance scenarios.

.

ckornaros commented 9 years ago

Hi,

I didn't agree when you say that it shouldn't, because what happend in "after_sign_in_path_for" can change expected values that you have to check after the login.

i.e. I'm a user (not logged in) and I have a cart with items. When I'm log in, I need that devise assign the cart to me. That's possible with "after_sign_in_path_for" and it will change the expected content of the page.

Maybe you have a work around for case like this ?

ayanko commented 9 years ago

No. You are wrong. It's not an argument. Rack session access is and will be agnostic from any authentication gem. The goal is to provide read/write access to application session. Nothing more. No special magic for devise, authlogic or any gem.

The logged_as means state. It does not say how did you log in and what happens after that. You are just logged in.

If you need to check special behavior after user is signed in - write corresponding scenarios (see above). When you want to test scenarios for already logged in user use logged_as helper.

Thats all folks.

karlingen commented 9 years ago

I totally agree with you @ayanko.

@ckornaros if you want after_sign_in_path_for to be triggered then you should be using the regular method for logging in (filling in login form).

ayanko commented 9 years ago

Closed as invalid.