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 3950046
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:33:57+00:00 2026-05-20T01:33:57+00:00

I am testing this controller: class SessionsController < ApplicationController def new end def create

  • 0

I am testing this controller:

class SessionsController < ApplicationController
  def new
  end

  def create
    @current_user = User.find_by_login_and_password(
      params[:login], params[:password]
    )

    if @current_user
      session[:user_id] = @current_user.id
      if session[:return_to]
        redirect_to session[:return_to]
        session[:return_to] = nil
      else
        redirect_to stories_path
      end
    else
      render :action => 'new'
    end
  end

  def destroy
    session[:user_id] = @current_user = nil
  end

end

with this fixture (users.yml):

patrick:
  login: patrick
  password: sekrit
  name: Patrick Lenz
  email: patrick@limited-overload.de

john:
  login: john
  password: gh752px
  name: John Doe
  email: john@doe.com

and this functional test:

require 'test_helper'

class SessionsControllerTest < ActionController::TestCase
  def test_should_show_login_form
    get :new
    assert_response :success
    assert_template 'new'
    assert_select 'form p', 4
  end

  def test_should_perform_user_login
    post :create, :login =>'patrick', :password => 'sekrit'
    assert_redirected_to stories_path
    assert_equal users(:patrick).id, session[:user_id]
    assert_equal users(:patrick), assigns(:current_user)
  end
end

However, I get this failure:

test_should_perform_user_login(SessionsControllerTest) [/home/ygamretuta/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-2.3.9/lib/action_controller/test_case.rb:119]:
Expected response to be a <:redirect>, but was <200>.
Expected block to return true value

the login logic is working but my tests fail, my route to the stories_path:

story_votes GET    /stories/:story_id/votes(.:format)          {:controller=>"votes", :action=>"index"}
                POST   /stories/:story_id/votes(.:format)          {:controller=>"votes", :action=>"create"}
 new_story_vote GET    /stories/:story_id/votes/new(.:format)      {:controller=>"votes", :action=>"new"}
edit_story_vote GET    /stories/:story_id/votes/:id/edit(.:format) {:controller=>"votes", :action=>"edit"}
     story_vote GET    /stories/:story_id/votes/:id(.:format)      {:controller=>"votes", :action=>"show"}
                PUT    /stories/:story_id/votes/:id(.:format)      {:controller=>"votes", :action=>"update"}
                DELETE /stories/:story_id/votes/:id(.:format)      {:controller=>"votes", :action=>"destroy"}
        stories GET    /stories(.:format)                          {:controller=>"stories", :action=>"index"}
                POST   /stories(.:format)                          {:controller=>"stories", :action=>"create"}
      new_story GET    /stories/new(.:format)                      {:controller=>"stories", :action=>"new"}
     edit_story GET    /stories/:id/edit(.:format)                 {:controller=>"stories", :action=>"edit"}
          story GET    /stories/:id(.:format)                      {:controller=>"stories", :action=>"show"}
                PUT    /stories/:id(.:format)                      {:controller=>"stories", :action=>"update"}

What could I be missing?

EDIT: This is the structure of my users table (it’s using a plain text password only for the book examples)

CREATE TABLE "users" (
 "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 
 "login" varchar(255), 
 "password" varchar(255), 
 "name" varchar(255), 
 "email" varchar(255), 
 "created_at" datetime, 
 "updated_at" datetime
)
  • 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-05-20T01:33:57+00:00Added an answer on May 20, 2026 at 1:33 am

    Ygam, I’m 99% sure that the problem is that the password doesn’t match. Are you using salted / encrypted passwords? if that’s the case, check that your fixture has plain text passwords.

    I’m quite confident that this is the case, because you’re doing a post and getting a 200, and the only path in create that returns a 200, is when the user / password pair validation fails.

    If you’re using salted passwords, you might need to do something like this in your fixture

    <% SALT = "NaCl" unless defined?(SALT) %>
    one:
      name: dave
      hashed_password: <%= User.encrypt_password('secret', SALT) %>
      salt: <%= SALT %>
    
    two:
      name: MyString
      hashed_password: MyString
      salt: MyString
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently testing this in Mozilla FireFox 3.0.5 using FireBug 1.3.0 with jQuery
I have done a bit of testing on this myself (During the server side
This question isn't about unit-testing. And it is for a desktop product. This is
I was testing on a customer's box this afternoon which has Windows Vista (He
I ran into this today when unit testing a generic dictionary. System.Collections.Generic.Dictionary<int, string> actual,
I recently stumbled across this entry in the google testing blog about guidelines for
When I commit I get this error from Subversion: bash-2.05b$ svn commit -m testing
I am stress testing a .NET web application. I did this for 2 reasons:
I was given this code a while back. I finally got around to testing
How would you define testing? In the interest of full disclosure, I'm posting this

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.