{"id":836,"date":"2022-08-30T15:07:59","date_gmt":"2022-08-30T15:07:59","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/functional-testing-with-warden-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:07:59","modified_gmt":"2022-08-30T15:07:59","slug":"functional-testing-with-warden-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/functional-testing-with-warden-collection-of-common-programming-errors\/","title":{"rendered":"Functional testing with Warden?-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m trying to do functional testing and need to login with Warden.<\/p>\n<p>I have done:<\/p>\n<pre><code>class ActionController::TestCase\n    include Warden::Test::Helpers\nend\n<\/code><\/pre>\n<p>My test case is simple:<\/p>\n<pre><code>def test_access_admin_as_superuser\n  login_as(Person.make(:superuser))\n  get :index\n  assert_response :success\n  assert_nil flash[:warning]\nend\n<\/code><\/pre>\n<p>I do a <code>login_as(user)<\/code> and it seems to work except when I do a <code>get '\/admin'<\/code> it will fail with:<\/p>\n<pre><code>1) Error:\ntest_access_admin_as_superuser(AdminControllerTest):\n NoMethodError: undefined method `user' for nil:NilClass\n\/home\/silas\/.rubygems\/gems\/gems\/rails_warden-0.5.2\/lib\/rails_warden\/controller_mixin.rb:21:in `current_user'\napp\/controllers\/application_controller.rb:100:in `require_user'\ntest\/functional\/admin_controller_test.rb:20:in `test_access_admin_as_superuser'\n<\/code><\/pre>\n<p>any ideas?<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 22:48:17. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;m trying to do functional testing and need to login with Warden. I have done: 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 do a get &#8216;\/admin&#8217; it will fail with: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-836","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/836","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=836"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/836\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=836"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=836"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=836"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}