Я тестирую этот контроллер:
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
с этим приспособлением (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
и этот функциональный тест:
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
Однако я получаю эту ошибку:
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
логика входа работает, но мои тесты не пройдены, мой путь к story_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"}
Чего мне не хватать?
РЕДАКТИРОВАТЬ : Это структура моей таблицы пользователей (она использует простой текстовый пароль только для примеров книг)
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
)