Home SessionsControllerTest#test_should_get_create fails
Reply: 0

SessionsControllerTest#test_should_get_create fails

user2788 Published in March 24, 2018, 2:17 am

I'm writing a unit test for a sso session in an application we modified from another campus. The original application was written using rails 4.1.6.

My unit test is:

require 'test_helper'

class SessionsControllerTest < ActionController::TestCase

  def setup
    OmniAuth.config.mock_auth[:shibboleth] = OmniAuth::AuthHash.new({
      :provider => 'shibboleth',
      :uid => '012345678',
      :info => {
        :name => 'Joe User'
      :credentials => {
        :token => 'my_token'
    request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:shibboleth]

  test "should get create" do
    get :create
    assert_redirected_to root_path


I have tried the following without success (different error):

get :create, :provider => 'shibboleth'

My controller is:

class SessionsController < ApplicationController

  def create
    user = User.from_omniauth(env["omniauth.auth"])

    # Confirm user exists in Alma
    if valid_alma_user?(user.uid)
      session[:user_id] = user.id
      redirect_to root_path
      flash.now[:alert] = "Your user doesn't exist in Alma. (#{user.uid})"
      render :error    


My routes file is:

Rails.application.routes.draw do

  root 'home#index'

  # Authentication routes
  get 'auth/:provider/callback', to: 'sessions#create'
  get 'auth/failure', to: redirect('/')
  get 'signout', to: 'sessions#destroy', as: 'signout'


I'm expecting an assertion that the user is redirected to the root path.

Instead, I'm getting the following.

$ bin/rake test test/controllers/sessions_controller_test.rb
Run options: --seed 27055

# Running:

DEPRECATION WARNING: You did not specify a value for the configuration option `active_support.test_order`. In Rails 5, the default value of this option will change from `:sorted` to `:random`.
To disable this warning and keep the current behavior, you can add the following line to your `config/environments/test.rb`:

  Rails.application.configure do
    config.active_support.test_order = :sorted

Alternatively, you can opt into the future behavior by setting this option to `:random`. (called from <main> at -e:1)

Finished in 0.229031s, 8.7324 runs/s, 13.0987 assertions/s.

  1) Error:
ActionController::UrlGenerationError: No route matches {:action=>"create", :controller=>"sessions"}
    test/controllers/sessions_controller_test.rb:20:in `block in <class:SessionsControllerTest>'

2 runs, 3 assertions, 0 failures, 1 errors, 0 skips
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.302804 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO