Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7777107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:03:16+00:00 2026-06-01T18:03:16+00:00

Sorcery authentication gem: https://github.com/NoamB/sorcery Sorcery’s creator provides an example Rails app with Sorcery test

  • 0

Sorcery authentication gem: https://github.com/NoamB/sorcery

Sorcery’s creator provides an example Rails app with Sorcery test helpers included in its Test::Unit functional tests: https://github.com/NoamB/sorcery-example-app/blob/master/test/functional/users_controller_test.rb

# Test::Unit functional test example
require 'test_helper'

class UsersControllerTest < ActionController::TestCase
  setup do
    @user = users(:noam)
  end

  test "should show user" do
    login_user
    get :show, :id => @user.to_param
    assert_response :success
  end

But I can’t figure out how to get login_user to work in my RSpec controller specs.

/gems/sorcery-0.7.5/lib/sorcery/test_helpers/rails.rb:7:in `login_user': 
undefined method `auto_login' for nil:NilClass (NoMethodError)

Here’s the relevant code in the Sorcery gem regarding the above error:
https://github.com/NoamB/sorcery/blob/master/lib/sorcery/test_helpers/rails.rb

module Sorcery
  module TestHelpers
    module Rails
      # logins a user and calls all callbacks
      def login_user(user = nil)
        user ||= @user
        @controller.send(:auto_login,user)
        @controller.send(:after_login!,user,[user.send(user.sorcery_config.username_attribute_names.first),'secret'])
      end

      def logout_user
        @controller.send(:logout)
      end
    end
  end
end

UPDATE:

As per Sorcery’s documentation “Testing in Rails 3“, I have indeed added include Sorcery::TestHelpers::Rails to my spec_helper.rb.

The Sorcery test helper login_user acts on @controller, but I’m getting the error because @controller is nil in my controller spec. Here’s my spec:

#spec/controllers/forums_controller_spec.rb
require 'spec_helper'

describe ForumsController do
  render_views

  describe 'GET new' do
    describe 'when guest' do
      it 'should deny and redirect' do
        get :new
        response.should redirect_to(root_path)
      end
    end

    describe 'when admin' do
      p @controller #=> nil
      @user = User.create!(username: "Test", password: "secret", email: "test@test.com")
      login_user # <--------------- where the error occurs
      it 'should resolve' do
        get :new
        response.should render_template(:new)
      end
    end
  end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:03:18+00:00Added an answer on June 1, 2026 at 6:03 pm

    FWIW, I spent a lot of time looking for an answer to this problem. I am using Capybara and RSpec. As it turns out, you need to login manually to using Sorcery to get the login to work.

    I’ve created a Gist on creating integration tests with Sorcery/Rspec/Capybara here:
    https://gist.github.com/2359120/9989c14af19a48ba726240d030c414b882b96a8a

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I using sorcery for email activation and I've followed their wiki tutorial: https://github.com/NoamB/sorcery/wiki/User-Activation .
I'm trying to install the Rails Admin Gem using Sorcery for authentication instead of
i am using the Sorcery gem for authentication. I've actually used it an another
Are there any robust authentication libraries for node.js as for rails (devise, sorcery), that
I'd like to integrate the sorcery-gem to achieve authentication while checking out in an
I'm using the Sorcery gem and their external module to authenticate with Twitter. I've
I added the twitter-bootstrap-rails gem and did bundle install. Then I went to do:
I'm using Sorcery for Authentication, and I need to setup third party authentication in
Hello I'm actually using Ryan' Bates cancan gem authorization to make my application's users
I'm attempting to send an HTTP POST to a Rails 3 Application. Currently all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.