ruby on rails - How to write proper rspec test for controller -
i have controller called application controller next method want write test for:
def require_admin p current_user.role return if current_user && current_user.role == 'admin' flash[:error] = "you not admin" redirect_to root_path end
how write proper test it, , kind of test should be?
you shouldn't test implementation. try testing 'how should controller action behave non-admin user', might this:
context 'user not admin' before user.role = 'not_admin' :some_action end 'is redirected root_path' expect(response).to redirect_to('/') end ... end
Comments
Post a Comment