I’ve used the Devise gem to create users and admins. I’ve successfully made the admin index page visible ONLY to admins, but it’s failing the tests (Capybara and minitest). For some reason, executing the “visit” command kills the session. WHY? What should I be doing about this?
I think need to change some code. You need to test sections of your app
independently, so if you want to check if the view is only available for
Admins, you can login it with test methods provided by Devise and
later, visit the admins_path.
Instead of call login_admin, you can use:
login_as(user, :scope => :user)
visit admin_path
# asserts...
In another test, check if an admin can login with the form (like
login_admin). You need to set Warden to test mode including this line at
top of your integration tests:
I've used the Devise gem to create users and admins. I've successfully made the admin index page visible ONLY to admins, but it's failing the tests (Capybara and minitest). For some reason, executing the "visit" command kills the session. WHY? What should I be doing about this?
What do you mean by "kills the session". What happens? How does the test fail?
The problem is that the session is lost as soon as the “visit” command is invoked. How do I get the test to retain the session?
Also, that link you cited revolves around RSpec instead of Minitest.
Are there any good examples of someone who has successfully done what I’m trying to do? I can’t possibly be the first person to use Minitest for testing the visibility of a page for different types of users.
I get error messages that indicate that nobody is logged in. The admin should be able to view the admin index page, but the users and the general public should not be able to. Unfortunately, the test doesn’t show that the admin can view the admin index page. While this works in my development environment, it doesn’t work in the test environment.