Created
November 5, 2013 17:57
-
-
Save jwo/7323240 to your computer and use it in GitHub Desktop.
Devise testing controllers - minitest / rails4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SecretController < ApplicationController | |
before_filter :authenticate_user! | |
def show | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test_helper' | |
class SecretControllerTest < ActionController::TestCase | |
include Devise::TestHelpers | |
test "logged in should get show" do | |
sign_in users(:one) | |
get :show | |
assert_response :success | |
end | |
test "not authenticated should get redirect" do | |
get :show | |
assert_response :redirect | |
end | |
end |
Hi, @seemantasaha, please check this out.
- include
Devise::Test::ControllerHelpers
on its parentActionController::TestCase
superclass. - include
Devise::Test::IntegrationHelpers
on its parentActionDispatch::IntegrationTest
superclass.
Maybe the root cause is that ControllerTest
inherits from IntegrationTest
:
class SecretControllerTest < ActionDispatch::IntegrationTest
include Devise::Test::ControllerHelpers
So make sure what class you inherit from, FYI.
I did the same but a user is not signing in.
For logged in user also I am getting 302:
Expected response to be a , but was <302>
Found the error. I was not signing in as admin.
Can you describe here for the reference how it works with signing in as admin
Thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I did the same but I am getting the following error:
NoMethodError: undefined method `env' for nil:NilClass