Ruby on Rails
Sunday, June 21, 2015
I have an app with admin users created with the devise gem.
I have succeeded in redirecting anyone who tries to access an admin profile page but is NOT logged in as an admin to the root_path (http://localhost:3000).
However, I'm having difficulty getting the tests to pass in my integration test. (I'm using Capybara and minitest.)
In the admins controller, the first line under "def index" is:
redirect_to(root_path) unless admin_signed_in?
In the integration test, I start with the following code:
test_prepare # From test/test_helper.rb
@u1 = users(:connery) # From test/fixtures/users.yml
@a1 = admins(:vivian_kensington) # From test/fixtures/admin.yml
visit new_user_session_path
fill_in('Email', with: 'sean_connery@example.com')
fill_in('Password', with: 'original')
uncheck('Remember me')
click_button('Log in')
visit admin_path(@a1)
How do I test for the redirect? The path parameter at this point is nil and NOT root_path or '/'.
-- I have succeeded in redirecting anyone who tries to access an admin profile page but is NOT logged in as an admin to the root_path (http://localhost:3000).
However, I'm having difficulty getting the tests to pass in my integration test. (I'm using Capybara and minitest.)
In the admins controller, the first line under "def index" is:
redirect_to(root_path) unless admin_signed_in?
In the integration test, I start with the following code:
test_prepare # From test/test_helper.rb
@u1 = users(:connery) # From test/fixtures/users.yml
@a1 = admins(:vivian_kensington) # From test/fixtures/admin.yml
visit new_user_session_path
fill_in('Email', with: 'sean_connery@example.com')
fill_in('Password', with: 'original')
uncheck('Remember me')
click_button('Log in')
visit admin_path(@a1)
How do I test for the redirect? The path parameter at this point is nil and NOT root_path or '/'.
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/040a3c5b-7719-4642-bd37-d95132f22317%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment