Functional testing with Warden?

I am trying to perform functional testing and must log in with Warden.

I did:

class ActionController::TestCase include Warden::Test::Helpers end 

My test case is simple:

 def test_access_admin_as_superuser login_as(Person.make(:superuser)) get :index assert_response :success assert_nil flash[:warning] end 

I do a login_as(user) and it seems to work, except when I make get '/admin' fail:

 1) Error: test_access_admin_as_superuser(AdminControllerTest): NoMethodError: undefined method `user' for nil:NilClass /home/silas/.rubygems/gems/gems/rails_warden-0.5.2/lib/rails_warden/controller_mixin.rb:21:in `current_user' app/controllers/application_controller.rb:100:in `require_user' test/functional/admin_controller_test.rb:20:in `test_access_admin_as_superuser' 

any ideas?

+4
source share
1 answer

The developer has assistants to handle this, which helps a little if you just use Warden. The reason for the break is because the action controller sets things up differently in the test environment. I have assembled a small stone that provides a module that you can enable to work with the boss with rails in test mode: github.com/ajsharp/warden-rspec-rails .

0
source

Source: https://habr.com/ru/post/1333735/


All Articles